Browse Source

HUE-4890 [editor] Graph bars are not in the same order as the column legend

Enrico Berti 9 years ago
parent
commit
4f073c2

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/nv.d3.growingDiscreteBar.js

@@ -65,6 +65,7 @@ nv.models.growingDiscreteBar = function() {
       data.forEach(function(series, i) {
         series.values.forEach(function(point) {
           point.series = i;
+          point.seriesKey = series.key;
         });
       });
 

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/nv.d3.growingDiscreteBarChart.js

@@ -69,7 +69,7 @@ nv.models.growingDiscreteBarChart = function() {
         top = e.pos[1] + ( offsetElement.offsetTop || 0),
         x = xAxis.tickFormat()(discretebar.x()(e.point, e.pointIndex)),
         y = yAxis.tickFormat()(discretebar.y()(e.point, e.pointIndex)),
-        content = tooltip(e.series.key, x, y, e, chart);
+        content = tooltip(e.point.seriesKey, x, y, e, chart);
 
     nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
   };

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/nv.d3.growingMultiBar.js

@@ -88,6 +88,7 @@ nv.models.growingMultiBar = function() {
       data.forEach(function(series, i) {
         series.values.forEach(function(point) {
           point.series = i;
+          point.seriesKey = series.key;
         });
       });
 

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/nv.d3.growingMultiBarChart.js

@@ -85,7 +85,7 @@ nv.models.growingMultiBarChart = function() {
         top = e.pos[1] + ( offsetElement.offsetTop || 0),
         x = xAxis.tickFormat()(multibar.x()(e.point, e.pointIndex)),
         y = yAxis.tickFormat()(multibar.y()(e.point, e.pointIndex)),
-        content = tooltip(e.series.key, x, y, e, chart);
+        content = tooltip(e.point.seriesKey, x, y, e, chart);
 
     nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
   };

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/nv.d3.multiBarWithBrushChart.js

@@ -98,7 +98,7 @@ nv.models.multiBarWithBrushChart = function() {
         top = e.pos[1] + ( offsetElement.offsetTop || 0),
         x = xAxis.tickFormat()(multibar.x()(e.point, e.pointIndex)),
         y = yAxis.tickFormat()(multibar.y()(e.point, e.pointIndex)),
-        content = tooltip(e.series.key, x, y, e, chart);
+        content = tooltip(e.point.seriesKey, x, y, e, chart);
 
     nv.tooltip.show([left, top], content, e.value < 0 ? 'n' : 's', null, offsetElement);
   };

+ 40 - 36
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -2654,47 +2654,51 @@ ${ hueIcons.symbols() }
 
     if (rawDatum.snippet.chartX() != null && rawDatum.snippet.chartYMulti().length > 0) {
       var _plottedSerie = 0;
-      rawDatum.snippet.chartYMulti().forEach(function (col) {
-        var _idxValue = -1;
-        var _idxLabel = -1;
-        var _isXDate = false;
-        rawDatum.snippet.result.meta().forEach(function (icol, idx) {
-          if (icol.name == rawDatum.snippet.chartX()) {
-            _isXDate = icol.type.toUpperCase().indexOf('DATE') > -1;
-            _idxLabel = idx;
-          }
-          if (icol.name == col) {
-            _idxValue = idx;
-          }
-        });
 
-        if (_idxValue > -1) {
-          var _data = [];
-          var colors = HueColors.cuiD3Scale();
-          $(rawDatum.counts()).each(function (cnt, item) {
-            _data.push({
-              series: _plottedSerie,
-              x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
-              y: item[_idxValue]*1,
-              color: colors[cnt % colors.length],
-              obj: item
-            });
+      rawDatum.snippet.result.meta().forEach(function (meta) {
+        if (rawDatum.snippet.chartYMulti().indexOf(meta.name) > -1) {
+          var col = meta.name;
+          var _idxValue = -1;
+          var _idxLabel = -1;
+          var _isXDate = false;
+          rawDatum.snippet.result.meta().forEach(function (icol, idx) {
+            if (icol.name == rawDatum.snippet.chartX()) {
+              _isXDate = icol.type.toUpperCase().indexOf('DATE') > -1;
+              _idxLabel = idx;
+            }
+            if (icol.name == col) {
+              _idxValue = idx;
+            }
           });
-          if (rawDatum.sorting == "asc") {
-            _data.sort(function (a, b) {
-              return a.y - b.y
+
+          if (_idxValue > -1) {
+            var _data = [];
+            var colors = HueColors.cuiD3Scale();
+            $(rawDatum.counts()).each(function (cnt, item) {
+              _data.push({
+                series: _plottedSerie,
+                x: _isXDate ? moment(item[_idxLabel]) : hueUtils.html2text(item[_idxLabel]),
+                y: item[_idxValue] * 1,
+                color: colors[cnt % colors.length],
+                obj: item
+              });
             });
-          }
-          if (rawDatum.sorting == "desc") {
-            _data.sort(function (a, b) {
-              return b.y - a.y
+            if (rawDatum.sorting == "asc") {
+              _data.sort(function (a, b) {
+                return a.y - b.y
+              });
+            }
+            if (rawDatum.sorting == "desc") {
+              _data.sort(function (a, b) {
+                return b.y - a.y
+              });
+            }
+            _datum.push({
+              key: col,
+              values: _data
             });
+            _plottedSerie++;
           }
-          _datum.push({
-            key: col,
-            values: _data
-          });
-          _plottedSerie++;
         }
       });
     }