← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18072: Dashboard, event chart legend names.

 

Merge authors:
  Jan Henrik Øverland (janhenrik-overland)
------------------------------------------------------------
revno: 18072 [merge]
committer: Jan Henrik Overland <janhenrik.overland@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-01-20 18:44:08 +0100
message:
  Dashboard, event chart legend names.
modified:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.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-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js	2015-01-19 16:34:04 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/eventchart.js	2015-01-20 17:42:18 +0000
@@ -1221,6 +1221,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) {
 				// supports [number], [string], [{key: number}], [{key: string}], [[string]], [[number]]
 
@@ -2668,6 +2688,7 @@
                     getDefaultStore,
                     getDefaultNumericAxis,
                     getDefaultCategoryAxis,
+                    getFormatedSeriesTitle,
                     getDefaultSeriesTitle,
                     getPieSeriesTitle,
                     getDefaultSeries,
@@ -3082,6 +3103,53 @@
                     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 >= minLength; 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);
+                };
+
                 getDefaultSeriesTitle = function(store) {
                     var a = [];
 
@@ -3093,17 +3161,17 @@
                             id = failSafeColumnIdMap[store.rangeFields[i]];
                             name = xResponse.metaData.optionNames[id] || xResponse.metaData.names[id];
 
-                            if (Ext.isString(name) && Ext.isObject(xLayout.legendStyle) && Ext.isNumber(xLayout.legendStyle.labelMaxLength)) {
-                                var mxl = parseInt(xLayout.legendStyle.labelMaxLength);
+                            //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;
-                            }
+                                //name = name.length > mxl ? name.substr(0, mxl) + '..' : name;
+                            //}
 
                             a.push(name);
                         }
                     }
 
-                    return a;
+                    return getFormatedSeriesTitle(a);
 				};
 
                 getPieSeriesTitle = function(store) {
@@ -3117,17 +3185,17 @@
                             id = rowIds[i];
                             name = xResponse.metaData.optionNames[id] || xResponse.metaData.names[id];
 
-                            if (Ext.isString(name) && Ext.isObject(xLayout.legendStyle) && Ext.isNumber(xLayout.legendStyle.labelMaxLength)) {
-                                var mxl = parseInt(xLayout.legendStyle.labelMaxLength);
+                            //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;
-                            }
+                                //name = name.length > mxl ? name.substr(0, mxl) + '..' : name;
+                            //}
 
                             a.push(name);
                         }
                     }
 
-                    return a;
+                    return getFormatedSeriesTitle(a);
 				};
 
                 getDefaultSeries = function(store) {

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js	2015-01-19 16:07:50 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/plugin/table.js	2015-01-20 16:23:39 +0000
@@ -3287,7 +3287,7 @@
 					getXResponse = service.response.getExtendedResponse,
 					getXAxis = service.layout.getExtendedAxis,
                     getTitleHtml = function(title) {
-                        return ns.dashboard && title ? '<div style="height: 19px; line-height: 14px; width: 100%; font: bold 12px LiberationSans; color: #333; text-align: center">' + title + '</div>' : '';
+                        return ns.dashboard && title ? '<div style="height: 19px; line-height: 14px; width: 100%; font: bold 12px LiberationSans; color: #333; text-align: center; letter-spacing: -0.1px"">' + title + '</div>' : '';
                     };
 
 				getHtml = function(xLayout, xResponse) {