victory-core 36.5.0 → 36.5.3
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 +13817 -10827
- package/dist/victory-core.min.js +1 -1
- package/es/index.d.ts +7 -27
- package/es/index.js +7 -53
- package/es/{types.d.ts → types/callbacks.d.ts} +12 -8
- package/es/types/callbacks.js +2 -0
- package/es/types/prop-types.d.ts +130 -0
- package/es/types/prop-types.js +2 -0
- package/es/victory-accessible-group/victory-accessible-group.d.ts +1 -0
- package/es/victory-accessible-group/victory-accessible-group.js +2 -1
- package/es/victory-animation/util.d.ts +2 -1
- package/es/victory-animation/util.js +6 -4
- package/es/victory-animation/victory-animation.d.ts +1 -0
- package/es/victory-animation/victory-animation.js +2 -1
- package/es/victory-clip-container/victory-clip-container.d.ts +6 -5
- package/es/victory-clip-container/victory-clip-container.js +2 -1
- package/es/victory-container/victory-container.d.ts +8 -7
- package/es/victory-container/victory-container.js +2 -1
- package/es/victory-label/victory-label.d.ts +3 -2
- package/es/victory-label/victory-label.js +4 -4
- package/es/victory-portal/portal-context.d.ts +1 -0
- package/es/victory-portal/portal-context.js +2 -1
- package/es/victory-portal/portal.d.ts +3 -2
- package/es/victory-portal/portal.js +2 -1
- package/es/victory-portal/victory-portal.d.ts +1 -0
- package/es/victory-portal/victory-portal.js +2 -1
- package/es/victory-primitives/arc.d.ts +31 -2
- package/es/victory-primitives/arc.js +3 -2
- package/es/victory-primitives/background.d.ts +31 -2
- package/es/victory-primitives/background.js +3 -2
- package/es/victory-primitives/border.d.ts +28 -2
- package/es/victory-primitives/border.js +3 -2
- package/es/victory-primitives/circle.d.ts +1 -0
- package/es/victory-primitives/circle.js +2 -1
- package/es/victory-primitives/clip-path.d.ts +2 -1
- package/es/victory-primitives/clip-path.js +2 -1
- package/es/victory-primitives/index.d.ts +1 -0
- package/es/victory-primitives/index.js +2 -1
- package/es/victory-primitives/line-segment.d.ts +29 -2
- package/es/victory-primitives/line-segment.js +3 -2
- package/es/victory-primitives/line.d.ts +1 -0
- package/es/victory-primitives/line.js +2 -1
- package/es/victory-primitives/path.d.ts +1 -0
- package/es/victory-primitives/path.js +2 -1
- package/es/victory-primitives/point.d.ts +30 -2
- package/es/victory-primitives/point.js +3 -2
- package/es/victory-primitives/rect.d.ts +1 -0
- package/es/victory-primitives/rect.js +2 -1
- package/es/victory-primitives/text.d.ts +2 -1
- package/es/victory-primitives/text.js +2 -1
- package/es/victory-primitives/tspan.d.ts +2 -1
- package/es/victory-primitives/tspan.js +2 -1
- package/es/victory-primitives/types.d.ts +2 -1
- package/es/victory-primitives/types.js +2 -1
- package/es/victory-primitives/whisker.d.ts +37 -2
- package/es/victory-primitives/whisker.js +3 -2
- package/es/victory-state/defaults.d.ts +3 -0
- package/es/victory-state/defaults.js +3 -0
- package/es/victory-state/helpers/get-axis-data.d.ts +3 -0
- package/es/victory-state/helpers/get-axis-data.js +15 -0
- package/es/victory-state/helpers/get-data.d.ts +15 -0
- package/es/victory-state/helpers/get-data.js +88 -0
- package/es/victory-state/helpers/get-domain.d.ts +6 -0
- package/es/victory-state/helpers/get-domain.js +68 -0
- package/es/victory-state/helpers/get-range.d.ts +6 -0
- package/es/victory-state/helpers/get-range.js +37 -0
- package/es/victory-state/helpers/get-scale.d.ts +6 -0
- package/es/victory-state/helpers/get-scale.js +59 -0
- package/es/victory-state/index.d.ts +3 -0
- package/es/victory-state/index.js +3 -0
- package/es/victory-state/types.d.ts +24 -0
- package/es/victory-state/types.js +2 -0
- package/es/victory-state/victory-provider.d.ts +19 -0
- package/es/victory-state/victory-provider.js +118 -0
- package/es/victory-theme/grayscale.d.ts +2 -1
- package/es/victory-theme/grayscale.js +2 -1
- package/es/victory-theme/material.d.ts +2 -1
- package/es/victory-theme/material.js +2 -1
- package/{lib/victory-theme/victory-theme-definition.d.ts → es/victory-theme/types.d.ts} +3 -8
- package/es/victory-theme/types.js +2 -0
- package/es/victory-theme/victory-theme.d.ts +4 -3
- package/es/victory-theme/victory-theme.js +3 -2
- package/es/victory-transition/victory-transition.d.ts +1 -0
- package/es/victory-transition/victory-transition.js +2 -1
- package/es/victory-util/add-events.d.ts +106 -0
- package/es/victory-util/add-events.js +40 -33
- package/es/victory-util/axis.d.ts +51 -0
- package/es/victory-util/axis.js +9 -7
- package/es/victory-util/collection.d.ts +9 -0
- package/es/victory-util/collection.js +6 -4
- package/es/victory-util/common-props.d.ts +84 -0
- package/es/victory-util/common-props.js +29 -12
- package/es/victory-util/data.d.ts +75 -0
- package/es/victory-util/data.js +2 -1
- package/es/victory-util/default-transitions.d.ts +5 -0
- package/es/victory-util/default-transitions.js +2 -1
- package/es/victory-util/domain.d.ts +91 -0
- package/es/victory-util/domain.js +6 -2
- package/es/victory-util/events.d.ts +65 -0
- package/es/victory-util/events.js +13 -8
- package/es/victory-util/helpers.d.ts +61 -0
- package/es/victory-util/helpers.js +8 -4
- package/es/victory-util/hooks/index.d.ts +3 -0
- package/es/victory-util/hooks/index.js +2 -1
- package/es/victory-util/hooks/use-animation-state.js +4 -3
- package/es/victory-util/hooks/use-previous-props.d.ts +2 -0
- package/es/victory-util/hooks/use-previous-props.js +4 -3
- package/es/victory-util/immutable.d.ts +12 -0
- package/es/victory-util/immutable.js +5 -4
- package/es/victory-util/index.d.ts +29 -0
- package/es/victory-util/index.js +48 -0
- package/es/victory-util/label-helpers.d.ts +27 -0
- package/es/victory-util/label-helpers.js +2 -1
- package/es/victory-util/line-helpers.d.ts +5 -0
- package/es/victory-util/line-helpers.js +24 -6
- package/es/victory-util/log.d.ts +2 -0
- package/es/victory-util/log.js +2 -1
- package/es/victory-util/point-path-helpers.d.ts +1 -0
- package/es/victory-util/point-path-helpers.js +2 -1
- package/es/victory-util/prop-types.d.ts +51 -0
- package/es/victory-util/prop-types.js +35 -44
- package/es/victory-util/scale.d.ts +10 -0
- package/es/victory-util/scale.js +14 -6
- package/es/victory-util/selection.d.ts +25 -23
- package/es/victory-util/selection.js +25 -14
- package/es/victory-util/style.d.ts +19 -0
- package/es/victory-util/style.js +2 -1
- package/es/victory-util/textsize.d.ts +37 -8
- package/es/victory-util/textsize.js +9 -6
- package/es/victory-util/timer-context.d.ts +1 -0
- package/es/victory-util/timer-context.js +2 -1
- package/es/victory-util/timer.d.ts +3 -2
- package/es/victory-util/timer.js +2 -1
- package/es/victory-util/transitions.d.ts +49 -0
- package/es/victory-util/transitions.js +5 -4
- package/es/victory-util/type-helpers.d.ts +10 -0
- package/es/victory-util/type-helpers.js +28 -0
- package/es/victory-util/user-props.d.ts +21 -0
- package/es/victory-util/user-props.js +6 -5
- package/es/victory-util/with-container.d.ts +5 -0
- package/es/victory-util/with-container.js +32 -0
- package/es/victory-util/wrapper.d.ts +38 -0
- package/es/victory-util/wrapper.js +4 -3
- package/lib/index.d.ts +7 -27
- package/lib/index.js +58 -147
- package/lib/{types.d.ts → types/callbacks.d.ts} +12 -8
- package/lib/types/callbacks.js +2 -0
- package/lib/types/prop-types.d.ts +130 -0
- package/lib/types/prop-types.js +2 -0
- package/lib/victory-accessible-group/victory-accessible-group.d.ts +1 -0
- package/lib/victory-accessible-group/victory-accessible-group.js +2 -1
- package/lib/victory-animation/util.d.ts +2 -1
- package/lib/victory-animation/util.js +6 -4
- package/lib/victory-animation/victory-animation.d.ts +1 -0
- package/lib/victory-animation/victory-animation.js +2 -1
- package/lib/victory-clip-container/victory-clip-container.d.ts +6 -5
- package/lib/victory-clip-container/victory-clip-container.js +2 -1
- package/lib/victory-container/victory-container.d.ts +8 -7
- package/lib/victory-container/victory-container.js +2 -1
- package/lib/victory-label/victory-label.d.ts +3 -2
- package/lib/victory-label/victory-label.js +4 -4
- package/lib/victory-portal/portal-context.d.ts +1 -0
- package/lib/victory-portal/portal-context.js +2 -1
- package/lib/victory-portal/portal.d.ts +3 -2
- package/lib/victory-portal/portal.js +2 -1
- package/lib/victory-portal/victory-portal.d.ts +1 -0
- package/lib/victory-portal/victory-portal.js +2 -1
- package/lib/victory-primitives/arc.d.ts +31 -2
- package/lib/victory-primitives/arc.js +4 -3
- package/lib/victory-primitives/background.d.ts +31 -2
- package/lib/victory-primitives/background.js +4 -3
- package/lib/victory-primitives/border.d.ts +28 -2
- package/lib/victory-primitives/border.js +4 -3
- package/lib/victory-primitives/circle.d.ts +1 -0
- package/lib/victory-primitives/circle.js +2 -1
- package/lib/victory-primitives/clip-path.d.ts +2 -1
- package/lib/victory-primitives/clip-path.js +2 -1
- package/lib/victory-primitives/index.d.ts +1 -0
- package/lib/victory-primitives/index.js +2 -1
- package/lib/victory-primitives/line-segment.d.ts +29 -2
- package/lib/victory-primitives/line-segment.js +4 -3
- package/lib/victory-primitives/line.d.ts +1 -0
- package/lib/victory-primitives/line.js +2 -1
- package/lib/victory-primitives/path.d.ts +1 -0
- package/lib/victory-primitives/path.js +2 -1
- package/lib/victory-primitives/point.d.ts +30 -2
- package/lib/victory-primitives/point.js +4 -3
- package/lib/victory-primitives/rect.d.ts +1 -0
- package/lib/victory-primitives/rect.js +2 -1
- package/lib/victory-primitives/text.d.ts +2 -1
- package/lib/victory-primitives/text.js +2 -1
- package/lib/victory-primitives/tspan.d.ts +2 -1
- package/lib/victory-primitives/tspan.js +2 -1
- package/lib/victory-primitives/types.d.ts +2 -1
- package/lib/victory-primitives/types.js +2 -1
- package/lib/victory-primitives/whisker.d.ts +37 -2
- package/lib/victory-primitives/whisker.js +4 -3
- package/lib/victory-state/defaults.d.ts +3 -0
- package/lib/victory-state/defaults.js +11 -0
- package/lib/victory-state/helpers/get-axis-data.d.ts +3 -0
- package/lib/victory-state/helpers/get-axis-data.js +23 -0
- package/lib/victory-state/helpers/get-data.d.ts +15 -0
- package/lib/victory-state/helpers/get-data.js +99 -0
- package/lib/victory-state/helpers/get-domain.d.ts +6 -0
- package/lib/victory-state/helpers/get-domain.js +82 -0
- package/lib/victory-state/helpers/get-range.d.ts +6 -0
- package/lib/victory-state/helpers/get-range.js +46 -0
- package/lib/victory-state/helpers/get-scale.d.ts +6 -0
- package/lib/victory-state/helpers/get-scale.js +74 -0
- package/lib/victory-state/index.d.ts +3 -0
- package/lib/victory-state/index.js +32 -0
- package/lib/victory-state/types.d.ts +24 -0
- package/lib/victory-state/types.js +2 -0
- package/lib/victory-state/victory-provider.d.ts +19 -0
- package/lib/victory-state/victory-provider.js +144 -0
- package/lib/victory-theme/grayscale.d.ts +2 -1
- package/lib/victory-theme/grayscale.js +2 -1
- package/lib/victory-theme/material.d.ts +2 -1
- package/lib/victory-theme/material.js +2 -1
- package/{es/victory-theme/victory-theme-definition.d.ts → lib/victory-theme/types.d.ts} +3 -8
- package/lib/victory-theme/types.js +2 -0
- package/lib/victory-theme/victory-theme.d.ts +4 -3
- package/lib/victory-theme/victory-theme.js +6 -5
- package/lib/victory-transition/victory-transition.d.ts +1 -0
- package/lib/victory-transition/victory-transition.js +2 -1
- package/lib/victory-util/add-events.d.ts +106 -0
- package/lib/victory-util/add-events.js +40 -36
- package/lib/victory-util/axis.d.ts +51 -0
- package/lib/victory-util/axis.js +8 -6
- package/lib/victory-util/collection.d.ts +9 -0
- package/lib/victory-util/collection.js +6 -4
- package/lib/victory-util/common-props.d.ts +84 -0
- package/lib/victory-util/common-props.js +27 -12
- package/lib/victory-util/data.d.ts +75 -0
- package/lib/victory-util/data.js +2 -1
- package/lib/victory-util/default-transitions.d.ts +5 -0
- package/lib/victory-util/default-transitions.js +2 -1
- package/lib/victory-util/domain.d.ts +91 -0
- package/lib/victory-util/domain.js +6 -2
- package/lib/victory-util/events.d.ts +65 -0
- package/lib/victory-util/events.js +13 -9
- package/lib/victory-util/helpers.d.ts +61 -0
- package/lib/victory-util/helpers.js +8 -4
- package/lib/victory-util/hooks/index.d.ts +3 -0
- package/lib/victory-util/hooks/index.js +2 -1
- package/lib/victory-util/hooks/use-animation-state.js +4 -3
- package/lib/victory-util/hooks/use-previous-props.d.ts +2 -0
- package/lib/victory-util/hooks/use-previous-props.js +5 -6
- package/lib/victory-util/immutable.d.ts +12 -0
- package/lib/victory-util/immutable.js +5 -4
- package/lib/victory-util/index.d.ts +29 -0
- package/lib/victory-util/index.js +181 -0
- package/lib/victory-util/label-helpers.d.ts +27 -0
- package/lib/victory-util/label-helpers.js +2 -1
- package/lib/victory-util/line-helpers.d.ts +5 -0
- package/lib/victory-util/line-helpers.js +28 -7
- package/lib/victory-util/log.d.ts +2 -0
- package/lib/victory-util/log.js +2 -1
- package/lib/victory-util/point-path-helpers.d.ts +1 -0
- package/lib/victory-util/point-path-helpers.js +2 -1
- package/lib/victory-util/prop-types.d.ts +51 -0
- package/lib/victory-util/prop-types.js +36 -44
- package/lib/victory-util/scale.d.ts +10 -0
- package/lib/victory-util/scale.js +14 -5
- package/lib/victory-util/selection.d.ts +25 -23
- package/lib/victory-util/selection.js +25 -19
- package/lib/victory-util/style.d.ts +19 -0
- package/lib/victory-util/style.js +2 -1
- package/lib/victory-util/textsize.d.ts +37 -8
- package/lib/victory-util/textsize.js +9 -6
- package/lib/victory-util/timer-context.d.ts +1 -0
- package/lib/victory-util/timer-context.js +2 -1
- package/lib/victory-util/timer.d.ts +3 -2
- package/lib/victory-util/timer.js +2 -1
- package/lib/victory-util/transitions.d.ts +49 -0
- package/lib/victory-util/transitions.js +5 -4
- package/lib/victory-util/type-helpers.d.ts +10 -0
- package/lib/victory-util/type-helpers.js +45 -0
- package/lib/victory-util/user-props.d.ts +21 -0
- package/lib/victory-util/user-props.js +6 -5
- package/lib/victory-util/with-container.d.ts +5 -0
- package/lib/victory-util/with-container.js +44 -0
- package/lib/victory-util/wrapper.d.ts +38 -0
- package/lib/victory-util/wrapper.js +4 -3
- package/package.json +3 -3
- package/src/index.ts +9 -31
- package/src/{types.ts → types/callbacks.ts} +21 -13
- package/src/types/prop-types.ts +195 -0
- package/src/victory-accessible-group/victory-accessible-group.tsx +3 -3
- package/src/victory-animation/util.ts +3 -2
- package/src/victory-animation/victory-animation.tsx +13 -13
- package/src/victory-clip-container/victory-clip-container.tsx +23 -23
- package/src/victory-container/victory-container.tsx +19 -19
- package/src/victory-label/victory-label.tsx +41 -39
- package/src/victory-portal/portal.tsx +1 -1
- package/src/victory-portal/victory-portal.tsx +3 -3
- package/src/victory-primitives/arc.tsx +8 -6
- package/src/victory-primitives/background.tsx +8 -6
- package/src/victory-primitives/border.tsx +8 -6
- package/src/victory-primitives/clip-path.tsx +3 -3
- package/src/victory-primitives/line-segment.tsx +8 -6
- package/src/victory-primitives/point.tsx +10 -8
- package/src/victory-primitives/text.tsx +2 -2
- package/src/victory-primitives/tspan.tsx +1 -1
- package/src/victory-primitives/types.ts +1 -1
- package/src/victory-primitives/whisker.tsx +15 -13
- package/src/victory-state/defaults.ts +2 -0
- package/src/victory-state/helpers/get-axis-data.ts +14 -0
- package/src/victory-state/helpers/get-data.ts +79 -0
- package/src/victory-state/helpers/get-domain.ts +62 -0
- package/src/victory-state/helpers/get-range.ts +39 -0
- package/src/victory-state/helpers/get-scale.ts +64 -0
- package/src/victory-state/index.ts +2 -0
- package/src/victory-state/types.ts +32 -0
- package/src/victory-state/victory-provider.tsx +116 -0
- package/src/victory-theme/grayscale.tsx +62 -62
- package/src/victory-theme/material.tsx +67 -67
- package/src/victory-theme/{victory-theme-definition.ts → types.ts} +10 -14
- package/src/victory-theme/victory-theme.tsx +1 -1
- package/src/victory-transition/victory-transition.tsx +19 -19
- package/src/victory-util/{add-events.js → add-events.tsx} +136 -59
- package/src/victory-util/{axis.js → axis.tsx} +17 -18
- package/src/victory-util/{collection.js → collection.tsx} +14 -10
- package/src/victory-util/common-props.tsx +307 -0
- package/src/victory-util/{data.js → data.ts} +14 -10
- package/src/victory-util/{default-transitions.js → default-transitions.ts} +20 -18
- package/src/victory-util/{domain.js → domain.ts} +26 -23
- package/src/victory-util/{events.js → events.ts} +82 -31
- package/src/victory-util/{helpers.js → helpers.ts} +41 -22
- package/src/victory-util/hooks/{index.js → index.ts} +0 -0
- package/src/victory-util/hooks/use-animation-state.js +12 -12
- package/src/victory-util/hooks/use-previous-props.ts +9 -0
- package/src/victory-util/{immutable.js → immutable.ts} +14 -10
- package/src/victory-util/index.ts +28 -0
- package/src/victory-util/{label-helpers.js → label-helpers.ts} +7 -7
- package/src/victory-util/line-helpers.ts +104 -0
- package/src/victory-util/{log.js → log.ts} +1 -1
- package/src/victory-util/{prop-types.js → prop-types.ts} +103 -101
- package/src/victory-util/{scale.js → scale.ts} +29 -16
- package/src/victory-util/selection.ts +158 -0
- package/src/victory-util/{style.js → style.ts} +3 -3
- package/src/victory-util/{textsize.js → textsize.ts} +32 -17
- package/src/victory-util/timer-context.ts +1 -1
- package/src/victory-util/timer.ts +5 -10
- package/src/victory-util/{transitions.js → transitions.ts} +50 -22
- package/src/victory-util/type-helpers.ts +50 -0
- package/src/victory-util/{user-props.js → user-props.ts} +16 -11
- package/src/victory-util/with-container.tsx +41 -0
- package/src/victory-util/{wrapper.js → wrapper.tsx} +38 -33
- package/es/types.js +0 -1
- package/es/victory-theme/victory-theme-definition.js +0 -1
- package/es/victory-util/types.d.ts +0 -188
- package/es/victory-util/types.js +0 -1
- package/lib/types.js +0 -1
- package/lib/victory-theme/victory-theme-definition.js +0 -1
- package/lib/victory-util/types.d.ts +0 -188
- package/lib/victory-util/types.js +0 -1
- package/src/victory-util/common-props.js +0 -197
- package/src/victory-util/hooks/use-previous-props.js +0 -9
- package/src/victory-util/line-helpers.js +0 -54
- package/src/victory-util/selection.d.ts +0 -23
- package/src/victory-util/selection.js +0 -98
- package/src/victory-util/textsize.d.ts +0 -8
- package/src/victory-util/types.ts +0 -247
|
@@ -52,7 +52,7 @@ export class VictoryTransition extends React.Component<
|
|
|
52
52
|
static propTypes = {
|
|
53
53
|
animate: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
54
54
|
animationWhitelist: PropTypes.array,
|
|
55
|
-
children: PropTypes.node
|
|
55
|
+
children: PropTypes.node,
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
static contextType = TimerContext;
|
|
@@ -64,7 +64,7 @@ export class VictoryTransition extends React.Component<
|
|
|
64
64
|
super(props, context);
|
|
65
65
|
this.state = {
|
|
66
66
|
nodesShouldLoad: false,
|
|
67
|
-
nodesDoneLoad: false
|
|
67
|
+
nodesDoneLoad: false,
|
|
68
68
|
};
|
|
69
69
|
const child = this.props.children;
|
|
70
70
|
const polar = child.props.polar;
|
|
@@ -80,7 +80,7 @@ export class VictoryTransition extends React.Component<
|
|
|
80
80
|
if (!isEqual(this.props, nextProps)) {
|
|
81
81
|
this.timer.bypassAnimation();
|
|
82
82
|
this.setState(this.getTransitionState(this.props, nextProps), () =>
|
|
83
|
-
this.timer.resumeAnimation()
|
|
83
|
+
this.timer.resumeAnimation(),
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
return true;
|
|
@@ -92,7 +92,7 @@ export class VictoryTransition extends React.Component<
|
|
|
92
92
|
|
|
93
93
|
private getTransitionState(
|
|
94
94
|
props: VictoryTransitionProps,
|
|
95
|
-
nextProps: VictoryTransitionProps
|
|
95
|
+
nextProps: VictoryTransitionProps,
|
|
96
96
|
): VictoryTransitionState {
|
|
97
97
|
const { animate } = props;
|
|
98
98
|
if (!animate) {
|
|
@@ -108,7 +108,7 @@ export class VictoryTransition extends React.Component<
|
|
|
108
108
|
nodesWillExit,
|
|
109
109
|
nodesWillEnter,
|
|
110
110
|
childrenTransitions,
|
|
111
|
-
nodesShouldEnter
|
|
111
|
+
nodesShouldEnter,
|
|
112
112
|
} = Transitions.getInitialTransitionState(oldChildren, nextChildren);
|
|
113
113
|
return {
|
|
114
114
|
nodesWillExit,
|
|
@@ -116,14 +116,14 @@ export class VictoryTransition extends React.Component<
|
|
|
116
116
|
childrenTransitions,
|
|
117
117
|
nodesShouldEnter,
|
|
118
118
|
oldProps: nodesWillExit ? props : null,
|
|
119
|
-
nextProps
|
|
119
|
+
nextProps,
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
private getDomainFromChildren(
|
|
125
125
|
props: VictoryTransitionProps,
|
|
126
|
-
axis: "x" | "y"
|
|
126
|
+
axis: "x" | "y",
|
|
127
127
|
) {
|
|
128
128
|
const getChildDomains = (children) => {
|
|
129
129
|
return children.reduce((memo, child) => {
|
|
@@ -133,7 +133,7 @@ export class VictoryTransition extends React.Component<
|
|
|
133
133
|
return childDomain ? memo.concat(childDomain) : memo;
|
|
134
134
|
} else if (child.props && child.props.children) {
|
|
135
135
|
return memo.concat(
|
|
136
|
-
getChildDomains(React.Children.toArray(child.props.children))
|
|
136
|
+
getChildDomains(React.Children.toArray(child.props.children)),
|
|
137
137
|
);
|
|
138
138
|
}
|
|
139
139
|
return memo;
|
|
@@ -141,7 +141,7 @@ export class VictoryTransition extends React.Component<
|
|
|
141
141
|
};
|
|
142
142
|
|
|
143
143
|
const child = React.Children.toArray(
|
|
144
|
-
props.children
|
|
144
|
+
props.children,
|
|
145
145
|
)[0] as VictoryTransitionChild;
|
|
146
146
|
const childProps: any = child.props || {};
|
|
147
147
|
const domain = Array.isArray(childProps.domain)
|
|
@@ -155,7 +155,7 @@ export class VictoryTransition extends React.Component<
|
|
|
155
155
|
? [0, 1]
|
|
156
156
|
: [
|
|
157
157
|
Collection.getMinValue(childDomains),
|
|
158
|
-
Collection.getMaxValue(childDomains)
|
|
158
|
+
Collection.getMaxValue(childDomains),
|
|
159
159
|
];
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -197,22 +197,22 @@ export class VictoryTransition extends React.Component<
|
|
|
197
197
|
const getTransitionProps = this.props.animate?.getTransitions
|
|
198
198
|
? this.props.animate.getTransitions
|
|
199
199
|
: Transitions.getTransitionPropsFactory(props, this.state, (newState) =>
|
|
200
|
-
this.setState(newState)
|
|
200
|
+
this.setState(newState),
|
|
201
201
|
);
|
|
202
202
|
const child = React.Children.toArray(
|
|
203
|
-
props.children
|
|
203
|
+
props.children,
|
|
204
204
|
)[0] as VictoryTransitionChild;
|
|
205
205
|
const transitionProps = getTransitionProps(child);
|
|
206
206
|
this.transitionProps = transitionProps;
|
|
207
207
|
const domain = {
|
|
208
208
|
x: this.getDomainFromChildren(this.pickDomainProps(props), "x"),
|
|
209
|
-
y: this.getDomainFromChildren(props, "y")
|
|
209
|
+
y: this.getDomainFromChildren(props, "y"),
|
|
210
210
|
};
|
|
211
211
|
const clipWidth = this.getClipWidth(props, child);
|
|
212
212
|
const combinedProps = defaults(
|
|
213
213
|
{ domain, clipWidth },
|
|
214
214
|
transitionProps,
|
|
215
|
-
child.props
|
|
215
|
+
child.props,
|
|
216
216
|
);
|
|
217
217
|
const animationWhitelist = props.animationWhitelist || [];
|
|
218
218
|
const whitelist = animationWhitelist.concat(["clipWidth"]);
|
|
@@ -225,7 +225,7 @@ export class VictoryTransition extends React.Component<
|
|
|
225
225
|
if (child.props.groupComponent) {
|
|
226
226
|
const groupComponent = this.continuous
|
|
227
227
|
? React.cloneElement(child.props.groupComponent, {
|
|
228
|
-
clipWidth: newProps.clipWidth || 0
|
|
228
|
+
clipWidth: newProps.clipWidth || 0,
|
|
229
229
|
})
|
|
230
230
|
: child.props.groupComponent;
|
|
231
231
|
return React.cloneElement(
|
|
@@ -233,8 +233,8 @@ export class VictoryTransition extends React.Component<
|
|
|
233
233
|
defaults(
|
|
234
234
|
{ animate: null, animating: true, groupComponent },
|
|
235
235
|
newProps,
|
|
236
|
-
combinedProps
|
|
237
|
-
)
|
|
236
|
+
combinedProps,
|
|
237
|
+
),
|
|
238
238
|
);
|
|
239
239
|
}
|
|
240
240
|
return React.cloneElement(
|
|
@@ -242,8 +242,8 @@ export class VictoryTransition extends React.Component<
|
|
|
242
242
|
defaults(
|
|
243
243
|
{ animate: null, animating: true },
|
|
244
244
|
newProps,
|
|
245
|
-
combinedProps
|
|
246
|
-
)
|
|
245
|
+
combinedProps,
|
|
246
|
+
),
|
|
247
247
|
);
|
|
248
248
|
}}
|
|
249
249
|
</VictoryAnimation>
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
/*global window:false */
|
|
2
2
|
import React from "react";
|
|
3
3
|
import {
|
|
4
|
-
defaults,
|
|
5
4
|
assign,
|
|
6
|
-
|
|
5
|
+
defaults,
|
|
6
|
+
difference,
|
|
7
|
+
isEmpty,
|
|
7
8
|
isFunction,
|
|
9
|
+
isNil,
|
|
10
|
+
keys,
|
|
8
11
|
pick,
|
|
9
12
|
without,
|
|
10
|
-
isEmpty,
|
|
11
|
-
isNil,
|
|
12
|
-
difference
|
|
13
13
|
} from "lodash";
|
|
14
|
+
import type { ComponentEvent } from "./events";
|
|
14
15
|
import * as Events from "./events";
|
|
15
16
|
import isEqual from "react-fast-compare";
|
|
16
17
|
import { VictoryTransition } from "../victory-transition/victory-transition";
|
|
18
|
+
import { VictoryCommonProps, VictoryDatableProps } from "./common-props";
|
|
19
|
+
import { VictoryLabelableProps } from "../types/prop-types";
|
|
17
20
|
|
|
18
21
|
// DISCLAIMER:
|
|
19
22
|
// This file is not currently tested, and it is first on the list of files
|
|
@@ -25,34 +28,104 @@ const datumHasXandY = (datum) => {
|
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
// used for checking state changes. Expected components can be passed in via options
|
|
28
|
-
const defaultComponents = [
|
|
31
|
+
const defaultComponents: NonNullable<MixinOptions["components"]> = [
|
|
29
32
|
{ name: "parent", index: "parent" },
|
|
30
33
|
{ name: "data" },
|
|
31
|
-
{ name: "labels" }
|
|
34
|
+
{ name: "labels" },
|
|
32
35
|
];
|
|
33
36
|
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
export type MixinOptions = {
|
|
38
|
+
components?: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
index?: string;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export interface EventMixinCommonProps
|
|
45
|
+
extends VictoryCommonProps,
|
|
46
|
+
VictoryDatableProps,
|
|
47
|
+
VictoryLabelableProps {}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* These methods will be implemented by the Mixin,
|
|
51
|
+
* and are accessible to the Wrapped Component.
|
|
52
|
+
*
|
|
53
|
+
* To make your Wrapped Component type-safe, use "interface merging" like so:
|
|
54
|
+
* @example
|
|
55
|
+
* interface MyComponent extends EventsMixinClass<MyProps> {}
|
|
56
|
+
* class MyComponent extends React.Component<MyProps> { ... }
|
|
57
|
+
*/
|
|
58
|
+
export interface EventsMixinClass<TProps> {
|
|
59
|
+
renderContainer(
|
|
60
|
+
component: React.ReactElement,
|
|
61
|
+
children: React.ReactElement[],
|
|
62
|
+
): React.ReactElement;
|
|
63
|
+
cacheValues<TThis>(this: TThis, obj: Partial<TThis>): void;
|
|
64
|
+
getEventState: typeof Events.getEventState;
|
|
65
|
+
renderContinuousData(props: TProps);
|
|
66
|
+
animateComponent(props: TProps, defaultAnimationWhitelist);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* These fields are calculated by the Mixin
|
|
71
|
+
*/
|
|
72
|
+
export interface EventMixinCalculatedValues {
|
|
73
|
+
componentEvents: Array<ComponentEvent>;
|
|
74
|
+
getSharedEventState: (key: string, value: string) => unknown;
|
|
75
|
+
baseProps: Record<string, object>;
|
|
76
|
+
dataKeys: string[];
|
|
77
|
+
hasEvents: unknown;
|
|
78
|
+
events: unknown;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* This represents the class itself, including static fields
|
|
83
|
+
*/
|
|
84
|
+
export interface WrappedComponentClass<TProps> {
|
|
85
|
+
new (props: TProps): React.Component<TProps>;
|
|
86
|
+
getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
|
|
87
|
+
role?: string;
|
|
88
|
+
expectedComponents?: string[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function addEvents<
|
|
92
|
+
TBase extends WrappedComponentClass<TProps>,
|
|
93
|
+
TProps extends EventMixinCommonProps,
|
|
94
|
+
>(WrappedComponent: TBase, options: MixinOptions = {}) {
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
96
|
+
interface AddEventsMixin extends EventMixinCalculatedValues {}
|
|
97
|
+
|
|
98
|
+
// @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
|
|
99
|
+
class AddEventsMixin
|
|
100
|
+
extends WrappedComponent
|
|
101
|
+
implements EventsMixinClass<TProps>
|
|
102
|
+
{
|
|
103
|
+
constructor(props: TProps) {
|
|
37
104
|
super(props);
|
|
38
|
-
const getScopedEvents = Events.getScopedEvents.bind(this);
|
|
39
|
-
const boundGetEvents = Events.getEvents.bind(this);
|
|
40
|
-
this.state = {};
|
|
41
|
-
this.getEvents = (p, target, eventKey) => {
|
|
42
|
-
return boundGetEvents(p, target, eventKey, getScopedEvents);
|
|
43
|
-
};
|
|
44
|
-
this.getEventState = Events.getEventState.bind(this);
|
|
45
|
-
const calculatedValues = this.getCalculatedValues(props);
|
|
46
|
-
this.cacheValues(calculatedValues);
|
|
47
|
-
this.externalMutations = this.getExternalMutations(props);
|
|
48
|
-
this.calculatedState = this.getStateChanges(props);
|
|
49
|
-
this.globalEvents = {};
|
|
50
|
-
this.prevGlobalEventKeys = [];
|
|
51
|
-
this.boundGlobalEvents = {};
|
|
52
|
-
}
|
|
53
105
|
|
|
54
|
-
|
|
106
|
+
this.cacheValues(this.getCalculatedValues(props));
|
|
107
|
+
}
|
|
108
|
+
state = {};
|
|
109
|
+
getEventState = Events.getEventState.bind(this);
|
|
110
|
+
getScopedEvents = Events.getScopedEvents.bind(this);
|
|
111
|
+
getEvents = (p, target, eventKey) => {
|
|
112
|
+
return Events.getEvents.call(
|
|
113
|
+
this,
|
|
114
|
+
p,
|
|
115
|
+
target,
|
|
116
|
+
eventKey,
|
|
117
|
+
this.getScopedEvents,
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
externalMutations = this.getExternalMutations(this.props);
|
|
121
|
+
calculatedState = this.getStateChanges(this.props);
|
|
122
|
+
globalEvents = {};
|
|
123
|
+
prevGlobalEventKeys: string[] = [];
|
|
124
|
+
boundGlobalEvents = {};
|
|
125
|
+
|
|
126
|
+
shouldComponentUpdate(nextProps: TProps) {
|
|
55
127
|
const externalMutations = this.getExternalMutations(nextProps);
|
|
128
|
+
// @ts-expect-error "Property 'animating' does not exist on type EventMixinCommonProps"
|
|
56
129
|
const animating = this.props.animating || this.props.animate;
|
|
57
130
|
const newMutation = !isEqual(externalMutations, this.externalMutations);
|
|
58
131
|
if (animating || newMutation) {
|
|
@@ -85,12 +158,12 @@ export default (WrappedComponent, options) => {
|
|
|
85
158
|
const globalEventKeys = keys(this.globalEvents);
|
|
86
159
|
const removedGlobalEventKeys = difference(
|
|
87
160
|
this.prevGlobalEventKeys,
|
|
88
|
-
globalEventKeys
|
|
161
|
+
globalEventKeys,
|
|
89
162
|
);
|
|
90
163
|
removedGlobalEventKeys.forEach((key) => this.removeGlobalListener(key));
|
|
91
164
|
const addedGlobalEventKeys = difference(
|
|
92
165
|
globalEventKeys,
|
|
93
|
-
this.prevGlobalEventKeys
|
|
166
|
+
this.prevGlobalEventKeys,
|
|
94
167
|
);
|
|
95
168
|
addedGlobalEventKeys.forEach((key) => this.addGlobalListener(key));
|
|
96
169
|
this.prevGlobalEventKeys = globalEventKeys;
|
|
@@ -108,14 +181,14 @@ export default (WrappedComponent, options) => {
|
|
|
108
181
|
this.boundGlobalEvents[key] = boundListener;
|
|
109
182
|
window.addEventListener(
|
|
110
183
|
Events.getGlobalEventNameFromKey(key),
|
|
111
|
-
boundListener
|
|
184
|
+
boundListener,
|
|
112
185
|
);
|
|
113
186
|
}
|
|
114
187
|
|
|
115
188
|
removeGlobalListener(key) {
|
|
116
189
|
window.removeEventListener(
|
|
117
190
|
Events.getGlobalEventNameFromKey(key),
|
|
118
|
-
this.boundGlobalEvents[key]
|
|
191
|
+
this.boundGlobalEvents[key],
|
|
119
192
|
);
|
|
120
193
|
}
|
|
121
194
|
|
|
@@ -130,12 +203,11 @@ export default (WrappedComponent, options) => {
|
|
|
130
203
|
const result = defaults(
|
|
131
204
|
{},
|
|
132
205
|
this.getEventState(key, type),
|
|
133
|
-
this.getSharedEventState(key, type)
|
|
206
|
+
this.getSharedEventState(key, type),
|
|
134
207
|
);
|
|
135
208
|
return isEmpty(result) ? undefined : result;
|
|
136
209
|
};
|
|
137
210
|
|
|
138
|
-
options = options || {};
|
|
139
211
|
const components = options.components || defaultComponents;
|
|
140
212
|
const stateChanges = components
|
|
141
213
|
.map((component) => {
|
|
@@ -163,7 +235,7 @@ export default (WrappedComponent, options) => {
|
|
|
163
235
|
: memo;
|
|
164
236
|
return memo;
|
|
165
237
|
},
|
|
166
|
-
[]
|
|
238
|
+
[] as Array<() => void>,
|
|
167
239
|
);
|
|
168
240
|
const compiledCallbacks = callbacks.length
|
|
169
241
|
? () => {
|
|
@@ -174,7 +246,7 @@ export default (WrappedComponent, options) => {
|
|
|
174
246
|
}
|
|
175
247
|
}
|
|
176
248
|
|
|
177
|
-
getCalculatedValues(props) {
|
|
249
|
+
getCalculatedValues(props): EventMixinCalculatedValues {
|
|
178
250
|
const { sharedEvents } = props;
|
|
179
251
|
const components = WrappedComponent.expectedComponents;
|
|
180
252
|
const componentEvents = Events.getComponentEvents(props, components);
|
|
@@ -192,18 +264,18 @@ export default (WrappedComponent, options) => {
|
|
|
192
264
|
baseProps,
|
|
193
265
|
dataKeys,
|
|
194
266
|
hasEvents,
|
|
195
|
-
events
|
|
267
|
+
events,
|
|
196
268
|
};
|
|
197
269
|
}
|
|
198
270
|
|
|
199
|
-
getExternalMutations(props) {
|
|
271
|
+
getExternalMutations(props: TProps) {
|
|
200
272
|
const { sharedEvents, externalEventMutations } = props;
|
|
201
273
|
return isEmpty(externalEventMutations) || sharedEvents
|
|
202
274
|
? undefined
|
|
203
275
|
: Events.getExternalMutations(
|
|
204
276
|
externalEventMutations,
|
|
205
277
|
this.baseProps,
|
|
206
|
-
this.state
|
|
278
|
+
this.state,
|
|
207
279
|
);
|
|
208
280
|
}
|
|
209
281
|
|
|
@@ -213,8 +285,9 @@ export default (WrappedComponent, options) => {
|
|
|
213
285
|
});
|
|
214
286
|
}
|
|
215
287
|
|
|
216
|
-
getBaseProps(props, getSharedEventState) {
|
|
217
|
-
getSharedEventState =
|
|
288
|
+
getBaseProps(props, getSharedEventState): this["baseProps"] {
|
|
289
|
+
getSharedEventState =
|
|
290
|
+
getSharedEventState || this.getSharedEventState.bind(this);
|
|
218
291
|
const sharedParentState = getSharedEventState("parent", "parent");
|
|
219
292
|
const parentState = this.getEventState("parent", "parent");
|
|
220
293
|
const baseParentProps = defaults({}, parentState, sharedParentState);
|
|
@@ -224,7 +297,7 @@ export default (WrappedComponent, options) => {
|
|
|
224
297
|
: {};
|
|
225
298
|
const modifiedProps = defaults({}, parentProps, props);
|
|
226
299
|
|
|
227
|
-
return
|
|
300
|
+
return typeof WrappedComponent.getBaseProps === "function"
|
|
228
301
|
? WrappedComponent.getBaseProps(modifiedProps)
|
|
229
302
|
: {};
|
|
230
303
|
}
|
|
@@ -259,13 +332,13 @@ export default (WrappedComponent, options) => {
|
|
|
259
332
|
this.getSharedEventState(key, type),
|
|
260
333
|
component.props,
|
|
261
334
|
baseProps,
|
|
262
|
-
{ id }
|
|
335
|
+
{ id },
|
|
263
336
|
);
|
|
264
337
|
|
|
265
338
|
const events = defaults(
|
|
266
339
|
{},
|
|
267
340
|
Events.getPartialEvents(baseEvents, key, componentProps),
|
|
268
|
-
componentProps.events
|
|
341
|
+
componentProps.events,
|
|
269
342
|
);
|
|
270
343
|
|
|
271
344
|
return assign({}, componentProps, { events });
|
|
@@ -288,46 +361,48 @@ export default (WrappedComponent, options) => {
|
|
|
288
361
|
return React.cloneElement(component, parentProps, children);
|
|
289
362
|
}
|
|
290
363
|
|
|
291
|
-
animateComponent(props, defaultAnimationWhitelist) {
|
|
364
|
+
animateComponent(props: TProps, defaultAnimationWhitelist: string[]) {
|
|
292
365
|
const animationWhitelist =
|
|
293
|
-
props.animate &&
|
|
294
|
-
|
|
295
|
-
|
|
366
|
+
(typeof props.animate === "object" &&
|
|
367
|
+
props.animate?.animationWhitelist) ||
|
|
368
|
+
defaultAnimationWhitelist;
|
|
369
|
+
|
|
370
|
+
const Comp = this.constructor;
|
|
296
371
|
|
|
297
372
|
return (
|
|
298
373
|
<VictoryTransition
|
|
299
374
|
animate={props.animate}
|
|
300
375
|
animationWhitelist={animationWhitelist}
|
|
301
376
|
>
|
|
302
|
-
{
|
|
377
|
+
<Comp {...props} />
|
|
303
378
|
</VictoryTransition>
|
|
304
379
|
);
|
|
305
380
|
}
|
|
306
381
|
|
|
307
382
|
// Used by `VictoryLine` and `VictoryArea`
|
|
308
|
-
renderContinuousData(props) {
|
|
383
|
+
renderContinuousData(props: TProps) {
|
|
309
384
|
const { dataComponent, labelComponent, groupComponent } = props;
|
|
310
385
|
const dataKeys = without(this.dataKeys, "all");
|
|
311
386
|
const labelComponents = dataKeys.reduce((memo, key) => {
|
|
312
387
|
const labelProps = this.getComponentProps(
|
|
313
388
|
labelComponent,
|
|
314
389
|
"labels",
|
|
315
|
-
key
|
|
390
|
+
key,
|
|
316
391
|
);
|
|
317
392
|
if (
|
|
318
393
|
labelProps &&
|
|
319
394
|
labelProps.text !== undefined &&
|
|
320
395
|
labelProps.text !== null
|
|
321
396
|
) {
|
|
322
|
-
memo = memo.concat(React.cloneElement(labelComponent
|
|
397
|
+
memo = memo.concat(React.cloneElement(labelComponent!, labelProps));
|
|
323
398
|
}
|
|
324
399
|
return memo;
|
|
325
|
-
}, []);
|
|
400
|
+
}, [] as React.ReactElement[]);
|
|
326
401
|
|
|
327
402
|
const dataProps = this.getComponentProps(dataComponent, "data", "all");
|
|
328
403
|
const children = [
|
|
329
|
-
React.cloneElement(dataComponent
|
|
330
|
-
...labelComponents
|
|
404
|
+
React.cloneElement(dataComponent!, dataProps),
|
|
405
|
+
...labelComponents,
|
|
331
406
|
];
|
|
332
407
|
return this.renderContainer(groupComponent, children);
|
|
333
408
|
}
|
|
@@ -339,16 +414,16 @@ export default (WrappedComponent, options) => {
|
|
|
339
414
|
const dataProps = this.getComponentProps(
|
|
340
415
|
dataComponent,
|
|
341
416
|
"data",
|
|
342
|
-
index
|
|
417
|
+
index,
|
|
343
418
|
);
|
|
344
419
|
if (shouldRenderDatum(dataProps.datum)) {
|
|
345
420
|
validDataComponents.push(
|
|
346
|
-
React.cloneElement(dataComponent, dataProps)
|
|
421
|
+
React.cloneElement(dataComponent, dataProps),
|
|
347
422
|
);
|
|
348
423
|
}
|
|
349
424
|
return validDataComponents;
|
|
350
425
|
},
|
|
351
|
-
[]
|
|
426
|
+
[] as React.ReactElement[],
|
|
352
427
|
);
|
|
353
428
|
|
|
354
429
|
const labelComponents = this.dataKeys
|
|
@@ -356,7 +431,7 @@ export default (WrappedComponent, options) => {
|
|
|
356
431
|
const labelProps = this.getComponentProps(
|
|
357
432
|
labelComponent,
|
|
358
433
|
"labels",
|
|
359
|
-
index
|
|
434
|
+
index,
|
|
360
435
|
);
|
|
361
436
|
if (labelProps.text !== undefined && labelProps.text !== null) {
|
|
362
437
|
return React.cloneElement(labelComponent, labelProps);
|
|
@@ -368,5 +443,7 @@ export default (WrappedComponent, options) => {
|
|
|
368
443
|
const children = [...dataComponents, ...labelComponents];
|
|
369
444
|
return this.renderContainer(groupComponent, children);
|
|
370
445
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return AddEventsMixin;
|
|
449
|
+
}
|
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
orderBy,
|
|
12
12
|
values,
|
|
13
13
|
includes,
|
|
14
|
-
without
|
|
14
|
+
without,
|
|
15
15
|
} from "lodash";
|
|
16
16
|
import * as Collection from "./collection";
|
|
17
17
|
import * as Domain from "./domain";
|
|
18
18
|
import * as Helpers from "./helpers";
|
|
19
|
+
import { D3Scale } from "../types/prop-types";
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Returns the axis (x or y) of a particular axis component
|
|
@@ -34,7 +35,7 @@ export function getAxis(props) {
|
|
|
34
35
|
* @param {Function} predicate: a predicate function that will be called with each
|
|
35
36
|
* @returns {Array} all axis components that pass the given predicate or []
|
|
36
37
|
*/
|
|
37
|
-
export function findAxisComponents(childComponents, predicate) {
|
|
38
|
+
export function findAxisComponents(childComponents, predicate?) {
|
|
38
39
|
predicate = predicate || identity;
|
|
39
40
|
const findAxes = (children) => {
|
|
40
41
|
return children.reduce((memo, child) => {
|
|
@@ -42,7 +43,7 @@ export function findAxisComponents(childComponents, predicate) {
|
|
|
42
43
|
return memo.concat(child);
|
|
43
44
|
} else if (child.props && child.props.children) {
|
|
44
45
|
return memo.concat(
|
|
45
|
-
findAxes(React.Children.toArray(child.props.children))
|
|
46
|
+
findAxes(React.Children.toArray(child.props.children)),
|
|
46
47
|
);
|
|
47
48
|
}
|
|
48
49
|
return memo;
|
|
@@ -86,7 +87,7 @@ export function getAxisComponentsWithParent(childComponents, type) {
|
|
|
86
87
|
return memo.concat(child);
|
|
87
88
|
} else if (child.props && child.props.children) {
|
|
88
89
|
const childAxis = findComponents(
|
|
89
|
-
React.Children.toArray(child.props.children)
|
|
90
|
+
React.Children.toArray(child.props.children),
|
|
90
91
|
);
|
|
91
92
|
return childAxis.length > 0 ? memo.concat(child) : memo;
|
|
92
93
|
}
|
|
@@ -110,7 +111,7 @@ export function getOrigin(domain) {
|
|
|
110
111
|
: getSingleOrigin(domain.x),
|
|
111
112
|
y: Collection.containsDates(domain.y)
|
|
112
113
|
? new Date(Math.min(...domain.y))
|
|
113
|
-
: getSingleOrigin(domain.y)
|
|
114
|
+
: getSingleOrigin(domain.y),
|
|
114
115
|
};
|
|
115
116
|
}
|
|
116
117
|
|
|
@@ -201,9 +202,9 @@ function getTickArray(props) {
|
|
|
201
202
|
? tickValues.map((tick) => stringMap[tick])
|
|
202
203
|
: range(1, tickValues.length + 1);
|
|
203
204
|
}
|
|
204
|
-
const tickArray = ticks ? uniq(ticks) : getTicksFromFormat(
|
|
205
|
-
const buildTickArray = (arr) => {
|
|
206
|
-
const newTickArray = [];
|
|
205
|
+
const tickArray = ticks ? uniq(ticks) : getTicksFromFormat();
|
|
206
|
+
const buildTickArray = (arr: number[]) => {
|
|
207
|
+
const newTickArray = [] as Array<{ value: number; index: number }>;
|
|
207
208
|
const domain = (props.domain && props.domain[axis]) || props.domain;
|
|
208
209
|
if (arr) {
|
|
209
210
|
arr.forEach(function (t, index) {
|
|
@@ -214,13 +215,13 @@ function getTickArray(props) {
|
|
|
214
215
|
) {
|
|
215
216
|
newTickArray.push({
|
|
216
217
|
value: t,
|
|
217
|
-
index
|
|
218
|
+
index,
|
|
218
219
|
});
|
|
219
220
|
}
|
|
220
221
|
} else {
|
|
221
222
|
newTickArray.push({
|
|
222
223
|
value: t,
|
|
223
|
-
index
|
|
224
|
+
index,
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
});
|
|
@@ -248,11 +249,9 @@ export function getTickFormat(props, scale) {
|
|
|
248
249
|
return defaultTickFormat || scaleTickFormat;
|
|
249
250
|
} else if (tickFormat && Array.isArray(tickFormat)) {
|
|
250
251
|
const tickArray = getTickArray(props);
|
|
251
|
-
const tickArrayIndices = tickArray
|
|
252
|
-
? tickArray.map((v) => v.index)
|
|
253
|
-
: undefined;
|
|
252
|
+
const tickArrayIndices = tickArray?.map((v) => v.index);
|
|
254
253
|
const filteredTickFormat = tickFormat.filter((t, index) =>
|
|
255
|
-
tickArrayIndices
|
|
254
|
+
tickArrayIndices?.includes(index),
|
|
256
255
|
);
|
|
257
256
|
return (x, index) => filteredTickFormat[index];
|
|
258
257
|
} else if (tickFormat && isFunction(tickFormat)) {
|
|
@@ -267,7 +266,7 @@ export function getTickFormat(props, scale) {
|
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
268
|
|
|
270
|
-
function downsampleTicks(ticks, tickCount) {
|
|
269
|
+
function downsampleTicks(ticks: number[], tickCount: number) {
|
|
271
270
|
if (!tickCount || !Array.isArray(ticks) || ticks.length <= tickCount) {
|
|
272
271
|
return ticks;
|
|
273
272
|
}
|
|
@@ -275,7 +274,7 @@ function downsampleTicks(ticks, tickCount) {
|
|
|
275
274
|
return ticks.filter((d, i) => i % k === 0);
|
|
276
275
|
}
|
|
277
276
|
|
|
278
|
-
export function getTicks(props, scale, filterZero) {
|
|
277
|
+
export function getTicks(props, scale: D3Scale, filterZero = false) {
|
|
279
278
|
const { tickCount } = props;
|
|
280
279
|
const tickArray = getTickArray(props);
|
|
281
280
|
const tickValues = tickArray ? tickArray.map((v) => v.value) : undefined;
|
|
@@ -335,7 +334,7 @@ function getDomainFromData(props, axis) {
|
|
|
335
334
|
}
|
|
336
335
|
|
|
337
336
|
// exposed for use by VictoryChart
|
|
338
|
-
export function getDomain(props, axis) {
|
|
337
|
+
export function getDomain(props, axis?) {
|
|
339
338
|
const inherentAxis = getAxis(props);
|
|
340
339
|
if (axis && axis !== inherentAxis) {
|
|
341
340
|
return undefined;
|
|
@@ -382,6 +381,6 @@ export function modifyProps(props, fallbackProps) {
|
|
|
382
381
|
return Helpers.modifyProps(
|
|
383
382
|
assign({}, props, { theme }),
|
|
384
383
|
fallbackProps,
|
|
385
|
-
"axis"
|
|
384
|
+
"axis",
|
|
386
385
|
);
|
|
387
386
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
|
|
3
1
|
function isNonEmptyArray(collection) {
|
|
4
2
|
return Array.isArray(collection) && collection.length > 0;
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
export function containsStrings(collection) {
|
|
5
|
+
export function containsStrings<T>(collection: Array<T>) {
|
|
8
6
|
return (
|
|
9
7
|
Array.isArray(collection) &&
|
|
10
8
|
collection.some((value) => typeof value === "string")
|
|
11
9
|
);
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
export function containsDates(collection) {
|
|
12
|
+
export function containsDates(collection: Array<number | Date>): boolean {
|
|
15
13
|
return (
|
|
16
14
|
Array.isArray(collection) &&
|
|
17
15
|
collection.some((value) => value instanceof Date)
|
|
@@ -40,16 +38,22 @@ export function removeUndefined(arr) {
|
|
|
40
38
|
return arr.filter((el) => el !== undefined);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
export function getMaxValue(
|
|
44
|
-
|
|
41
|
+
export function getMaxValue(
|
|
42
|
+
arr: Array<number | Date>,
|
|
43
|
+
...values: Array<number | Date>
|
|
44
|
+
): number | Date {
|
|
45
|
+
const array = arr.concat(values) as number[];
|
|
45
46
|
return containsDates(array)
|
|
46
|
-
? new Date(Math.max(...array))
|
|
47
|
+
? new Date(Math.max(...array)) // Dates will be coerced to numbers
|
|
47
48
|
: Math.max(...array);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
export function getMinValue(
|
|
51
|
-
|
|
51
|
+
export function getMinValue(
|
|
52
|
+
arr: Array<number | Date>,
|
|
53
|
+
...values: Array<number | Date>
|
|
54
|
+
): number | Date {
|
|
55
|
+
const array = arr.concat(values) as number[];
|
|
52
56
|
return containsDates(array)
|
|
53
|
-
? new Date(Math.min(...array))
|
|
57
|
+
? new Date(Math.min(...array)) // Dates will be coerced to numbers
|
|
54
58
|
: Math.min(...array);
|
|
55
59
|
}
|