Hexastack / eazychart

EazyChart is a reactive chart library 📈, it allows you to easily add SVG charts in your React and Vue web applications.
https://eazychart.com
MIT License
23 stars 14 forks source link

🤔 [ISSUE] - eazychart-[react | vue]- Color scale type safeguard #109

Open marrouchi opened 1 year ago

marrouchi commented 1 year ago

Description

We need a type safe-guard for the certain shapes that would be included under the color scale context provider. Shapes like Segments or Area do not support non ordinal scale. So we need to find a solution in the future on how to make the developer aware of that while coding recipes.

We already tried to use a type safe guard (instanceof / contructor.name) but it lead to some issues in deployments (see https://github.com/Hexastack/eazychart/issues/107).The root cause for this issue is well detailed here : https://www.dannyguo.com/blog/how-to-fix-instanceof-not-working-for-custom-errors-in-typescript

The OrdinalScale class extends the AstractScale class and when we perform an "instanceof", in storybook preview :

const scale = new ScaleOrdinal( ... );
console.log(scale instanceof ScaleOrdinal); // prints false
console.log(scale instanceof AbstractScale); // prints true 

This seems to be an issue if when the compilation target is ES3 or ES5, but the wierd thing is that the configured target we have is ESNEXT. "Storybook" relies on Babel and does not account apparently for that config.

We did remove the type safeguard for the moment so that we would think of a better way to handle this in the future : https://github.com/Hexastack/eazychart/pull/108