Skip to content

Commit

Permalink
fixes bucket scales with less values than colors
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Mar 20, 2019
1 parent cc6a31c commit 1102bb2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
},
"dependencies": {
"d3-array": "^1.2.1",
"d3-interpolate": "^1.2.0",
"d3-scale": "^2.0.0",
"d3-selection": "^1.3.0",
"d3plus-axis": "^0.4.4",
Expand Down
9 changes: 1 addition & 8 deletions src/ColorScale.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ckmeans from "./ckmeans";
import Legend from "./Legend";

import {extent, merge, range} from "d3-array";
import {interpolateHsl} from "d3-interpolate";
import {scaleLinear, scaleThreshold} from "d3-scale";
import {select} from "d3-selection";

Expand Down Expand Up @@ -113,13 +112,7 @@ export default class ColorScale extends BaseClass {
.filter(d => d !== null && typeof d === "number");

if (data.length <= colors.length) {

const ts = scaleLinear()
.domain(range(0, data.length - 1))
.interpolate(interpolateHsl)
.range(colors);

colors = data.slice(0, data.length - 1).map((d, i) => ts(i));
colors = colors.slice(colors.length - data.length);
}

const jenks = ckmeans(data, colors.length);
Expand Down

0 comments on commit 1102bb2

Please sign in to comment.