victory-core 36.3.2 → 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.
Files changed (253) hide show
  1. package/dist/victory-core.js +15084 -15018
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.d.ts +38 -941
  4. package/es/index.js +19 -28
  5. package/es/types.d.ts +33 -0
  6. package/es/types.js +1 -0
  7. package/es/victory-accessible-group/victory-accessible-group.d.ts +25 -0
  8. package/es/victory-accessible-group/victory-accessible-group.js +35 -45
  9. package/es/victory-animation/util.d.ts +66 -0
  10. package/es/victory-animation/util.js +3 -2
  11. package/es/victory-animation/victory-animation.d.ts +69 -0
  12. package/es/victory-animation/victory-animation.js +92 -102
  13. package/es/victory-clip-container/victory-clip-container.d.ts +76 -0
  14. package/es/victory-clip-container/victory-clip-container.js +75 -82
  15. package/es/victory-container/victory-container.d.ts +99 -0
  16. package/es/victory-container/victory-container.js +97 -107
  17. package/es/victory-label/victory-label.d.ts +61 -0
  18. package/es/victory-label/victory-label.js +43 -31
  19. package/es/victory-portal/portal-context.d.ts +11 -0
  20. package/es/victory-portal/portal-context.js +3 -4
  21. package/es/victory-portal/portal.d.ts +28 -0
  22. package/es/victory-portal/portal.js +44 -50
  23. package/es/victory-portal/victory-portal.d.ts +31 -0
  24. package/es/victory-portal/victory-portal.js +38 -47
  25. package/es/victory-primitives/arc.d.ts +21 -0
  26. package/es/victory-primitives/arc.js +9 -9
  27. package/es/victory-primitives/background.d.ts +22 -0
  28. package/es/victory-primitives/background.js +12 -12
  29. package/es/victory-primitives/border.d.ts +18 -0
  30. package/es/victory-primitives/border.js +9 -9
  31. package/es/victory-primitives/circle.d.ts +2 -0
  32. package/es/victory-primitives/circle.js +17 -10
  33. package/es/victory-primitives/clip-path.d.ts +14 -0
  34. package/es/victory-primitives/clip-path.js +6 -6
  35. package/es/victory-primitives/index.d.ts +14 -0
  36. package/es/victory-primitives/index.js +14 -0
  37. package/es/victory-primitives/line-segment.d.ts +19 -0
  38. package/es/victory-primitives/line-segment.js +9 -9
  39. package/es/victory-primitives/line.d.ts +2 -0
  40. package/es/victory-primitives/line.js +17 -10
  41. package/es/victory-primitives/path.d.ts +2 -0
  42. package/es/victory-primitives/path.js +15 -8
  43. package/es/victory-primitives/point.d.ts +21 -0
  44. package/es/victory-primitives/point.js +15 -23
  45. package/es/victory-primitives/rect.d.ts +2 -0
  46. package/es/victory-primitives/rect.js +17 -10
  47. package/es/victory-primitives/text.d.ts +16 -0
  48. package/es/victory-primitives/text.js +13 -8
  49. package/es/victory-primitives/tspan.d.ts +2 -0
  50. package/es/victory-primitives/tspan.js +7 -6
  51. package/es/victory-primitives/types.d.ts +7 -0
  52. package/es/victory-primitives/types.js +1 -0
  53. package/es/victory-primitives/whisker.d.ts +24 -0
  54. package/es/victory-primitives/whisker.js +12 -12
  55. package/es/victory-theme/grayscale.d.ts +2 -0
  56. package/es/victory-theme/grayscale.js +1 -1
  57. package/es/victory-theme/material.d.ts +2 -0
  58. package/es/victory-theme/material.js +1 -1
  59. package/es/victory-theme/victory-theme-definition.d.ts +244 -0
  60. package/es/victory-theme/victory-theme-definition.js +1 -0
  61. package/es/victory-theme/victory-theme.d.ts +5 -0
  62. package/es/victory-theme/victory-theme.js +6 -5
  63. package/es/victory-transition/victory-transition.d.ts +59 -0
  64. package/es/victory-transition/victory-transition.js +38 -44
  65. package/es/victory-util/add-events.js +328 -319
  66. package/es/victory-util/axis.js +12 -6
  67. package/es/victory-util/collection.js +7 -5
  68. package/es/victory-util/common-props.js +2 -2
  69. package/es/victory-util/data.js +8 -6
  70. package/es/victory-util/default-transitions.js +0 -1
  71. package/es/victory-util/domain.js +7 -5
  72. package/es/victory-util/events.js +8 -4
  73. package/es/victory-util/helpers.js +1 -3
  74. package/es/victory-util/hooks/use-animation-state.js +11 -5
  75. package/es/victory-util/immutable.js +0 -1
  76. package/es/victory-util/label-helpers.js +0 -2
  77. package/es/victory-util/line-helpers.js +1 -1
  78. package/es/victory-util/log.js +0 -1
  79. package/es/victory-util/point-path-helpers.d.ts +9 -0
  80. package/es/victory-util/point-path-helpers.js +59 -61
  81. package/es/victory-util/scale.js +19 -19
  82. package/es/victory-util/selection.d.ts +23 -0
  83. package/es/victory-util/selection.js +0 -2
  84. package/es/victory-util/style.js +0 -2
  85. package/es/victory-util/textsize.d.ts +8 -0
  86. package/es/victory-util/textsize.js +11 -7
  87. package/es/victory-util/timer-context.d.ts +11 -0
  88. package/es/victory-util/timer-context.js +1 -1
  89. package/es/victory-util/timer.d.ts +16 -0
  90. package/es/victory-util/timer.js +16 -13
  91. package/es/victory-util/types.d.ts +188 -0
  92. package/es/victory-util/types.js +1 -0
  93. package/es/victory-util/user-props.js +44 -4
  94. package/es/victory-util/wrapper.js +18 -12
  95. package/lib/index.d.ts +38 -941
  96. package/lib/index.js +201 -189
  97. package/lib/types.d.ts +33 -0
  98. package/lib/types.js +1 -0
  99. package/lib/victory-accessible-group/victory-accessible-group.d.ts +25 -0
  100. package/lib/victory-accessible-group/victory-accessible-group.js +37 -45
  101. package/lib/victory-animation/util.d.ts +66 -0
  102. package/lib/victory-animation/util.js +4 -3
  103. package/lib/victory-animation/victory-animation.d.ts +69 -0
  104. package/lib/victory-animation/victory-animation.js +97 -102
  105. package/lib/victory-clip-container/victory-clip-container.d.ts +76 -0
  106. package/lib/victory-clip-container/victory-clip-container.js +81 -82
  107. package/lib/victory-container/victory-container.d.ts +99 -0
  108. package/lib/victory-container/victory-container.js +102 -107
  109. package/lib/victory-label/victory-label.d.ts +61 -0
  110. package/lib/victory-label/victory-label.js +49 -32
  111. package/lib/victory-portal/portal-context.d.ts +11 -0
  112. package/lib/victory-portal/portal-context.js +4 -5
  113. package/lib/victory-portal/portal.d.ts +28 -0
  114. package/lib/victory-portal/portal.js +49 -50
  115. package/lib/victory-portal/victory-portal.d.ts +31 -0
  116. package/lib/victory-portal/victory-portal.js +43 -47
  117. package/lib/victory-primitives/arc.d.ts +21 -0
  118. package/lib/victory-primitives/arc.js +13 -10
  119. package/lib/victory-primitives/background.d.ts +22 -0
  120. package/lib/victory-primitives/background.js +16 -13
  121. package/lib/victory-primitives/border.d.ts +18 -0
  122. package/lib/victory-primitives/border.js +13 -10
  123. package/lib/victory-primitives/circle.d.ts +2 -0
  124. package/lib/victory-primitives/circle.js +17 -8
  125. package/lib/victory-primitives/clip-path.d.ts +14 -0
  126. package/lib/victory-primitives/clip-path.js +7 -5
  127. package/lib/victory-primitives/index.d.ts +14 -0
  128. package/lib/victory-primitives/index.js +187 -0
  129. package/lib/victory-primitives/line-segment.d.ts +19 -0
  130. package/lib/victory-primitives/line-segment.js +13 -10
  131. package/lib/victory-primitives/line.d.ts +2 -0
  132. package/lib/victory-primitives/line.js +17 -8
  133. package/lib/victory-primitives/path.d.ts +2 -0
  134. package/lib/victory-primitives/path.js +15 -6
  135. package/lib/victory-primitives/point.d.ts +21 -0
  136. package/lib/victory-primitives/point.js +21 -25
  137. package/lib/victory-primitives/rect.d.ts +2 -0
  138. package/lib/victory-primitives/rect.js +17 -8
  139. package/lib/victory-primitives/text.d.ts +16 -0
  140. package/lib/victory-primitives/text.js +14 -7
  141. package/lib/victory-primitives/tspan.d.ts +2 -0
  142. package/lib/victory-primitives/tspan.js +7 -4
  143. package/lib/victory-primitives/types.d.ts +7 -0
  144. package/lib/victory-primitives/types.js +1 -0
  145. package/lib/victory-primitives/whisker.d.ts +24 -0
  146. package/lib/victory-primitives/whisker.js +16 -13
  147. package/lib/victory-theme/grayscale.d.ts +2 -0
  148. package/lib/victory-theme/grayscale.js +3 -3
  149. package/lib/victory-theme/material.d.ts +2 -0
  150. package/lib/victory-theme/material.js +3 -3
  151. package/lib/victory-theme/victory-theme-definition.d.ts +244 -0
  152. package/lib/victory-theme/victory-theme-definition.js +1 -0
  153. package/lib/victory-theme/victory-theme.d.ts +5 -0
  154. package/lib/victory-theme/victory-theme.js +22 -8
  155. package/lib/victory-transition/victory-transition.d.ts +59 -0
  156. package/lib/victory-transition/victory-transition.js +43 -45
  157. package/lib/victory-util/add-events.js +326 -316
  158. package/lib/victory-util/axis.js +20 -11
  159. package/lib/victory-util/collection.js +10 -8
  160. package/lib/victory-util/common-props.js +6 -4
  161. package/lib/victory-util/data.js +13 -7
  162. package/lib/victory-util/default-transitions.js +1 -2
  163. package/lib/victory-util/domain.js +11 -5
  164. package/lib/victory-util/events.js +17 -11
  165. package/lib/victory-util/helpers.js +14 -16
  166. package/lib/victory-util/hooks/index.js +4 -4
  167. package/lib/victory-util/hooks/use-animation-state.js +14 -6
  168. package/lib/victory-util/immutable.js +3 -5
  169. package/lib/victory-util/label-helpers.js +6 -6
  170. package/lib/victory-util/line-helpers.js +4 -2
  171. package/lib/victory-util/log.js +0 -1
  172. package/lib/victory-util/point-path-helpers.d.ts +9 -0
  173. package/lib/victory-util/point-path-helpers.js +86 -73
  174. package/lib/victory-util/prop-types.js +5 -3
  175. package/lib/victory-util/scale.js +24 -21
  176. package/lib/victory-util/selection.d.ts +23 -0
  177. package/lib/victory-util/selection.js +5 -5
  178. package/lib/victory-util/style.js +0 -2
  179. package/lib/victory-util/textsize.d.ts +8 -0
  180. package/lib/victory-util/textsize.js +12 -8
  181. package/lib/victory-util/timer-context.d.ts +11 -0
  182. package/lib/victory-util/timer-context.js +1 -1
  183. package/lib/victory-util/timer.d.ts +16 -0
  184. package/lib/victory-util/timer.js +16 -13
  185. package/lib/victory-util/types.d.ts +188 -0
  186. package/lib/victory-util/types.js +1 -0
  187. package/lib/victory-util/user-props.js +53 -6
  188. package/lib/victory-util/wrapper.js +31 -23
  189. package/package.json +6 -13
  190. package/src/index.ts +42 -0
  191. package/src/types.ts +45 -0
  192. package/src/victory-accessible-group/{victory-accessible-group.js → victory-accessible-group.tsx} +10 -3
  193. package/src/victory-animation/{util.js → util.ts} +5 -4
  194. package/src/victory-animation/{victory-animation.js → victory-animation.tsx} +90 -13
  195. package/src/victory-clip-container/{victory-clip-container.js → victory-clip-container.tsx} +32 -6
  196. package/src/victory-container/{victory-container.js → victory-container.tsx} +70 -26
  197. package/src/victory-label/{victory-label.js → victory-label.tsx} +80 -19
  198. package/src/victory-portal/portal-context.ts +14 -0
  199. package/src/victory-portal/{portal.js → portal.tsx} +23 -12
  200. package/src/victory-portal/{victory-portal.js → victory-portal.tsx} +21 -6
  201. package/src/victory-primitives/{arc.js → arc.tsx} +15 -5
  202. package/src/victory-primitives/{background.js → background.tsx} +17 -7
  203. package/src/victory-primitives/{border.js → border.tsx} +12 -5
  204. package/src/victory-primitives/{circle.js → circle.tsx} +4 -3
  205. package/src/victory-primitives/clip-path.tsx +25 -0
  206. package/src/victory-primitives/index.ts +14 -0
  207. package/src/victory-primitives/{line-segment.js → line-segment.tsx} +13 -5
  208. package/src/victory-primitives/{line.js → line.tsx} +4 -3
  209. package/src/victory-primitives/{path.js → path.tsx} +4 -3
  210. package/src/victory-primitives/{point.js → point.tsx} +25 -20
  211. package/src/victory-primitives/{rect.js → rect.tsx} +4 -2
  212. package/src/victory-primitives/{text.js → text.tsx} +9 -3
  213. package/src/victory-primitives/tspan.tsx +7 -0
  214. package/src/victory-primitives/types.ts +19 -0
  215. package/src/victory-primitives/{whisker.js → whisker.tsx} +20 -7
  216. package/src/victory-theme/{grayscale.js → grayscale.tsx} +2 -1
  217. package/src/victory-theme/{material.js → material.tsx} +2 -1
  218. package/src/victory-theme/victory-theme-definition.ts +261 -0
  219. package/src/victory-theme/victory-theme.tsx +5 -0
  220. package/src/victory-transition/{victory-transition.js → victory-transition.tsx} +68 -19
  221. package/src/victory-util/add-events.js +7 -5
  222. package/src/victory-util/axis.js +3 -1
  223. package/src/victory-util/collection.js +0 -1
  224. package/src/victory-util/common-props.js +2 -2
  225. package/src/victory-util/data.js +0 -1
  226. package/src/victory-util/default-transitions.js +0 -1
  227. package/src/victory-util/domain.js +0 -1
  228. package/src/victory-util/events.js +1 -1
  229. package/src/victory-util/helpers.js +0 -1
  230. package/src/victory-util/immutable.js +0 -1
  231. package/src/victory-util/label-helpers.js +0 -1
  232. package/src/victory-util/line-helpers.js +1 -1
  233. package/src/victory-util/log.js +0 -1
  234. package/src/victory-util/point-path-helpers.ts +119 -0
  235. package/src/victory-util/prop-types.js +0 -1
  236. package/src/victory-util/scale.js +18 -10
  237. package/src/victory-util/selection.d.ts +23 -0
  238. package/src/victory-util/selection.js +0 -1
  239. package/src/victory-util/style.js +0 -1
  240. package/src/victory-util/textsize.d.ts +8 -0
  241. package/src/victory-util/{timer-context.js → timer-context.ts} +0 -0
  242. package/src/victory-util/{timer.js → timer.ts} +20 -5
  243. package/src/victory-util/transitions.js +0 -1
  244. package/src/victory-util/types.ts +247 -0
  245. package/src/victory-util/user-props.js +31 -1
  246. package/src/victory-util/wrapper.js +0 -1
  247. package/src/index.d.ts +0 -941
  248. package/src/index.js +0 -51
  249. package/src/victory-portal/portal-context.js +0 -10
  250. package/src/victory-primitives/clip-path.js +0 -18
  251. package/src/victory-primitives/tspan.js +0 -5
  252. package/src/victory-theme/victory-theme.js +0 -7
  253. package/src/victory-util/point-path-helpers.js +0 -121
