Skip to content

Commit

Permalink
fix(vx-scale): make bandScale domain Generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Williams committed Jan 3, 2020
1 parent 3b29e87 commit 8c47c9c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/vx-scale/src/scales/band.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { scaleBand } from 'd3-scale';

type Domain = string | { valueOf(): string };
type Range = number | { valueOf(): number };
type StringLike = string | { valueOf(): string };
type Numeric = number | { valueOf(): number };

export type BandConfig = {
export type BandConfig<Datum extends StringLike> = {
/** Sets the output values of the scale, which are numbers for band scales. */
range?: [Range, Range];
range?: [Numeric, Numeric];
/** Sets the output values of the scale while setting its interpolator to round. If the elements are not numbers, they will be coerced to numbers. */
rangeRound?: [Range, Range];
rangeRound?: [Numeric, Numeric];
/** Sets the input values of the scale, which are strings for band scales. */
domain?: Domain[];
domain?: Datum[];
/** 0-1, determines how any leftover unused space in the range is distributed. 0.5 distributes it equally left and right. */
align?: number;
/** 0-1, determines the ratio of the range that is reserved for blank space before the first point and after the last. */
Expand All @@ -21,7 +21,7 @@ export type BandConfig = {
tickFormat?: unknown;
};

export default ({
export default function bandScale<Datum extends StringLike = StringLike>({
range,
rangeRound,
domain,
Expand All @@ -30,8 +30,8 @@ export default ({
paddingOuter,
align,
tickFormat,
}: BandConfig) => {
const scale = scaleBand<Domain>();
}: BandConfig<Datum>) {
const scale = scaleBand<Datum>();

if (range) scale.range(range);
if (rangeRound) scale.rangeRound(rangeRound);
Expand All @@ -48,4 +48,4 @@ export default ({
scale.type = 'band';

return scale;
};
}

0 comments on commit 8c47c9c

Please sign in to comment.