Commit 5c88b9aa authored by Administrator's avatar Administrator

Merge branch 'mat-angular'

Intégration des modifs de Mathieu.
parents 80dd36a9 60517996
...@@ -267,7 +267,7 @@ gargantext.controller("DatasetController", function($scope, $http) { ...@@ -267,7 +267,7 @@ gargantext.controller("DatasetController", function($scope, $http) {
} }
// event firing to parent(s) // event firing to parent(s)
$scope.$emit('updateDataset', { $scope.$emit('updateDataset', {
datasetId: $scope.$id, datasetIndex: $scope.$index,
url: url, url: url,
filters: filters, filters: filters,
mesured: $scope.mesured mesured: $scope.mesured
...@@ -280,9 +280,16 @@ gargantext.controller("DatasetController", function($scope, $http) { ...@@ -280,9 +280,16 @@ gargantext.controller("DatasetController", function($scope, $http) {
gargantext.controller("GraphController", function($scope, $http, $element) { gargantext.controller("GraphController", function($scope, $http, $element) {
// initialization // initialization
$scope.datasets = [{}]; $scope.datasets = [{}];
$scope.resultsList = [];
$scope.queries = {};
$scope.groupingKey = 'year'; $scope.groupingKey = 'year';
$scope.options = {
stacking: false
};
$scope.seriesOptions = {
thicknessNumber: 3,
thickness: '3px',
type: 'area',
striped: false
};
$scope.graph = { $scope.graph = {
data: [], data: [],
options: { options: {
...@@ -305,22 +312,22 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -305,22 +312,22 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
// remove a dataset // remove a dataset
$scope.removeDataset = function(datasetIndex) { $scope.removeDataset = function(datasetIndex) {
$scope.datasets.shift(datasetIndex); $scope.datasets.shift(datasetIndex);
$scope.query();
}; };
// show results on the graph // show results on the graph
$scope.showResults = function(keys) { $scope.showResults = function() {
// Format specifications // Format specifications
var xKey = 0;
var yKey = 1;
var grouping = groupings.datetime[$scope.groupingKey]; var grouping = groupings.datetime[$scope.groupingKey];
var convert = function(x) {return new Date(x);}; var convert = function(x) {return new Date(x);};
// Find extrema for X // Find extrema for X
var xMin, xMax; var xMin, xMax;
angular.forEach($scope.resultsList, function(results){ angular.forEach($scope.datasets, function(dataset){
if (results.length == 0) { if (!dataset.results) {
return false; return false;
} }
var xMinTmp = results[0][xKey]; var results = dataset.results;
var xMaxTmp = results[results.length - 1][xKey]; var xMinTmp = results[0][0];
var xMaxTmp = results[results.length - 1][0];
if (xMin === undefined || xMinTmp < xMin) { if (xMin === undefined || xMinTmp < xMin) {
xMin = xMinTmp; xMin = xMinTmp;
} }
...@@ -334,17 +341,18 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -334,17 +341,18 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
xMax = grouping.truncate(xMax); xMax = grouping.truncate(xMax);
for (var x=xMin; x<=xMax; x=grouping.next(x)) { for (var x=xMin; x<=xMax; x=grouping.next(x)) {
var row = []; var row = [];
angular.forEach($scope.resultsList, function(results){ angular.forEach($scope.datasets, function(){
row.push(0); row.push(0);
}); });
dataObject[x] = row; dataObject[x] = row;
} }
// Fill the dataObject with results // Fill the dataObject with results
angular.forEach($scope.resultsList, function(results, resultsIndex){ angular.forEach($scope.datasets, function(dataset, datasetIndex){
var results = dataset.results;
angular.forEach(results, function(result, r){ angular.forEach(results, function(result, r){
var x = grouping.truncate(result[xKey]); var x = grouping.truncate(result[0]);
var y = result[yKey]; var y = result[1];
dataObject[x][resultsIndex] += parseFloat(y); dataObject[x][datasetIndex] += parseFloat(y);
}); });
}); });
// Convert this object back to a sorted array // Convert this object back to a sorted array
...@@ -359,26 +367,48 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -359,26 +367,48 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
} }
// Finally, update the graph // Finally, update the graph
var series = []; var series = [];
for (var i=0, n=$scope.resultsList.length; i<n; i++) { for (var i=0, n=$scope.datasets.length; i<n; i++) {
series.push({ var seriesElement = {
y: 'y'+i, id: 'series_'+ i,
y: 'y'+ i,
axis: 'y', axis: 'y',
color: $scope.getColor(i, n) color: $scope.getColor(i, n)
};
angular.forEach($scope.seriesOptions, function(value, key) {
seriesElement[key] = value;
}); });
series.push(seriesElement);
} }
$scope.graph.options.series = series; $scope.graph.options.series = series;
$scope.graph.data = linearData; $scope.graph.data = linearData;
// shall we stack?
if ($scope.options.stacking) {
var stack = {
axis: 'y',
series: []
};
angular.forEach(series, function(seriesElement) {
stack.series.push(seriesElement.id);
});
$scope.graph.options.stacks = [stack];
} else {
delete $scope.graph.options.stacks;
}
}; };
// perform a query on the server // perform a query on the server
$scope.query = function() { $scope.query = function() {
// reinitialize data // number of requests made to the server
$scope.resultsList = new Array($scope.datasets.length); var requestsCount = 0;
$scope.indexById = {}; // reinitialize graph data
$scope.graph.data = []; $scope.graph.data = [];
// add all the server request to the queue // queue all the server requests
var index = 0; angular.forEach($scope.datasets, function(dataset, datasetIndex) {
angular.forEach($scope.queries, function(query, datasetId) { // if the results are already present, don't send a query
$scope.indexById[datasetId] = index++; if (dataset.results !== undefined) {
return;
}
// format data to be sent as a query
var query = dataset.query;
var data = { var data = {
filters: query.filters, filters: query.filters,
sort: ['metadata.publication_date.day'], sort: ['metadata.publication_date.day'],
...@@ -387,57 +417,65 @@ gargantext.controller("GraphController", function($scope, $http, $element) { ...@@ -387,57 +417,65 @@ gargantext.controller("GraphController", function($scope, $http, $element) {
list: ['metadata.publication_date.day', query.mesured] list: ['metadata.publication_date.day', query.mesured]
} }
}; };
// request to the server
$http.post(query.url, data, {cache: true}).success(function(response) { $http.post(query.url, data, {cache: true}).success(function(response) {
var index = $scope.indexById[datasetId]; dataset.results = response.results;
$scope.resultsList[index] = response.results; for (var i=0, n=$scope.datasets.length; i<n; i++) {
for (var i=0, n=$scope.resultsList.length; i<n; i++) { if ($scope.datasets[i].results == undefined) {
if ($scope.resultsList[i] == undefined) {
return; return;
} }
} }
$scope.showResults(response.retrieve); $scope.showResults();
}).error(function(response) { }).error(function(response) {
console.error('An error occurred while retrieving the query response'); console.error('An error occurred while retrieving the query response');
}); });
requestsCount++;
}); });
// if no request have been made at all, refresh the chart
if (requestsCount == 0) {
$scope.showResults();
}
}; };
// update the queries (catches the vent thrown by children dataset controllers) // update the datasets (catches the vent thrown by children dataset controllers)
$scope.$on('updateDataset', function(e, data) { $scope.$on('updateDataset', function(e, data) {
$scope.queries[data.datasetId] = { var dataset = $scope.datasets[data.datasetIndex]
dataset.query = {
url: data.url, url: data.url,
filters: data.filters, filters: data.filters,
mesured: data.mesured mesured: data.mesured
}; };
dataset.results = undefined;
$scope.query(); $scope.query();
}); });
}); });
// // For debugging only! // For debugging only!
// setTimeout(function(){ setTimeout(function(){
// var corpusId = $('div.corpus select option').last().val(); // first dataset
// // first dataset $('div.corpus select').change();
// $('div.corpus select').val(corpusId).change(); $('button.add').first().click();
// setTimeout(function(){ setTimeout(function(){
// $('div.filters button').last().click(); $('div.corpus select').change();
// var d = $('li.dataset').last(); // $('div.filters button').last().click();
// d.find('select').last().val('metadata').change(); // var d = $('li.dataset').last();
// d.find('select').last().val('publication_date').change(); // d.find('select').last().val('metadata').change();
// d.find('select').last().val('>').change(); // d.find('select').last().val('publication_date').change();
// d.find('input').last().val('2010').change(); // d.find('select').last().val('>').change();
// d.find('input').last().val('2010').change();
// // second dataset // // second dataset
// // $('button.add').first().click(); // // $('button.add').first().click();
// // var d = $('li.dataset').last(); // // var d = $('li.dataset').last();
// // d.find('select').change(); // // d.find('select').change();
// // // second dataset's filter // // // second dataset's filter
// // d.find('div.filters button').last().click(); // // d.find('div.filters button').last().click();
// // d.find('select').last().val('metadata').change(); // // d.find('select').last().val('metadata').change();
// // d.find('select').last().val('abstract').change(); // // d.find('select').last().val('abstract').change();
// // d.find('select').last().val('contains').change(); // // d.find('select').last().val('contains').change();
// // d.find('input').last().val('dea').change(); // // d.find('input').last().val('dea').change();
// // refresh // // refresh
// $('button.refresh').first().click(); // // $('button.refresh').first().click();
// }, 500); }, 500);
// }, 500); }, 250);
\ No newline at end of file \ No newline at end of file
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<!-- {% load staticfiles %} --> <!-- {% load staticfiles %} -->
<link rel="stylesheet" href="{% static "css/bootstrap.css" %}"> <link rel="stylesheet" href="{% static "css/bootstrap.css" %}">
<link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}"> <link rel="stylesheet" href="{% static "css/bootstrap-theme.min.css" %}">
<title>GarganText: Analyze your data with graphs</title>
{% endblock %} {% endblock %}
...@@ -121,6 +122,7 @@ ...@@ -121,6 +122,7 @@
--> -->
<style type="text/css"> <style type="text/css">
div.corpus button:first-child+select {color:#FFF;}
div.list-results table {border-collapse: collapse;} div.list-results table {border-collapse: collapse;}
div.list-results th, div.list-results td {border: solid 1px #888; padding: 0.5em;} div.list-results th, div.list-results td {border: solid 1px #888; padding: 0.5em;}
div.list-results th {background: #444; color: #FFF} div.list-results th {background: #444; color: #FFF}
...@@ -266,7 +268,7 @@ ...@@ -266,7 +268,7 @@
</div> </div>
<div class="graph-parameters"> <div class="graph-parameters">
X-axis: groups the results by X-axis: groups the results by
<select ng-model="groupingKey" ng-options="key for key in ['day', 'month', 'year', 'decade', 'century']" ng-change="showResults()"> <select ng-model="groupingKey" ng-options="key for key in ['day', 'month', 'year', 'decade', 'century']" ng-change="query()">
</select> </select>
<br/> <br/>
...@@ -274,15 +276,32 @@ ...@@ -274,15 +276,32 @@
<select ng-model="graph.options.axes.y.type" ng-options="type for type in ['log', 'linear']"></select> <select ng-model="graph.options.axes.y.type" ng-options="type for type in ['log', 'linear']"></select>
scale scale
<br/> <br/>
<hr/>
Interpolation: Represent data with
<select ng-model="graph.options.lineMode"> <select ng-model="seriesOptions.type" ng-options="type for type in ['line', 'area', 'column']" ng-change="query()"></select>
<option ng-repeat="mode in ['bundle', 'linear']" value="{{ mode }}">{{ mode }}</option> <span ng-show="seriesOptions.type == 'area'">
</select> (<select ng-model="seriesOptions.striped" ng-options="value as key for (key, value) in {'with':true, 'without':false}" ng-change="query()"></select> stripes)
<span ng-if="graph.options.lineMode != 'linear'"> </span>
with a smoothing of smoothing: <span ng-show="seriesOptions.type == 'area' || seriesOptions.type == 'column'">
<input type="text" disabled="disabled" ng-model="graph.options.tension" /> (<select ng-model="options.stacking" ng-options="value as key for (key, value) in {'with':true, 'without':false}" ng-change="query()"></select> stacking)
<input type="range" min="0" max="2" step=".1" ng-model="graph.options.tension" /> </span>
<br/>
<span ng-hide="seriesOptions.type == 'column'">
Line thickness:
<input ng-model="seriesOptions.thicknessNumber" type="range" min="1" max="8" ng-change="seriesOptions.thickness = seriesOptions.thicknessNumber + 'px'; query()" />
<br/>
Interpolation:
<select ng-model="graph.options.lineMode">
<option ng-repeat="mode in ['bundle', 'linear']" value="{{ mode }}">{{ mode }}</option>
</select>
<span ng-if="graph.options.lineMode != 'linear'">
with a tension of
<input type="text" disabled="disabled" ng-model="graph.options.tension" />
<input type="range" min="0" max="2" step=".1" ng-model="graph.options.tension" />
</span>
</span> </span>
</div> </div>
</div> </div>
......
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