← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18930: DV EV series fixes.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18930 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-17 01:55:45 +0200
message:
  DV EV series fixes.
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core.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-event-visualizer/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js	2015-04-11 17:59:06 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/app.js	2015-04-16 23:50:18 +0000
@@ -843,7 +843,7 @@
                         optionSetId = optionSetId || container.dataElement.optionSet.id;
                         pageSize = pageSize || 100;
 
-                        dhis2.er.store.get('optionSets', optionSetId).done( function(obj) {
+                        dhis2.ev.store.get('optionSets', optionSetId).done( function(obj) {
                             if (Ext.isObject(obj) && Ext.isArray(obj.options) && obj.options.length) {
                                 var data = [];
 
@@ -984,7 +984,7 @@
                         var me = this,
                             records = [];
 
-                        dhis2.er.store.get('optionSets', container.dataElement.optionSet.id).done( function(obj) {
+                        dhis2.ev.store.get('optionSets', container.dataElement.optionSet.id).done( function(obj) {
                             if (Ext.isObject(obj) && Ext.isArray(obj.options) && obj.options.length) {
                                 records = container.getRecordsByCode(obj.options, codeArray);
 
@@ -5824,6 +5824,8 @@
 			if (!updateGui) {
 				return;
 			}
+            
+			ns.app.viewport.chartType.setChartType(layout.type);
 
             setLayout(layout);
 		};
@@ -7680,7 +7682,8 @@
 
 				NS.instances.push(ns);
 
-				ns.core = NS.getCore(init);
+                ns.init = init;
+				ns.core = NS.getCore(ns);
 				extendCore(ns.core);
 
 				dimConf = ns.core.conf.finals.dimension;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js	2015-04-12 18:31:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-event-visualizer/scripts/core.js	2015-04-16 23:47:29 +0000
@@ -516,8 +516,9 @@
 	NS.isDebug = false;
 	NS.isSessionStorage = ('sessionStorage' in window && window['sessionStorage'] !== null);
 
-	NS.getCore = function(init) {
-        var conf = {},
+	NS.getCore = function(ns) {
+        var init = ns.init,
+            conf = {},
             api = {},
             support = {},
             service = {},
@@ -1234,6 +1235,26 @@
 				return array.length;
 			};
 
+            support.prototype.array.getMaxLength = function(array, suppressWarning) {
+				if (!Ext.isArray(array)) {
+					if (!suppressWarning) {
+						console.log('support.prototype.array.getLength: not an array');
+					}
+
+					return null;
+				}
+
+                var maxLength = 0;
+
+                for (var i = 0; i < array.length; i++) {
+                    if (Ext.isString(array[i]) && array[i].length > maxLength) {
+                        maxLength = array[i].length;
+                    }
+                }
+
+                return maxLength;
+            };
+
 			support.prototype.array.sort = function(array, direction, key, emptyFirst) {
 				// supports [number], [string], [{key: number}], [{key: string}], [[string]], [[number]]
 
@@ -2828,6 +2849,8 @@
                     getDefaultStore,
                     getDefaultNumericAxis,
                     getDefaultCategoryAxis,
+                    getFormatedSeriesTitle,
+                    getPieSeriesTitle,
                     getDefaultSeriesTitle,
                     getDefaultSeries,
                     getDefaultTrendLines,
@@ -3159,6 +3182,76 @@
                     return axis;
                 };
 
+                getFormatedSeriesTitle = function(titles) {
+                    var itemLength = ns.dashboard ? 23 : 30,
+                        charLength = ns.dashboard ? 5 : 6,
+                        numberOfItems = titles.length,
+                        numberOfChars,
+                        totalItemLength = numberOfItems * itemLength,
+                        //minLength = 5,
+                        maxLength = support.prototype.array.getMaxLength(titles),
+                        fallbackLength = 10,
+                        maxWidth = ns.app.centerRegion.getWidth(),
+                        width,
+                        validateTitles;
+
+                    getValidatedTitles = function(titles, len) {
+                        var numberOfItems = titles.length,
+                            newTitles,
+                            fallbackTitles;
+
+                        fallbackLength = len < fallbackLength ? len : fallbackLength;
+
+                        for (var i = len, width; i > 0; i--) {
+                            newTitles = [];
+
+                            for (var j = 0, title, numberOfChars, newTitle; j < titles.length; j++) {
+                                title = titles[j];
+
+                                newTitles.push(title.length > i ? (title.slice(0, i) + '..') : title);
+                            }
+
+                            numberOfChars = newTitles.join('').length;
+                            width = totalItemLength + (numberOfChars * charLength);
+
+                            if (i === fallbackLength) {
+                                fallbackTitles = Ext.clone(newTitles);
+                            }
+
+                            if (width < maxWidth) {
+                                return newTitles;
+                            }
+                        }
+
+                        return fallbackTitles;
+                    };
+
+                    return getValidatedTitles(titles, maxLength);
+                };
+
+                getPieSeriesTitle = function(store) {
+                    var a = [];
+
+                    if (Ext.isObject(xLayout.legendStyle) && Ext.isArray(xLayout.legendStyle.labelNames)) {
+                        return xLayout.legendStyle.labelNames;
+                    }
+                    else {
+                        var id = store.domainFields[0];
+
+                        store.each( function(r) {
+                            a.push(r.data[id]);
+
+                            //if (Ext.isString(name) && Ext.isObject(xLayout.legendStyle) && Ext.isNumber(xLayout.legendStyle.labelMaxLength)) {
+                                //var mxl = parseInt(xLayout.legendStyle.labelMaxLength);
+
+                                //name = name.length > mxl ? name.substr(0, mxl) + '..' : name;
+                            //}
+                        });
+                    }
+
+                    return getFormatedSeriesTitle(a);
+				};
+
                 getDefaultSeriesTitle = function(store) {
                     var a = [],
                         md = xResponse.metaData;
@@ -3556,34 +3649,47 @@
                 getDefaultChart = function(config) {
                     var chart,
                         store = config.store || {},
+                        width = ns.app.centerRegion.getWidth(),
+                        height = ns.app.centerRegion.getHeight(),
+                        isLineBased = Ext.Array.contains(['line', 'area'], xLayout.type),
                         defaultConfig = {
-                            animate: true,
+                            //animate: true,
+                            animate: false,
                             shadow: false,
-                            insetPadding: 35,
-                            width: centerRegion.getWidth() - 15,
-                            height: centerRegion.getHeight() - 40,
+                            insetPadding: ns.dashboard ? 17 : 35,
+                            insetPaddingObject: {
+                                top: ns.dashboard ? 12 : 32,
+                                right: ns.dashboard ? (isLineBased ? 5 : 3) : (isLineBased ? 25 : 15),
+                                bottom: ns.dashboard ? 2 : 10,
+                                left: ns.dashboard ? (isLineBased ? 15 : 7) : (isLineBased ? 70 : 50)
+                            },
+                            width: ns.dashboard ? width : width - 15,
+                            height: ns.dashboard ? height : height - 40,
                             theme: 'dv1'
                         };
-
+                        
                     // legend
                     if (!xLayout.hideLegend) {
-                        defaultConfig.legend = getDefaultLegend(store);
+                        defaultConfig.legend = getDefaultLegend(store, config);
 
                         if (defaultConfig.legend.position === 'right') {
-                            defaultConfig.insetPadding = 40;
+                            defaultConfig.insetPaddingObject.top = ns.dashboard ? 22 : 40;
+                            defaultConfig.insetPaddingObject.right = ns.dashboard ? 5 : 40;
                         }
                     }
 
                     // title
-                    if (!xLayout.hideTitle) {
+                    if (xLayout.hideTitle) {
+                        defaultConfig.insetPadding = ns.dashboard ? 1 : 10;
+                        defaultConfig.insetPaddingObject.top = ns.dashboard ? 3 : 10;
+                    }
+                    else {
                         defaultConfig.items = [getDefaultChartTitle(store)];
                     }
-                    else {
-                        defaultConfig.insetPadding = 10;
-                    }
 
                     Ext.apply(defaultConfig, config);
 
+                    // chart
                     chart = Ext.create('Ext.chart.Chart', defaultConfig);
 
                     chart.setChartSize = getDefaultChartSizeHandler();
@@ -3595,7 +3701,7 @@
                         chart.setTitlePosition();
                     };
 
-                    chart.on('afterrender', function() {
+                    chart.on('resize', function() {
                         chart.setTitlePosition();
                     });
 
@@ -3858,12 +3964,34 @@
 
                     // Label
                     if (xLayout.showValues) {
+                        var labelFont = conf.chart.style.fontFamily,
+                            labelColor;
+
+                        if (Ext.isObject(xLayout.seriesStyle)) {
+                            var style = xLayout.seriesStyle;
+
+                            // color
+                            labelColor = style.labelColor || labelColor;
+
+                            if (style.labelFont) {
+                                labelFont = style.labelFont;
+                            }
+                            else {
+                                labelFont = style.labelFontWeight ? style.labelFontWeight + ' ' : 'normal ';
+                                labelFont += style.labelFontSize ? parseFloat(style.labelFontSize) + 'px ' : '11px ';
+                                labelFont +=  style.labelFontFamily ? style.labelFontFamily : conf.chart.style.fontFamily;
+                            }
+                        }
+
                         label.display = 'middle';
-                        label.contrast = true;
-                        label.font = '14px ' + conf.chart.style.fontFamily;
+                        label.contrast = !labelColor;
+                        label.font = labelFont;
+                        label.fill = labelColor;
                         label.renderer = function(value) {
-                            var record = store.getAt(store.findExact(conf.finals.data.domain, value));
-                            return record.data[store.rangeFields[0]];
+                            var record = store.getAt(store.findExact(conf.finals.data.domain, value)),
+                                v = record.data[store.rangeFields[0]];
+                                
+                            return support.prototype.number.prettyPrint(v);
                         };
                     }
 
@@ -3871,7 +3999,7 @@
                     series = [{
                         type: 'pie',
                         field: store.rangeFields[0],
-                        donut: 7,
+                        donut: 5,
                         showInLegend: true,
                         highlight: {
                             segment: {
@@ -3887,9 +4015,14 @@
                             trackMouse: true,
                             cls: 'dv-chart-tips',
                             renderer: function(item) {
-                                this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + item.data[store.rangeFields[0]] + '</div><div style="font-size:10px">' + item.data[conf.finals.data.domain] + '</div></div>');
+                                var value = support.prototype.number.prettyPrint(item.data[store.rangeFields[0]]),
+                                    data = item.data[conf.finals.data.domain];
+                                    
+                                this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + value + '</div><div style="font-size:10px">' + data + '</div></div>');
                             }
-                        }
+                        },
+                        shadowAttributes: false,
+                        title: getPieSeriesTitle(store)
                     }];
 
                     // Theme
@@ -3904,17 +4037,18 @@
                         }
                     });
 
-                    // Chart
+                    // chart
                     chart = getDefaultChart({
                         store: store,
-                        series: series
+                        series: series,
+                        insetPaddingObject: {
+                            top: ns.dashboard ? 15 : 40,
+                            right: ns.dashboard ? 2 : 30,
+                            bottom: ns.dashboard ? 13: 30,
+                            left: ns.dashboard ? 7 : 30
+                        }
                     });
 
-                    //chart.legend.position = 'right';
-                    //chart.legend.isVertical = true;
-                    chart.insetPadding = 40;
-                    chart.shadow = true;
-
                     return chart;
                 };
 

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js	2015-04-12 20:00:37 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/app.js	2015-04-16 08:51:08 +0000
@@ -5800,7 +5800,7 @@
 				});
 
 				window = Ext.create('Ext.window.Window', {
-                    title: 'Embed in web page' + '<span style="font-weight:normal">&nbsp;|&nbsp;&nbsp;' + ns.app.layout.name + '</span>',
+                    title: 'Embed in web page' + (ns.app.layout.name ? '<span style="font-weight:normal">&nbsp;|&nbsp;&nbsp;' + ns.app.layout.name + '</span>' : ''),
 					layout: 'fit',
 					modal: true,
 					resizable: false,

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core.js	2015-04-12 18:31:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-pivot/scripts/core.js	2015-04-16 08:51:08 +0000
@@ -1671,6 +1671,10 @@
 					delete layout.showRowSubTotals;
 				}
 
+				if (layout.showDimensionLabels) {
+					delete layout.showDimensionLabels;
+				}
+
 				if (!layout.hideEmptyRows) {
 					delete layout.hideEmptyRows;
 				}

=== 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	2015-04-12 18:31:24 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-visualizer/scripts/core.js	2015-04-16 22:30:22 +0000
@@ -3201,7 +3201,7 @@
                             shadow: false,
                             insetPadding: ns.dashboard ? 17 : 35,
                             insetPaddingObject: {
-                                top: ns.dashboard ? 12 : 22,
+                                top: ns.dashboard ? 12 : 32,
                                 right: ns.dashboard ? (isLineBased ? 5 : 3) : (isLineBased ? 25 : 15),
                                 bottom: ns.dashboard ? 2 : 10,
                                 left: ns.dashboard ? (isLineBased ? 15 : 7) : (isLineBased ? 70 : 50)
@@ -3210,7 +3210,7 @@
                             height: ns.dashboard ? height : height - 40,
                             theme: 'dv1'
                         };
-
+                        
                     // legend
                     if (!xLayout.hideLegend) {
                         defaultConfig.legend = getDefaultLegend(store, config);
@@ -3531,8 +3531,10 @@
                         label.font = labelFont;
                         label.fill = labelColor;
                         label.renderer = function(value) {
-                            var record = store.getAt(store.findExact(conf.finals.data.domain, value));
-                            return record.data[store.rangeFields[0]];
+                            var record = store.getAt(store.findExact(conf.finals.data.domain, value)),
+                                v = record.data[store.rangeFields[0]];
+                                
+                            return support.prototype.number.prettyPrint(v);
                         };
                     }
 
@@ -3556,7 +3558,10 @@
                             trackMouse: true,
                             cls: 'dv-chart-tips',
                             renderer: function(item) {
-                                this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + item.data[store.rangeFields[0]] + '</div><div style="font-size:10px">' + item.data[conf.finals.data.domain] + '</div></div>');
+                                var value = support.prototype.number.prettyPrint(item.data[store.rangeFields[0]]),
+                                    data = item.data[conf.finals.data.domain];
+                                    
+                                this.update('<div style="text-align:center"><div style="font-size:17px; font-weight:bold">' + value + '</div><div style="font-size:10px">' + data + '</div></div>');
                             }
                         },
                         shadowAttributes: false,
@@ -3580,10 +3585,10 @@
                         store: store,
                         series: series,
                         insetPaddingObject: {
-                            top: 15,
-                            right: 2,
-                            bottom: 13,
-                            left: 7
+                            top: ns.dashboard ? 15 : 40,
+                            right: ns.dashboard ? 2 : 30,
+                            bottom: ns.dashboard ? 13: 30,
+                            left: ns.dashboard ? 7 : 30
                         }
                     });