-
Notifications
You must be signed in to change notification settings - Fork 715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: re-type vx/scale with new functionalities #766
Merged
Merged
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
047140d
feat: update vx scale types
kristw 26277e6
feat: add types and factory for all scales
kristw 7201124
fix: correctly type inputs
kristw cc311e1
refactor: update input types and add overload
kristw a2e83f0
fix: fallback to linear scale
kristw 707e87b
fix: docs
kristw 81408f3
fix: overload
kristw a7ab837
refactor: add DefaultThresholdInput
kristw c52affc
fix: generic type
kristw 48e2c4a
refactor: simplify overloading
kristw c5a718c
fix: omit type from config and remove scale type
kristw 21c738a
refactor: update scale
kristw bbebebf
feat: use operator
kristw b57bc94
refactor: use operator for all
kristw 783e56a
test: fix unit test
kristw 28a3783
fix: broken tests
kristw 56e0a47
fix: violin type
kristw f5fb093
fix: symlog round
kristw 7f45b41
docs: update comment
kristw 41f4229
fix: update generic
kristw 8d772a5
feat: add inferScaleType and export types
kristw c948e0e
fix: domain and range
kristw 6ef370d
test: add unit tests
kristw bad21bb
test: mock timezone
kristw a0a24c2
fix: rename export and remove extends value
kristw deb50d6
refactor: rename value to default output
kristw aabe8e3
docs: update comment
kristw 32cee04
fix: better undefined check
kristw dc8786f
fix: type
kristw 653693d
fix: enforce order
kristw 90a5fee
test: add unit test for scales
kristw eff7091
test: add createScale test
kristw 820c706
test: more tests
kristw 2c7152e
test: more tests
kristw d9d21f2
fix: make config optional for factories
kristw e9eb41c
test: more unit tests
kristw 9e24d65
test: 100% statement coverage
kristw 70a9a66
refactor: simplify updateScale
kristw 5c2f2e9
test: last unit test
kristw fe8d0b2
test: zero test
kristw a13314a
docs: update warning text
kristw 27f6836
docs: add comment
kristw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { ScaleConfig, PickScaleConfigWithoutType, PickScaleConfig } from './types/ScaleConfig'; | ||
import { DefaultThresholdInput, PickD3Scale } from './types/Scale'; | ||
import { StringLike, DefaultOutput } from './types/Base'; | ||
import createLinearScale from './scales/linear'; | ||
import createLogScale from './scales/log'; | ||
import createPowScale from './scales/power'; | ||
import createSqrtScale from './scales/squareRoot'; | ||
import createSymlogScale from './scales/symlog'; | ||
import createTimeScale from './scales/time'; | ||
import createUtcScale from './scales/utc'; | ||
import createQuantileScale from './scales/quantile'; | ||
import createQuantizeScale from './scales/quantize'; | ||
import createThresholdScale from './scales/threshold'; | ||
import createOrdinalScale from './scales/ordinal'; | ||
import createPointScale from './scales/point'; | ||
import createBandScale from './scales/band'; | ||
|
||
// Overload function for more strict typing, e.g., | ||
// If the config is a linear config then a ScaleLinear will be returned | ||
// instead of a union type of all scales. | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>( | ||
config?: PickScaleConfig<'linear', Output> | PickScaleConfigWithoutType<'linear', Output>, | ||
): PickD3Scale<'linear', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'log', Output>): PickD3Scale<'log', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'pow', Output>): PickD3Scale<'pow', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'sqrt', Output>): PickD3Scale<'sqrt', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'symlog', Output>): PickD3Scale<'symlog', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'time', Output>): PickD3Scale<'time', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'utc', Output>): PickD3Scale<'utc', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'quantile', Output>): PickD3Scale<'quantile', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>(config: PickScaleConfig<'quantize', Output>): PickD3Scale<'quantize', Output>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>( | ||
config: PickScaleConfig<'threshold', Output, StringLike, ThresholdInput>, | ||
): PickD3Scale<'threshold', Output, StringLike, ThresholdInput>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>( | ||
config: PickScaleConfig<'ordinal', Output, DiscreteInput>, | ||
): PickD3Scale<'ordinal', Output, DiscreteInput>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>( | ||
config: PickScaleConfig<'point', Output, DiscreteInput>, | ||
): PickD3Scale<'point', Output, DiscreteInput>; | ||
|
||
function createScale< | ||
Output = DefaultOutput, | ||
DiscreteInput extends StringLike = StringLike, | ||
ThresholdInput extends DefaultThresholdInput = DefaultThresholdInput | ||
>( | ||
config: PickScaleConfig<'band', Output, DiscreteInput>, | ||
): PickD3Scale<'band', Output, DiscreteInput>; | ||
|
||
// Actual implementation | ||
|
||
function createScale< | ||
Output, | ||
DiscreteInput extends StringLike, | ||
ThresholdInput extends DefaultThresholdInput | ||
>( | ||
config?: | ||
| ScaleConfig<Output, DiscreteInput, ThresholdInput> | ||
| PickScaleConfigWithoutType<'linear', Output>, | ||
) { | ||
if (typeof config !== 'undefined' && 'type' in config) { | ||
switch (config.type) { | ||
case 'linear': | ||
return createLinearScale(config); | ||
case 'log': | ||
return createLogScale(config); | ||
case 'pow': | ||
return createPowScale(config); | ||
case 'sqrt': | ||
return createSqrtScale(config); | ||
case 'symlog': | ||
return createSymlogScale(config); | ||
case 'time': | ||
return createTimeScale(config); | ||
case 'utc': | ||
return createUtcScale(config); | ||
case 'quantile': | ||
return createQuantileScale(config); | ||
case 'quantize': | ||
return createQuantizeScale(config); | ||
case 'threshold': | ||
return createThresholdScale(config); | ||
case 'ordinal': | ||
return createOrdinalScale(config); | ||
case 'point': | ||
return createPointScale(config); | ||
case 'band': | ||
return createBandScale(config); | ||
default: | ||
} | ||
} | ||
|
||
// If type is not specified, fallback to linear scale | ||
return createLinearScale(config); | ||
} | ||
|
||
export default createScale; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will be amazing for
XYChart
🤩