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] account for bounds = 0 (#3474)
Date Tue, 19 Sep 2017 04:32:41 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 c5252d0  [heatmap] account for bounds = 0 (#3474)
c5252d0 is described below

commit c5252d0f43621999030d3dcf3d2e8bfee5452510
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Mon Sep 18 21:32:39 2017 -0700

    [heatmap] account for bounds = 0 (#3474)
    
    * [heatmap] account for bounds = 0
    
    * Fix sorting
    
    * linting
---
 .../assets/javascripts/explore/stores/controls.jsx     |  8 ++++----
 superset/assets/visualizations/heatmap.js              | 18 +++++++++++++-----
 superset/viz.py                                        |  4 ++--
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx
index b87e988..c226f66 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -37,10 +37,10 @@ const timeColumnOption = {
     'account'),
 };
 const sortAxisChoices = [
-  ['alpha_asc', 'Alphabetical ascending'],
-  ['alpha_desc', 'Alphabetical descending'],
-  ['value_asc', 'Value ascending'],
-  ['value_desc', 'Value descending'],
+  ['alpha_asc', 'Axis ascending'],
+  ['alpha_desc', 'Axis descending'],
+  ['value_asc', 'sum(value) ascending'],
+  ['value_desc', 'sum(value) descending'],
 ];
 
 const groupByControl = {
diff --git a/superset/assets/visualizations/heatmap.js b/superset/assets/visualizations/heatmap.js
index 1f76a3a..002af8a 100644
--- a/superset/assets/visualizations/heatmap.js
+++ b/superset/assets/visualizations/heatmap.js
@@ -7,6 +7,10 @@ import { colorScalerFactory } from '../javascripts/modules/colors';
 import '../stylesheets/d3tip.css';
 import './heatmap.css';
 
+function cmp(a, b) {
+  return a > b ? 1 : -1;
+}
+
 // Inspired from http://bl.ocks.org/mbostock/3074470
 // https://jsfiddle.net/cyril123/h0reyumq/
 function heatmapVis(slice, payload) {
@@ -52,17 +56,21 @@ function heatmapVis(slice, payload) {
 
   function ordScale(k, rangeBands, sortMethod) {
     let domain = {};
+    const actualKeys = {};  // hack to preserve type of keys when number
     data.forEach((d) => {
-      domain[d[k]] = domain[d[k]] || 0 + d.v;
+      domain[d[k]] = (domain[d[k]] || 0) + d.v;
+      actualKeys[d[k]] = d[k];
     });
+    // Not usgin object.keys() as it converts to strings
+    const keys = Object.keys(actualKeys).map(s => actualKeys[s]);
     if (sortMethod === 'alpha_asc') {
-      domain = Object.keys(domain).sort();
+      domain = keys.sort(cmp);
     } else if (sortMethod === 'alpha_desc') {
-      domain = Object.keys(domain).sort().reverse();
+      domain = keys.sort(cmp).reverse();
     } else if (sortMethod === 'value_desc') {
-      domain = Object.keys(domain).sort((d1, d2) => domain[d2] - domain[d1]);
+      domain = Object.keys(domain).sort((a, b) => domain[a] > domain[b] ? -1 : 1);
     } else if (sortMethod === 'value_asc') {
-      domain = Object.keys(domain).sort((d1, d2) => domain[d1] - domain[d2]);
+      domain = Object.keys(domain).sort((a, b) => domain[b] > domain[a] ? -1 : 1);
     }
 
     if (k === 'y' && rangeBands) {
diff --git a/superset/viz.py b/superset/viz.py
index 1f844ed..b22af08 100644
--- a/superset/viz.py
+++ b/superset/viz.py
@@ -1484,9 +1484,9 @@ class HeatmapViz(BaseViz):
         max_ = df.v.max()
         min_ = df.v.min()
         bounds = fd.get('y_axis_bounds')
-        if bounds and bounds[0]:
+        if bounds and bounds[0] is not None:
             min_ = bounds[0]
-        if bounds and bounds[1]:
+        if bounds and bounds[1] is not None:
             max_ = bounds[1]
         if norm == 'heatmap':
             overall = True

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

Mime
View raw message