Skip to content

Commit

Permalink
refactor: reorganize type files
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Aug 5, 2020
1 parent 82325a2 commit 020d5b1
Show file tree
Hide file tree
Showing 35 changed files with 421 additions and 396 deletions.
41 changes: 0 additions & 41 deletions packages/vx-shape/src/factories/arcPath.ts

This file was deleted.

45 changes: 0 additions & 45 deletions packages/vx-shape/src/factories/areaPath.ts

This file was deleted.

24 changes: 0 additions & 24 deletions packages/vx-shape/src/factories/linePath.ts

This file was deleted.

46 changes: 0 additions & 46 deletions packages/vx-shape/src/factories/piePath.ts

This file was deleted.

29 changes: 0 additions & 29 deletions packages/vx-shape/src/factories/radialLinePath.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/vx-shape/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ export { default as LinkVerticalStep, pathVerticalStep } from './shapes/link/ste
export { default as LinkRadialStep, pathRadialStep } from './shapes/link/step/LinkRadialStep';
export { default as Polygon, getPoints, getPoint } from './shapes/Polygon';
export { default as Circle } from './shapes/Circle';

// Export factory functions
export * from './types/D3ShapeConfig';
export * from './util/D3ShapeFactories';
4 changes: 2 additions & 2 deletions packages/vx-shape/src/shapes/Arc.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import cx from 'classnames';
import { Arc as ArcType } from 'd3-shape';
import { $TSFIXME, AddSVGProps } from '../types';
import arc, { ArcPathConfig } from '../factories/arcPath';
import { $TSFIXME, AddSVGProps, ArcPathConfig } from '../types';
import { arc } from '../util/D3ShapeFactories';

