Skip to content
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

typescript(vx-shape): Re-write package in TypeScript #507

Merged
merged 22 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fc9fcf2
typescript(vx-shape): *.jsx? => *.tsx?
Sep 18, 2019
769bb49
typescript: mid-re-write
Sep 19, 2019
ed13545
typescript(vx-shape): fix method override types, convert links OMG KI…
Sep 20, 2019
3768e98
typescript(vx-shape): re-write BarGroups and BarStacks in TypeScript
Sep 20, 2019
9eea4ed
deps(vx-shape): remove @vx/point dep
Sep 20, 2019
e354590
typescript(vx-shape): fix Stack and AreaStack error
Sep 20, 2019
bb9d5af
typescript(vx-shape): update children(*) => <>children(*)</>
Sep 20, 2019
990eb6f
typescript(vx-shape): update types path, update all restProps signatu…
Sep 20, 2019
abc5033
deps(vx-shape): remove @types/d3-scale dep
Sep 20, 2019
fd478c4
typescript(vx-shape): fix type errors
Sep 20, 2019
4a13d83
typescript(vx-shape): fix Key types in stacks
Sep 21, 2019
15ce723
typescript(vx-shape): fix default horizontal link accessor functions
Sep 21, 2019
3b22b07
typescript(vx-shape): consolidate and move stack and group types into…
Sep 21, 2019
edbb05e
typescript(vx-shape): replace any with
Sep 21, 2019
35445b1
typescript(vx-shape): lots of fixes
Sep 23, 2019
138353f
deps(vx-shape): require react@^16.3.0-0 peerDep
Sep 24, 2019
d5cee59
fix(vx-shape): path => pathGen, remove duplicate number type
Oct 9, 2019
2090151
typescript(vx-shape): update PathType<Link> to return string | null
Oct 9, 2019
fb2c5fb
typescript(vx-shape): fix diagonal/LinkRadial Node + Link generics
Oct 9, 2019
ad4eea5
tests(vx-shape): fix types in tests
Oct 9, 2019
f00bb1a
typescript(vx-shape): more test type fixes
Oct 9, 2019
4ee5a3d
typescript(vx-shape): fix Arc return signature + types
Oct 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/vx-shape/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"sideEffects": false,
"main": "lib/index.js",
"module": "esm/index.js",
"types": "lib/index.d.ts",
"repository": "https://github.com/hshoff/vx",
"files": [
"lib",
Expand All @@ -23,21 +24,25 @@
"author": "@hshoff",
"license": "MIT",
"dependencies": {
"@types/classnames": "^2.2.9",
"@types/d3-path": "^1.0.8",
"@types/d3-shape": "^1.3.1",
"@types/react": "*",
"@vx/curve": "0.0.192",
"@vx/group": "0.0.192",
"@vx/point": "0.0.192",
"classnames": "^2.2.5",
"d3-path": "^1.0.5",
"d3-shape": "^1.2.0",
"prop-types": "^15.5.10"
},
"peerDependencies": {
"react": "^15.0.0-0 || ^16.0.0-0"
"react": "^16.3.0-0"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/d3-hierarchy": "^1.1.6",
"d3-hierarchy": "^1.1.8"
}
}
File renamed without changes.
47 changes: 0 additions & 47 deletions packages/vx-shape/src/shapes/Arc.jsx

This file was deleted.

62 changes: 62 additions & 0 deletions packages/vx-shape/src/shapes/Arc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-disable @typescript-eslint/unbound-method */
import React from 'react';
import cx from 'classnames';
import { arc as d3Arc, Arc as ArcType } from 'd3-shape';
import setNumOrAccessor, { NumberAccessor } from '../util/setNumberOrNumberAccessor';
import { $TSFIXME } from '../types';

export type ArcProps<Datum> = {
/** className applied to path element. */
className?: string;
/** A Datum for which to generate an arc. */
data?: Datum;
/** Override render function which is passed the configured arc generator as input. */
children?: (args: { path: ArcType<$TSFIXME, Datum> }) => React.ReactNode;
/** React ref to the path element. */
innerRef?: React.Ref<SVGPathElement>;
/** Number or accessor function which returns a number, which defines the arc innerRadius. */
innerRadius?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc outerRadius. */
outerRadius?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc cornerRadius. */
cornerRadius?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc startAngle. */
startAngle?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc endAngle. */
endAngle?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc padAngle. */
padAngle?: NumberAccessor<Datum> | number;
/** Number or accessor function which returns a number, which defines the arc padRadius. */
padRadius?: NumberAccessor<Datum> | number;
};

export default function Arc<Datum>({
className,
data,
innerRadius,
outerRadius,
cornerRadius,
startAngle,
endAngle,
padAngle,
padRadius,
children,
innerRef,
...restProps
}: ArcProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof ArcProps<Datum>>) {
const arc = d3Arc<Datum>();
if (innerRadius != null) setNumOrAccessor(arc.innerRadius, innerRadius);
if (outerRadius != null) setNumOrAccessor(arc.outerRadius, outerRadius);
if (cornerRadius != null) setNumOrAccessor(arc.cornerRadius, cornerRadius);
if (startAngle != null) setNumOrAccessor(arc.startAngle, startAngle);
if (endAngle != null) setNumOrAccessor(arc.endAngle, endAngle);
if (padAngle != null) setNumOrAccessor(arc.padAngle, padAngle);
if (padRadius != null) setNumOrAccessor(arc.padRadius, padRadius);

if (children) return <>{children({ path: arc })}</>;
if (!data) return null;

return (
<path ref={innerRef} className={cx('vx-arc', className)} d={arc(data) || ''} {...restProps} />
);
}
51 changes: 0 additions & 51 deletions packages/vx-shape/src/shapes/Area.jsx

