Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/player #30

Merged
merged 4 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,206 changes: 1,111 additions & 1,095 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jquery": "^3.3.1",
"node-sass": "^4.9.0",
"postcss-cli": "^5.0.0",
"rangeslider.js": "^2.3.2",
"virtual-scroll": "^1.3.1"
}
}
5 changes: 5 additions & 0 deletions src/static/img/pause.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/static/img/play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/static/img/stop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 47 additions & 7 deletions src/static/js/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getUrlParameters() {
return $.param(urlParameters);
}

function loadData(url, callback) {
function loadData(url, callback, loadOnly = false) {
var newArray = [];

$.ajax({
Expand Down Expand Up @@ -65,8 +65,10 @@ function loadData(url, callback) {
});

if (data.length === 0) {
$('.js-active-slider').removeClass('-hide');
$('.js-error-data').removeClass('-hide');
if (loadOnly === false) {
$('.js-active-slider').removeClass('-hide');
}
} else {
$('.js-error-data').addClass('-hide');
callback(data);
Expand All @@ -75,8 +77,10 @@ function loadData(url, callback) {

} else {
if (data.length === 0) {
$('.js-active-slider').removeClass('-hide');
$('.js-error-data').removeClass('-hide');
if (loadOnly === false) {
$('.js-active-slider').removeClass('-hide');
}
} else {
$('.js-error-data').addClass('-hide');
callback(data);
Expand Down Expand Up @@ -187,7 +191,7 @@ function drawCanvas(selector, chartName) {
.classed("js-chart", true)
}

function createHexagonGroup(canvas, data) {
function createHexagonGroup(canvas, data, loadOnly = false) {
return canvas.selectAll("rect")
.data(data)
.enter()
Expand All @@ -202,8 +206,15 @@ function createHexagonGroup(canvas, data) {
var chartName = $(this).closest('.js-svg-root').data('chartName');
return `${chartName}-hexagon-${d.id}`;
})
.classed('_hidden', true)
.classed('-small', true)
// .classed('_hidden', true)
.classed('_hidden', function(d, i) {
if (loadOnly === true) {
return false;
} else {
return true;
}
});
}

function hexagonOnClick(hexagonGroup, callback) {
Expand Down Expand Up @@ -319,6 +330,37 @@ function setTransformOrigin(canvas) {
}
}

function onlyLoadWordChart(callback) {
$('.js-page').remove();
loadData("/visualizations/tokens/", function(data) {
var canvas = drawCanvas('.wrapper', 'token');
var hexagonGroup = createHexagonGroup(canvas, data, loadOnly = true);
addHexagons(hexagonGroup, 90);
hexagonOnClick(hexagonGroup, function(data) {
var currentPage = $(data.element).closest('.js-page');
currentPage.removeClass('-active');
$('.js-active-slider').addClass('-hide');
$('.js-circle').one('transitionend', function(){
currentPage.addClass('_hidden');
setNavigationTitle(data.token);
$('.js-back').removeClass('_hidden');

});
tokensChart(data.stem);
tokensScroll = scrollPosition;
hammertime.destroy();
});
positionHexagon(hexagonGroup);
addText(hexagonGroup);
showHexagonGroup(hexagonGroup);
updateCanvasSize(canvas);
setTransformOrigin(canvas);
enableScroll();
visiblePage = 'tokens';
callback();
}, loadOnly = true);
}

function wordChart() {
$('.js-page').remove();
const params = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -373,7 +415,6 @@ function tokensChart(tokenId) {
currentPage.addClass('_hidden');
currentPage.removeClass('-active');
setNavigationName(data.token);
$('.js-inactive-slider').removeClass('-negative');
});
authorsChart(tokenId, data.id);
authorsScroll = scrollPosition;
Expand All @@ -390,7 +431,6 @@ function tokensChart(tokenId) {
$('.js-slider-min').text(parsedMinValue);
$('.js-slider-max').text(parsedMaxValue);
$('.js-inactive-slider').removeClass('-hide');
$('.js-inactive-slider').addClass('-negative');
updateCanvasSize(canvas);
setTransformOrigin(canvas);
enableScroll();
Expand Down
131 changes: 131 additions & 0 deletions src/static/js/player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
$('.js-player').rangeslider({

polyfill: false,

rangeClass: 'controls',
disabledClass: 'rangeslider--disabled',
horizontalClass: 'rangeslider--horizontal',
verticalClass: 'rangeslider--vertical',
fillClass: 'fill',
handleClass: 'handle',

onInit: function() {
$('.js-range-player .handle').prepend('<span class="currentdate js-current-date"></span>')
}
});
var interval = undefined;
var datesRange = [];
var currentMonthFromRange = undefined;

$('.js-player-play').click(function(){
var initialDate = $(".js-slider").dateRangeSlider("values").min;
var lastDate = $(".js-slider").dateRangeSlider("values").max;

var currentYear = initialDate.getFullYear();
var currentMonth = initialDate.getMonth();

$('.js-slider-min').text((monthShortNames[initialDate.getMonth()]+"/"+initialDate.getFullYear()))
$('.js-slider-max').text((monthShortNames[lastDate.getMonth()]+"/"+lastDate.getFullYear()))

var dateDiff = (lastDate.getFullYear() - initialDate.getFullYear())*12 + (lastDate.getMonth() - initialDate.getMonth());

$('.js-active-slider').addClass('-hide');
$('.js-range-player').removeClass('-hide');

for (i = 0; i < dateDiff + 1; i++) {
datesRange.push(monthShortNames[currentMonth]+"/"+currentYear);

if (currentMonth == 11) {
currentMonth = 0;
currentYear++;
} else {
currentMonth++;
};
};

var playerInput = $('.js-player');

var max = 500;
var months = datesRange.length;

var monthSecs = 2;
var monthRatio = max / months;

var speed = max / monthRatio * monthSecs * 2;

var showingMonth = 0;
playerInput.attr('max', max);

playerInput.on('input', function(){
var currentTick = parseInt(playerInput.val());
var currentMonthFromRange = Math.floor(currentTick / monthRatio);

$('.js-current-date').html(datesRange[currentMonthFromRange]);

});

if (interval) {
clearInterval(interval)
};

function loadInterval() {
var currentTick = parseInt(playerInput.val());

currentMonthFromRange = Math.floor(currentTick / monthRatio);
console.log(currentMonthFromRange)
if (currentMonthFromRange !== showingMonth) {
var urlMinMonthValue = ("0" + ((monthShortNames.indexOf(datesRange[currentMonthFromRange].split('/')[0]))+1)).slice(-2);
var urlMinYearValue = datesRange[currentMonthFromRange].split('/')[1]
var urlMaxMonthValue = ("0" + ((monthShortNames.indexOf(datesRange[currentMonthFromRange].split('/')[0]))+2)).slice(-2);

var urlMinValue = urlMinYearValue+"-"+urlMinMonthValue;

if (urlMinMonthValue == "12") {
var urlMaxValue = parseInt(urlMinYearValue) + 1 +"-"+"01";

} else {
var urlMaxValue = urlMinYearValue +"-"+urlMaxMonthValue
}
console.log(urlMaxValue);

const params = new URLSearchParams(window.location.search);
params.set('initialDate', urlMinValue);
params.set('endDate', urlMaxValue);
window.history.replaceState({}, '', `${location.pathname}?${params}`);

onlyLoadWordChart(function() {
interval = setInterval(loadInterval, speed);
});
if (interval) {
clearInterval(interval)
};
showingMonth = currentMonthFromRange;
}

var nextTick = currentTick + 1;
if (nextTick <= max) {
playerInput.val(nextTick).change();
} else {
clearInterval(interval);
}
}

interval = setInterval(loadInterval, speed);


});

$('.js-player-pause').click(function(){
if (interval) {
clearInterval(interval)
};
});

$('.js-player-stop').click(function(){
clearInterval(interval);
$('.js-player').val(0);
$('.js-player').off('input');
$('.js-active-slider').removeClass('-hide');
$('.js-range-player').addClass('-hide');
});

1 change: 0 additions & 1 deletion src/static/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ $('.js-back').on('click', function() {
hammertime.destroy();

if (visiblePage === 'manifestation' || visiblePage === 'manifestations') {
$('.js-inactive-slider').addClass('-negative');
setNavigationName('');
} else if (visiblePage === 'authors') {
setNavigationTitle('Parla');
Expand Down
3 changes: 2 additions & 1 deletion src/static/scss/ambience/_z-index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$z-index: (
reveal-circle : 200,
reveal-circle : 200,
filter-modal : 100,
player-controls : 90,
back : 80,
hex-bg : -1,
);
6 changes: 5 additions & 1 deletion src/static/scss/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
@import 'components/speeches-list';
@import 'components/hexagon-group';
@import 'components/simple-link';
@import 'components/range-slider';
@import 'components/error-message';
@import 'components/selected-bar';
@import 'components/player-controls';
@import 'components/range-slider';
@import 'components/range-player';
@import 'components/range-selected';
@import 'components/date-filters';

// Trumps

Expand Down
6 changes: 6 additions & 0 deletions src/static/scss/components/_date-filters.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.date-filters {
position: relative;

height: 58px;
margin: 0 10vw;
}
39 changes: 39 additions & 0 deletions src/static/scss/components/_player-controls.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.player-controls {
position: relative;
z-index: map-get($z-index, player-controls);

display: flex;
justify-content: center;

margin: 0 10vw 15px 10vw;

& > * + * {
margin-left: 20px;
}

& > span {
display: inline-block;

width: 16px;
height: 16px;
padding: 10px;

cursor: pointer;

background-repeat: no-repeat;
background-position: center;
background-size: 50%;
}

& > .play {
background-image: url('../img/play.svg');
}

& > .stop {
background-image: url('../img/stop.svg');
}

& > .pause {
background-image: url('../img/pause.svg');
}
}
Loading