@@ -1,9 +1,8 @@
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
- import * as d3Scale from "d3-scale";
5
+ import * as d3Scale from "victory-vendor/d3-scale";
7
6
 
8
7
  const supportedScaleStrings = ["linear", "time", "log", "sqrt"];
9
8
 
@@ -110,19 +109,28 @@ export function getScaleType(props, axis) {
110
109
  );
111
110
  }
112
111
 
112
+ // Ordered type inference off of function fields.
113
+ // **Note**: Brittle because reliant on d3 internals.
114
+ const DUCK_TYPES = [
115
+ { name: "quantile", method: "quantiles" },
116
+ { name: "log", method: "base" }
117
+ // TODO(2214): Re-evaluate (1) duck typing approach, and (2) if duck typing,
118
+ // do we need a different approach? (Multiple keys? Stringifying functions?)
119
+ // https://github.com/FormidableLabs/victory/issues/2214
120
+ // Below are matches that don't seem to otherwise occur in Victory code base.
121
+ // { name: "ordinal", method: "unknown" },
122
+ // { name: "pow-sqrt", method: "exponent" },
123
+ // { name: "quantize-threshold", method: "invertExtent" }
124
+ ];
125
+
113
126
  export function getType(scale) {
114
127
  if (typeof scale === "string") {
115
128
  return scale;
116
129
  }
117
- const duckTypes = [
118
- { name: "log", method: "base" },
119
- { name: "ordinal", method: "unknown" },
120
- { name: "pow-sqrt", method: "exponent" },
121
- { name: "quantile", method: "quantiles" },
122
- { name: "quantize-threshold", method: "invertExtent" }
123
- ];
124
- const scaleType = duckTypes.filter((type) => {
130
+
131
+ const scaleType = DUCK_TYPES.filter((type) => {
125
132
  return scale[type.method] !== undefined;
126
133
  })[0];
134
+
127
135
  return scaleType ? scaleType.name : undefined;
128
136
  }
@@ -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;
@@ -1,4 +1,3 @@
1
- /* eslint-disable func-style */
2
1
  /* eslint-disable no-use-before-define */
3
2
 
4
3
  import * as Collection from "./collection";
@@ -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
@@ -0,0 +1,8 @@
1
+ import { TextSizeStyleInterface } from "./types";
2
+
3
+ export function approximateTextSize(
4
+ text: string,
5
+ style?: TextSizeStyleInterface
6
+ ): { width: number; height: number };
7
+
8
+ export function convertLengthToPixels(length: string, fontSize: number): number;
@@ -1,10 +1,25 @@
1
- import { timer, now } from "d3-timer";
1
+ import { timer, now } from "victory-vendor/d3-timer";
2
+
3
+ interface D3Timer {
4
+ new (callback): void;
5
+ stop(): void;
6
+ }
7
+
8
+ type Callback = (elapsed: number, duration: number) => void;
2
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(),
@@ -1,4 +1,3 @@
1
- /* eslint-disable func-style */
2
1
  import { assign, defaults, identity, keys } from "lodash";
3
2
  import React from "react";
4
3
 
@@ -0,0 +1,247 @@
1
+ import * as React from "react";
2
+ import { OriginType } from "../victory-label/victory-label";
3
+ import {
4
+ NumberOrCallback,
5
+ PaddingProps,
6
+ VictoryThemeDefinition
7
+ } from "../victory-theme/victory-theme";
8
+ import { StringOrCallback, StringOrNumberOrCallback } from "../types";
9
+ import {
10
+ AnimationEasing,
11
+ AnimationStyle
12
+ } from "../victory-animation/victory-animation";
13
+
14
+ export type StringOrNumberOrList = string | number | (string | number)[];
15
+
16
+ export interface AnimatePropTypeInterface {
17
+ duration?: number;
18
+ onEnd?: () => void;
19
+ onExit?: {
20
+ duration?: number;
21
+ before?: (datum: any) => AnimationStyle;
22
+ };
23
+ onEnter?: {
24
+ duration?: number;
25
+ before?: (datum: any) => AnimationStyle;
26
+ after?: (datum: any) => AnimationStyle;
27
+ };
28
+ onLoad?: {
29
+ duration?: number;
30
+ before?: (datum: any) => AnimationStyle;
31
+ after?: (datum: any) => AnimationStyle;
32
+ };
33
+ easing?: AnimationEasing;
34
+ animationWhitelist?: string[];
35
+ }
36
+
37
+ export interface EventCallbackInterface<TTarget, TEventKey> {
38
+ childName?: string | string[];
39
+ target?: TTarget;
40
+ eventKey?: TEventKey;
41
+ mutation: (props: any) => any;
42
+ callback?: (props: any) => any;
43
+ }
44
+
45
+ export interface EventPropTypeInterface<TTarget, TEventKey> {
46
+ childName?: string | Array<StringOrNumberOrCallback>;
47
+ target: TTarget;
48
+ eventKey?: TEventKey;
49
+ eventHandlers: {
50
+ [key: string]:
51
+ | {
52
+ (
53
+ event: React.SyntheticEvent<any>,
54
+ props?: any
55
+ ): EventCallbackInterface<TTarget, TEventKey>;
56
+ }
57
+ | {
58
+ (
59
+ event: React.SyntheticEvent<any>,
60
+ props?: any
61
+ ): EventCallbackInterface<TTarget, TEventKey>[];
62
+ }
63
+ | {
64
+ (event: React.SyntheticEvent<any>, props?: any): void;
65
+ };
66
+ };
67
+ }
68
+
69
+ export type DomainTuple = [number, number] | [Date, Date];
70
+ export type DomainPropObjectType =
71
+ | { x?: DomainTuple; y: DomainTuple }
72
+ | { x: DomainTuple; y?: DomainTuple };
73
+ export type DomainPropType = DomainPropObjectType | DomainTuple;
74
+
75
+ export type PaddingType = number | [number, number];
76
+ export type DomainPaddingPropType =
77
+ | PaddingType
78
+ | {
79
+ x?: PaddingType;
80
+ y?: PaddingType;
81
+ };
82
+
83
+ export type RangeTuple = [number, number];
84
+ export type RangePropType = RangeTuple | { x?: RangeTuple; y?: RangeTuple };
85
+
86
+ /**
87
+ * D3 scale function shape. Don"t want to introduce typing dependency to d3
88
+ */
89
+ export interface D3Scale {
90
+ (input: string | number): number;
91
+ domain: () => any;
92
+ range: () => any;
93
+ copy: () => any;
94
+ }
95
+
96
+ export type ScalePropType = "linear" | "time" | "log" | "sqrt";
97
+
98
+ export type CategoryPropType =
99
+ | string[]
100
+ | { x: string[] }
101
+ | { y: string[] }
102
+ | {
103
+ x: string[];
104
+ y: string[];
105
+ };
106
+
107
+ export type DataGetterPropType =
108
+ | number
109
+ | string
110
+ | string[]
111
+ | { (data: any): number | string | string[] }
112
+ // eslint-disable-next-line @typescript-eslint/ban-types
113
+ | Function;
114
+
115
+ export type InterpolationPropType =
116
+ | "basis"
117
+ | "basisClosed"
118
+ | "basisOpen"
119
+ | "bundle"
120
+ | "cardinal"
121
+ | "cardinalClosed"
122
+ | "cardinalOpen"
123
+ | "catmullRom"
124
+ | "catmullRomClosed"
125
+ | "catmullRomOpen"
126
+ | "linear"
127
+ | "linearClosed"
128
+ | "monotoneX"
129
+ | "monotoneY"
130
+ | "natural"
131
+ | "radial"
132
+ | "step"
133
+ | "stepAfter"
134
+ | "stepBefore";
135
+
136
+ export type ColorScalePropType =
137
+ | "grayscale"
138
+ | "qualitative"
139
+ | "heatmap"
140
+ | "warm"
141
+ | "cool"
142
+ | "red"
143
+ | "green"
144
+ | "blue"
145
+ | string[];
146
+
147
+ export type SortOrderPropType = "ascending" | "descending";
148
+
149
+ export type SVGCoordinateType = { x: number; y: number };
150
+
151
+ export interface VictoryCommonThemeProps {
152
+ animate?: boolean | AnimatePropTypeInterface;
153
+ colorScale?: ColorScalePropType;
154
+ containerComponent?: React.ReactElement;
155
+ domainPadding?: DomainPaddingPropType;
156
+ externalEventMutations?: EventCallbackInterface<
157
+ string | string[],
158
+ StringOrNumberOrList
159
+ >[];
160
+ groupComponent?: React.ReactElement;
161
+ height?: number;
162
+ horizontal?: boolean;
163
+ maxDomain?: number | { x?: number; y?: number };
164
+ minDomain?: number | { x?: number; y?: number };
165
+ name?: string;
166
+ origin?: OriginType;
167
+ padding?: PaddingProps;
168
+ polar?: boolean;
169
+ range?: RangePropType;
170
+ scale?:
171
+ | ScalePropType
172
+ | D3Scale
173
+ | {
174
+ x?: ScalePropType | D3Scale;
175
+ y?: ScalePropType | D3Scale;
176
+ };
177
+ // eslint-disable-next-line @typescript-eslint/ban-types
178
+ sharedEvents?: { events: any[]; getEventState: Function };
179
+ singleQuadrantDomainPadding?: boolean | { x?: boolean; y?: boolean };
180
+ standalone?: boolean;
181
+ width?: number;
182
+ }
183
+
184
+ export interface VictoryCommonProps extends VictoryCommonThemeProps {
185
+ theme?: VictoryThemeDefinition;
186
+ }
187
+
188
+ export interface VictoryCommonPrimitiveProps {
189
+ active?: boolean;
190
+ ariaLabel?: StringOrCallback;
191
+ className?: string;
192
+ clipPath?: string;
193
+ data?: any;
194
+ // eslint-disable-next-line @typescript-eslint/ban-types
195
+ desc?: string | Function;
196
+ disableInlineStyles?: boolean;
197
+ events?: object;
198
+ // eslint-disable-next-line @typescript-eslint/ban-types
199
+ id?: number | string | Function;
200
+ index?: number | string;
201
+ origin?: OriginType;
202
+ polar?: boolean;
203
+ role?: string;
204
+ scale?: any;
205
+ shapeRendering?: string;
206
+ style?: any;
207
+ tabIndex?: NumberOrCallback;
208
+ transform?: string;
209
+ }
210
+
211
+ export interface VictoryDatableProps {
212
+ categories?: CategoryPropType;
213
+ data?: any[];
214
+ dataComponent?: React.ReactElement;
215
+ domain?: DomainPropType;
216
+ domainPadding?: DomainPaddingPropType;
217
+ samples?: number;
218
+ sortKey?: DataGetterPropType;
219
+ sortOrder?: SortOrderPropType;
220
+ x?: DataGetterPropType;
221
+ y?: DataGetterPropType;
222
+ y0?: DataGetterPropType;
223
+ }
224
+
225
+ export interface VictoryLabelableProps {
226
+ labelComponent?: React.ReactElement;
227
+ }
228
+
229
+ export interface VictoryMultiLabelableProps extends VictoryLabelableProps {
230
+ labels?:
231
+ | string[]
232
+ | number[]
233
+ | { (data: any): string | string[] | number | number[] | null };
234
+ }
235
+
236
+ export interface VictorySingleLabelableProps extends VictoryLabelableProps {
237
+ label?: string | { (data: any): string | number | null };
238
+ }
239
+
240
+ export interface TextSizeStyleInterface {
241
+ angle?: number;
242
+ characterConstant?: string;
243
+ fontFamily?: string;
244
+ fontSize?: number | string;
245
+ letterSpacing?: string;
246
+ lineHeight?: number;
247
+ }
@@ -1,3 +1,5 @@
1
+ import * as React from "react";
2
+
1
3
  /*
2
4
  USER_PROPS_SAFELIST is to contain any string deemed safe for user props.
3
5
  The startsWidth array will contain the start of any accepted user-prop that
@@ -48,6 +50,19 @@ const testIfSafeProp = (key) => {
48
50
  return false;
49
51
  };
50
52
 
53
+ /**
54
+ * Gets the value from props if a function value is provided
55
+ * @param {any} value: maybe function value
56
+ * @param {Object} props: props object
57
+ * @returns {any} newValue
58
+ */
59
+ const getValue = (value, props) => {
60
+ if (typeof value === "function") {
61
+ return value(props);
62
+ }
63
+ return value;
64
+ };
65
+
51
66
  /**
52
67
  * getSafeUserProps - function that takes in a props object and removes any
53
68
  * key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
@@ -59,6 +74,21 @@ const testIfSafeProp = (key) => {
59
74
  export const getSafeUserProps = (props) => {
60
75
  const propsToFilter = { ...props };
61
76
  return Object.fromEntries(
62
- Object.entries(propsToFilter).filter(([key]) => testIfSafeProp(key))
77
+ Object.entries(propsToFilter)
78
+ .filter(([key]) => testIfSafeProp(key))
79
+ .map(([key, value]) => {
80
+ return [key, getValue(value, props)];
81
+ })
63
82
  );
64
83
  };
84
+
85
+ /**
86
+ * Wraps a component and adds safe user props
87
+ *
88
+ * @param {ReactNode} component: parent component
89
+ * @param {Object} props: props to be filtered
90
+ * @returns {ReactNode} modified component
91
+ */
92
+ export const withSafeUserProps = (component, props) => {
93
+ return React.cloneElement(component, getSafeUserProps(props));
94
+ };
@@ -1,4 +1,3 @@
1
- /* eslint-disable func-style */
2
1
  import {
3
2
  assign,
4
3
  defaults,