|
1 | 1 | import { useMemo } from 'react' |
| 2 | +import isPlainObject from 'lodash/isPlainObject.js' |
2 | 3 | import { ScaleDiverging, ScaleQuantize, ScaleSequential, scaleLinear } from 'd3-scale' |
3 | 4 | import { |
4 | 5 | SequentialColorScaleConfig, |
@@ -26,18 +27,25 @@ export type ContinuousColorScaleValues = |
26 | 27 | | DivergingColorScaleValues |
27 | 28 | | QuantizeColorScaleValues |
28 | 29 |
|
29 | | -const isSequentialColorScaleConfig = ( |
| 30 | +export const isSequentialColorScaleConfig = ( |
30 | 31 | config: ContinuousColorScaleConfig |
31 | 32 | ): config is SequentialColorScaleConfig => config.type === 'sequential' |
32 | 33 |
|
33 | | -const isDivergingColorScaleConfig = ( |
| 34 | +export const isDivergingColorScaleConfig = ( |
34 | 35 | config: ContinuousColorScaleConfig |
35 | 36 | ): config is DivergingColorScaleConfig => config.type === 'diverging' |
36 | 37 |
|
37 | | -const isQuantizeColorScaleConfig = ( |
| 38 | +export const isQuantizeColorScaleConfig = ( |
38 | 39 | config: ContinuousColorScaleConfig |
39 | 40 | ): config is QuantizeColorScaleConfig => config.type === 'quantize' |
40 | 41 |
|
| 42 | +export const isContinuousColorScale = (config: unknown): config is ContinuousColorScaleConfig => { |
| 43 | + if (!isPlainObject(config)) return false |
| 44 | + |
| 45 | + const { type } = config as { type: string } |
| 46 | + return type === 'sequential' || type === 'diverging' || type === 'quantize' |
| 47 | +} |
| 48 | + |
41 | 49 | export const getContinuousColorScale = <Config extends ContinuousColorScaleConfig>( |
42 | 50 | config: Config, |
43 | 51 | values: ContinuousColorScaleValues |
|
0 commit comments