Browse Source

HUE-4225 [editor] Colors are flipped when sorting bar results in reverse order

Enrico Berti 9 years ago
parent
commit
406fb88

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/hue.colors.js

@@ -52,6 +52,9 @@ var HueColors = {
   d3Scale: function () {
     return d3.scale.category20().range().concat(d3.scale.category20b().range().concat(d3.scale.category20c().range()));
   },
+  cuiD3Scale: function () {
+    return ['#29A7DE', '#417575', '#00B9AA', '#0F9D56', '#69AC13', '#E99F01', '#D0021B', '#D8276F', '#7B46AD', '#1C749B', '#2D5252', '#008177', '#0A6E3C', '#49780D', '#A36F00', '#910112', '#971B4D', '#62388A', '#A9DBF1', '#A0BABA', '#80DCD5', '#87CEAB', '#B4D689', '#EDC582', '#FFE5E5', '#EC93B7', '#BDA3D6'];
+  },
   LIGHT_BLUE: "#DBE8F1",
   BLUE: "#87BAD5",
   DARK_BLUE: "#338BB8",

+ 2 - 2
desktop/core/src/desktop/static/desktop/js/nv.d3.growingPie.js

@@ -174,8 +174,8 @@ nv.models.growingPie = function() {
               });
 
         slices
-            .attr('fill', function(d,i) { return color(d, i); })
-            .attr('stroke', function(d,i) { return color(d, i); });
+            .attr('fill', function(d,i) { return d.data.color || color(d,i) })
+            .attr('stroke', function(d,i) { return d.data.color || color(d,i) });
 
         var paths = ae.append('path')
             .each(function(d) { this._current = d; });

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

@@ -920,7 +920,7 @@ nv.utils.getColor = function(color) {
 
 // Default color chooser uses the index of an object as before.
 nv.utils.defaultColor = function() {
-    var colors = d3.scale.ordinal().range(['#29A7DE', '#417575', '#00B9AA', '#0F9D56', '#69AC13', '#E99F01', '#D0021B', '#D8276F', '#7B46AD', '#1C749B', '#2D5252', '#008177', '#0A6E3C', '#49780D', '#A36F00', '#910112', '#971B4D', '#62388A', '#A9DBF1', '#A0BABA', '#80DCD5', '#87CEAB', '#B4D689', '#EDC582', '#FFE5E5', '#EC93B7', '#BDA3D6']).range();
+    var colors = d3.scale.ordinal().range(HueColors.cuiD3Scale()).range();
     return function(d, i) { return d.color || colors[i % colors.length] };
 }
 

+ 4 - 0
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -2336,6 +2336,7 @@ ${ hueIcons.symbols() }
           _idxValue = idx;
         }
       });
+      var colors = HueColors.cuiD3Scale();
       $(rawDatum.counts()).each(function (cnt, item) {
         var val = item[_idxValue] * 1;
         if (isNaN(val)) {
@@ -2344,6 +2345,7 @@ ${ hueIcons.symbols() }
         _data.push({
           label: hueUtils.html2text(item[_idxLabel]),
           value: val,
+          color: colors[cnt % colors.length],
           obj: item
         });
       });
@@ -2449,11 +2451,13 @@ ${ hueIcons.symbols() }
 
         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
             });
           });