Commit 403a670d authored by Mathieu Rodic's avatar Mathieu Rodic

[BUGFIX] Empty datasets kept the advanced chart from being displayed

https://forge.iscpif.fr/issues/1361
parent 75530220
...@@ -29,12 +29,12 @@ var operators = { ...@@ -29,12 +29,12 @@ var operators = {
}; };
var strDate = function(date) { var strDate = function(date) {
return date.getUTCFullYear() + '-' + return date.getFullYear() + '-' +
('00' + (date.getUTCMonth() + 1)).slice(-2) + '-' + ('00' + (date.getMonth() + 1)).slice(-2) + '-' +
('00' + date.getUTCDate()).slice(-2) + 'T' + ('00' + date.getDate()).slice(-2) + 'T' +
('00' + date.getUTCHours()).slice(-2) + ':' + ('00' + date.getHours()).slice(-2) + ':' +
('00' + date.getUTCMinutes()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' +
('00' + date.getUTCSeconds()).slice(-2) + 'Z'; ('00' + date.getSeconds()).slice(-2) + 'Z';
} }
var addZero = function(x) { var addZero = function(x) {
return (x<10) ? ('0'+x) : x; return (x<10) ? ('0'+x) : x;
...@@ -47,14 +47,27 @@ var groupings = { ...@@ -47,14 +47,27 @@ var groupings = {
datetime: { datetime: {
century: { century: {
truncate: function(x) {return x.substr(0, 2) + '00-01-01T00:00:00Z';}, truncate: function(x) {return x.substr(0, 2) + '00-01-01T00:00:00Z';},
next: function(x) {x = new Date(x); x.setFullYear(x.getFullYear()+100); return strDate(x);}, display: function(x) {return x.substr(0, 2) + 'th century'},
next: function(x) {
x = new Date(x);
x.setFullYear(x.getFullYear()+100);
x.setHours(0);
return strDate(x);
},
}, },
decade: { decade: {
truncate: function(x) {return x.substr(0, 3) + '0-01-01T00:00:00Z';}, truncate: function(x) {return x.substr(0, 3) + '0-01-01T00:00:00Z';},
next: function(x) {x = new Date(x); x.setFullYear(x.getFullYear()+10); return strDate(x);}, display: function(x) {return x.substr(0, 3)} + '0s',
next: function(x) {
x = new Date(x);
x.setFullYear(x.getFullYear() + 10);
x.setHours(0);
return strDate(x);
},
}, },
year: { year: {
truncate: function(x) {return x.substr(0, 4) + '-01-01T00:00:00Z';}, truncate: function(x) {return x.substr(0, 4) + '-01-01T00:00:00Z';},
display: function(x) {return x.substr(0, 4)},
next: function(x) { next: function(x) {
var y = parseInt(x.substr(0, 4)); var y = parseInt(x.substr(0, 4));
return addZeros(y + 1, 4) + x.substr(4); return addZeros(y + 1, 4) + x.substr(4);
...@@ -62,6 +75,7 @@ var groupings = { ...@@ -62,6 +75,7 @@ var groupings = {
}, },
month: { month: {
truncate: function(x) {return x.substr(0, 7) + '-01T00:00:00Z';}, truncate: function(x) {return x.substr(0, 7) + '-01T00:00:00Z';},
display: function(x) {return x.substr(0, 7)},
next: function(x) { next: function(x) {
var m = parseInt(x.substr(5, 2)); var m = parseInt(x.substr(5, 2));
if (m == 12) { if (m == 12) {
...@@ -74,7 +88,13 @@ var groupings = { ...@@ -74,7 +88,13 @@ var groupings = {
}, },
day: { day: {
truncate: function(x) {return x.substr(0, 10) + 'T00:00:00Z';}, truncate: function(x) {return x.substr(0, 10) + 'T00:00:00Z';},
next: function(x) {x = new Date(x); x.setDate(x.getDate()+1); return strDate(x);}, display: function(x) {return x.substr(0, 10)},
next: function(x) {
x = new Date(x);
x.setDate(x.getDate() + 1);
x.setHours(0);
return strDate(x);
},
}, },
}, },
numeric: { numeric: {
...@@ -309,6 +329,7 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -309,6 +329,7 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
// initialization // initialization
$scope.datasets = [{}]; $scope.datasets = [{}];
$scope.groupingKey = 'year'; $scope.groupingKey = 'year';
$scope.grouping = groupings.datetime[$scope.groupingKey];
$scope.options = { $scope.options = {
stacking: false stacking: false
}; };
...@@ -327,7 +348,10 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -327,7 +348,10 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
}, },
tension: 1.0, tension: 1.0,
lineMode: 'bundle', lineMode: 'bundle',
tooltip: {mode: 'scrubber', formatter: function(x, y, series) {return x + ' → ' + y;}}, tooltip: {mode: 'scrubber', formatter: function(x, y, series) {
alert($scope.grouping.display(x))
return $scope.grouping.display(x) + ' → ' + y;
}},
drawLegend: false, drawLegend: false,
drawDots: true, drawDots: true,
columnsHGap: 5 columnsHGap: 5
...@@ -354,25 +378,29 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -354,25 +378,29 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
return false; return false;
} }
var results = dataset.results; var results = dataset.results;
var xMinTmp = results[0][0]; if (results.length) {
var xMaxTmp = results[results.length - 1][0]; var xMinTmp = results[0][0];
if (xMin === undefined || xMinTmp < xMin) { var xMaxTmp = results[results.length - 1][0];
xMin = xMinTmp; if (xMin === undefined || xMinTmp < xMin) {
} xMin = xMinTmp;
if (xMax === undefined || xMaxTmp < xMax) { }
xMax = xMaxTmp; if (xMax === undefined || xMaxTmp < xMax) {
xMax = xMaxTmp;
}
} }
}); });
// Create the dataObject for interpolation // Create the dataObject for interpolation
var dataObject = {}; var dataObject = {};
xMin = grouping.truncate(xMin); if (xMin != undefined && xMax != undefined) {
xMax = grouping.truncate(xMax); xMin = grouping.truncate(xMin);
for (var x=xMin; x<=xMax; x=grouping.next(x)) { xMax = grouping.truncate(xMax);
var row = []; for (var x=xMin; x<=xMax; x=grouping.next(x)) {
angular.forEach($scope.datasets, function(){ var row = [];
row.push(0); angular.forEach($scope.datasets, function(){
}); row.push(0);
dataObject[x] = row; });
dataObject[x] = row;
}
} }
// Fill the dataObject with results // Fill the dataObject with results
angular.forEach($scope.datasets, function(dataset, datasetIndex){ angular.forEach($scope.datasets, function(dataset, datasetIndex){
...@@ -404,7 +432,7 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -404,7 +432,7 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
// Update the axis // Update the axis
$scope.graph.options.axes.y.min = yMin; $scope.graph.options.axes.y.min = yMin;
$scope.graph.options.axes.y.max = yMax; $scope.graph.options.axes.y.max = yMax;
$scope.graph.options.axes.y.ticks = 100; $scope.graph.options.axes.y.ticks = Math.pow(10, Math.floor(Math.abs(Math.log10(yMax - yMin))));
// Finally, update the graph // Finally, update the graph
var series = []; var series = [];
for (var i=0, n=$scope.datasets.length; i<n; i++) { for (var i=0, n=$scope.datasets.length; i<n; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment