-
Notifications
You must be signed in to change notification settings - Fork 272
feat: add functions for parsing scales #207
Conversation
Codecov Report
@@ Coverage Diff @@
## master #207 +/- ##
==========================================
+ Coverage 99.91% 99.92% +<.01%
==========================================
Files 112 130 +18
Lines 1245 1406 +161
Branches 307 354 +47
==========================================
+ Hits 1244 1405 +161
Partials 1 1
Continue to review full report at Codecov.
|
Deploy preview for superset-ui ready! Built with commit b40089d |
0460162
to
f027bcb
Compare
Nice! Looks great, I wish there was a better abstraction for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a ton of work and looks great overall! didn't have much to add ✨
.replace(/\)$/, '') | ||
.split(',') | ||
.map((chunk: string) => Number(chunk.trim())) as [ | ||
number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if it'd be useful to add comments for the parts, can probably just look up the Date
api
// if (isAFunction(scaleFn)) const encodedValue = scaleFn(10) | ||
// | ||
// CategoricalColorScale is actually a function, | ||
// but TypeScript is not smart enough to realize that by itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is a tricky one
config: ScaleConfig<Output>, | ||
) { | ||
switch (config.type) { | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoa have never seen default
first 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will move to bottom :)
// quantile depends on distribution so zero does not matter | ||
zeroSet.delete(ScaleType.QUANTILE); | ||
|
||
const supportedScaleTypes: Record<keyof CombinedScaleConfig, Set<ScaleType>> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 💯
export const continuousScaleTypes: ScaleType[] = continuousToContinuousScaleTypes; | ||
export const continuousScaleTypesSet = continuousToContinuousScaleTypesSet; | ||
|
||
export const discreteScaleTypes: ScaleType[] = ['band', 'point', 'ordinal']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to use ScaleType.BAND
, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. forgot changed. Thank you for catching.
|
||
export default function getScaleCategoryFromScaleType(scaleType: ScaleType) { | ||
if (continuousScaleTypesSet.has(scaleType)) { | ||
return 'continuous'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think it's worth making these constants? or could at least specify the return type is ScaleCategory | undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree 👍 . Will specify the return type to enforce stricter check
🏆 Enhancements
This is part of the ongoing work for
@superset-ui/encodeable
.vega-lite
and override some fields.@superset-ui/colors
to get color schemes by name. Support most types of scale that D3/vega-lite has. See [vega-lite's scale documentation](https://vega.github.io/vega-lite/docs/scale.html for more details).The main function in this PR is
createScaleFromScaleConfig(...)
Example usage
The following scale properties are supported. (See
Scale.ts
.)