Skip to content

Commit

Permalink
fix(core): show a useful error message when a scheme contains invalid…
Browse files Browse the repository at this point in the history
… colors
  • Loading branch information
tuner committed Nov 27, 2024
1 parent 861c0c9 commit 7b637fb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/core/src/gl/colorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,17 @@ function colorArrayToTextureData(scheme, count) {

const textureData = new Uint8Array(size * 3);
for (let i = 0; i < size; i++) {
const color = d3color(scheme[i % scheme.length]).rgb();
textureData[i * 3 + 0] = color.r;
textureData[i * 3 + 1] = color.g;
textureData[i * 3 + 2] = color.b;
const colorString = scheme[i % scheme.length];
const color = d3color(colorString);
if (!color) {
throw new Error(
`Invalid color "${colorString}" in the scheme ${JSON.stringify(scheme)}!`
);
}
const rgb = color.rgb();
textureData[i * 3 + 0] = rgb.r;
textureData[i * 3 + 1] = rgb.g;
textureData[i * 3 + 2] = rgb.b;
}
return textureData;
}

0 comments on commit 7b637fb

Please sign in to comment.