victory-core 36.4.1 → 36.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/victory-core.js +874 -879
- package/dist/victory-core.min.js +1 -1
- package/es/index.d.ts +38 -941
- package/es/index.js +19 -28
- package/es/types.d.ts +33 -0
- package/es/types.js +1 -0
- package/es/victory-accessible-group/victory-accessible-group.d.ts +25 -0
- package/es/victory-accessible-group/victory-accessible-group.js +8 -16
- package/es/victory-animation/util.d.ts +66 -0
- package/es/victory-animation/util.js +2 -1
- package/es/victory-animation/victory-animation.d.ts +69 -0
- package/es/victory-animation/victory-animation.js +59 -67
- package/es/victory-clip-container/victory-clip-container.d.ts +76 -0
- package/es/victory-clip-container/victory-clip-container.js +15 -21
- package/es/victory-container/victory-container.d.ts +99 -0
- package/es/victory-container/victory-container.js +31 -31
- package/es/victory-label/victory-label.d.ts +61 -0
- package/es/victory-label/victory-label.js +13 -8
- package/es/victory-portal/portal-context.d.ts +11 -0
- package/es/victory-portal/portal-context.js +3 -4
- package/es/victory-portal/portal.d.ts +28 -0
- package/es/victory-portal/portal.js +25 -33
- package/es/victory-portal/victory-portal.d.ts +31 -0
- package/es/victory-portal/victory-portal.js +23 -22
- package/es/victory-primitives/arc.d.ts +21 -0
- package/es/victory-primitives/arc.js +3 -5
- package/es/victory-primitives/background.d.ts +22 -0
- package/es/victory-primitives/background.js +4 -6
- package/es/victory-primitives/border.d.ts +18 -0
- package/es/victory-primitives/border.js +3 -5
- package/es/victory-primitives/circle.d.ts +2 -0
- package/es/victory-primitives/circle.js +11 -8
- package/es/victory-primitives/clip-path.d.ts +14 -0
- package/es/victory-primitives/clip-path.js +6 -6
- package/es/victory-primitives/index.d.ts +14 -0
- package/es/victory-primitives/index.js +14 -0
- package/es/victory-primitives/line-segment.d.ts +19 -0
- package/es/victory-primitives/line-segment.js +3 -5
- package/es/victory-primitives/line.d.ts +2 -0
- package/es/victory-primitives/line.js +11 -8
- package/es/victory-primitives/path.d.ts +2 -0
- package/es/victory-primitives/path.js +9 -6
- package/es/victory-primitives/point.d.ts +21 -0
- package/es/victory-primitives/point.js +9 -19
- package/es/victory-primitives/rect.d.ts +2 -0
- package/es/victory-primitives/rect.js +11 -8
- package/es/victory-primitives/text.d.ts +16 -0
- package/es/victory-primitives/text.js +7 -6
- package/es/victory-primitives/tspan.d.ts +2 -0
- package/es/victory-primitives/tspan.js +7 -6
- package/es/victory-primitives/types.d.ts +7 -0
- package/es/victory-primitives/types.js +1 -0
- package/es/victory-primitives/whisker.d.ts +24 -0
- package/es/victory-primitives/whisker.js +3 -5
- package/es/victory-theme/grayscale.d.ts +2 -0
- package/es/victory-theme/grayscale.js +1 -1
- package/es/victory-theme/material.d.ts +2 -0
- package/es/victory-theme/material.js +1 -1
- package/es/victory-theme/victory-theme-definition.d.ts +244 -0
- package/es/victory-theme/victory-theme-definition.js +1 -0
- package/es/victory-theme/victory-theme.d.ts +5 -0
- package/es/victory-theme/victory-theme.js +6 -5
- package/es/victory-transition/victory-transition.d.ts +59 -0
- package/es/victory-transition/victory-transition.js +19 -23
- package/es/victory-util/add-events.js +6 -3
- package/es/victory-util/axis.js +0 -1
- package/es/victory-util/collection.js +0 -2
- package/es/victory-util/data.js +0 -2
- package/es/victory-util/default-transitions.js +0 -1
- package/es/victory-util/domain.js +0 -2
- package/es/victory-util/helpers.js +0 -2
- package/es/victory-util/immutable.js +0 -1
- package/es/victory-util/label-helpers.js +0 -2
- package/es/victory-util/log.js +0 -1
- package/es/victory-util/point-path-helpers.d.ts +9 -0
- package/es/victory-util/point-path-helpers.js +59 -61
- package/es/victory-util/selection.d.ts +23 -0
- package/es/victory-util/selection.js +0 -2
- package/es/victory-util/style.js +0 -2
- package/es/victory-util/textsize.d.ts +8 -0
- package/es/victory-util/timer-context.d.ts +11 -0
- package/es/victory-util/timer.d.ts +16 -0
- package/es/victory-util/timer.js +13 -8
- package/es/victory-util/types.d.ts +188 -0
- package/es/victory-util/types.js +1 -0
- package/lib/index.d.ts +38 -941
- package/lib/index.js +195 -193
- package/lib/types.d.ts +33 -0
- package/lib/types.js +1 -0
- package/lib/victory-accessible-group/victory-accessible-group.d.ts +25 -0
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -15
- package/lib/victory-animation/util.d.ts +66 -0
- package/lib/victory-animation/util.js +2 -1
- package/lib/victory-animation/victory-animation.d.ts +69 -0
- package/lib/victory-animation/victory-animation.js +60 -65
- package/lib/victory-clip-container/victory-clip-container.d.ts +76 -0
- package/lib/victory-clip-container/victory-clip-container.js +19 -22
- package/lib/victory-container/victory-container.d.ts +99 -0
- package/lib/victory-container/victory-container.js +34 -31
- package/lib/victory-label/victory-label.d.ts +61 -0
- package/lib/victory-label/victory-label.js +19 -13
- package/lib/victory-portal/portal-context.d.ts +11 -0
- package/lib/victory-portal/portal-context.js +3 -4
- package/lib/victory-portal/portal.d.ts +28 -0
- package/lib/victory-portal/portal.js +26 -31
- package/lib/victory-portal/victory-portal.d.ts +31 -0
- package/lib/victory-portal/victory-portal.js +24 -20
- package/lib/victory-primitives/arc.d.ts +21 -0
- package/lib/victory-primitives/arc.js +5 -6
- package/lib/victory-primitives/background.d.ts +22 -0
- package/lib/victory-primitives/background.js +7 -8
- package/lib/victory-primitives/border.d.ts +18 -0
- package/lib/victory-primitives/border.js +5 -6
- package/lib/victory-primitives/circle.d.ts +2 -0
- package/lib/victory-primitives/circle.js +11 -6
- package/lib/victory-primitives/clip-path.d.ts +14 -0
- package/lib/victory-primitives/clip-path.js +7 -5
- package/lib/victory-primitives/index.d.ts +14 -0
- package/lib/victory-primitives/index.js +187 -0
- package/lib/victory-primitives/line-segment.d.ts +19 -0
- package/lib/victory-primitives/line-segment.js +5 -6
- package/lib/victory-primitives/line.d.ts +2 -0
- package/lib/victory-primitives/line.js +11 -6
- package/lib/victory-primitives/path.d.ts +2 -0
- package/lib/victory-primitives/path.js +9 -4
- package/lib/victory-primitives/point.d.ts +21 -0
- package/lib/victory-primitives/point.js +13 -21
- package/lib/victory-primitives/rect.d.ts +2 -0
- package/lib/victory-primitives/rect.js +11 -6
- package/lib/victory-primitives/text.d.ts +16 -0
- package/lib/victory-primitives/text.js +8 -5
- package/lib/victory-primitives/tspan.d.ts +2 -0
- package/lib/victory-primitives/tspan.js +7 -4
- package/lib/victory-primitives/types.d.ts +7 -0
- package/lib/victory-primitives/types.js +1 -0
- package/lib/victory-primitives/whisker.d.ts +24 -0
- package/lib/victory-primitives/whisker.js +5 -6
- package/lib/victory-theme/grayscale.d.ts +2 -0
- package/lib/victory-theme/grayscale.js +3 -3
- package/lib/victory-theme/material.d.ts +2 -0
- package/lib/victory-theme/material.js +3 -3
- package/lib/victory-theme/victory-theme-definition.d.ts +244 -0
- package/lib/victory-theme/victory-theme-definition.js +1 -0
- package/lib/victory-theme/victory-theme.d.ts +5 -0
- package/lib/victory-theme/victory-theme.js +22 -8
- package/lib/victory-transition/victory-transition.d.ts +59 -0
- package/lib/victory-transition/victory-transition.js +21 -23
- package/lib/victory-util/add-events.js +8 -4
- package/lib/victory-util/collection.js +0 -2
- package/lib/victory-util/default-transitions.js +0 -1
- package/lib/victory-util/helpers.js +0 -2
- package/lib/victory-util/immutable.js +0 -2
- package/lib/victory-util/label-helpers.js +0 -2
- package/lib/victory-util/log.js +0 -1
- package/lib/victory-util/point-path-helpers.d.ts +9 -0
- package/lib/victory-util/point-path-helpers.js +86 -73
- package/lib/victory-util/selection.d.ts +23 -0
- package/lib/victory-util/selection.js +0 -2
- package/lib/victory-util/style.js +0 -2
- package/lib/victory-util/textsize.d.ts +8 -0
- package/lib/victory-util/timer-context.d.ts +11 -0
- package/lib/victory-util/timer.d.ts +16 -0
- package/lib/victory-util/timer.js +13 -8
- package/lib/victory-util/types.d.ts +188 -0
- package/lib/victory-util/types.js +1 -0
- package/package.json +4 -4
- package/src/index.ts +42 -0
- package/src/types.ts +45 -0
- package/src/victory-accessible-group/{victory-accessible-group.js → victory-accessible-group.tsx} +10 -3
- package/src/victory-animation/{util.js → util.ts} +4 -3
- package/src/victory-animation/{victory-animation.js → victory-animation.tsx} +89 -12
- package/src/victory-clip-container/{victory-clip-container.js → victory-clip-container.tsx} +29 -5
- package/src/victory-container/{victory-container.js → victory-container.tsx} +70 -26
- package/src/victory-label/{victory-label.js → victory-label.tsx} +71 -14
- package/src/victory-portal/portal-context.ts +14 -0
- package/src/victory-portal/{portal.js → portal.tsx} +23 -12
- package/src/victory-portal/{victory-portal.js → victory-portal.tsx} +21 -6
- package/src/victory-primitives/{arc.js → arc.tsx} +15 -5
- package/src/victory-primitives/{background.js → background.tsx} +17 -7
- package/src/victory-primitives/{border.js → border.tsx} +12 -5
- package/src/victory-primitives/{circle.js → circle.tsx} +4 -3
- package/src/victory-primitives/clip-path.tsx +25 -0
- package/src/victory-primitives/index.ts +14 -0
- package/src/victory-primitives/{line-segment.js → line-segment.tsx} +13 -5
- package/src/victory-primitives/{line.js → line.tsx} +4 -3
- package/src/victory-primitives/{path.js → path.tsx} +4 -3
- package/src/victory-primitives/{point.js → point.tsx} +25 -20
- package/src/victory-primitives/{rect.js → rect.tsx} +4 -2
- package/src/victory-primitives/{text.js → text.tsx} +9 -3
- package/src/victory-primitives/tspan.tsx +7 -0
- package/src/victory-primitives/types.ts +19 -0
- package/src/victory-primitives/{whisker.js → whisker.tsx} +20 -7
- package/src/victory-theme/{grayscale.js → grayscale.tsx} +2 -1
- package/src/victory-theme/{material.js → material.tsx} +2 -1
- package/src/victory-theme/victory-theme-definition.ts +261 -0
- package/src/victory-theme/victory-theme.tsx +5 -0
- package/src/victory-transition/{victory-transition.js → victory-transition.tsx} +68 -19
- package/src/victory-util/add-events.js +6 -1
- package/src/victory-util/axis.js +0 -1
- package/src/victory-util/collection.js +0 -1
- package/src/victory-util/data.js +0 -1
- package/src/victory-util/default-transitions.js +0 -1
- package/src/victory-util/domain.js +0 -1
- package/src/victory-util/events.js +1 -1
- package/src/victory-util/helpers.js +0 -1
- package/src/victory-util/immutable.js +0 -1
- package/src/victory-util/label-helpers.js +0 -1
- package/src/victory-util/log.js +0 -1
- package/src/victory-util/point-path-helpers.ts +119 -0
- package/src/victory-util/prop-types.js +0 -1
- package/src/victory-util/scale.js +0 -1
- package/src/victory-util/selection.d.ts +23 -0
- package/src/victory-util/selection.js +0 -1
- package/src/victory-util/style.js +0 -1
- package/src/victory-util/textsize.d.ts +8 -0
- package/src/victory-util/{timer-context.js → timer-context.ts} +0 -0
- package/src/victory-util/{timer.js → timer.ts} +19 -4
- package/src/victory-util/transitions.js +0 -1
- package/src/victory-util/types.ts +247 -0
- package/src/victory-util/wrapper.js +0 -1
- package/src/index.d.ts +0 -941
- package/src/index.js +0 -51
- package/src/victory-portal/portal-context.js +0 -10
- package/src/victory-primitives/clip-path.js +0 -18
- package/src/victory-primitives/tspan.js +0 -5
- package/src/victory-theme/victory-theme.js +0 -7
- package/src/victory-util/point-path-helpers.js +0 -121
|
@@ -1,14 +1,52 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import VictoryAnimation from "../victory-animation/victory-animation";
|
|
3
|
+
import { VictoryAnimation } from "../victory-animation/victory-animation";
|
|
4
4
|
import * as Collection from "../victory-util/collection";
|
|
5
5
|
import * as Helpers from "../victory-util/helpers";
|
|
6
6
|
import TimerContext from "../victory-util/timer-context";
|
|
7
7
|
import * as Transitions from "../victory-util/transitions";
|
|
8
|
-
import { defaults, isFunction, pick
|
|
8
|
+
import { defaults, isFunction, pick } from "lodash";
|
|
9
9
|
import isEqual from "react-fast-compare";
|
|
10
|
+
import Timer from "../victory-util/timer";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
type VictoryTransitionChild = React.ReactElement<
|
|
13
|
+
// Props:
|
|
14
|
+
{
|
|
15
|
+
polar?: boolean;
|
|
16
|
+
domain?: number[] | { x: number[]; y: number[] };
|
|
17
|
+
groupComponent?: React.ReactElement;
|
|
18
|
+
},
|
|
19
|
+
// Type:
|
|
20
|
+
{
|
|
21
|
+
new (props: any): React.Component<any, any>;
|
|
22
|
+
continuous?: boolean;
|
|
23
|
+
}
|
|
24
|
+
>;
|
|
25
|
+
interface VictoryTransitionProps {
|
|
26
|
+
animate?: boolean | any;
|
|
27
|
+
animationWhitelist?: string[];
|
|
28
|
+
children: VictoryTransitionChild;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface VictoryTransitionState {
|
|
32
|
+
oldProps?: VictoryTransitionProps | null;
|
|
33
|
+
nextProps?: VictoryTransitionProps;
|
|
34
|
+
nodesShouldLoad?: boolean;
|
|
35
|
+
nodesDoneLoad?: boolean;
|
|
36
|
+
nodesWillExit?: boolean;
|
|
37
|
+
nodesWillEnter?: boolean;
|
|
38
|
+
nodesShouldEnter?: boolean;
|
|
39
|
+
childrenTransitions?: unknown;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface VictoryTransition {
|
|
43
|
+
context: React.ContextType<typeof TimerContext>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class VictoryTransition extends React.Component<
|
|
47
|
+
VictoryTransitionProps,
|
|
48
|
+
VictoryTransitionState
|
|
49
|
+
> {
|
|
12
50
|
static displayName = "VictoryTransition";
|
|
13
51
|
|
|
14
52
|
static propTypes = {
|
|
@@ -18,6 +56,9 @@ export default class VictoryTransition extends React.Component {
|
|
|
18
56
|
};
|
|
19
57
|
|
|
20
58
|
static contextType = TimerContext;
|
|
59
|
+
private continuous: boolean;
|
|
60
|
+
private timer: Timer;
|
|
61
|
+
private transitionProps: any;
|
|
21
62
|
|
|
22
63
|
constructor(props, context) {
|
|
23
64
|
super(props, context);
|
|
@@ -28,7 +69,6 @@ export default class VictoryTransition extends React.Component {
|
|
|
28
69
|
const child = this.props.children;
|
|
29
70
|
const polar = child.props.polar;
|
|
30
71
|
this.continuous = !polar && child.type && child.type.continuous === true;
|
|
31
|
-
this.getTransitionState = this.getTransitionState.bind(this);
|
|
32
72
|
this.timer = this.context.transitionTimer;
|
|
33
73
|
}
|
|
34
74
|
|
|
@@ -36,7 +76,7 @@ export default class VictoryTransition extends React.Component {
|
|
|
36
76
|
this.setState({ nodesShouldLoad: true }); //eslint-disable-line react/no-did-mount-set-state
|
|
37
77
|
}
|
|
38
78
|
|
|
39
|
-
shouldComponentUpdate(nextProps) {
|
|
79
|
+
shouldComponentUpdate(nextProps: VictoryTransitionProps) {
|
|
40
80
|
if (!isEqual(this.props, nextProps)) {
|
|
41
81
|
this.timer.bypassAnimation();
|
|
42
82
|
this.setState(this.getTransitionState(this.props, nextProps), () =>
|
|
@@ -50,7 +90,10 @@ export default class VictoryTransition extends React.Component {
|
|
|
50
90
|
this.timer.stop();
|
|
51
91
|
}
|
|
52
92
|
|
|
53
|
-
getTransitionState(
|
|
93
|
+
private getTransitionState(
|
|
94
|
+
props: VictoryTransitionProps,
|
|
95
|
+
nextProps: VictoryTransitionProps
|
|
96
|
+
): VictoryTransitionState {
|
|
54
97
|
const { animate } = props;
|
|
55
98
|
if (!animate) {
|
|
56
99
|
return {};
|
|
@@ -78,7 +121,10 @@ export default class VictoryTransition extends React.Component {
|
|
|
78
121
|
}
|
|
79
122
|
}
|
|
80
123
|
|
|
81
|
-
getDomainFromChildren(
|
|
124
|
+
private getDomainFromChildren(
|
|
125
|
+
props: VictoryTransitionProps,
|
|
126
|
+
axis: "x" | "y"
|
|
127
|
+
) {
|
|
82
128
|
const getChildDomains = (children) => {
|
|
83
129
|
return children.reduce((memo, child) => {
|
|
84
130
|
if (child.type && isFunction(child.type.getDomain)) {
|
|
@@ -94,8 +140,10 @@ export default class VictoryTransition extends React.Component {
|
|
|
94
140
|
}, []);
|
|
95
141
|
};
|
|
96
142
|
|
|
97
|
-
const child = React.Children.toArray(
|
|
98
|
-
|
|
143
|
+
const child = React.Children.toArray(
|
|
144
|
+
props.children
|
|
145
|
+
)[0] as VictoryTransitionChild;
|
|
146
|
+
const childProps: any = child.props || {};
|
|
99
147
|
const domain = Array.isArray(childProps.domain)
|
|
100
148
|
? childProps.domain
|
|
101
149
|
: childProps.domain && childProps.domain[axis];
|
|
@@ -121,10 +169,10 @@ export default class VictoryTransition extends React.Component {
|
|
|
121
169
|
: this.props;
|
|
122
170
|
}
|
|
123
171
|
|
|
124
|
-
pickDomainProps(props) {
|
|
125
|
-
const parentState =
|
|
172
|
+
private pickDomainProps(props: VictoryTransitionProps) {
|
|
173
|
+
const parentState = props.animate?.parentState;
|
|
126
174
|
if (parentState && parentState.nodesWillExit) {
|
|
127
|
-
return this.
|
|
175
|
+
return this.continuous || parentState.continuous
|
|
128
176
|
? parentState.nextProps || this.state.nextProps || props
|
|
129
177
|
: props;
|
|
130
178
|
}
|
|
@@ -146,13 +194,14 @@ export default class VictoryTransition extends React.Component {
|
|
|
146
194
|
|
|
147
195
|
render() {
|
|
148
196
|
const props = this.pickProps();
|
|
149
|
-
const getTransitionProps =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
197
|
+
const getTransitionProps = this.props.animate?.getTransitions
|
|
198
|
+
? this.props.animate.getTransitions
|
|
199
|
+
: Transitions.getTransitionPropsFactory(props, this.state, (newState) =>
|
|
200
|
+
this.setState(newState)
|
|
201
|
+
);
|
|
202
|
+
const child = React.Children.toArray(
|
|
203
|
+
props.children
|
|
204
|
+
)[0] as VictoryTransitionChild;
|
|
156
205
|
const transitionProps = getTransitionProps(child);
|
|
157
206
|
this.transitionProps = transitionProps;
|
|
158
207
|
const domain = {
|
|
@@ -13,7 +13,12 @@ import {
|
|
|
13
13
|
} from "lodash";
|
|
14
14
|
import * as Events from "./events";
|
|
15
15
|
import isEqual from "react-fast-compare";
|
|
16
|
-
import VictoryTransition from "../victory-transition/victory-transition";
|
|
16
|
+
import { VictoryTransition } from "../victory-transition/victory-transition";
|
|
17
|
+
|
|
18
|
+
// DISCLAIMER:
|
|
19
|
+
// This file is not currently tested, and it is first on the list of files
|
|
20
|
+
// to refactor in our current refactoring effort. Please do not make changes
|
|
21
|
+
// to this file without manual testing and/or refactoring and adding tests.
|
|
17
22
|
|
|
18
23
|
const datumHasXandY = (datum) => {
|
|
19
24
|
return !isNil(datum._x) && !isNil(datum._y);
|
package/src/victory-util/axis.js
CHANGED
package/src/victory-util/data.js
CHANGED
package/src/victory-util/log.js
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2, 2.5, 3] }]*/
|
|
2
|
+
import { range } from "lodash";
|
|
3
|
+
|
|
4
|
+
export function circle(x: number, y: number, size: number) {
|
|
5
|
+
return `M ${x}, ${y}
|
|
6
|
+
m ${-size}, 0
|
|
7
|
+
a ${size}, ${size} 0 1,0 ${size * 2},0
|
|
8
|
+
a ${size}, ${size} 0 1,0 ${-size * 2},0`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function square(x: number, y: number, size: number) {
|
|
12
|
+
const baseSize = 0.87 * size; // eslint-disable-line no-magic-numbers
|
|
13
|
+
const x0 = x - baseSize;
|
|
14
|
+
const y1 = y + baseSize;
|
|
15
|
+
const distance = x + baseSize - x0;
|
|
16
|
+
return `M ${x0}, ${y1}
|
|
17
|
+
h${distance}
|
|
18
|
+
v-${distance}
|
|
19
|
+
h-${distance}
|
|
20
|
+
z`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function diamond(x: number, y: number, size: number) {
|
|
24
|
+
const baseSize = 0.87 * size; // eslint-disable-line no-magic-numbers
|
|
25
|
+
const length = Math.sqrt(2 * (baseSize * baseSize));
|
|
26
|
+
return `M ${x}, ${y + length}
|
|
27
|
+
l ${length}, -${length}
|
|
28
|
+
l -${length}, -${length}
|
|
29
|
+
l -${length}, ${length}
|
|
30
|
+
l ${length}, ${length}
|
|
31
|
+
z`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function triangleDown(x: number, y: number, size: number) {
|
|
35
|
+
const height = (size / 2) * Math.sqrt(3);
|
|
36
|
+
const x0 = x - size;
|
|
37
|
+
const x1 = x + size;
|
|
38
|
+
const y0 = y - size;
|
|
39
|
+
const y1 = y + height;
|
|
40
|
+
return `M ${x0}, ${y0}
|
|
41
|
+
L ${x1}, ${y0}
|
|
42
|
+
L ${x}, ${y1}
|
|
43
|
+
z`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function triangleUp(x: number, y: number, size: number) {
|
|
47
|
+
const height = (size / 2) * Math.sqrt(3);
|
|
48
|
+
const x0 = x - size;
|
|
49
|
+
const x1 = x + size;
|
|
50
|
+
const y0 = y - height;
|
|
51
|
+
const y1 = y + size;
|
|
52
|
+
return `M ${x0}, ${y1}
|
|
53
|
+
L ${x1}, ${y1}
|
|
54
|
+
L ${x}, ${y0}
|
|
55
|
+
z`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function plus(x: number, y: number, size: number) {
|
|
59
|
+
const baseSize = 1.1 * size; // eslint-disable-line no-magic-numbers
|
|
60
|
+
const distance = baseSize / 1.5; // eslint-disable-line no-magic-numbers
|
|
61
|
+
return `
|
|
62
|
+
M ${x - distance / 2}, ${y + baseSize}
|
|
63
|
+
v-${distance}
|
|
64
|
+
h-${distance}
|
|
65
|
+
v-${distance}
|
|
66
|
+
h${distance}
|
|
67
|
+
v-${distance}
|
|
68
|
+
h${distance}
|
|
69
|
+
v${distance}
|
|
70
|
+
h${distance}
|
|
71
|
+
v${distance}
|
|
72
|
+
h-${distance}
|
|
73
|
+
v${distance}
|
|
74
|
+
z`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function cross(x: number, y: number, size: number) {
|
|
78
|
+
const baseSize = 0.8 * size; // eslint-disable-line no-magic-numbers
|
|
79
|
+
const distance = baseSize / 1.5; // eslint-disable-line no-magic-numbers
|
|
80
|
+
return `
|
|
81
|
+
M ${x - distance / 2}, ${y + baseSize + distance}
|
|
82
|
+
v-${distance * 2}
|
|
83
|
+
h-${distance}
|
|
84
|
+
v-${distance}
|
|
85
|
+
h${distance}
|
|
86
|
+
v-${distance}
|
|
87
|
+
h${distance}
|
|
88
|
+
v${distance}
|
|
89
|
+
h${distance}
|
|
90
|
+
v${distance}
|
|
91
|
+
h-${distance}
|
|
92
|
+
v${distance * 2}
|
|
93
|
+
z`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function minus(x: number, y: number, size: number) {
|
|
97
|
+
const baseSize = 1.1 * size; // eslint-disable-line no-magic-numbers
|
|
98
|
+
const lineHeight = baseSize - baseSize * 0.3; // eslint-disable-line no-magic-numbers
|
|
99
|
+
const x0 = x - baseSize;
|
|
100
|
+
const y1 = y + lineHeight / 2;
|
|
101
|
+
const distance = x + baseSize - x0;
|
|
102
|
+
return `M ${x0}, ${y1}
|
|
103
|
+
h${distance}
|
|
104
|
+
v-${lineHeight}
|
|
105
|
+
h-${distance}
|
|
106
|
+
z`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function star(x: number, y: number, size: number) {
|
|
110
|
+
const baseSize = 1.35 * size; // eslint-disable-line no-magic-numbers
|
|
111
|
+
const angle = Math.PI / 5; // eslint-disable-line no-magic-numbers
|
|
112
|
+
// eslint-disable-next-line no-magic-numbers
|
|
113
|
+
const starCoords = range(10).map((index) => {
|
|
114
|
+
const length = index % 2 === 0 ? baseSize : baseSize / 2;
|
|
115
|
+
return `${length * Math.sin(angle * (index + 1)) + x},
|
|
116
|
+
${length * Math.cos(angle * (index + 1)) + y}`;
|
|
117
|
+
});
|
|
118
|
+
return `M ${starCoords.join("L")} z`;
|
|
119
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { DomainPropType, ScalePropType, SVGCoordinateType } from "./types";
|
|
3
|
+
|
|
4
|
+
export function getParentSVG(evt: React.SyntheticEvent): string;
|
|
5
|
+
|
|
6
|
+
export function getSVGEventCoordinates(
|
|
7
|
+
evt: React.SyntheticEvent,
|
|
8
|
+
svg?: SVGElement
|
|
9
|
+
): SVGCoordinateType;
|
|
10
|
+
|
|
11
|
+
export function getDomainCoordinates(
|
|
12
|
+
props: any,
|
|
13
|
+
domain?: DomainPropType
|
|
14
|
+
): DomainPropType;
|
|
15
|
+
|
|
16
|
+
export function getDataCoordinates(
|
|
17
|
+
props: any,
|
|
18
|
+
scale: ScalePropType,
|
|
19
|
+
x: number,
|
|
20
|
+
y: number
|
|
21
|
+
): SVGCoordinateType;
|
|
22
|
+
|
|
23
|
+
export function getBounds(props: any): SVGCoordinateType;
|
|
File without changes
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { timer, now } from "victory-vendor/d3-timer";
|
|
2
2
|
|
|
3
|
+
interface D3Timer {
|
|
4
|
+
new (callback): void;
|
|
5
|
+
stop(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type Callback = (elapsed: number, duration: number) => void;
|
|
9
|
+
|
|
3
10
|
export default class Timer {
|
|
11
|
+
private shouldAnimate: boolean;
|
|
12
|
+
private readonly subscribers: Array<{
|
|
13
|
+
callback: Callback;
|
|
14
|
+
startTime: number;
|
|
15
|
+
duration: number;
|
|
16
|
+
}>;
|
|
17
|
+
private activeSubscriptions: number;
|
|
18
|
+
private timer: D3Timer | null;
|
|
19
|
+
|
|
4
20
|
constructor() {
|
|
5
21
|
this.shouldAnimate = true;
|
|
6
22
|
this.subscribers = [];
|
|
7
|
-
this.loop = this.loop.bind(this);
|
|
8
23
|
this.timer = null;
|
|
9
24
|
this.activeSubscriptions = 0;
|
|
10
25
|
}
|
|
@@ -17,11 +32,11 @@ export default class Timer {
|
|
|
17
32
|
this.shouldAnimate = true;
|
|
18
33
|
}
|
|
19
34
|
|
|
20
|
-
loop() {
|
|
35
|
+
loop = () => {
|
|
21
36
|
this.subscribers.forEach((s) => {
|
|
22
37
|
s.callback(now() - s.startTime, s.duration);
|
|
23
38
|
});
|
|
24
|
-
}
|
|
39
|
+
};
|
|
25
40
|
|
|
26
41
|
start() {
|
|
27
42
|
if (!this.timer) {
|
|
@@ -36,7 +51,7 @@ export default class Timer {
|
|
|
36
51
|
}
|
|
37
52
|
}
|
|
38
53
|
|
|
39
|
-
subscribe(callback, duration) {
|
|
54
|
+
subscribe(callback: Callback, duration: number) {
|
|
40
55
|
duration = this.shouldAnimate ? duration : 0;
|
|
41
56
|
const subscriptionID = this.subscribers.push({
|
|
42
57
|
startTime: now(),
|