← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17011: DV sorting implemented as option. Regular charts sorted on first series. Stacked charts sorted on...

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 17011 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-10-09 00:41:28 +0200
message:
  DV sorting implemented as option. Regular charts sorted on first series. Stacked charts sorted on total.
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/i18n/en.properties
  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-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-10-07 10:08:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-10-08 22:37:32 +0000
@@ -501,6 +501,7 @@
         executeSql( "update chart set userorganisationunitchildren = false where userorganisationunitchildren is null" );
         executeSql( "update chart set userorganisationunitgrandchildren = false where userorganisationunitgrandchildren is null" );
         executeSql( "update chart set hidetitle = false where hidetitle is null" );
+        executeSql( "update chart set sortorder = 0 where sortorder is null" );
         
         executeSql( "update eventreport set showhierarchy = false where showhierarchy is null" );
         executeSql( "update eventreport set counttype = 'events' where counttype is null" );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml	2014-04-21 16:49:18 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/chart/hibernate/Chart.hbm.xml	2014-10-08 21:49:29 +0000
@@ -169,6 +169,8 @@
     <property name="rangeAxisSteps" />
 
     <property name="rangeAxisDecimals" />
+    
+    <property name="sortOrder" />
 
     <!-- Access properties -->
     <property name="externalAccess" />

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java	2014-09-29 16:10:58 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/mapping/GeoFeatureController.java	2014-10-08 21:49:29 +0000
@@ -100,7 +100,7 @@
 
         DataQueryParams params = analyticsService.getFromUrl( set, null, AggregationType.SUM, null, false, false, false, false, false, false, null, null );
 
-        DimensionalObject dim = params.getDimension( DimensionalObject.ORGUNIT_DIM_ID );
+        DimensionalObject dim = params.getDimension( DimensionalObject.ORGUNIT_DIM_ID );       
 
         List<OrganisationUnit> organisationUnits = NameableObjectUtils.asTypedList( dim.getItems() );
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/i18n/en.properties'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/i18n/en.properties	2014-09-29 15:12:43 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/i18n/en.properties	2014-10-08 21:49:29 +0000
@@ -239,3 +239,6 @@
 example6=Click Options to show trend lines, target lines, axis titles and more
 example7=Click Favorites to save your chart for later use
 example8=Click Download to save chart graphics to your computer
+low_to_high=Low to high
+high_to_low=High to low
+sort_order=Sort order

=== 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-07 10:55:39 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/app.js	2014-10-08 21:49:29 +0000
@@ -523,13 +523,28 @@
 			general,
 			window,
 
+            comboBottomMargin = 1,
+            checkboxBottomMargin = 2,
+            separatorTopMargin = 6,
 			cmpWidth = 340,
 			labelWidth = 125,
 			numberWidth = 80;
 
+        // data
+		showValues = Ext.create('Ext.form.field.Checkbox', {
+			boxLabel: NS.i18n.show_values,
+			style: 'margin-bottom:' + checkboxBottomMargin + 'px',
+			checked: true
+		});
+
+		hideEmptyRows = Ext.create('Ext.form.field.Checkbox', {
+			boxLabel: NS.i18n.hide_empty_category_items,
+			style: 'margin-bottom:' + checkboxBottomMargin + 'px'
+		});
+
 		showTrendLine = Ext.create('Ext.form.field.Checkbox', {
 			boxLabel: NS.i18n.trend_line,
-			style: 'margin-bottom:6px'
+			style: 'margin-bottom:' + checkboxBottomMargin + 'px'
 		});
 
 		targetLineValue = Ext.create('Ext.form.field.Number', {
@@ -567,7 +582,6 @@
 		});
 
 		baseLineTitle = Ext.create('Ext.form.field.Text', {
-			//cls: 'ns-textfield-alt1',
 			style: 'margin-left:1px; margin-bottom:1px',
 			fieldStyle: 'padding-left:3px',
 			emptyText: NS.i18n.base,
@@ -580,11 +594,28 @@
 			}
 		});
 
