-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
123 additions
and
159 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,31 @@ | ||
import { | ||
ScaleAxis, | ||
ScaleBand, | ||
ScaleBandSpec, | ||
ScalePoint, | ||
ScalePointSpec, | ||
ScaleSpec, | ||
ComputedSerieAxis, | ||
ScaleValue, | ||
StringValue, | ||
NumericValue, | ||
ScaleLinear, | ||
ScaleLinearSpec, | ||
ScaleLogSpec, | ||
ScaleLog, | ||
ScaleSymLogSpec, | ||
} from './types' | ||
import { ScaleAxis, ScaleSpec, ComputedSerieAxis, ScaleValue } from './types' | ||
import { createLinearScale } from './linearScale' | ||
import { createPointScale } from './pointScale' | ||
import { createBandScale } from './bandScale' | ||
import { createTimeScale } from './timeScale' | ||
import { createLogScale } from './logScale' | ||
import { createSymLogScale } from './symLogScale' | ||
|
||
// override for linear scale | ||
export function computeScale<Input extends NumericValue>( | ||
spec: ScaleLinearSpec, | ||
data: ComputedSerieAxis<Input>, | ||
size: number, | ||
axis: ScaleAxis | ||
): ScaleLinear<Input> | ||
|
||
// override for point scale | ||
export function computeScale<Input extends StringValue>( | ||
spec: ScalePointSpec, | ||
data: ComputedSerieAxis<Input>, | ||
size: number, | ||
axis: ScaleAxis | ||
): ScalePoint<Input> | ||
|
||
// override for band scale | ||
export function computeScale<Input extends StringValue>( | ||
spec: ScaleBandSpec, | ||
data: ComputedSerieAxis<Input>, | ||
size: number, | ||
axis: ScaleAxis | ||
): ScaleBand<Input> | ||
|
||
// override for log scale | ||
export function computeScale( | ||
spec: ScaleLogSpec, | ||
data: ComputedSerieAxis<number>, | ||
size: number, | ||
axis: ScaleAxis | ||
): ScaleLog | ||
|
||
// override for symlog scale | ||
export function computeScale( | ||
spec: ScaleSymLogSpec, | ||
data: ComputedSerieAxis<number>, | ||
size: number, | ||
axis: ScaleAxis | ||
): ScaleLog | ||
|
||
export function computeScale<Input extends ScaleValue, Output>( | ||
export function computeScale<Input extends ScaleValue>( | ||
spec: ScaleSpec, | ||
data: ComputedSerieAxis<Input>, | ||
data: ComputedSerieAxis<any>, | ||
size: number, | ||
axis: ScaleAxis | ||
) { | ||
if (spec.type === 'linear') { | ||
return createLinearScale(spec, data, size, axis) | ||
} else if (spec.type === 'point') { | ||
return createPointScale<Input>(spec, data, size) | ||
} else if (spec.type === 'band') { | ||
return createBandScale<Input>(spec, data, size) | ||
} else if (spec.type === 'time') { | ||
return createTimeScale(spec, data, size) | ||
} else if (spec.type === 'log') { | ||
return createLogScale(spec, data, size, axis) | ||
} else if (spec.type === 'symlog') { | ||
return createSymLogScale(spec, data, size, axis) | ||
switch (spec.type) { | ||
case 'linear': | ||
return createLinearScale(spec, data, size, axis) | ||
case 'point': | ||
return createPointScale<Input>(spec, data, size) | ||
case 'band': | ||
return createBandScale<Input>(spec, data, size) | ||
case 'time': | ||
return createTimeScale(spec, data, size) | ||
case 'log': | ||
return createLogScale(spec, data, size, axis) | ||
case 'symlog': | ||
return createSymLogScale(spec, data, size, axis) | ||
default: | ||
throw new Error('invalid scale spec') | ||
} | ||
|
||
throw new Error('invalid scale spec') | ||
} |
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.