Skip to content

Commit

Permalink
Fix off-by-one error with linear color scales (#3452)
Browse files Browse the repository at this point in the history
* Fix off-by-one error with linear color scales

* linting
  • Loading branch information
mistercrunch authored Sep 12, 2017
1 parent fe77534 commit 90e46cb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 1 addition & 0 deletions superset/assets/javascripts/explore/stores/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const controls = {
['black_white', 'black/white'],
],
default: 'blue_white_yellow',
clearable: false,
description: '',
renderTrigger: true,
schemes: spectrums,
Expand Down
8 changes: 2 additions & 6 deletions superset/assets/javascripts/modules/colors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import $ from 'jquery';
import d3 from 'd3';

// Color related utility functions go in this object
Expand Down Expand Up @@ -127,10 +126,7 @@ export const colorScalerFactory = function (colors, data, accessor) {
if (data !== undefined) {
ext = d3.extent(data, accessor);
}
const points = [];
const chunkSize = (ext[1] - ext[0]) / colors.length;
$.each(colors, function (i) {
points.push(i * chunkSize);
});
const chunkSize = (ext[1] - ext[0]) / (colors.length - 1);
const points = colors.map((col, i) => i * chunkSize);
return d3.scale.linear().domain(points).range(colors);
};

0 comments on commit 90e46cb

Please sign in to comment.