-		hideEmptyRows = Ext.create('Ext.form.field.Checkbox', {
-			boxLabel: NS.i18n.hide_empty_category_items,
-			style: 'margin-bottom:4px'
+		sortOrder = Ext.create('Ext.form.field.ComboBox', {
+			cls: 'ns-combo',
+			style: 'margin-bottom:' + comboBottomMargin + 'px',
+			width: cmpWidth,
+			labelWidth: 125,
+			fieldLabel: NS.i18n.sort_order,
+			labelStyle: 'color:#333',
+			queryMode: 'local',
+			valueField: 'id',
+			editable: false,
+			value: 0,
+			store: Ext.create('Ext.data.Store', {
+				fields: ['id', 'text'],
+				data: [
+					{id: 0, text: NS.i18n.none},
+					{id: -1, text: NS.i18n.low_to_high},
+					{id: 1, text: NS.i18n.high_to_low}
+				]
+			})
 		});
 
+        // axes
 		rangeAxisMinValue = Ext.create('Ext.form.field.Number', {
 			width: numberWidth,
 			height: 18,
@@ -616,15 +647,10 @@
 			minValue: 0
 		});
 
-		showValues = Ext.create('Ext.form.field.Checkbox', {
-			boxLabel: NS.i18n.show_values,
-			style: 'margin-bottom:4px',
-			checked: true
-		});
-
+        // general
 		hideLegend = Ext.create('Ext.form.field.Checkbox', {
 			boxLabel: NS.i18n.hide_legend,
-			style: 'margin-bottom:4px'
+			style: 'margin-bottom:' + checkboxBottomMargin + 'px'
 		});
 
 		hideTitle = Ext.create('Ext.form.field.Checkbox', {
@@ -638,7 +664,7 @@
 		});
 
 		title = Ext.create('Ext.form.field.Text', {
-			style: 'margin-bottom:2px',
+			style: 'margin-bottom:0',
 			width: cmpWidth,
 			fieldLabel: NS.i18n.chart_title,
 			labelStyle: 'color:#333',
@@ -682,6 +708,7 @@
 					xtype: 'container',
 					layout: 'column',
 					bodyStyle: 'border:0 none',
+                    style: 'margin-top:' + (separatorTopMargin + 1) + 'px',
 					items: [
 						{
 							bodyStyle: 'border:0 none; padding-top:3px; margin-right:5px; color:#333',
@@ -705,7 +732,8 @@
 						baseLineValue,
 						baseLineTitle
 					]
-				}
+				},
+                sortOrder
 			]
 		};
 
@@ -760,6 +788,7 @@
 					targetLineTitle: targetLineTitle.getValue(),
 					baseLineValue: baseLineValue.getValue(),
 					baseLineTitle: baseLineTitle.getValue(),
+                    sortOrder: sortOrder.getValue(),
 					rangeAxisMaxValue: rangeAxisMaxValue.getValue(),
 					rangeAxisMinValue: rangeAxisMinValue.getValue(),
 					rangeAxisSteps: rangeAxisSteps.getValue(),
@@ -806,6 +835,8 @@
 					baseLineTitle.reset();
 				}
 
+                sortOrder.setValue(Ext.isNumber(layout.sortOrder) ? layout.sortOrder : 0);
+
 				// rangeAxisMaxValue
 				if (Ext.isNumber(layout.rangeAxisMaxValue)) {
 					rangeAxisMaxValue.setValue(layout.rangeAxisMaxValue);
@@ -926,6 +957,7 @@
 					w.targetLineTitle = targetLineTitle;
 					w.baseLineValue = baseLineValue;
 					w.baseLineTitle = baseLineTitle;
+                    w.sortOrder = sortOrder;
 
 					w.rangeAxisMaxValue = rangeAxisMaxValue;
 					w.rangeAxisMinValue = rangeAxisMinValue;

=== 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-09-10 13:31:39 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js	2014-10-08 22:32:23 +0000
@@ -357,6 +357,8 @@
 
                 // baseLineTitle: string
 
+                // sortOrder: number
+
                 // rangeAxisMaxValue: number
 
                 // rangeAxisMinValue: number
@@ -602,6 +604,7 @@
                     layout.baseLineValue = Ext.isNumber(config.baseLineValue) ? config.baseLineValue : null;
                     layout.baseLineTitle = Ext.isString(config.baseLineLabel) && !Ext.isEmpty(config.baseLineLabel) ? config.baseLineLabel :
                         (Ext.isString(config.baseLineTitle) && !Ext.isEmpty(config.baseLineTitle) ? config.baseLineTitle : null);
+                    layout.sortOrder = Ext.isNumber(config.sortOrder) ? config.sortOrder : 0;
 
 					layout.rangeAxisMaxValue = Ext.isNumber(config.rangeAxisMaxValue) ? config.rangeAxisMaxValue : null;
 					layout.rangeAxisMinValue = Ext.isNumber(config.rangeAxisMinValue) ? config.rangeAxisMinValue : null;
@@ -1806,6 +1809,30 @@
                         return map;
                     }(),
 
