// Pre-defined constants var operators = { 'text': [ {'label': 'contains', 'key': 'contains'} ], 'string': [ {'label': 'starts with', 'key': 'startswith'}, {'label': 'contains', 'key': 'contains'}, {'label': 'ends with', 'key': 'endswith'}, {'label': 'is', 'key': '='}, {'label': 'is before', 'key': '<'}, {'label': 'is after', 'key': '>'} ], 'integer': [ {'label': 'is', 'key': '='}, {'label': 'is lower than', 'key': '<'}, {'label': 'is higher than', 'key': '>'} ], 'float': [ {'label': 'is', 'key': '='}, {'label': 'is lower than', 'key': '<'}, {'label': 'is higher than', 'key': '>'} ], 'datetime': [ {'label': 'is', 'key': '='}, {'label': 'is before', 'key': '<'}, {'label': 'is after', 'key': '>'} ], }; var strDate = function(date) { return date.getFullYear() + '-' + ('00' + (date.getMonth() + 1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + 'T' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2) + 'Z'; } var addZero = function(x) { return (x<10) ? ('0'+x) : x; }; var addZeros = function(x, n) { x = x.toString(); return '0000'.substr(0, n - x.length) + x; }; var groupings = { datetime: { century: { representation: function(x) {return x.toISOString().substr(0, 2) + 'th century'}, 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); x.setHours(0); return strDate(x); }, }, decade: { representation: function(x) {return x.toISOString().substr(0, 3)} + '0s', 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); x.setHours(0); return strDate(x); }, }, year: { representation: function(x) {return x.toISOString().substr(0, 4)}, truncate: function(x) {return x.substr(0, 4) + '-01-01T00:00:00Z';}, next: function(x) { var y = parseInt(x.substr(0, 4)); return addZeros(y + 1, 4) + x.substr(4); }, }, month: { representation: function(x) {return x.toISOString().substr(0, 7)}, truncate: function(x) {return x.substr(0, 7) + '-01T00:00:00Z';}, next: function(x) { var m = parseInt(x.substr(5, 2)); if (m == 12) { var y = parseInt(x.substr(0, 4)); return addZeros(y + 1, 4) + '-01' + x.substr(7); } else { return x.substr(0, 5) + addZero(m + 1) + x.substr(7); } }, }, day: { representation: function(x) {return x.toISOString().substr(0, 10)}, truncate: function(x) {return x.substr(0, 10) + 'T00:00:00Z';}, next: function(x) { x = new Date(x); x.setDate(x.getDate() + 1); x.setHours(0); return strDate(x); }, }, }, numeric: { unit: { representation: function(x) {return x.toString()}, truncate: function(x) {return Math.round(x)}, next: function(x) {return x+1;}, }, }, }; // Define the application var gargantext = angular.module('Gargantext', ['n3-charts.linechart', 'ngCookies', 'ngTagsInput']); // Customize the application's scope angular.module('Gargantext').run(function($rootScope, $http, $cookies){ // Access Math library from anywhere in the scope of the application $rootScope.Math = Math; // Access to an HSB to RGB converter $rootScope.getColor = function(i, n){ var h = .3 + (i / n) % 1; var s = .7; var v = .8; var i = Math.floor(h * 6); var f = h * 6 - i; var p = v * (1 - s); var q = v * (1 - f * s); var t = v * (1 - (1 - f) * s); var r, g, b; switch (i % 6) { case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; case 5: r = v; g = p; b = q; break; } r = Math.round(255 * r); g = Math.round(255 * g); b = Math.round(255 * b); var color = 'rgb(' + r + ',' + g + ',' + b + ')'; return color; }; // Access to a range function, very similar to the one available in Python $rootScope.range = function(min, max, step){ if (max == undefined){ max = min; min = 0; } step = step || 1; var output = []; for (var i=min; i 0) { $scope.pagination.offset--; } $scope.postQuery(); }; $scope.increment = function() { if ($scope.pagination.offset < $scope.resultsCount) { $scope.pagination.offset += $scope.pagination.limit; } $scope.postQuery(); }; }); // Controller for datasets gargantext.controller("DatasetController", function($scope, $http) { // query-specific information $scope.mesured = 'nodes.count'; $scope.filters = []; $scope.pagination = {offset:0, limit: 20}; // results information $scope.loading = false; $scope.results = []; $scope.resultsCount = undefined; // corpus retrieval $scope.projects = []; $scope.corpora = []; $http.get('/api/nodes?type=Project', {cache: true}).success(function(response){ $scope.projects = response.data; }); // update corpora according to the select parent project $scope.updateCorpora = function() { $http.get('/api/nodes?type=Corpus&parent=' + $scope.projectId, {cache: true}).success(function(response){ $scope.corpora = response.data; }); }; // update entities depending on the selected corpus $scope.updateEntities = function() { var url = '/api/nodes/' + $scope.corpusId + '/children/metadata'; $scope.entities = undefined; $scope.filters = []; $http.get(url, {cache: true}).success(function(response){ $scope.entities = [ { key: 'metadata', columns: response.data }, { key: 'ngrams', columns: [ {key:'terms', type:'string'}, {key:'terms count', type:'integer'} ], } ]; }); $scope.updateQuery(); }; // query ngrams $scope.getNgrams = function(query) { var url = '/api/nodes/' + $scope.corpusId + '/children/ngrams?limit=10&contain=' + encodeURI(query); var appendTransform = function(defaults, transform) { defaults = angular.isArray(defaults) ? defaults : [defaults]; return defaults.concat(transform); } return $http.get(url, { cache: true, transformResponse: appendTransform($http.defaults.transformResponse, function(value) { return value.data; }) }); }; // filtering informations retrieval $scope.operators = operators; // add a filter $scope.addFilter = function() { $scope.filters.push({}); }; // remove a filter $scope.removeFilter = function(filterIndex) { $scope.filters.splice(filterIndex, 1); $scope.updateQuery(); }; // transmit query parameters to parent elements $scope.updateQuery = function() { if ($scope.corpusId) { // query parameters: sort var url = '/api/nodes/' + $scope.corpusId + '/children/queries'; // filters var filters = []; var keys = ['entity', 'column', 'operator', 'value']; for (var i=0, m=$scope.filters.length; i yMax) { yMax = y; } if (yMin == undefined || y < yMin) { yMin = y; } } linearData.push(row); } // // Update the axis // $scope.graph.options.axes.y.min = yMin; // $scope.graph.options.axes.y.max = yMax; // $scope.graph.options.axes.y.ticks = Math.pow(10, Math.floor(Math.abs(Math.log10(yMax - yMin)))); // Finally, update the graph var series = []; for (var i=0, n=$scope.datasets.length; i').change(); // d.find('input').last().val('2010').change(); // // second dataset // // $('button.add').first().click(); // // var d = $('li.dataset').last(); // // d.find('select').change(); // // // second dataset's filter // // d.find('div.filters button').last().click(); // // d.find('select').last().val('metadata').change(); // // d.find('select').last().val('abstract').change(); // // d.find('select').last().val('contains').change(); // // d.find('input').last().val('dea').change(); // // refresh // // $('button.refresh').first().click(); }, 500); }, 250); */