Greater-London-Authority / ldn-viz-tools

https://greater-london-authority.github.io/ldn-viz-tools/
1 stars 0 forks source link

create utils package including color functions #189

Closed jamesscottbrown closed 5 months ago

jamesscottbrown commented 7 months ago

What does this change?

This adds the definitions of ldnColors, theme, getColorScale(), and getThresholdBreaksColorsLabels() from https://observablehq.com/@ldn/color-system, so that they can be easily imported by chart components or projects.

After this has been published to npm, the notebook can be updated to import the functions form @ldn-viz/charts, so that there is a single source-of-truth.

The functions swatch()/swatches()/swatchGrid()/asRamp()/ramp() haven't been added, as they are specific to showing color schemes/ramps in Observable notebooks.

This replaces https://github.com/Greater-London-Authority/ldn-viz-tools/pull/185.

jamesscottbrown commented 7 months ago

We've decided to move these color functions to the themes package instead.

jamesscottbrown commented 7 months ago

Actually we'll put them in utils.

jamesscottbrown commented 6 months ago

@mikeldn, since getColorScale() returns an array of colors, how would you feel about renaming it to something like getColorScheme() (since what it returns is similar to, e.g. d3.schemeBlues[9]) or getColorRamp()?

We could then use the name getColorScale() for a function that constructs a d3.scaleOrdinal color scale.

mikeldn commented 6 months ago

@jamesscottbrown hmm... good point. It's not really returning a scale is it.. you're right. I think getColorRamp() is best. If we used scheme, you might expect to be able to pass it in ('blue') and get back a blue scheme... which isn't a terrible idea actually :) (But actually that is in ldnColors.perceptual.blue.... (all of which need work).

so, yes, getColorRamp() is good. Don't forget that getThresholdBreaksColorsLabels() uses it, so will need changing too.