This file was deleted.

63 changes: 63 additions & 0 deletions packages/vx-shape/src/shapes/Area.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import cx from 'classnames';
import { area, Area as AreaType, CurveFactory } from 'd3-shape';
import setNumOrAccessor from '../util/setNumberOrNumberAccessor';

type NumberAccessor<Datum> = (datum: Datum, index: number, data: Datum[]) => number;

export type AreaProps<Datum> = {
/** Override render function which is passed the configured area generator as input. */
children?: (args: { path: AreaType<Datum> }) => React.ReactNode;
/** Classname applied to path element. */
className?: string;
/** Array of data for which to generate an area shape. */
data?: Datum[];
/** The defined accessor for the shape. The final area shape includes all points for which this function returns true. By default all points are defined. */
defined?: (datum: Datum, index: number, data: Datum[]) => boolean;
/** Sets the curve factory (from @vx/curve or d3-curve) for the area generator. Defaults to curveLinear. */
curve?: CurveFactory;
/** React RefObject passed to the path element. */
innerRef?: React.Ref<SVGPathElement>;
/** Sets the x0 accessor function, and sets x1 to null. */
x?: NumberAccessor<Datum> | number;
/** Specifies the x0 accessor function which defaults to d => d[0]. */
x0?: NumberAccessor<Datum> | number;
/** Specifies the x1 accessor function which defaults to null. */
x1?: NumberAccessor<Datum> | number;
/** Sets the y0 accessor function, and sets y1 to null. */
y?: NumberAccessor<Datum> | number;
/** Specifies the y0 accessor function which defaults to d => 0. */
y0?: NumberAccessor<Datum> | number;
/** Specifies the y1 accessor function which defaults to d => d[1]. */
y1?: NumberAccessor<Datum> | number;
};

export default function Area<Datum>({
children,
x,
x0,
x1,
y,
y0,
y1,
data = [],
defined = () => true,
className,
curve,
innerRef,
...restProps
}: AreaProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof AreaProps<Datum>>) {
const path = area<Datum>();
if (x) setNumOrAccessor(path.x, x);
if (x0) setNumOrAccessor(path.x0, x0);
if (x1) setNumOrAccessor(path.x1, x1);
if (y) setNumOrAccessor(path.y, y);
if (y0) setNumOrAccessor(path.y0, y0);
if (y1) setNumOrAccessor(path.y1, y1);
if (defined) path.defined(defined);
if (curve) path.curve(curve);
if (children) return <>{children({ path })}</>;
return (
<path ref={innerRef} className={cx('vx-area', className)} d={path(data) || ''} {...restProps} />
);
}
60 changes: 0 additions & 60 deletions packages/vx-shape/src/shapes/AreaClosed.jsx

This file was deleted.

69 changes: 69 additions & 0 deletions packages/vx-shape/src/shapes/AreaClosed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-disable @typescript-eslint/unbound-method */
import React from 'react';
import cx from 'classnames';
import { area } from 'd3-shape';
import { AreaProps } from './Area';
import { ScaleType } from '../types';
import setNumOrAccessor from '../util/setNumberOrNumberAccessor';

export type AreaClosedProps<Datum> = {
yScale: ScaleType;
} & Pick<
AreaProps<Datum>,
| 'className'
| 'innerRef'
| 'children'
| 'curve'
| 'defined'
| 'data'
| 'x'
| 'x0'
| 'x1'
| 'y'
| 'y0'
| 'y1'
>;

export default function AreaClosed<Datum>({
x,
x0,
x1,
y,
y1,
y0,
yScale,
data = [],
defined = () => true,
className,
curve,
innerRef,
children,
...restProps
}: AreaClosedProps<Datum> & Omit<React.SVGProps<SVGPathElement>, keyof AreaClosedProps<Datum>>) {
const path = area<Datum>();
if (x) setNumOrAccessor(path.x, x);
if (x0) setNumOrAccessor(path.x0, x0);
if (x1) setNumOrAccessor(path.x1, x1);
if (y0) {
setNumOrAccessor(path.y0, y0);
} else {
/**
* by default set the baseline to the first element of the yRange
* @TODO take the minimum instead?
*/
path.y0(yScale.range()[0]);
}
if (y && !y1) setNumOrAccessor(path.y1, y);
if (y1 && !y) setNumOrAccessor(path.y1, y1);
if (defined) path.defined(defined);
if (curve) path.curve(curve);
if (children) return <>{children({ path })}</>;
return (
<path
ref={innerRef}
className={cx('vx-area-closed', className)}
d={path(data) || ''}
{...restProps}
/>
);
}
Loading