superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: [heatmap] fix default sorting (#3450)
Date Tue, 12 Sep 2017 16:06:05 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new f3de758  [heatmap] fix default sorting (#3450)
f3de758 is described below

commit f3de758363cc4cd533a3e8a8a6225aa05836ed46
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Tue Sep 12 09:06:03 2017 -0700

    [heatmap] fix default sorting (#3450)
    
    Currently the heatmap axis are sorted randomly, this PR makes it such
    that it's properly sorted.
    
    Also allowing for specifying the left and bottom margins
---
 .../assets/javascripts/explore/stores/visTypes.js  |  1 +
 superset/assets/visualizations/heatmap.js          | 24 ++++++++++++++--------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/superset/assets/javascripts/explore/stores/visTypes.js b/superset/assets/javascripts/explore/stores/visTypes.js
index 318d3327..fad261c 100644
--- a/superset/assets/javascripts/explore/stores/visTypes.js
+++ b/superset/assets/javascripts/explore/stores/visTypes.js
@@ -943,6 +943,7 @@ export const visTypes = {
           ['xscale_interval', 'yscale_interval'],
           ['canvas_image_rendering'],
           ['normalize_across'],
+          ['left_margin', 'bottom_margin'],
         ],
       },
     ],
diff --git a/superset/assets/visualizations/heatmap.js b/superset/assets/visualizations/heatmap.js
index dad613f..af03739 100644
--- a/superset/assets/visualizations/heatmap.js
+++ b/superset/assets/visualizations/heatmap.js
@@ -21,22 +21,31 @@ function heatmapVis(slice, payload) {
   };
 
   const data = payload.data;
+  const fd = slice.formData;
   // Dynamically adjusts  based on max x / y category lengths
   function adjustMargins() {
     const pixelsPerCharX = 4.5; // approx, depends on font size
-    const pixelsPerCharY = 6.8; // approx, depends on font size
+    const pixelsPerCharY = 10; // approx, depends on font size
     let longestX = 1;
     let longestY = 1;
     let datum;
 
     for (let i = 0; i < data.length; i++) {
       datum = data[i];
-      longestX = Math.max(longestX, datum.x.length || 1);
-      longestY = Math.max(longestY, datum.y.length || 1);
+      longestX = Math.max(longestX, datum.x.toString().length || 1);
+      longestY = Math.max(longestY, datum.y.toString().length || 1);
     }
 
-    margin.left = Math.ceil(Math.max(margin.left, pixelsPerCharY * longestY));
-    margin.bottom = Math.ceil(Math.max(margin.bottom, pixelsPerCharX * longestX));
+    if (fd.left_margin === 'auto') {
+      margin.left = Math.ceil(Math.max(margin.left, pixelsPerCharY * longestY));
+    } else {
+      margin.left = fd.left_margin;
+    }
+    if (fd.bottom_margin === 'auto') {
+      margin.bottom = Math.ceil(Math.max(margin.bottom, pixelsPerCharX * longestX));
+    } else {
+      margin.bottom = fd.bottom_margin;
+    }
   }
 
   function ordScale(k, rangeBands, reverse = false) {
@@ -44,9 +53,7 @@ function heatmapVis(slice, payload) {
     $.each(data, function (i, d) {
       domain[d[k]] = true;
     });
-    domain = Object.keys(domain).sort(function (a, b) {
-      return b - a;
-    });
+    domain = Object.keys(domain).sort();
     if (reverse) {
       domain.reverse();
     }
@@ -58,7 +65,6 @@ function heatmapVis(slice, payload) {
 
   slice.container.html('');
   const matrix = {};
-  const fd = slice.formData;
 
   adjustMargins();
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message