Skip to content

Commit

Permalink
[heatmap] account for bounds = 0 (#3474)
Browse files Browse the repository at this point in the history
* [heatmap] account for bounds = 0

* Fix sorting

* linting
  • Loading branch information
mistercrunch authored Sep 19, 2017
1 parent ede1432 commit c5252d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
8 changes: 4 additions & 4 deletions superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
18 changes: 13 additions & 5 deletions superset/assets/visualizations/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,9 +1484,9 @@ def get_data(self, df):
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
Expand Down

0 comments on commit c5252d0

Please sign in to comment.