dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33497
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17102: DV meter chart, indicators will pick color from assigned legend set.
Merge authors:
Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17102 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-14 10:43:56 +0200
message:
DV meter chart, indicators will pick color from assigned legend set.
modified:
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js
dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2014-10-09 07:58:13 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js 2014-10-14 08:36:36 +0000
@@ -2339,7 +2339,39 @@
var xResponse,
xColAxis,
xRowAxis,
- config;
+ config,
+ ind = dimConf.indicator.objectName,
+ legendSet,
+ fn;
+
+ fn = function() {
+
+ // create chart
+ ns.app.chart = ns.core.web.chart.createChart(ns ,legendSet);
+
+ // update viewport
+ ns.app.centerRegion.update();
+ ns.app.centerRegion.removeAll();
+ ns.app.centerRegion.add(ns.app.chart);
+
+ // after render
+ if (NS.isSessionStorage) {
+ web.storage.session.set(layout, 'chart');
+ }
+
+ ns.app.viewport.setGui(layout, xLayout, isUpdateGui);
+
+ web.mask.hide(ns.app.centerRegion);
+
+ if (NS.isDebug) {
+ console.log("layout", ns.app.layout);
+ console.log("xLayout", ns.app.xLayout);
+ console.log("response", ns.app.response);
+ console.log("xResponse", ns.app.xResponse);
+ console.log("core", ns.core);
+ console.log("app", ns.app);
+ }
+ };
if (!xLayout) {
xLayout = service.layout.getExtendedLayout(layout);
@@ -2354,31 +2386,22 @@
ns.app.response = response;
ns.app.xResponse = xResponse;
- // create chart
- ns.app.chart = ns.core.web.chart.createChart(ns);
-
- // update viewport
- ns.app.centerRegion.update();
- ns.app.centerRegion.removeAll();
- ns.app.centerRegion.add(ns.app.chart);
-
- // after render
- if (NS.isSessionStorage) {
- web.storage.session.set(layout, 'chart');
- }
-
- ns.app.viewport.setGui(layout, xLayout, isUpdateGui);
-
- web.mask.hide(ns.app.centerRegion);
-
- if (NS.isDebug) {
- console.log("layout", ns.app.layout);
- console.log("xLayout", ns.app.xLayout);
- console.log("response", ns.app.response);
- console.log("xResponse", ns.app.xResponse);
- console.log("core", ns.core);
- console.log("app", ns.app);
- }
+ // legend set
+ if (xLayout.type === 'gauge' && Ext.Array.contains(xLayout.axisObjectNames, ind) && xLayout.objectNameIdsMap[ind].length) {
+ Ext.Ajax.request({
+ url: ns.core.init.contextPath + '/api/indicators/' + xLayout.objectNameIdsMap[ind][0] + '.json?fields=legendSet[mapLegends[id,name,startValue,endValue,color]]',
+ disableCaching: false,
+ success: function(r) {
+ legendSet = Ext.decode(r.responseText).legendSet;
+ },
+ callback: function() {
+ fn();
+ }
+ });
+ }
+ else {
+ fn();
+ }
};
}());
};
=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js 2014-10-09 18:13:21 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js 2014-10-14 08:36:36 +0000
@@ -1648,6 +1648,26 @@
//return response;
};
+ // legend set
+ service.mapLegend = {};
+
+ service.mapLegend.getColorByValue = function(legendSet, value) {
+ var color;
+
+ if (!(legendSet && value)) {
+ return;
+ }
+
+ for (var i = 0, legend; i < legendSet.mapLegends.length; i++) {
+ legend = legendSet.mapLegends[i];
+
+ if (value >= parseFloat(legend.startValue) && value < parseFloat(legend.endValue)) {
+ return legend.color;
+ }
+ }
+
+ return;
+ };
}());
// web
@@ -1773,7 +1793,7 @@
// chart
web.chart = {};
- web.chart.createChart = function(ns) {
+ web.chart.createChart = function(ns, legendSet) {
var dataTotalKey = Ext.data.IdGenerator.get('uuid').generate(),
xLayout = ns.app.xLayout,
xResponse = ns.app.xResponse,
@@ -1795,7 +1815,6 @@
return ids;
}(),
replacedFilterIds = support.prototype.str.replaceAll(Ext.clone(filterIds), '.', ''),
-
replacedIdMap = function() {
var map = {},
names = xResponse.metaData.names,
@@ -1808,7 +1827,6 @@
return map;
}(),
-
addDataTotals = function(data, ids) {
for (var i = 0, obj, total; i < data.length; i++) {
obj = data[i];
@@ -1840,15 +1858,11 @@
getDefaultChartSizeHandler,
getDefaultChartTitlePositionHandler,
getDefaultChart,
-
+
generator = {};
getDefaultStore = function(isStacked) {
- var pe = conf.finals.dimension.period.dimensionName,
- columnDimensionName = xLayout.columns[0].dimensionName,
- rowDimensionName = xLayout.rows[0].dimensionName,
-
- data = [],
+ var data = [],
trendLineFields = [],
targetLineFields = [],
baseLineFields = [],
@@ -1859,8 +1873,7 @@
obj = {};
category = rowIds[i];
rowValues = [];
- isEmpty = false;
-
+ isEmpty = false;
obj[conf.finals.data.domain] = xResponse.metaData.names[category];
@@ -2872,13 +2885,24 @@
};
generator.gauge = function() {
- var store = getDefaultStore(),
+ var valueColor = '#aaa',
+ store,
axis,
series,
legend,
config,
chart;
-
+
+ // overwrite items
+ columnIds = [columnIds[0]];
+ replacedColumnIds = [replacedColumnIds[0]];
+ rowIds = [rowIds[0]];
+ replacedRowIds = [replacedRowIds[0]];
+
+ // store
+ store = getDefaultStore();
+
+ // axis
axis = {
type: 'gauge',
position: 'gauge',
@@ -2888,11 +2912,16 @@
margin: -7
};
+ // series, legendset
+ if (legendSet) {
+ valueColor = service.mapLegend.getColorByValue(legendSet, store.getRange()[0].data[columnIds[0]]) || valueColor;
+ }
+
series = {
type: 'gauge',
field: store.rangeFields[0],
//donut: 5,
- colorSet: ['#82B525', '#ddd']
+ colorSet: [valueColor, '#ddd']
};
chart = getDefaultChart({