cubesviewer icon indicating copy to clipboard operation
cubesviewer copied to clipboard

Chart shows the measure name, not the measure label

Open bdauvergne opened this issue 9 years ago • 2 comments

I think that in a chat the y-axis should be labeled using the measure label. I can work on it if I'm given some direction.

bdauvergne avatar Nov 20 '15 12:11 bdauvergne

I'd love to see this happen @bdauvergne, but I don't have time to really dig in to it. I experimented today and came up with this, which hopefully is the direction you're looking for? Fork the repository, make these changes, and see where you get.

You'll still need to read through a LOT of javascript files and use your browser developer tools to set breakpoints, etc, to finish it.

diff --git a/src/web/static/js/cubesviewer/cubesviewer.views.cube.chart.js b/src/web/static/js/cubesviewer/cubesviewer.views.cube.chart.js
index aca1462..50aa527 100644
--- a/src/web/static/js/cubesviewer/cubesviewer.views.cube.chart.js
+++ b/src/web/static/js/cubesviewer/cubesviewer.views.cube.chart.js
@@ -305,6 +305,35 @@ function cubesviewerViewCubeChart() {

   };

+  this.findLabel = function(view, name) {
+    //check for a label in aggregates first
+    //then check in dimensions
+    to_return = "";
+    $(view.cube.aggregates).each(function(idx, agg) {
+      if (name === agg.name) {
+        to_return = agg.label || agg.name;
+        return false; //break
+      }
+    });
+    if (to_return !== "") {
+      return to_return;
+    }
+
+    $(view.cube.dimensions).each(function(idx, dim) {
+      if (name === dim.name) {
+        to_return = dim.label || dim.name;
+        return false; //break
+      }
+    });
+    if (to_return !== "") {
+      return to_return;
+    }
+
+    //fallback to using the name
+    return name;
+  };
+
        /**
         * Draws a vertical bars chart.
         */
@@ -320,11 +349,12 @@ function cubesviewerViewCubeChart() {
            $(dataRows).each(function(idx, e) {
                serie = [];
                for (var i = 1; i < colNames.length; i++) {
+                       var label = this.findLabel(view, colNames[i]);
                        var value = e[colNames[i]];
                        if (value != undefined) {
-                               serie.push( { "x": colNames[i], "y":  value } );
+                               serie.push( { "x": label, "y":  value } );
                        } else {
-                               serie.push( { "x": colNames[i], "y":  0} );
+                               serie.push( { "x": label, "y":  0} );
                        }
                }
                var series = { "values": serie, "key": e["key"] != "" ? e["key"] : view.params.yaxis };
@@ -335,7 +365,7 @@ function cubesviewerViewCubeChart() {
                }
                d.push(series);
                serieCount++;
-           });
+           }.bind(this));
            d.sort(function(a,b) { return a.key < b.key ? -1 : (a.key > b.key ? +1 : 0) });

            /*

devvmh avatar Dec 29 '15 07:12 devvmh

This shall be fixed by 2174b95, still in the devel branch.

Will keep this open until 2.0 is out and resolution is confirmed.

jjmontesl avatar May 23 '16 02:05 jjmontesl