Skip to content

Commit

Permalink
fix(scales): improve constraints for scales
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Apr 30, 2023
1 parent 478cfd3 commit 96862f9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/bar/src/compute/grouped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const generateGroupedBars = <RawDatum extends BarDatum>({
getIndex: (datum: RawDatum) => string
getTooltipLabel: (datum: ComputedDatum<RawDatum>) => string
margin: Margin
hiddenIds?: string[]
hiddenIds?: (string | number)[]
}) => {
const keys = props.keys.filter(key => !hiddenIds.includes(key))
const data = normalizeData(props.data, keys)
Expand Down
2 changes: 1 addition & 1 deletion packages/bar/src/compute/stacked.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const generateStackedBars = <RawDatum extends BarDatum>({
getIndex: (datum: RawDatum) => string
getTooltipLabel: (datum: ComputedDatum<RawDatum>) => string
margin: Margin
hiddenIds?: string[]
hiddenIds?: (string | number)[]
}) => {
const keys = props.keys.filter(key => !hiddenIds.includes(key))
const stackedData = stack<RawDatum, string>().keys(keys).offset(stackOffsetDiverging)(
Expand Down
2 changes: 1 addition & 1 deletion packages/bar/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const useBar = <RawDatum extends BarDatum>({
legendLabel?: BarCommonProps<RawDatum>['legendLabel']
}) => {
const [hiddenIds, setHiddenIds] = useState(initialHiddenIds ?? [])
const toggleSerie = useCallback(id => {
const toggleSerie = useCallback((id: string | number) => {
setHiddenIds(state =>
state.indexOf(id) > -1 ? state.filter(item => item !== id) : [...state, id]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/bar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export type BarCommonProps<RawDatum> = {

renderWrapper?: boolean

initialHiddenIds: string[]
initialHiddenIds: (string | number)[]
}

export type BarSvgProps<RawDatum extends BarDatum> = Partial<BarCommonProps<RawDatum>> &
Expand Down
16 changes: 8 additions & 8 deletions packages/scales/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export interface ScaleTypeToSpec {
export type ScaleType = keyof ScaleTypeToSpec
export type ScaleSpec = ScaleTypeToSpec[keyof ScaleTypeToSpec]

export interface ScaleTypeToScale<Input extends StringValue, Output> {
linear: ScaleLinear<Output>
log: ScaleLog
symlog: ScaleSymlog
point: ScalePoint<Input>
band: ScaleBand<Input>
time: ScaleTime<Input>
export interface ScaleTypeToScale<Input, Output> {
linear: Input extends NumericValue ? ScaleLinear<Output> : never
log: Input extends NumericValue ? ScaleLog : never
symlog: Input extends NumericValue ? ScaleSymlog : never
point: Input extends StringValue ? ScalePoint<Input> : never
band: Input extends StringValue ? ScaleBand<Input> : never
time: Input extends (StringValue | Date) ? ScaleTime<Input> : never
}

export type Scale<Input extends StringValue, Output> = ScaleTypeToScale<
export type Scale<Input, Output> = ScaleTypeToScale<
Input,
Output
>[keyof ScaleTypeToScale<Input, Output>]
Expand Down

0 comments on commit 96862f9

Please sign in to comment.