Skip to content

Commit

Permalink
Fixed series column label (fixes #55).
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmontesl committed Dec 23, 2018
1 parent b00b7f6 commit f8a1f54
Show file tree
Hide file tree
Showing 16 changed files with 342 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fixed chart figure export (was not working). Chart images can again be exported as PNG.
* Fixed series missing data with same label but different key value.
* Fixed #71 for cases where more than one grid was on screen.
* Added map view.

[2.0.2]

Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = function(grunt) {
'cubesviewer/views/cube/chart/chart-radar.js',
'cubesviewer/views/cube/chart/chart-sunburst.js',
'cubesviewer/views/cube/chart/map/chart-map.js',
'cubesviewer/views/cube/chart/map/chart-map-layers.js',
//'cubesviewer/cubesviewer.views.cube.rangefilter.js',
'cubesviewer/views/cube/export.js',
'cubesviewer/views/undo.js',
Expand Down
39 changes: 34 additions & 5 deletions cubesviewer/cubes/cubes-cvextensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"use strict";

/* Extensions to cubesviewer client lib */


cubes.Dimension.prototype.hierarchies_count = function() {

var count = 0;
Expand All @@ -39,18 +41,18 @@ cubes.Dimension.prototype.default_hierarchy = function() {
return this.hierarchies[this.default_hierarchy_name];
};

/*
/**
* Extend model prototype to support datefilter dimensions.
* Inform if a dimension is a date dimension and can be used as a date
* filter (i.e. with date selection tool).
* @returns Whether the dimension is a date dimension.
*/
cubes.Dimension.prototype.isDateDimension = function() {

// Inform if a dimension is a date dimension and can be used as a date
// filter (i.e. with date selection tool).
return ((this.role == "time") &&
((! ("cv-datefilter" in this.info)) || (this.info["cv-datefilter"] == true)) );

};


/**
* List date dimensions.
*
Expand All @@ -66,6 +68,33 @@ cubes.Cube.prototype.dateDimensions = function() {
};


/**
* Extend model prototype to support geographic dimensions.
* @returns Whether the dimension level is a geographic dimension.
*/
cubes.Level.prototype.isGeoLevel = function() {
return ((this.role == "geo") || ("cv-geo-source" in this.info));
};


/**
* List date dimensions.
*
* @returns An array with the dimensions that are date dimensions (role: time).
*/
cubes.Cube.prototype.geoLevels = function() {
var result = [];
for (var index in this.dimensions) {
var dimension = this.dimensions[index];
for (var indexL in dimension.levels) {
var level = dimension.levels[indexL];
if (level.isGeoLevel()) result.push(level);
}
}
return result;
};


cubes.Cube.prototype.cvdim_dim = function(dimensionString) {
// Get a dimension by name. Accepts dimension hierarchy and level in the input string.
var dimname = dimensionString;
Expand Down
4 changes: 2 additions & 2 deletions cubesviewer/views/cube/chart/chart-bars-horizontal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartBarsHorizon
var columnDefs = view.grid.columnDefs;

var container = $($element).find("svg").get(0);
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "None")
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "");

var d = [];

Expand All @@ -61,7 +61,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartBarsHorizon
$(dataRows).each(function(idx, e) {
var serie = [];
for (var i = 1; i < columnDefs.length; i++) {
var value = e[columnDefs[i].name];
var value = e[columnDefs[i].field];

// If second serie is reversed
if (dataRows.length == 2 && serieCount == 1 && view.params.chartoptions.mirrorSerie2) value = (value != undefined) ? -value : 0;
Expand Down
4 changes: 2 additions & 2 deletions cubesviewer/views/cube/chart/chart-bars-vertical.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartBarsVertica
var columnDefs = view.grid.columnDefs;

var container = $($element).find("svg").get(0);
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "None")
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "");

var d = [];

Expand All @@ -62,7 +62,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartBarsVertica
$(dataRows).each(function(idx, e) {
var serie = [];
for (var i = 1; i < columnDefs.length; i++) {
var value = e[columnDefs[i].name];
var value = e[columnDefs[i].field];
serie.push( { "x": columnDefs[i].name, "y": (value != undefined) ? value : 0 } );
}
var series = { "values": serie, "key": e["key"] != "" ? e["key"] : view.params.yaxis };
Expand Down
4 changes: 2 additions & 2 deletions cubesviewer/views/cube/chart/chart-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartLinesContro

var container = $($element).find("svg").get(0);

var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "None")
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.dimensionParts(view.params.xaxis).label : "");


// TODO: Check there's only one value column
Expand Down Expand Up @@ -196,7 +196,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartLinesContro
this.drawChartLinesCumulative = function (view, colNames, dataRows, dataTotals) {
var container = $('#seriesChart-' + view.id).find("svg").get(0);
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.getDimensionParts(view.params.xaxis).label : "None")
var xAxisLabel = ( (view.params.xaxis != null) ? view.cube.getDimensionParts(view.params.xaxis).label : "");
var d = [];
Expand Down
2 changes: 1 addition & 1 deletion cubesviewer/views/cube/chart/chart-pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartPieControll
var value = e[columnDefs[1].field];
if ((value != undefined) && (value > 0)) {

var series = { "y": value, "key": e["key"] != "" ? e["key"] : columnDefs[0].name };
var series = { "y": value, "key": e["key"] != "" ? e["key"] : columnDefs[0].field };
if (view.params["chart-disabledseries"]) {
if (view.params["chart-disabledseries"]["key"] == (view.params.drilldown.join(","))) {
series.disabled = !! view.params["chart-disabledseries"]["disabled"][series.key];
Expand Down
2 changes: 2 additions & 0 deletions cubesviewer/views/cube/chart/chart-sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartSunburstCon
*/
$scope.prepareDrilldownTree = function (data) {

// FIXME: This representation is using cells directly, instead of data from series.

var view = $scope.view;

var json = [{
Expand Down
7 changes: 6 additions & 1 deletion cubesviewer/views/cube/chart/chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ <h3><i class="fa fa-fw fa-sun-o"></i> Chart
</div>

<div ng-if="view.params.charttype == 'map'">
<h3><i class="fa fa-fw fa-globe"></i> Map chart</h3>
<h3><i class="fa fa-fw fa-globe"></i> Map chart
<i ng-show="view.pendingRequests > 0" class="fa fa-circle-o-notch fa-spin fa-fw margin-bottom text-info pull-right"></i>
</h3>
<div ng-if="view.pendingRequests > 0" class="loadingbar-content">
<span class="loadingbar-expand"></span>
</div>
<div ng-controller="CubesViewerViewsCubeChartMapController">
<div ng-include="'views/cube/chart/map/chart-map.html'"></div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion cubesviewer/views/cube/chart/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ angular.module('cv.views.cube').controller("CubesViewerViewsCubeChartController"

$(rows).each(function(idx, e) {
var jointkey = [];
var jointlabel = [];
for (var i = 0; i < view.params.drilldown.length; i++) jointkey.push(e["key" + i]);
e["key"] = jointkey.join(" / ");
for (var i = 0; i < view.params.drilldown.length; i++) jointlabel.push(e["label" + i]);
e["key"] = jointkey.join("_");
e["label"] = jointlabel.join(" / ");

// FIXME: Using label as key for charts, but we should properly use keys/labels for charts and column definitions in general
e["key"] = e["label"];
});
}

Expand Down
189 changes: 189 additions & 0 deletions cubesviewer/views/cube/chart/map/chart-map-layers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* CubesViewer
* Copyright (c) 2012-2016 Jose Juan Montes, see AUTHORS for more details
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

"use strict";


var defineMapControllerLayerMethods = function($scope) {

/**
* Creates a Tile XYZ layer.
* @param mapLayer
* @returns The created layer.
*/
$scope.createLayerXYZ = function (mapLayer) {

var sourceParams = {};
angular.extend(sourceParams, mapLayer.params);
if (mapLayer.attribution) sourceParams['attributions'] = [ new ol.Attribution({ 'html': "" + mapLayer.attribution }) ];

var layer = new ol.layer.Tile({
source: new ol.source.XYZ(sourceParams),
opacity: mapLayer.opacity ? mapLayer.opacity : 1.0,
visible: false
});

return layer;
};

/**
* Creates a WMTS layer. This provides a set of default parameters.
* @returns The created layer.
*/
$scope.createLayerWMTS = function (mapLayer) {

// Generate resolutions and matrixIds arrays for this WMTS (having seen capabilities)
// Note: Grid may be built also by: ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(matrixSet, opt_extent)
var projection = ol.proj.get('EPSG:3857');
var projectionExtent = projection.getExtent();
var size = ol.extent.getWidth(projectionExtent) / 256;
var resolutions = new Array(20);
var matrixIds = new Array(20);
for (var z = 0; z < 20; ++z) {
resolutions[z] = size / Math.pow(2, z);
matrixIds[z] = z;
}

var sourceParamsBase = {
//url: 'http://www.ign.es/wmts/pnoa-ma?service=WMTS',
//layer: 'OI.OrthoimageCoverage',
matrixSet: 'GoogleMapsCompatible', // 'EPSG:3857',
format: 'image/png',
projection: projection,
tileGrid: new ol.tilegrid.WMTS({
origin: ol.extent.getTopLeft(projectionExtent),
resolutions: resolutions,
matrixIds: matrixIds
}),
style: 'default'
};

var sourceParams = {};
angular.extend(sourceParams, sourceParamsBase);
angular.extend(sourceParams, mapLayer.params);
if (mapLayer.attribution) sourceParams['attributions'] = [ new ol.Attribution({ 'html': "" + mapLayer.attribution }) ];

var layer = new ol.layer.Tile({
source: new ol.source.WMTS(sourceParams),
opacity: mapLayer.opacity ? mapLayer.opacity : 1.0,
visible: false
//extent: projectionExtent,
})

return layer;
};

/**
* Creates a KML layer.
* @returns The created layer.
*/
$scope.createLayerKML = function (mapLayer) {

var sourceParams = {};
angular.extend(sourceParams, { format: new ol.format.KML() });
angular.extend(sourceParams, mapLayer.params);
if (mapLayer.attribution) sourceParams['attributions'] = [ new ol.Attribution({ 'html': "" + mapLayer.attribution }) ];

var layer = new ol.layer.Vector({
source: new ol.source.Vector(sourceParams)
});

return layer;
};

/**
* Creates a GeoJSON layer.
* @returns The created layer.
*/
$scope.createLayerGeoJSON = function (mapLayer) {

var sourceParams = {};
angular.extend(sourceParams, { format: new ol.format.GeoJSON() });
angular.extend(sourceParams, mapLayer.params);

var cityNamesStyle = function(feature, resolution) {
var fontSize = 1.5 - 0.5 * feature.get("scalerank") / 10;
return [ new ol.style.Style({
text: new ol.style.Text({
text: resolution < 3600 || (resolution < 14400 && feature.get("scalerank") < 4) ? feature.get("name") : "",
font: 'bold ' + (fontSize * 10) + 'px Calibri,sans-serif',
fill: new ol.style.Fill({color: "#ffffff"}),
stroke: new ol.style.Stroke({color: "#000000", width: 3}),
})
}) ]
};

// Populated places GeoJSON
var layer = new ol.layer.Vector({
title: mapLayer.label,
source: new ol.source.Vector(sourceParams),
visible: false,

// TODO: Layer styles shall be optional and chosen from several possibilities (if applied)
style: cityNamesStyle
});

return layer;
};


/**
* Creates various types of map layers based on settings.
*/
$scope.createLayers = function(mapLayers) {

var layers = {};
layers['_order'] = [];
angular.forEach(mapLayers, function(mapLayer) {

var layer = null;

if (mapLayer.params.url && (mapLayer.params.url.search('{}') >= 0)) {
mapLayer.params.url = mapLayer.params.url.replace('{}', $location.host());
}

if (mapLayer.source == 'wmts') {
layer = $scope.createLayerWMTS(mapLayer);
} else if (mapLayer.source == 'xyz') {
layer = $scope.createLayerXYZ(mapLayer);
} else if (mapLayer.source == 'geojson') {
layer = $scope.createLayerGeoJSON(mapLayer);
} else if (mapLayer.source == 'kml') {
layer = $scope.createLayerKML(mapLayer);
} else {
console.error('Wrong map settings. Could not create map layer of source type: ' + mapLayer.source);
return;
}

layers[mapLayer.name] = layer;
layers['_order'].push(layer);


});
};

};




Loading

0 comments on commit f8a1f54

Please sign in to comment.