Upgrading Nivo scatterplot from 0.73 to 0.79 broke custom colors
See original GitHub issueDescribe/explain the bug After upgrading Nivo and it’s respective scatterplot package from 0.73.0 to 0.79.0/1, all of my scatterplot’s custom color function broke.
A snippet of my code is as follows:
export type CustomDatum = {
x: string;
y: number;
trait: string;
total: string;
item: ESOItem;
quant: number;
quality: string | undefined;
};
<ResponsiveScatterPlot
data={[{ id: "Item", data }]}
colors={(d: CustomDatum) => {
switch (colorPreset) {
case ColorPreset.QUALITY: {
return (
((gradient.current as GradientQualityGenerator)?.(
d.quality as keyof typeof QualityColors
) as unknown as string) ?? "#00F"
);
}
case ColorPreset.QUANTITY: {
return (
((gradient.current as GradientQuantityGenerator)?.(
d.quant
) as unknown as string) ?? "#00F"
);
}
case ColorPreset.TRAIT: {
return (
((gradient.current as GradientTraitGenerator)?.(
d.trait as keyof typeof TraitColors
) as unknown as string) ?? "#00F"
);
}
default: {
return "#00F";
}
}
}}
/>
For version 0.73, it looked like the color property had the type OrdinalColorScaleConfig
which in my use case became OrdinalColorScaleConfigCustomFunction<Datum>
.
For version 0.79, it seems like the generic type was pre-set to
OrdinalColorScaleConfig<{
serieId: ScatterPlotRawSerie<RawDatum>['id'];
}>
when I print the value the function received on the new version, the only info I get back is the series ID. I no longer have access to the data of the corresponding point.
On the otherhand, my custom tooltips still work as intended as the generic used is the data model of the chart ScatterPlotTooltip<RawDatum>
.
Is this an intended change? If so, what is the new way of accessing a nodes data from a custom colors function?
Desktop (please complete the following information):
- OS: Ubuntu
- Browser: Firefox
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (2 by maintainers)
Top GitHub Comments
Thanks to this post I managed to build the feature I needed! Unfortunately that required me to rollback to version
0.73.0
as described by @NicolasNewman.Here is an use case of how one can use such feature: 😊
https://user-images.githubusercontent.com/181076/185995149-0ece696f-3e57-4106-8516-767501bbdcb6.mov
Any updates on this issue?