victory-core 36.4.1 → 36.5.2
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 +14463 -11478
- package/dist/victory-core.min.js +1 -1
- package/dist/victory-core.min.js.LICENSE.txt +19 -0
- package/es/index.d.ts +18 -941
- package/es/index.js +18 -73
- package/es/types/callbacks.d.ts +37 -0
- 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 +26 -0
- package/es/victory-accessible-group/victory-accessible-group.js +9 -16
- package/es/victory-animation/util.d.ts +67 -0
- package/es/victory-animation/util.js +7 -4
- package/es/victory-animation/victory-animation.d.ts +70 -0
- package/es/victory-animation/victory-animation.js +60 -67
- package/es/victory-clip-container/victory-clip-container.d.ts +77 -0
- package/es/victory-clip-container/victory-clip-container.js +16 -21
- package/es/victory-container/victory-container.d.ts +100 -0
- package/es/victory-container/victory-container.js +32 -31
- package/es/victory-label/victory-label.d.ts +62 -0
- package/es/victory-label/victory-label.js +14 -9
- package/es/victory-portal/portal-context.d.ts +12 -0
- package/es/victory-portal/portal-context.js +3 -3
- package/es/victory-portal/portal.d.ts +29 -0
- package/es/victory-portal/portal.js +26 -33
- package/es/victory-portal/victory-portal.d.ts +32 -0
- package/es/victory-portal/victory-portal.js +24 -22
- package/es/victory-primitives/arc.d.ts +50 -0
- package/es/victory-primitives/arc.js +4 -5
- package/es/victory-primitives/background.d.ts +51 -0
- package/es/victory-primitives/background.js +5 -6
- package/es/victory-primitives/border.d.ts +44 -0
- package/es/victory-primitives/border.js +4 -5
- package/es/victory-primitives/circle.d.ts +3 -0
- package/es/victory-primitives/circle.js +11 -7
- package/es/victory-primitives/clip-path.d.ts +15 -0
- package/es/victory-primitives/clip-path.js +6 -5
- package/es/victory-primitives/index.d.ts +15 -0
- package/es/victory-primitives/index.js +15 -0
- package/es/victory-primitives/line-segment.d.ts +46 -0
- package/es/victory-primitives/line-segment.js +4 -5
- package/es/victory-primitives/line.d.ts +3 -0
- package/es/victory-primitives/line.js +11 -7
- package/es/victory-primitives/path.d.ts +3 -0
- package/es/victory-primitives/path.js +9 -5
- package/es/victory-primitives/point.d.ts +49 -0
- package/es/victory-primitives/point.js +10 -19
- package/es/victory-primitives/rect.d.ts +3 -0
- package/es/victory-primitives/rect.js +11 -7
- package/es/victory-primitives/text.d.ts +17 -0
- package/es/victory-primitives/text.js +7 -5
- package/es/victory-primitives/tspan.d.ts +3 -0
- package/es/victory-primitives/tspan.js +7 -5
- package/es/victory-primitives/types.d.ts +8 -0
- package/es/victory-primitives/types.js +2 -0
- package/es/victory-primitives/whisker.d.ts +59 -0
- package/es/victory-primitives/whisker.js +4 -5
- 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 +3 -0
- package/es/victory-theme/grayscale.js +3 -2
- package/es/victory-theme/material.d.ts +3 -0
- package/es/victory-theme/material.js +3 -2
- package/es/victory-theme/types.d.ts +239 -0
- package/es/victory-theme/types.js +2 -0
- package/es/victory-theme/victory-theme.d.ts +6 -0
- package/es/victory-theme/victory-theme.js +8 -6
- package/es/victory-transition/victory-transition.d.ts +60 -0
- package/es/victory-transition/victory-transition.js +20 -23
- package/es/victory-util/add-events.d.ts +106 -0
- package/es/victory-util/add-events.js +44 -34
- package/es/victory-util/axis.d.ts +51 -0
- package/es/victory-util/axis.js +9 -8
- package/es/victory-util/collection.d.ts +9 -0
- package/es/victory-util/collection.js +6 -6
- 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 -3
- package/es/victory-util/default-transitions.d.ts +5 -0
- package/es/victory-util/default-transitions.js +2 -2
- package/es/victory-util/domain.d.ts +91 -0
- package/es/victory-util/domain.js +6 -4
- 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 -6
- 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 +2 -1
- 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 -5
- 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 -3
- 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 -2
- package/es/victory-util/point-path-helpers.d.ts +10 -0
- package/es/victory-util/point-path-helpers.js +60 -61
- 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 -0
- package/es/victory-util/selection.js +25 -16
- package/es/victory-util/style.d.ts +19 -0
- package/es/victory-util/style.js +2 -3
- package/es/victory-util/textsize.d.ts +37 -0
- package/es/victory-util/textsize.js +9 -6
- package/es/victory-util/timer-context.d.ts +12 -0
- package/es/victory-util/timer-context.js +2 -1
- package/es/victory-util/timer.d.ts +17 -0
- package/es/victory-util/timer.js +15 -9
- 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 +18 -941
- package/lib/index.js +224 -311
- package/lib/types/callbacks.d.ts +37 -0
- 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 +26 -0
- package/lib/victory-accessible-group/victory-accessible-group.js +10 -15
- package/lib/victory-animation/util.d.ts +67 -0
- package/lib/victory-animation/util.js +7 -4
- package/lib/victory-animation/victory-animation.d.ts +70 -0
- package/lib/victory-animation/victory-animation.js +61 -65
- package/lib/victory-clip-container/victory-clip-container.d.ts +77 -0
- package/lib/victory-clip-container/victory-clip-container.js +20 -22
- package/lib/victory-container/victory-container.d.ts +100 -0
- package/lib/victory-container/victory-container.js +35 -31
- package/lib/victory-label/victory-label.d.ts +62 -0
- package/lib/victory-label/victory-label.js +20 -14
- package/lib/victory-portal/portal-context.d.ts +12 -0
- package/lib/victory-portal/portal-context.js +3 -3
- package/lib/victory-portal/portal.d.ts +29 -0
- package/lib/victory-portal/portal.js +27 -31
- package/lib/victory-portal/victory-portal.d.ts +32 -0
- package/lib/victory-portal/victory-portal.js +25 -20
- package/lib/victory-primitives/arc.d.ts +50 -0
- package/lib/victory-primitives/arc.js +7 -7
- package/lib/victory-primitives/background.d.ts +51 -0
- package/lib/victory-primitives/background.js +9 -9
- package/lib/victory-primitives/border.d.ts +44 -0
- package/lib/victory-primitives/border.js +7 -7
- package/lib/victory-primitives/circle.d.ts +3 -0
- package/lib/victory-primitives/circle.js +12 -6
- package/lib/victory-primitives/clip-path.d.ts +15 -0
- package/lib/victory-primitives/clip-path.js +7 -4
- package/lib/victory-primitives/index.d.ts +15 -0
- package/lib/victory-primitives/index.js +188 -0
- package/lib/victory-primitives/line-segment.d.ts +46 -0
- package/lib/victory-primitives/line-segment.js +7 -7
- package/lib/victory-primitives/line.d.ts +3 -0
- package/lib/victory-primitives/line.js +12 -6
- package/lib/victory-primitives/path.d.ts +3 -0
- package/lib/victory-primitives/path.js +10 -4
- package/lib/victory-primitives/point.d.ts +49 -0
- package/lib/victory-primitives/point.js +15 -22
- package/lib/victory-primitives/rect.d.ts +3 -0
- package/lib/victory-primitives/rect.js +12 -6
- package/lib/victory-primitives/text.d.ts +17 -0
- package/lib/victory-primitives/text.js +8 -4
- package/lib/victory-primitives/tspan.d.ts +3 -0
- package/lib/victory-primitives/tspan.js +8 -4
- package/lib/victory-primitives/types.d.ts +8 -0
- package/lib/victory-primitives/types.js +2 -0
- package/lib/victory-primitives/whisker.d.ts +59 -0
- package/lib/victory-primitives/whisker.js +7 -7
- 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 +3 -0
- package/lib/victory-theme/grayscale.js +4 -3
- package/lib/victory-theme/material.d.ts +3 -0
- package/lib/victory-theme/material.js +4 -3
- package/lib/victory-theme/types.d.ts +239 -0
- package/lib/victory-theme/types.js +2 -0
- package/lib/victory-theme/victory-theme.d.ts +6 -0
- package/lib/victory-theme/victory-theme.js +23 -8
- package/lib/victory-transition/victory-transition.d.ts +60 -0
- package/lib/victory-transition/victory-transition.js +22 -23
- package/lib/victory-util/add-events.d.ts +106 -0
- package/lib/victory-util/add-events.js +48 -40
- 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 -6
- 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 -2
- 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 -6
- 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 +2 -1
- 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 -6
- 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 -3
- 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 -2
- package/lib/victory-util/point-path-helpers.d.ts +10 -0
- package/lib/victory-util/point-path-helpers.js +87 -73
- 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 -0
- package/lib/victory-util/selection.js +25 -21
- package/lib/victory-util/style.d.ts +19 -0
- package/lib/victory-util/style.js +2 -3
- package/lib/victory-util/textsize.d.ts +37 -0
- package/lib/victory-util/textsize.js +9 -6
- package/lib/victory-util/timer-context.d.ts +12 -0
- package/lib/victory-util/timer-context.js +2 -1
- package/lib/victory-util/timer.d.ts +17 -0
- package/lib/victory-util/timer.js +15 -9
- 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 +4 -4
- package/src/index.ts +17 -0
- package/src/types/callbacks.ts +53 -0
- package/src/types/prop-types.ts +195 -0
- package/src/victory-accessible-group/{victory-accessible-group.js → victory-accessible-group.tsx} +13 -6
- package/src/victory-animation/{util.js → util.ts} +6 -4
- package/src/victory-animation/{victory-animation.js → victory-animation.tsx} +100 -23
- package/src/victory-clip-container/{victory-clip-container.js → victory-clip-container.tsx} +52 -28
- package/src/victory-container/{victory-container.js → victory-container.tsx} +86 -42
- package/src/victory-label/{victory-label.js → victory-label.tsx} +108 -49
- package/src/victory-portal/portal-context.ts +14 -0
- package/src/victory-portal/{portal.js → portal.tsx} +24 -13
- package/src/victory-portal/{victory-portal.js → victory-portal.tsx} +24 -9
- package/src/victory-primitives/{arc.js → arc.tsx} +22 -10
- package/src/victory-primitives/{background.js → background.tsx} +24 -12
- package/src/victory-primitives/{border.js → border.tsx} +19 -10
- 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} +20 -10
- 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} +33 -26
- package/src/victory-primitives/{rect.js → rect.tsx} +4 -2
- package/src/victory-primitives/{text.js → text.tsx} +10 -4
- package/src/victory-primitives/tspan.tsx +7 -0
- package/src/victory-primitives/types.ts +19 -0
- package/src/victory-primitives/{whisker.js → whisker.tsx} +34 -19
- 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.js → grayscale.tsx} +63 -62
- package/src/victory-theme/{material.js → material.tsx} +68 -67
- package/src/victory-theme/types.ts +257 -0
- package/src/victory-theme/victory-theme.tsx +5 -0
- package/src/victory-transition/{victory-transition.js → victory-transition.tsx} +82 -33
- package/src/victory-util/{add-events.js → add-events.tsx} +142 -60
- package/src/victory-util/{axis.js → axis.tsx} +17 -19
- package/src/victory-util/{collection.js → collection.tsx} +14 -11
- package/src/victory-util/common-props.tsx +307 -0
- package/src/victory-util/{data.js → data.ts} +14 -11
- package/src/victory-util/{default-transitions.js → default-transitions.ts} +20 -19
- package/src/victory-util/{domain.js → domain.ts} +26 -24
- package/src/victory-util/{events.js → events.ts} +83 -32
- package/src/victory-util/{helpers.js → helpers.ts} +41 -23
- package/src/victory-util/hooks/{index.js → index.ts} +0 -0
- package/src/victory-util/hooks/use-animation-state.js +10 -10
- package/src/victory-util/hooks/use-previous-props.ts +9 -0
- package/src/victory-util/{immutable.js → immutable.ts} +14 -11
- package/src/victory-util/index.ts +28 -0
- package/src/victory-util/{label-helpers.js → label-helpers.ts} +7 -8
- package/src/victory-util/line-helpers.ts +104 -0
- package/src/victory-util/{log.js → log.ts} +1 -2
- package/src/victory-util/point-path-helpers.ts +119 -0
- package/src/victory-util/{prop-types.js → prop-types.ts} +103 -102
- package/src/victory-util/{scale.js → scale.ts} +29 -17
- package/src/victory-util/selection.ts +158 -0
- package/src/victory-util/{style.js → style.ts} +3 -4
- package/src/victory-util/{textsize.js → textsize.ts} +32 -17
- package/src/victory-util/{timer-context.js → timer-context.ts} +1 -1
- package/src/victory-util/{timer.js → timer.ts} +16 -6
- package/src/victory-util/{transitions.js → transitions.ts} +50 -23
- 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 -34
- 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/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/point-path-helpers.js +0 -121
- package/src/victory-util/selection.js +0 -99
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
/* eslint-
|
|
2
|
-
/*eslint
|
|
3
|
-
|
|
1
|
+
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }] */
|
|
2
|
+
/* eslint-disable max-params */
|
|
3
|
+
|
|
4
|
+
import { find, isRegExp } from "lodash";
|
|
4
5
|
import * as Log from "./log";
|
|
5
6
|
import PropTypes from "prop-types";
|
|
7
|
+
import * as Scale from "./scale";
|
|
8
|
+
import { D3Scale, ScaleName } from "../types/prop-types";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Return a new validator based on `validator` but with the option to chain
|
|
@@ -11,29 +14,25 @@ import PropTypes from "prop-types";
|
|
|
11
14
|
* @param {Function} validator Validation function.
|
|
12
15
|
* @returns {Function} Validator with `isRequired` option.
|
|
13
16
|
*/
|
|
14
|
-
const makeChainable = function (validator) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return new Error(
|
|
27
|
-
`Required \`${propName}\` was not specified in \`${componentName}\`.`
|
|
28
|
-
);
|
|
17
|
+
const makeChainable = function <T>(validator: PropTypes.Validator<T>) {
|
|
18
|
+
const createChainable =
|
|
19
|
+
(isRequired: boolean): PropTypes.Validator<T | undefined> =>
|
|
20
|
+
(props, propName, componentName, ...rest) => {
|
|
21
|
+
const value = props[propName];
|
|
22
|
+
if (value === undefined || value === null) {
|
|
23
|
+
if (isRequired) {
|
|
24
|
+
return new Error(
|
|
25
|
+
`Required \`${propName}\` was not specified in \`${componentName}\`.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
29
|
}
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
chainable
|
|
36
|
-
return chainable;
|
|
30
|
+
return validator(props, propName, componentName, ...rest);
|
|
31
|
+
};
|
|
32
|
+
const chainable = Object.assign(createChainable(false), {
|
|
33
|
+
isRequired: createChainable(true),
|
|
34
|
+
});
|
|
35
|
+
return chainable as PropTypes.Requireable<T | undefined>;
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
const nullConstructor = () => null;
|
|
@@ -57,7 +56,7 @@ const getConstructor = (value) => {
|
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
58
|
* Get the name of the constructor used to create `value`, using
|
|
60
|
-
* `Object.
|
|
59
|
+
* `Object.prototype.toString`. If the value is null or undefined, return
|
|
61
60
|
* "null" or "undefined", respectively.
|
|
62
61
|
* @param {*} value Instance to return the constructor name of.
|
|
63
62
|
* @returns {String} Name of the constructor.
|
|
@@ -78,20 +77,24 @@ const getConstructorName = (value) => {
|
|
|
78
77
|
* @param {String} explanation The message to provide the user of the deprecated propType.
|
|
79
78
|
* @returns {Function} Validator which logs usage of this propType
|
|
80
79
|
*/
|
|
81
|
-
export function deprecated(
|
|
80
|
+
export function deprecated<T>(
|
|
81
|
+
propType: PropTypes.Validator<T>,
|
|
82
|
+
explanation: string,
|
|
83
|
+
): PropTypes.Validator<T> {
|
|
82
84
|
return (props, propName, componentName) => {
|
|
83
85
|
const value = props[propName];
|
|
84
86
|
if (value !== null && value !== undefined) {
|
|
85
87
|
Log.warn(
|
|
86
|
-
`"${propName}" property of "${componentName}" has been deprecated ${explanation}
|
|
88
|
+
`"${propName}" property of "${componentName}" has been deprecated ${explanation}`,
|
|
87
89
|
);
|
|
88
90
|
}
|
|
89
|
-
|
|
91
|
+
PropTypes.checkPropTypes(
|
|
90
92
|
{ [propName]: propType },
|
|
91
93
|
props,
|
|
92
94
|
propName,
|
|
93
|
-
componentName
|
|
95
|
+
componentName,
|
|
94
96
|
);
|
|
97
|
+
return null;
|
|
95
98
|
};
|
|
96
99
|
}
|
|
97
100
|
|
|
@@ -102,109 +105,105 @@ export function deprecated(propType, explanation) {
|
|
|
102
105
|
* @param {Array} validators Validation functions.
|
|
103
106
|
* @returns {Function} Combined validator function
|
|
104
107
|
*/
|
|
105
|
-
export function allOfType(validators) {
|
|
106
|
-
return makeChainable((props, propName, componentName, ...rest) =>
|
|
107
|
-
validators.reduce(
|
|
108
|
+
export function allOfType<T>(validators: Array<PropTypes.Validator<T>>) {
|
|
109
|
+
return makeChainable<T>((props, propName, componentName, ...rest) => {
|
|
110
|
+
return validators.reduce<null | Error>(
|
|
108
111
|
(result, validator) =>
|
|
109
112
|
result || validator(props, propName, componentName, ...rest),
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
+
null,
|
|
114
|
+
);
|
|
115
|
+
});
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
/**
|
|
116
119
|
* Check that the value is a non-negative number.
|
|
117
120
|
*/
|
|
118
|
-
export const nonNegative = makeChainable(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
export const nonNegative = makeChainable<number>(
|
|
122
|
+
(props, propName, componentName) => {
|
|
123
|
+
const value = props[propName];
|
|
124
|
+
if (typeof value !== "number" || value < 0) {
|
|
125
|
+
return new Error(
|
|
126
|
+
`\`${propName}\` in \`${componentName}\` must be a non-negative number.`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
},
|
|
131
|
+
);
|
|
127
132
|
|
|
128
133
|
/**
|
|
129
134
|
* Check that the value is an integer.
|
|
130
135
|
*/
|
|
131
|
-
export const integer = makeChainable(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
export const integer = makeChainable<number>(
|
|
137
|
+
(props, propName, componentName) => {
|
|
138
|
+
const value = props[propName];
|
|
139
|
+
if (typeof value !== "number" || value % 1 !== 0) {
|
|
140
|
+
return new Error(
|
|
141
|
+
`\`${propName}\` in \`${componentName}\` must be an integer.`,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
},
|
|
146
|
+
);
|
|
140
147
|
|
|
141
148
|
/**
|
|
142
149
|
* Check that the value is greater than zero.
|
|
143
150
|
*/
|
|
144
|
-
export const greaterThanZero = makeChainable(
|
|
151
|
+
export const greaterThanZero = makeChainable<number>(
|
|
145
152
|
(props, propName, componentName) => {
|
|
146
153
|
const value = props[propName];
|
|
147
154
|
if (typeof value !== "number" || value <= 0) {
|
|
148
155
|
return new Error(
|
|
149
|
-
`\`${propName}\` in \`${componentName}\` must be a number greater than zero
|
|
156
|
+
`\`${propName}\` in \`${componentName}\` must be a number greater than zero.`,
|
|
150
157
|
);
|
|
151
158
|
}
|
|
152
|
-
return
|
|
153
|
-
}
|
|
159
|
+
return null;
|
|
160
|
+
},
|
|
154
161
|
);
|
|
155
162
|
|
|
156
163
|
/**
|
|
157
164
|
* Check that the value is an Array of two unique values.
|
|
158
165
|
*/
|
|
159
|
-
export const domain = makeChainable
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
export const domain = makeChainable<[number, number]>(
|
|
167
|
+
(props, propName, componentName) => {
|
|
168
|
+
const value = props[propName];
|
|
169
|
+
if (!Array.isArray(value) || value.length !== 2 || value[1] === value[0]) {
|
|
170
|
+
return new Error(
|
|
171
|
+
`\`${propName}\` in \`${componentName}\` must be an array of two unique numeric values.`,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
},
|
|
176
|
+
);
|
|
168
177
|
|
|
169
178
|
/**
|
|
170
179
|
* Check that the value looks like a d3 `scale` function.
|
|
171
180
|
*/
|
|
172
|
-
export const scale = makeChainable
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
return (
|
|
177
|
-
|
|
181
|
+
export const scale = makeChainable<ScaleName | D3Scale>(
|
|
182
|
+
(props, propName, componentName) => {
|
|
183
|
+
const value = props[propName];
|
|
184
|
+
if (!Scale.validScale(value)) {
|
|
185
|
+
return new Error(
|
|
186
|
+
`\`${propName}\` in \`${componentName}\` must be a d3 scale.`,
|
|
178
187
|
);
|
|
179
|
-
} else if (typeof scl === "string") {
|
|
180
|
-
return supportedScaleStrings.indexOf(scl) !== -1;
|
|
181
188
|
}
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const value = props[propName];
|
|
186
|
-
if (!validScale(value)) {
|
|
187
|
-
return new Error(
|
|
188
|
-
`\`${propName}\` in \`${componentName}\` must be a d3 scale.`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
return undefined;
|
|
192
|
-
});
|
|
189
|
+
return null;
|
|
190
|
+
},
|
|
191
|
+
);
|
|
193
192
|
|
|
194
193
|
/**
|
|
195
194
|
* Check that an array contains items of the same type.
|
|
196
195
|
*/
|
|
197
|
-
export const homogeneousArray = makeChainable(
|
|
196
|
+
export const homogeneousArray = makeChainable<unknown[]>(
|
|
198
197
|
(props, propName, componentName) => {
|
|
199
198
|
const values = props[propName];
|
|
200
199
|
if (!Array.isArray(values)) {
|
|
201
200
|
return new Error(
|
|
202
|
-
`\`${propName}\` in \`${componentName}\` must be an array
|
|
201
|
+
`\`${propName}\` in \`${componentName}\` must be an array.`,
|
|
203
202
|
);
|
|
204
203
|
}
|
|
205
204
|
|
|
206
205
|
if (values.length < 2) {
|
|
207
|
-
return
|
|
206
|
+
return null;
|
|
208
207
|
}
|
|
209
208
|
|
|
210
209
|
const comparisonConstructor = getConstructor(values[0]);
|
|
@@ -220,17 +219,17 @@ export const homogeneousArray = makeChainable(
|
|
|
220
219
|
return new Error(
|
|
221
220
|
`Expected \`${propName}\` in \`${componentName}\` to be a ` +
|
|
222
221
|
`homogeneous array, but found types \`${constructorName}\` and ` +
|
|
223
|
-
`\`${otherConstructorName}
|
|
222
|
+
`\`${otherConstructorName}\`.`,
|
|
224
223
|
);
|
|
225
224
|
}
|
|
226
|
-
return
|
|
227
|
-
}
|
|
225
|
+
return null;
|
|
226
|
+
},
|
|
228
227
|
);
|
|
229
228
|
|
|
230
229
|
/**
|
|
231
230
|
* Check that array prop length matches props.data.length
|
|
232
231
|
*/
|
|
233
|
-
export const matchDataLength = makeChainable((props, propName) => {
|
|
232
|
+
export const matchDataLength = makeChainable<unknown[]>((props, propName) => {
|
|
234
233
|
if (
|
|
235
234
|
props[propName] &&
|
|
236
235
|
Array.isArray(props[propName]) &&
|
|
@@ -238,17 +237,19 @@ export const matchDataLength = makeChainable((props, propName) => {
|
|
|
238
237
|
) {
|
|
239
238
|
return new Error(`Length of data and ${propName} arrays must match.`);
|
|
240
239
|
}
|
|
241
|
-
return
|
|
240
|
+
return null;
|
|
242
241
|
});
|
|
243
242
|
|
|
244
243
|
/**
|
|
245
244
|
* Check that the value is a regular expression
|
|
246
245
|
*/
|
|
247
|
-
export const regExp = makeChainable(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
246
|
+
export const regExp = makeChainable<RegExp>(
|
|
247
|
+
(props, propName, componentName) => {
|
|
248
|
+
if (props[propName] && !isRegExp(props[propName])) {
|
|
249
|
+
return new Error(
|
|
250
|
+
`\`${propName}\` in \`${componentName}\` must be a regular expression.`,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
},
|
|
255
|
+
);
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
/* eslint-disable func-style */
|
|
2
1
|
/* eslint-disable no-use-before-define */
|
|
3
2
|
import { includes, isFunction, isPlainObject } from "lodash";
|
|
4
3
|
import * as Helpers from "./helpers";
|
|
5
4
|
import * as Collection from "./collection";
|
|
6
5
|
import * as d3Scale from "victory-vendor/d3-scale";
|
|
6
|
+
import { D3Scale, ScaleName } from "../types/prop-types";
|
|
7
7
|
|
|
8
|
-
const supportedScaleStrings = ["linear", "time", "log", "sqrt"];
|
|
8
|
+
const supportedScaleStrings = ["linear", "time", "log", "sqrt"] as const;
|
|
9
|
+
|
|
10
|
+
type D3ScaleMethods = Pick<
|
|
11
|
+
typeof d3Scale,
|
|
12
|
+
"scaleLinear" | "scaleTime" | "scaleLog" | "scaleSqrt"
|
|
13
|
+
>;
|
|
9
14
|
|
|
10
15
|
// Private Functions
|
|
11
16
|
|
|
12
|
-
function toNewName(scale) {
|
|
17
|
+
function toNewName(scale: ScaleName): keyof D3ScaleMethods {
|
|
13
18
|
// d3 scale changed the naming scheme for scale from "linear" -> "scaleLinear" etc.
|
|
14
19
|
const capitalize = (s) => s && s[0].toUpperCase() + s.slice(1);
|
|
15
|
-
return `scale${capitalize(scale)}
|
|
20
|
+
return `scale${capitalize(scale)}` as keyof D3ScaleMethods;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
function validScale(
|
|
23
|
+
export function validScale(
|
|
24
|
+
scale: string | D3Scale,
|
|
25
|
+
): scale is ScaleName | D3Scale {
|
|
19
26
|
if (typeof scale === "function") {
|
|
20
27
|
return (
|
|
21
28
|
isFunction(scale.copy) &&
|
|
@@ -28,7 +35,7 @@ function validScale(scale) {
|
|
|
28
35
|
return false;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
function isScaleDefined(props, axis) {
|
|
38
|
+
function isScaleDefined(props, axis: "x" | "y") {
|
|
32
39
|
if (!props.scale) {
|
|
33
40
|
return false;
|
|
34
41
|
} else if (props.scale.x || props.scale.y) {
|
|
@@ -37,7 +44,7 @@ function isScaleDefined(props, axis) {
|
|
|
37
44
|
return true;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
function getScaleTypeFromProps(props, axis) {
|
|
47
|
+
function getScaleTypeFromProps(props, axis: "x" | "y"): string | undefined {
|
|
41
48
|
if (!isScaleDefined(props, axis)) {
|
|
42
49
|
return undefined;
|
|
43
50
|
}
|
|
@@ -45,7 +52,7 @@ function getScaleTypeFromProps(props, axis) {
|
|
|
45
52
|
return typeof scale === "string" ? scale : getType(scale);
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
function getScaleFromDomain(props, axis) {
|
|
55
|
+
function getScaleFromDomain(props, axis: "x" | "y"): ScaleName | undefined {
|
|
49
56
|
let domain;
|
|
50
57
|
if (props.domain && props.domain[axis]) {
|
|
51
58
|
domain = props.domain[axis];
|
|
@@ -58,7 +65,7 @@ function getScaleFromDomain(props, axis) {
|
|
|
58
65
|
return Collection.containsDates(domain) ? "time" : "linear";
|
|
59
66
|
}
|
|
60
67
|
|
|
61
|
-
function getScaleTypeFromData(props, axis) {
|
|
68
|
+
function getScaleTypeFromData(props, axis): ScaleName {
|
|
62
69
|
if (!props.data) {
|
|
63
70
|
return "linear";
|
|
64
71
|
}
|
|
@@ -74,36 +81,41 @@ function getScaleTypeFromData(props, axis) {
|
|
|
74
81
|
|
|
75
82
|
// Exported Functions
|
|
76
83
|
|
|
77
|
-
export function getScaleFromName(name) {
|
|
78
|
-
|
|
84
|
+
export function getScaleFromName(name: ScaleName | string): D3Scale {
|
|
85
|
+
if (validScale(name)) {
|
|
86
|
+
const methodName = toNewName(name as ScaleName);
|
|
87
|
+
// @ts-expect-error scaleTime is not directly compatible with our D3Scale definition
|
|
88
|
+
return d3Scale[methodName]();
|
|
89
|
+
}
|
|
90
|
+
return d3Scale.scaleLinear();
|
|
79
91
|
}
|
|
80
92
|
|
|
81
|
-
export function getBaseScale(props, axis) {
|
|
93
|
+
export function getBaseScale(props, axis: "x" | "y") {
|
|
82
94
|
const scale = getScaleFromProps(props, axis);
|
|
83
95
|
if (scale) {
|
|
84
96
|
return typeof scale === "string" ? getScaleFromName(scale) : scale;
|
|
85
97
|
}
|
|
86
98
|
const defaultScale =
|
|
87
99
|
getScaleFromDomain(props, axis) || getScaleTypeFromData(props, axis);
|
|
88
|
-
return
|
|
100
|
+
return getScaleFromName(defaultScale);
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
export function getDefaultScale() {
|
|
92
104
|
return d3Scale.scaleLinear();
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
export function getScaleFromProps(props, axis) {
|
|
107
|
+
export function getScaleFromProps(props, axis): D3Scale | undefined {
|
|
96
108
|
if (!isScaleDefined(props, axis)) {
|
|
97
109
|
return undefined;
|
|
98
110
|
}
|
|
99
111
|
const scale = props.scale[axis] || props.scale;
|
|
100
112
|
if (validScale(scale)) {
|
|
101
|
-
return isFunction(scale) ? scale :
|
|
113
|
+
return isFunction(scale) ? scale : getScaleFromName(scale);
|
|
102
114
|
}
|
|
103
115
|
return undefined;
|
|
104
116
|
}
|
|
105
117
|
|
|
106
|
-
export function getScaleType(props, axis) {
|
|
118
|
+
export function getScaleType(props, axis): string {
|
|
107
119
|
// if the scale was not given in props, it will be set to linear or time depending on data
|
|
108
120
|
return (
|
|
109
121
|
getScaleTypeFromProps(props, axis) || getScaleTypeFromData(props, axis)
|
|
@@ -114,7 +126,7 @@ export function getScaleType(props, axis) {
|
|
|
114
126
|
// **Note**: Brittle because reliant on d3 internals.
|
|
115
127
|
const DUCK_TYPES = [
|
|
116
128
|
{ name: "quantile", method: "quantiles" },
|
|
117
|
-
{ name: "log", method: "base" }
|
|
129
|
+
{ name: "log", method: "base" },
|
|
118
130
|
// TODO(2214): Re-evaluate (1) duck typing approach, and (2) if duck typing,
|
|
119
131
|
// do we need a different approach? (Multiple keys? Stringifying functions?)
|
|
120
132
|
// https://github.com/FormidableLabs/victory/issues/2214
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Collection, VictoryCommonProps } from "./index";
|
|
3
|
+
import type { DomainPropType, ScaleXYPropType } from "../types/prop-types";
|
|
4
|
+
|
|
5
|
+
// Private Functions
|
|
6
|
+
|
|
7
|
+
function transformTarget(
|
|
8
|
+
target: number,
|
|
9
|
+
matrix: DOMMatrix,
|
|
10
|
+
dimension: "x" | "y",
|
|
11
|
+
) {
|
|
12
|
+
const { a, d, e, f } = matrix;
|
|
13
|
+
return dimension === "y" ? d * target + f : a * target + e;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getTransformationMatrix(svg: SVGGraphicsElement): DOMMatrix {
|
|
17
|
+
return svg.getScreenCTM()!.inverse();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ReactNativeTouchEvent extends Event {
|
|
21
|
+
identifier?: number;
|
|
22
|
+
locationX: number;
|
|
23
|
+
locationY: number;
|
|
24
|
+
}
|
|
25
|
+
function isNativeTouchEvent(
|
|
26
|
+
nativeEvent: Event | undefined,
|
|
27
|
+
): nativeEvent is ReactNativeTouchEvent {
|
|
28
|
+
return !!(
|
|
29
|
+
nativeEvent &&
|
|
30
|
+
(nativeEvent as ReactNativeTouchEvent).identifier !== undefined
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function isReactTouchEvent(evt: React.SyntheticEvent): evt is React.TouchEvent {
|
|
34
|
+
return (
|
|
35
|
+
(evt as React.TouchEvent).changedTouches &&
|
|
36
|
+
(evt as React.TouchEvent).changedTouches.length > 0
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Exported Functions
|
|
41
|
+
|
|
42
|
+
export function getParentSVG(
|
|
43
|
+
evt: Pick<React.SyntheticEvent, "target"> &
|
|
44
|
+
Partial<Pick<React.SyntheticEvent, "nativeEvent">>,
|
|
45
|
+
): SVGElement {
|
|
46
|
+
if (isNativeTouchEvent(evt.nativeEvent)) {
|
|
47
|
+
// @ts-expect-error Seems like a superfluous check.
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const getParent = (target) => {
|
|
51
|
+
if (target.nodeName === "svg") {
|
|
52
|
+
return target;
|
|
53
|
+
} else {
|
|
54
|
+
return target.parentNode ? getParent(target.parentNode) : target;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return getParent(evt.target);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getSVGEventCoordinates(
|
|
61
|
+
evt: React.SyntheticEvent,
|
|
62
|
+
svg?: SVGElement,
|
|
63
|
+
): SVGCoordinateType {
|
|
64
|
+
if (isNativeTouchEvent(evt.nativeEvent)) {
|
|
65
|
+
// react-native override. relies on the RN.View being the _exact_ same size as its child SVG.
|
|
66
|
+
// this should be fine: the svg is the only child of View and the View shirks to its children
|
|
67
|
+
return {
|
|
68
|
+
x: evt.nativeEvent.locationX,
|
|
69
|
+
y: evt.nativeEvent.locationY,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const location = isReactTouchEvent(evt)
|
|
73
|
+
? evt.changedTouches[0]
|
|
74
|
+
: (evt as React.MouseEvent);
|
|
75
|
+
svg = svg || getParentSVG(location);
|
|
76
|
+
const matrix = getTransformationMatrix(svg as SVGGraphicsElement);
|
|
77
|
+
return {
|
|
78
|
+
x: transformTarget(location.clientX, matrix, "x"),
|
|
79
|
+
y: transformTarget(location.clientY, matrix, "y"),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getDomainCoordinates(
|
|
84
|
+
props: Pick<VictoryCommonProps, "scale" | "horizontal">,
|
|
85
|
+
domain?: DomainPropType,
|
|
86
|
+
): DomainPropType {
|
|
87
|
+
const { horizontal } = props;
|
|
88
|
+
const scale = props.scale as ScaleXYPropType;
|
|
89
|
+
// FIXME: add support for DomainTuple: [number, number]
|
|
90
|
+
const domainObj: any = domain || {
|
|
91
|
+
x: scale.x.domain(),
|
|
92
|
+
y: scale.y.domain(),
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
x: horizontal
|
|
96
|
+
? [scale.y(domainObj.y[0]), scale.y(domainObj.y[1])]
|
|
97
|
+
: [scale.x(domainObj.x[0]), scale.x(domainObj.x[1])],
|
|
98
|
+
y: horizontal
|
|
99
|
+
? [scale.x(domainObj.x[0]), scale.x(domainObj.x[1])]
|
|
100
|
+
: [scale.y(domainObj.y[0]), scale.y(domainObj.y[1])],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// eslint-disable-next-line max-params
|
|
105
|
+
export function getDataCoordinates(
|
|
106
|
+
props: any,
|
|
107
|
+
scale: ScaleXYPropType,
|
|
108
|
+
x: number,
|
|
109
|
+
y: number,
|
|
110
|
+
): SVGCoordinateType {
|
|
111
|
+
const { polar, horizontal } = props;
|
|
112
|
+
if (!polar) {
|
|
113
|
+
return {
|
|
114
|
+
x: horizontal ? scale.x.invert(y) : scale.x.invert(x),
|
|
115
|
+
y: horizontal ? scale.y.invert(x) : scale.y.invert(y),
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
const origin = props.origin || { x: 0, y: 0 };
|
|
119
|
+
const baseX = x - origin.x;
|
|
120
|
+
const baseY = y - origin.y;
|
|
121
|
+
const radius = Math.abs(baseX * Math.sqrt(1 + Math.pow(-baseY / baseX, 2)));
|
|
122
|
+
const angle = (-Math.atan2(baseY, baseX) + Math.PI * 2) % (Math.PI * 2);
|
|
123
|
+
return {
|
|
124
|
+
x: scale.x.invert(angle),
|
|
125
|
+
y: scale.y.invert(radius),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getBounds(props: ComputedCommonProps): SVGCoordinateBounds {
|
|
131
|
+
const { x1, x2, y1, y2, scale } = props;
|
|
132
|
+
const point1 = getDataCoordinates(props, scale, x1, y1);
|
|
133
|
+
const point2 = getDataCoordinates(props, scale, x2, y2);
|
|
134
|
+
const makeBound = (a: number, b: number) => {
|
|
135
|
+
return [
|
|
136
|
+
Collection.getMinValue([a, b]) as number,
|
|
137
|
+
Collection.getMaxValue([a, b]) as number,
|
|
138
|
+
] as const;
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
x: makeBound(point1.x, point2.x),
|
|
142
|
+
y: makeBound(point1.y, point2.y),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type SVGCoordinateType = { x: number; y: number };
|
|
147
|
+
export type SVGCoordinateBounds = {
|
|
148
|
+
x: readonly [number, number];
|
|
149
|
+
y: readonly [number, number];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
type ComputedCommonProps = {
|
|
153
|
+
scale: ScaleXYPropType;
|
|
154
|
+
x1: number;
|
|
155
|
+
x2: number;
|
|
156
|
+
y1: number;
|
|
157
|
+
y2: number;
|
|
158
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable func-style */
|
|
2
1
|
/**
|
|
3
2
|
* Given an object with CSS/SVG transform definitions, return the string value
|
|
4
3
|
* for use with the `transform` CSS property or SVG attribute. Note that we
|
|
@@ -19,7 +18,7 @@ export const toTransformString = function (obj, ...more) {
|
|
|
19
18
|
if (obj === undefined || obj === null || typeof obj === "string") {
|
|
20
19
|
return obj;
|
|
21
20
|
}
|
|
22
|
-
const transforms = [];
|
|
21
|
+
const transforms = [] as string[];
|
|
23
22
|
for (const key in obj) {
|
|
24
23
|
if (obj.hasOwnProperty(key)) {
|
|
25
24
|
const value = obj[key];
|
|
@@ -50,14 +49,14 @@ export function getColorScale(name) {
|
|
|
50
49
|
"#55DBC1",
|
|
51
50
|
"#EFDA97",
|
|
52
51
|
"#E2A37F",
|
|
53
|
-
"#DF948A"
|
|
52
|
+
"#DF948A",
|
|
54
53
|
],
|
|
55
54
|
heatmap: ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"],
|
|
56
55
|
warm: ["#940031", "#C43343", "#DC5429", "#FF821D", "#FFAF55"],
|
|
57
56
|
cool: ["#2746B9", "#0B69D4", "#2794DB", "#31BB76", "#60E83B"],
|
|
58
57
|
red: ["#FCAE91", "#FB6A4A", "#DE2D26", "#A50F15", "#750B0E"],
|
|
59
58
|
blue: ["#002C61", "#004B8F", "#006BC9", "#3795E5", "#65B4F4"],
|
|
60
|
-
green: ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"]
|
|
59
|
+
green: ["#354722", "#466631", "#649146", "#8AB25C", "#A9C97E"],
|
|
61
60
|
};
|
|
62
61
|
return name ? scales[name] : scales.grayscale;
|
|
63
62
|
}
|