+                    sortStoreBySum = function(store, ids, sortOrder) {
+                        var key = Ext.data.IdGenerator.get('uuid').generate(),
+                            total;
+
+                        // add totals
+                        store.each( function(record) {
+                            total = 0;
+
+                            for (var i = 0; i < ids.length; i++) {
+                                total += parseFloat(record.data[ids[i]]);
+
+                                record.set(key, total);
+                            }
+                        });
+
+                        // sort
+                        store.sort(key, sortOrder === -1 ? 'ASC' : 'DESC');
+
+                        // remove totals
+                        store.each( function(record) {
+                            delete record.data[key];
+                        });
+                    },
+
 					getSyncronizedXLayout,
                     getExtendedResponse,
                     validateUrl,
@@ -1915,6 +1942,11 @@
                         data: data
                     });
 
+                    // sort order
+                    if (xLayout.sortOrder) {
+                        store.sort(replacedColumnIds[0], xLayout.sortOrder === -1 ? 'ASC' : 'DESC');
+                    }
+
                     store.rangeFields = columnIds;
                     store.domainFields = [conf.finals.data.domain];
                     store.trendLineFields = trendLineFields;
@@ -2226,8 +2258,10 @@
                         trackMouse: true,
                         cls: 'dv-chart-tips',
                         renderer: function(si, item) {
-                            var value = item.value[1] === '0.0' ? '-' : item.value[1];
-                            this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + value + '</div><div style="font-size:10px">' + si.data[conf.finals.data.domain] + '</div></div>');
+                            if (item.value) {
+                                var value = item.value[1] === '0.0' ? '-' : item.value[1];
+                                this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + value + '</div><div style="font-size:10px">' + si.data[conf.finals.data.domain] + '</div></div>');
+                            }
                         }
                     };
                 };
@@ -2479,6 +2513,11 @@
                 generator.stackedcolumn = function() {
                     var chart = this.column();
 
+                    // sort order
+                    if (xLayout.sortOrder) {
+                        sortStoreBySum(chart.store, replacedColumnIds, xLayout.sortOrder);
+                    }
+
                     for (var i = 0, item; i < chart.series.items.length; i++) {
                         item = chart.series.items[i];
 
@@ -2565,6 +2604,11 @@
                 generator.stackedbar = function() {
                     var chart = this.bar();
 
+                    // sort order
+                    if (xLayout.sortOrder) {
+                        sortStoreBySum(chart.store, replacedColumnIds, xLayout.sortOrder);
+                    }
+
                     for (var i = 0, item; i < chart.series.items.length; i++) {
                         item = chart.series.items[i];
 
@@ -2652,7 +2696,7 @@
 
                 generator.area = function() {
 
-                    // NB, always on for area charts as area extjs area charts cannot handle nulls
+                    // NB, always true for area charts as extjs area charts cannot handle nulls
                     xLayout.hideEmptyRows = true;
                     
                     var store = getDefaultStore(),
@@ -2660,6 +2704,11 @@
                         categoryAxis = getDefaultCategoryAxis(store),
                         axes = [numericAxis, categoryAxis],
                         series = getDefaultSeries(store);
+                        
+                    // sort order
+                    if (xLayout.sortOrder) {
+                        sortStoreBySum(store, replacedColumnIds, xLayout.sortOrder);
+                    }
 
                     series.type = 'area';
                     series.style.opacity = 0.7;