export type ArcProps<Datum> = {
/** className applied to path element. */
Expand Down
7 changes: 3 additions & 4 deletions packages/vx-shape/src/shapes/Area.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import cx from 'classnames';
import { AddSVGProps } from '../types';
import { BaseAreaProps } from '../types/area';
import areaPath from '../factories/areaPath';
import { AddSVGProps, BaseAreaProps } from '../types';
import { area } from '../util/D3ShapeFactories';

export type AreaProps<Datum> = BaseAreaProps<Datum>;

Expand All @@ -21,7 +20,7 @@ export default function Area<Datum>({
innerRef,
...restProps
}: AddSVGProps<AreaProps<Datum>, SVGPathElement>) {
const path = areaPath<Datum>({ x, x0, x1, y, y0, y1, defined, curve });
const path = area<Datum>({ x, x0, x1, y, y0, y1, defined, curve });
// eslint-disable-next-line react/jsx-no-useless-fragment
if (children) return <>{children({ path })}</>;
return (
Expand Down
5 changes: 2 additions & 3 deletions packages/vx-shape/src/shapes/AreaClosed.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import cx from 'classnames';
import { PositionScale, AddSVGProps, BaseAreaProps } from '../types';
import setNumOrAccessor from '../util/setNumberOrNumberAccessor';
import { PositionScale, AddSVGProps } from '../types';
import { BaseAreaProps } from '../types/area';
import area from '../factories/areaPath';
import { area } from '../util/D3ShapeFactories';

export type AreaClosedProps<Datum> = BaseAreaProps<Datum> & {
yScale: PositionScale;
Expand Down
2 changes: 1 addition & 1 deletion packages/vx-shape/src/shapes/AreaStack.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import cx from 'classnames';
import Stack, { StackProps } from './Stack';
import { StackKey, AddSVGProps } from '../types';
import { AddSVGProps, StackKey } from '../types';

type PickProps =
| 'className'
Expand Down
17 changes: 12 additions & 5 deletions packages/vx-shape/src/shapes/BarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import cx from 'classnames';
import { Group } from '@vx/group';
import { ScaleInput } from '@vx/scale';
import Bar from './Bar';
import { PositionScale, DatumObject, AnyScaleBand, AddSVGProps } from '../types';
import { BaseBarGroupProps, BarGroup } from '../types/bar';
import { Accessor } from '../types/accessor';
import {
PositionScale,
DatumObject,
AnyScaleBand,
AddSVGProps,
BaseBarGroupProps,
BarGroup,
GroupKey,
Accessor,
} from '../types';
import getBandwidth from '../util/getBandwidth';

export type BarGroupProps<
Datum extends DatumObject,
Key extends keyof Datum = keyof Datum,
Key extends GroupKey = GroupKey,
X0Scale extends AnyScaleBand = AnyScaleBand,
X1Scale extends AnyScaleBand = AnyScaleBand
> = BaseBarGroupProps<Datum, Key> & {
Expand Down Expand Up @@ -68,7 +75,7 @@ export type BarGroupProps<
*/
export default function BarGroupComponent<
Datum extends DatumObject,
Key extends keyof Datum = keyof Datum,
Key extends GroupKey = GroupKey,
X0Scale extends AnyScaleBand = AnyScaleBand,
X1Scale extends AnyScaleBand = AnyScaleBand
>({
Expand Down
17 changes: 12 additions & 5 deletions packages/vx-shape/src/shapes/BarGroupHorizontal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import cx from 'classnames';
import { Group } from '@vx/group';
import { ScaleInput } from '@vx/scale';
import Bar from './Bar';
import { PositionScale, AnyScaleBand, DatumObject, AddSVGProps } from '../types';
import { BarGroupHorizontal, BaseBarGroupProps } from '../types/bar';
import { Accessor } from '../types/accessor';
import {
PositionScale,
AnyScaleBand,
DatumObject,
AddSVGProps,
BarGroupHorizontal,
BaseBarGroupProps,
GroupKey,
Accessor,
} from '../types';
import getBandwidth from '../util/getBandwidth';

export type BarGroupHorizontalProps<
Datum extends DatumObject,
Key extends keyof Datum = keyof Datum,
Key extends GroupKey = GroupKey,
Y0Scale extends AnyScaleBand = AnyScaleBand,
Y1Scale extends AnyScaleBand = AnyScaleBand
> = BaseBarGroupProps<Datum, Key> & {
Expand All @@ -32,7 +39,7 @@ export type BarGroupHorizontalProps<

export default function BarGroupHorizontalComponent<
Datum extends DatumObject,
Key extends keyof Datum = keyof Datum,
Key extends GroupKey = GroupKey,
Y0Scale extends AnyScaleBand = AnyScaleBand,
Y1Scale extends AnyScaleBand = AnyScaleBand
>({
Expand Down
23 changes: 9 additions & 14 deletions packages/vx-shape/src/shapes/BarStack.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import React from 'react';
import cx from 'classnames';
import { Group } from '@vx/group';
import { stack as d3stack, SeriesPoint } from 'd3-shape';

import { Group } from '@vx/group';
import { ScaleInput } from '@vx/scale';
import { PositionScale, AddSVGProps, BarStack, BaseBarStackProps, StackKey } from '../types';
import { getFirstItem, getSecondItem } from '../util/accessors';
import getBandwidth from '../util/getBandwidth';
import setNumOrAccessor from '../util/setNumberOrNumberAccessor';
import stackOrder from '../util/stackOrder';
import stackOffset from '../util/stackOffset';
import Bar from './Bar';
import { StackKey, $TSFIXME, PositionScale, AddSVGProps } from '../types';
import setNumOrAccessor from '../util/setNumberOrNumberAccessor';
import { BarStack, BaseBarStackProps } from '../types/stack';
import getBandwidth from '../util/getBandwidth';

export type BarStackProps<
Datum,
Key,
Key extends StackKey = StackKey,
XScale extends PositionScale = PositionScale,
YScale extends PositionScale = PositionScale
> = BaseBarStackProps<Datum, Key> & {
> = BaseBarStackProps<Datum, Key, XScale, YScale> & {
/** Returns the value mapped to the x of a bar. */
x: (d: Datum) => ScaleInput<XScale>;
/** Returns the value mapped to the y0 of a bar. */
y0?: (d: SeriesPoint<Datum>) => ScaleInput<YScale>;
/** Returns the value mapped to the y1 of a bar. */
y1?: (d: SeriesPoint<Datum>) => ScaleInput<YScale>;
/** @vx/scale or d3-scale that takes an x value and maps it to an x axis position. */
xScale: XScale;
/** @vx/scale or d3-scale that takes a y value and maps it to an y axis position. */
yScale: YScale;
};

export default function BarStackComponent<
Expand All @@ -41,8 +36,8 @@ export default function BarStackComponent<
top,
left,
x,
y0 = (d: $TSFIXME) => d?.[0],
y1 = (d: $TSFIXME) => d?.[1],
y0 = getFirstItem,
y1 = getSecondItem,
xScale,
yScale,
color,
Expand Down
Loading

0 comments on commit 020d5b1

Please sign in to comment.