victory-core 36.4.1 → 36.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/dist/victory-core.js +874 -879
  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 +8 -16
  9. package/es/victory-animation/util.d.ts +66 -0
  10. package/es/victory-animation/util.js +2 -1
  11. package/es/victory-animation/victory-animation.d.ts +69 -0
  12. package/es/victory-animation/victory-animation.js +59 -67
  13. package/es/victory-clip-container/victory-clip-container.d.ts +76 -0
  14. package/es/victory-clip-container/victory-clip-container.js +15 -21
  15. package/es/victory-container/victory-container.d.ts +99 -0
  16. package/es/victory-container/victory-container.js +31 -31
  17. package/es/victory-label/victory-label.d.ts +61 -0
  18. package/es/victory-label/victory-label.js +13 -8
  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 +25 -33
  23. package/es/victory-portal/victory-portal.d.ts +31 -0
  24. package/es/victory-portal/victory-portal.js +23 -22
  25. package/es/victory-primitives/arc.d.ts +21 -0
  26. package/es/victory-primitives/arc.js +3 -5
  27. package/es/victory-primitives/background.d.ts +22 -0
  28. package/es/victory-primitives/background.js +4 -6
  29. package/es/victory-primitives/border.d.ts +18 -0
  30. package/es/victory-primitives/border.js +3 -5
  31. package/es/victory-primitives/circle.d.ts +2 -0
  32. package/es/victory-primitives/circle.js +11 -8
  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 +3 -5
  39. package/es/victory-primitives/line.d.ts +2 -0
  40. package/es/victory-primitives/line.js +11 -8
  41. package/es/victory-primitives/path.d.ts +2 -0
  42. package/es/victory-primitives/path.js +9 -6
  43. package/es/victory-primitives/point.d.ts +21 -0
  44. package/es/victory-primitives/point.js +9 -19
  45. package/es/victory-primitives/rect.d.ts +2 -0
  46. package/es/victory-primitives/rect.js +11 -8
  47. package/es/victory-primitives/text.d.ts +16 -0
  48. package/es/victory-primitives/text.js +7 -6
  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 +3 -5
  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 +19 -23
  65. package/es/victory-util/add-events.js +6 -3
  66. package/es/victory-util/axis.js +0 -1
  67. package/es/victory-util/collection.js +0 -2
  68. package/es/victory-util/data.js +0 -2
  69. package/es/victory-util/default-transitions.js +0 -1
  70. package/es/victory-util/domain.js +0 -2
  71. package/es/victory-util/helpers.js +0 -2
  72. package/es/victory-util/immutable.js +0 -1
  73. package/es/victory-util/label-helpers.js +0 -2
  74. package/es/victory-util/log.js +0 -1
  75. package/es/victory-util/point-path-helpers.d.ts +9 -0
  76. package/es/victory-util/point-path-helpers.js +59 -61
  77. package/es/victory-util/selection.d.ts +23 -0
  78. package/es/victory-util/selection.js +0 -2
  79. package/es/victory-util/style.js +0 -2
  80. package/es/victory-util/textsize.d.ts +8 -0
  81. package/es/victory-util/timer-context.d.ts +11 -0
  82. package/es/victory-util/timer.d.ts +16 -0
  83. package/es/victory-util/timer.js +13 -8
  84. package/es/victory-util/types.d.ts +188 -0
  85. package/es/victory-util/types.js +1 -0
  86. package/lib/index.d.ts +38 -941
  87. package/lib/index.js +195 -193
  88. package/lib/types.d.ts +33 -0
  89. package/lib/types.js +1 -0
  90. package/lib/victory-accessible-group/victory-accessible-group.d.ts +25 -0
  91. package/lib/victory-accessible-group/victory-accessible-group.js +9 -15
  92. package/lib/victory-animation/util.d.ts +66 -0
  93. package/lib/victory-animation/util.js +2 -1
  94. package/lib/victory-animation/victory-animation.d.ts +69 -0
  95. package/lib/victory-animation/victory-animation.js +60 -65
  96. package/lib/victory-clip-container/victory-clip-container.d.ts +76 -0
  97. package/lib/victory-clip-container/victory-clip-container.js +19 -22
  98. package/lib/victory-container/victory-container.d.ts +99 -0
  99. package/lib/victory-container/victory-container.js +34 -31
  100. package/lib/victory-label/victory-label.d.ts +61 -0
  101. package/lib/victory-label/victory-label.js +19 -13
  102. package/lib/victory-portal/portal-context.d.ts +11 -0
  103. package/lib/victory-portal/portal-context.js +3 -4
  104. package/lib/victory-portal/portal.d.ts +28 -0
  105. package/lib/victory-portal/portal.js +26 -31
  106. package/lib/victory-portal/victory-portal.d.ts +31 -0
  107. package/lib/victory-portal/victory-portal.js +24 -20
  108. package/lib/victory-primitives/arc.d.ts +21 -0
  109. package/lib/victory-primitives/arc.js +5 -6
  110. package/lib/victory-primitives/background.d.ts +22 -0
  111. package/lib/victory-primitives/background.js +7 -8
  112. package/lib/victory-primitives/border.d.ts +18 -0
  113. package/lib/victory-primitives/border.js +5 -6
  114. package/lib/victory-primitives/circle.d.ts +2 -0
  115. package/lib/victory-primitives/circle.js +11 -6
  116. package/lib/victory-primitives/clip-path.d.ts +14 -0
  117. package/lib/victory-primitives/clip-path.js +7 -5
  118. package/lib/victory-primitives/index.d.ts +14 -0
  119. package/lib/victory-primitives/index.js +187 -0
  120. package/lib/victory-primitives/line-segment.d.ts +19 -0
  121. package/lib/victory-primitives/line-segment.js +5 -6
  122. package/lib/victory-primitives/line.d.ts +2 -0
  123. package/lib/victory-primitives/line.js +11 -6
  124. package/lib/victory-primitives/path.d.ts +2 -0
  125. package/lib/victory-primitives/path.js +9 -4
  126. package/lib/victory-primitives/point.d.ts +21 -0
  127. package/lib/victory-primitives/point.js +13 -21
  128. package/lib/victory-primitives/rect.d.ts +2 -0
  129. package/lib/victory-primitives/rect.js +11 -6
  130. package/lib/victory-primitives/text.d.ts +16 -0
  131. package/lib/victory-primitives/text.js +8 -5
  132. package/lib/victory-primitives/tspan.d.ts +2 -0
  133. package/lib/victory-primitives/tspan.js +7 -4
  134. package/lib/victory-primitives/types.d.ts +7 -0
  135. package/lib/victory-primitives/types.js +1 -0
  136. package/lib/victory-primitives/whisker.d.ts +24 -0
  137. package/lib/victory-primitives/whisker.js +5 -6
  138. package/lib/victory-theme/grayscale.d.ts +2 -0
  139. package/lib/victory-theme/grayscale.js +3 -3
  140. package/lib/victory-theme/material.d.ts +2 -0
  141. package/lib/victory-theme/material.js +3 -3
  142. package/lib/victory-theme/victory-theme-definition.d.ts +244 -0
  143. package/lib/victory-theme/victory-theme-definition.js +1 -0
  144. package/lib/victory-theme/victory-theme.d.ts +5 -0
  145. package/lib/victory-theme/victory-theme.js +22 -8
  146. package/lib/victory-transition/victory-transition.d.ts +59 -0
  147. package/lib/victory-transition/victory-transition.js +21 -23
  148. package/lib/victory-util/add-events.js +8 -4
  149. package/lib/victory-util/collection.js +0 -2
  150. package/lib/victory-util/default-transitions.js +0 -1
  151. package/lib/victory-util/helpers.js +0 -2
  152. package/lib/victory-util/immutable.js +0 -2
  153. package/lib/victory-util/label-helpers.js +0 -2
  154. package/lib/victory-util/log.js +0 -1
  155. package/lib/victory-util/point-path-helpers.d.ts +9 -0
  156. package/lib/victory-util/point-path-helpers.js +86 -73
  157. package/lib/victory-util/selection.d.ts +23 -0
  158. package/lib/victory-util/selection.js +0 -2
  159. package/lib/victory-util/style.js +0 -2
  160. package/lib/victory-util/textsize.d.ts +8 -0
  161. package/lib/victory-util/timer-context.d.ts +11 -0
  162. package/lib/victory-util/timer.d.ts +16 -0
  163. package/lib/victory-util/timer.js +13 -8
  164. package/lib/victory-util/types.d.ts +188 -0
  165. package/lib/victory-util/types.js +1 -0
  166. package/package.json +4 -4
  167. package/src/index.ts +42 -0
  168. package/src/types.ts +45 -0
  169. package/src/victory-accessible-group/{victory-accessible-group.js → victory-accessible-group.tsx} +10 -3
  170. package/src/victory-animation/{util.js → util.ts} +4 -3
  171. package/src/victory-animation/{victory-animation.js → victory-animation.tsx} +89 -12
  172. package/src/victory-clip-container/{victory-clip-container.js → victory-clip-container.tsx} +29 -5
  173. package/src/victory-container/{victory-container.js → victory-container.tsx} +70 -26
  174. package/src/victory-label/{victory-label.js → victory-label.tsx} +71 -14
  175. package/src/victory-portal/portal-context.ts +14 -0
  176. package/src/victory-portal/{portal.js → portal.tsx} +23 -12
  177. package/src/victory-portal/{victory-portal.js → victory-portal.tsx} +21 -6
  178. package/src/victory-primitives/{arc.js → arc.tsx} +15 -5
  179. package/src/victory-primitives/{background.js → background.tsx} +17 -7
  180. package/src/victory-primitives/{border.js → border.tsx} +12 -5
  181. package/src/victory-primitives/{circle.js → circle.tsx} +4 -3
  182. package/src/victory-primitives/clip-path.tsx +25 -0
  183. package/src/victory-primitives/index.ts +14 -0
  184. package/src/victory-primitives/{line-segment.js → line-segment.tsx} +13 -5
  185. package/src/victory-primitives/{line.js → line.tsx} +4 -3
  186. package/src/victory-primitives/{path.js → path.tsx} +4 -3
  187. package/src/victory-primitives/{point.js → point.tsx} +25 -20
  188. package/src/victory-primitives/{rect.js → rect.tsx} +4 -2
  189. package/src/victory-primitives/{text.js → text.tsx} +9 -3
  190. package/src/victory-primitives/tspan.tsx +7 -0
  191. package/src/victory-primitives/types.ts +19 -0
  192. package/src/victory-primitives/{whisker.js → whisker.tsx} +20 -7
  193. package/src/victory-theme/{grayscale.js → grayscale.tsx} +2 -1
  194. package/src/victory-theme/{material.js → material.tsx} +2 -1
  195. package/src/victory-theme/victory-theme-definition.ts +261 -0
  196. package/src/victory-theme/victory-theme.tsx +5 -0
  197. package/src/victory-transition/{victory-transition.js → victory-transition.tsx} +68 -19
  198. package/src/victory-util/add-events.js +6 -1
  199. package/src/victory-util/axis.js +0 -1
  200. package/src/victory-util/collection.js +0 -1
  201. package/src/victory-util/data.js +0 -1
  202. package/src/victory-util/default-transitions.js +0 -1
  203. package/src/victory-util/domain.js +0 -1
  204. package/src/victory-util/events.js +1 -1
  205. package/src/victory-util/helpers.js +0 -1
  206. package/src/victory-util/immutable.js +0 -1
  207. package/src/victory-util/label-helpers.js +0 -1
  208. package/src/victory-util/log.js +0 -1
  209. package/src/victory-util/point-path-helpers.ts +119 -0
  210. package/src/victory-util/prop-types.js +0 -1
  211. package/src/victory-util/scale.js +0 -1
  212. package/src/victory-util/selection.d.ts +23 -0
  213. package/src/victory-util/selection.js +0 -1
  214. package/src/victory-util/style.js +0 -1
  215. package/src/victory-util/textsize.d.ts +8 -0
  216. package/src/victory-util/{timer-context.js → timer-context.ts} +0 -0
  217. package/src/victory-util/{timer.js → timer.ts} +19 -4
  218. package/src/victory-util/transitions.js +0 -1
  219. package/src/victory-util/types.ts +247 -0
  220. package/src/victory-util/wrapper.js +0 -1
  221. package/src/index.d.ts +0 -941
  222. package/src/index.js +0 -51
  223. package/src/victory-portal/portal-context.js +0 -10
  224. package/src/victory-primitives/clip-path.js +0 -18
  225. package/src/victory-primitives/tspan.js +0 -5
  226. package/src/victory-theme/victory-theme.js +0 -7
  227. package/src/victory-util/point-path-helpers.js +0 -121
@@ -2,13 +2,48 @@ import React from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import * as CustomPropTypes from "../victory-util/prop-types";
4
4
  import { assign, defaults, uniqueId, isObject, isFunction } from "lodash";
5
- import Portal from "../victory-portal/portal";
6
- import PortalContext from "../victory-portal/portal-context";
5
+ import { Portal } from "../victory-portal/portal";
6
+ import { PortalContext } from "../victory-portal/portal-context";
7
7
  import TimerContext from "../victory-util/timer-context";
8
8
  import * as Helpers from "../victory-util/helpers";
9
9
  import * as UserProps from "../victory-util/user-props";
10
+ import { OriginType } from "../victory-label/victory-label";
11
+ import { D3Scale } from "../victory-util/types";
12
+ import { VictoryThemeDefinition } from "../victory-theme/victory-theme-definition";
10
13
 
11
- export default class VictoryContainer extends React.Component {
14
+ export interface VictoryContainerProps {
15
+ "aria-describedby"?: string;
16
+ "aria-labelledby"?: string;
17
+ children?: React.ReactElement | React.ReactElement[];
18
+ className?: string;
19
+ containerId?: number | string;
20
+ containerRef?: React.Ref<HTMLElement>;
21
+ desc?: string;
22
+ events?: React.DOMAttributes<any>;
23
+ height?: number;
24
+ name?: string;
25
+ origin?: OriginType;
26
+ ouiaId?: number | string;
27
+ ouiaSafe?: boolean;
28
+ ouiaType?: string;
29
+ polar?: boolean;
30
+ portalComponent?: React.ReactElement;
31
+ portalZIndex?: number;
32
+ preserveAspectRatio?: string;
33
+ responsive?: boolean;
34
+ role?: string;
35
+ scale?: {
36
+ x?: D3Scale;
37
+ y?: D3Scale;
38
+ };
39
+ style?: React.CSSProperties;
40
+ tabIndex?: number;
41
+ theme?: VictoryThemeDefinition;
42
+ title?: string;
43
+ width?: number;
44
+ }
45
+
46
+ export class VictoryContainer extends React.Component<VictoryContainerProps> {
12
47
  static displayName = "VictoryContainer";
13
48
  static role = "container";
14
49
  static propTypes = {
@@ -54,34 +89,39 @@ export default class VictoryContainer extends React.Component {
54
89
  };
55
90
 
56
91
  static contextType = TimerContext;
92
+ private containerId: VictoryContainerProps["containerId"];
93
+ // @ts-expect-error Ref will be initialized on mount
94
+ private portalRef: Portal;
95
+ // @ts-expect-error Ref will be initialized on mount
96
+ private containerRef: HTMLElement;
97
+ private shouldHandleWheel: boolean;
57
98
 
58
- constructor(props) {
99
+ constructor(props: VictoryContainerProps) {
59
100
  super(props);
60
101
  this.containerId =
61
102
  !isObject(props) || props.containerId === undefined
62
103
  ? uniqueId("victory-container-")
63
104
  : props.containerId;
64
- this.savePortalRef = (portal) => {
65
- this.portalRef = portal;
66
- return portal;
67
- };
68
- this.portalUpdate = (key, el) => this.portalRef.portalUpdate(key, el);
69
- this.portalRegister = () => this.portalRef.portalRegister();
70
- this.portalDeregister = (key) => this.portalRef.portalDeregister(key);
71
-
72
- this.saveContainerRef =
73
- props && isFunction(props.containerRef)
74
- ? props.containerRef
75
- : (container) => {
76
- this.containerRef = container;
77
- return container;
78
- };
79
-
80
- this.shouldHandleWheel = props && props.events && props.events.onWheel;
81
- if (this.shouldHandleWheel) {
82
- this.handleWheel = (e) => e.preventDefault();
83
- }
105
+
106
+ this.shouldHandleWheel = !!(props && props.events && props.events.onWheel);
84
107
  }
108
+ savePortalRef = (portal) => {
109
+ this.portalRef = portal;
110
+ return portal;
111
+ };
112
+ portalUpdate = (key, el) => this.portalRef.portalUpdate(key, el);
113
+ portalRegister = () => this.portalRef.portalRegister();
114
+ portalDeregister = (key) => this.portalRef.portalDeregister(key);
115
+
116
+ saveContainerRef = (container: HTMLElement) => {
117
+ if (isFunction(this.props.containerRef)) {
118
+ this.props.containerRef(container);
119
+ }
120
+ this.containerRef = container;
121
+ return container;
122
+ };
123
+
124
+ handleWheel = (e) => e.preventDefault();
85
125
 
86
126
  componentDidMount() {
87
127
  if (this.shouldHandleWheel && this.containerRef) {
@@ -131,11 +171,15 @@ export default class VictoryContainer extends React.Component {
131
171
  ? { width: "100%", height: "100%" }
132
172
  : { width, height };
133
173
  const divStyle = assign(
134
- { pointerEvents: "none", touchAction: "none", position: "relative" },
174
+ {
175
+ pointerEvents: "none",
176
+ touchAction: "none",
177
+ position: "relative"
178
+ } as const,
135
179
  dimensions
136
180
  );
137
181
  const portalDivStyle = assign(
138
- { zIndex: portalZIndex, position: "absolute", top: 0, left: 0 },
182
+ { zIndex: portalZIndex, position: "absolute", top: 0, left: 0 } as const,
139
183
  dimensions
140
184
  );
141
185
  const svgStyle = assign({ pointerEvents: "all" }, dimensions);
@@ -2,10 +2,10 @@
2
2
  import { assign, defaults, isEmpty } from "lodash";
3
3
  import PropTypes from "prop-types";
4
4
  import React from "react";
5
- import VictoryPortal from "../victory-portal/victory-portal";
6
- import Rect from "../victory-primitives/rect";
7
- import Text from "../victory-primitives/text";
8
- import TSpan from "../victory-primitives/tspan";
5
+ import { VictoryPortal } from "../victory-portal/victory-portal";
6
+ import { Rect } from "../victory-primitives/rect";
7
+ import { Text } from "../victory-primitives/text";
8
+ import { TSpan } from "../victory-primitives/tspan";
9
9
  import * as Helpers from "../victory-util/helpers";
10
10
  import * as LabelHelpers from "../victory-util/label-helpers";
11
11
  import * as Log from "../victory-util/log";
@@ -13,6 +13,55 @@ import * as CustomPropTypes from "../victory-util/prop-types";
13
13
  import * as Style from "../victory-util/style";
14
14
  import * as TextSize from "../victory-util/textsize";
15
15
  import * as UserProps from "../victory-util/user-props";
16
+ import { StringOrCallback, StringOrNumberOrCallback } from "../types";
17
+ import {
18
+ NumberOrCallback,
19
+ PaddingProps,
20
+ VerticalAnchorType,
21
+ VictoryLabelStyleObject
22
+ } from "../victory-theme/victory-theme";
23
+
24
+ export type TextAnchorType = "start" | "middle" | "end" | "inherit";
25
+ export type OriginType = { x: number; y: number };
26
+ export type LabelOrientationType = "parallel" | "perpendicular" | "vertical";
27
+
28
+ export interface VictoryLabelProps {
29
+ angle?: StringOrNumberOrCallback;
30
+ ariaLabel?: StringOrCallback;
31
+ backgroundComponent?: React.ReactElement;
32
+ backgroundStyle?: VictoryLabelStyleObject | VictoryLabelStyleObject[];
33
+ backgroundPadding?: PaddingProps | PaddingProps[];
34
+ capHeight?: StringOrNumberOrCallback;
35
+ children?: StringOrNumberOrCallback;
36
+ className?: string;
37
+ datum?: object;
38
+ data?: any[];
39
+ desc?: string;
40
+ direction?: string;
41
+ disableInlineStyles?: boolean;
42
+ events?: React.DOMAttributes<any>;
43
+ groupComponent?: React.ReactElement;
44
+ id?: StringOrNumberOrCallback;
45
+ inline?: boolean;
46
+ labelPlacement?: LabelOrientationType;
47
+ lineHeight?: StringOrNumberOrCallback | (string | number)[];
48
+ origin?: OriginType;
49
+ polar?: boolean;
50
+ renderInPortal?: boolean;
51
+ style?: VictoryLabelStyleObject | VictoryLabelStyleObject[];
52
+ tabIndex?: NumberOrCallback;
53
+ text?: string[] | StringOrNumberOrCallback;
54
+ textComponent?: React.ReactElement;
55
+ textAnchor?: TextAnchorType | { (): TextAnchorType };
56
+ title?: string;
57
+ transform?: string | object | (() => string | object);
58
+ tspanComponent?: React.ReactElement;
59
+ verticalAnchor?: VerticalAnchorType | { (): VerticalAnchorType };
60
+ x?: number;
61
+ y?: number;
62
+ dx?: StringOrNumberOrCallback;
63
+ dy?: StringOrNumberOrCallback;
64
+ }
16
65
 
17
66
  const defaultStyles = {
18
67
  fill: "#252525",
@@ -48,7 +97,7 @@ const getFontSize = (style) => {
48
97
  return defaultStyles.fontSize;
49
98
  };
50
99
 
51
- const getSingleValue = (prop, index = 0) => {
100
+ const getSingleValue = <T,>(prop: T | T[], index = 0): T => {
52
101
  return Array.isArray(prop) ? prop[index] || prop[0] : prop;
53
102
  };
54
103
 
@@ -433,9 +482,9 @@ const evaluateProps = (props) => {
433
482
  });
434
483
  };
435
484
 
436
- const getCalculatedProps = (props) => {
485
+ const getCalculatedProps = <T extends VictoryLabelProps>(props: T) => {
437
486
  const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
438
- const style = getSingleValue(props.style);
487
+ const style = getSingleValue(props.style!);
439
488
  const lineHeight = getLineHeight(props);
440
489
  const direction = props.direction
441
490
  ? Helpers.evaluateProp(props.direction, props)
@@ -524,7 +573,10 @@ const renderLabel = (calculatedProps, tspanValues) => {
524
573
  return React.cloneElement(textComponent, textProps, tspans);
525
574
  };
526
575
 
527
- const VictoryLabel = (props) => {
576
+ export const VictoryLabel: {
577
+ role: string;
578
+ defaultStyles: typeof defaultStyles;
579
+ } & React.FC<VictoryLabelProps> = (props) => {
528
580
  props = evaluateProps(props);
529
581
 
530
582
  if (props.text === null || props.text === undefined) {
@@ -535,11 +587,11 @@ const VictoryLabel = (props) => {
535
587
  const { text, style, capHeight, backgroundPadding, lineHeight } =
536
588
  calculatedProps;
537
589
 
538
- const tspanValues = text.map((line, i) => {
539
- const currentStyle = getSingleValue(style, i);
590
+ const tspanValues = (text as string[]).map((line, i) => {
591
+ const currentStyle = getSingleValue(style!, i);
540
592
  const capHeightPx = TextSize.convertLengthToPixels(
541
593
  `${capHeight}em`,
542
- currentStyle.fontSize
594
+ currentStyle.fontSize as number
543
595
  );
544
596
  const currentLineHeight = getSingleValue(lineHeight, i);
545
597
  return {
@@ -547,6 +599,7 @@ const VictoryLabel = (props) => {
547
599
  fontSize: currentStyle.fontSize || defaultStyles.fontSize,
548
600
  capHeight: capHeightPx,
549
601
  text: line,
602
+ // @ts-expect-error TODO: This looks like a bug:
550
603
  textSize: TextSize.approximateTextSize(line, currentStyle),
551
604
  lineHeight: currentLineHeight,
552
605
  backgroundPadding: getSingleValue(backgroundPadding, i)
@@ -562,7 +615,7 @@ const VictoryLabel = (props) => {
562
615
  );
563
616
  const children = [backgroundElement, label];
564
617
  const backgroundWithLabel = React.cloneElement(
565
- props.groupComponent,
618
+ props.groupComponent!,
566
619
  {},
567
620
  children
568
621
  );
@@ -603,6 +656,7 @@ VictoryLabel.propTypes = {
603
656
  className: PropTypes.string,
604
657
  data: PropTypes.array,
605
658
  datum: PropTypes.any,
659
+ // @ts-expect-error "Function is not assignable to string"
606
660
  desc: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
607
661
  direction: PropTypes.oneOf(["rtl", "ltr", "inherit"]),
608
662
  dx: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.func]),
@@ -619,6 +673,7 @@ VictoryLabel.propTypes = {
619
673
  PropTypes.func,
620
674
  PropTypes.array
621
675
  ]),
676
+ // @ts-expect-error "x is required in origin"
622
677
  origin: PropTypes.shape({
623
678
  x: CustomPropTypes.nonNegative,
624
679
  y: CustomPropTypes.nonNegative
@@ -637,6 +692,7 @@ VictoryLabel.propTypes = {
637
692
  PropTypes.func,
638
693
  PropTypes.array
639
694
  ]),
695
+ // @ts-expect-error Function is not assignable to string"
640
696
  textAnchor: PropTypes.oneOfType([
641
697
  PropTypes.oneOf(["start", "middle", "end", "inherit"]),
642
698
  PropTypes.func
@@ -649,11 +705,14 @@ VictoryLabel.propTypes = {
649
705
  PropTypes.func
650
706
  ]),
651
707
  tspanComponent: PropTypes.element,
708
+ // @ts-expect-error Function is not assignable to string"
652
709
  verticalAnchor: PropTypes.oneOfType([
653
710
  PropTypes.oneOf(["start", "middle", "end"]),
654
711
  PropTypes.func
655
712
  ]),
713
+ // @ts-expect-error Number is not assignable to string
656
714
  x: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
715
+ // @ts-expect-error Number is not assignable to string
657
716
  y: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
658
717
  };
659
718
 
@@ -666,5 +725,3 @@ VictoryLabel.defaultProps = {
666
725
  capHeight: 0.71, // Magic number from d3.
667
726
  lineHeight: 1
668
727
  };
669
-
670
- export default VictoryLabel;
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+
3
+ export interface PortalContextValue {
4
+ portalRegister(): number;
5
+ portalUpdate(key: number, element: React.ReactElement): void;
6
+ portalDeregister(key: number): void;
7
+ }
8
+
9
+ /**
10
+ * The React context object consumers may use to access the context of the
11
+ * portal.
12
+ */
13
+ export const PortalContext = React.createContext({} as PortalContextValue);
14
+ PortalContext.displayName = "PortalContext";
@@ -2,8 +2,20 @@ import React from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import * as CustomPropTypes from "../victory-util/prop-types";
4
4
  import { keys } from "lodash";
5
+ import { PortalContextValue } from "./portal-context";
6
+
7
+ export interface PortalProps {
8
+ className?: string;
9
+ height?: number;
10
+ style?: React.CSSProperties;
11
+ viewBox?: string;
12
+ width?: number;
13
+ }
5
14
 
6
- export default class Portal extends React.Component {
15
+ export class Portal
16
+ extends React.Component<PortalProps>
17
+ implements PortalContextValue
18
+ {
7
19
  static displayName = "Portal";
8
20
 
9
21
  static propTypes = {
@@ -13,31 +25,30 @@ export default class Portal extends React.Component {
13
25
  viewBox: PropTypes.string,
14
26
  width: CustomPropTypes.nonNegative
15
27
  };
28
+ private readonly map: Record<string, React.ReactElement>;
29
+ private index: number;
16
30
 
17
- constructor(props) {
31
+ constructor(props: PortalProps) {
18
32
  super(props);
19
33
  this.map = {};
20
34
  this.index = 1;
21
- this.portalUpdate = this.portalUpdate.bind(this);
22
- this.portalRegister = this.portalRegister.bind(this);
23
- this.portalDeregister = this.portalDeregister.bind(this);
24
35
  }
25
36
 
26
- portalRegister() {
37
+ public portalRegister = (): number => {
27
38
  return ++this.index;
28
- }
39
+ };
29
40
 
30
- portalUpdate(key, element) {
41
+ public portalUpdate = (key: number, element: React.ReactElement) => {
31
42
  this.map[key] = element;
32
43
  this.forceUpdate();
33
- }
44
+ };
34
45
 
35
- portalDeregister(key) {
46
+ public portalDeregister = (key: number) => {
36
47
  delete this.map[key];
37
48
  this.forceUpdate();
38
- }
49
+ };
39
50
 
40
- getChildren() {
51
+ private getChildren() {
41
52
  return keys(this.map).map((key) => {
42
53
  const el = this.map[key];
43
54
  return el ? React.cloneElement(el, { key }) : el;
@@ -3,9 +3,18 @@ import PropTypes from "prop-types";
3
3
  import { defaults } from "lodash";
4
4
  import * as Log from "../victory-util/log";
5
5
  import * as Helpers from "../victory-util/helpers";
6
- import PortalContext from "./portal-context";
6
+ import { PortalContext } from "./portal-context";
7
7
 
8
- export default class VictoryPortal extends React.Component {
8
+ export interface VictoryPortalProps {
9
+ children?: React.ReactElement;
10
+ groupComponent?: React.ReactElement;
11
+ }
12
+
13
+ export interface VictoryPortal {
14
+ context: React.ContextType<typeof PortalContext>;
15
+ }
16
+
17
+ export class VictoryPortal extends React.Component<VictoryPortalProps> {
9
18
  static displayName = "VictoryPortal";
10
19
 
11
20
  static role = "portal";
@@ -20,6 +29,10 @@ export default class VictoryPortal extends React.Component {
20
29
  };
21
30
 
22
31
  static contextType = PortalContext;
32
+ private checkedContext!: boolean;
33
+ private renderInPlace!: boolean;
34
+ private element!: React.ReactElement;
35
+ private portalKey!: number;
23
36
 
24
37
  componentDidMount() {
25
38
  if (!this.checkedContext) {
@@ -49,7 +62,7 @@ export default class VictoryPortal extends React.Component {
49
62
  }
50
63
 
51
64
  // Overridden in victory-core-native
52
- renderPortal(child) {
65
+ renderPortal(child: React.ReactElement) {
53
66
  if (this.renderInPlace) {
54
67
  return child;
55
68
  }
@@ -58,9 +71,11 @@ export default class VictoryPortal extends React.Component {
58
71
  }
59
72
 
60
73
  render() {
61
- const children = Array.isArray(this.props.children)
62
- ? this.props.children[0]
63
- : this.props.children;
74
+ const children = (
75
+ Array.isArray(this.props.children)
76
+ ? this.props.children[0]
77
+ : this.props.children
78
+ ) as React.ReactElement;
64
79
  const { groupComponent } = this.props;
65
80
  const childProps = (children && children.props) || {};
66
81
  const standardProps = childProps.groupComponent
@@ -4,7 +4,19 @@ import PropTypes from "prop-types";
4
4
  import * as Helpers from "../victory-util/helpers";
5
5
  import { assign } from "lodash";
6
6
  import * as CommonProps from "../victory-util/common-props";
7
- import Path from "./path";
7
+ import { Path } from "./path";
8
+ import { VictoryCommonPrimitiveProps } from "../victory-util/types";
9
+
10
+ export interface ArcProps extends VictoryCommonPrimitiveProps {
11
+ closedPath?: boolean;
12
+ cx?: number;
13
+ cy?: number;
14
+ datum?: any;
15
+ endAngle?: number;
16
+ pathComponent?: React.ReactElement;
17
+ r?: number;
18
+ startAngle?: number;
19
+ }
8
20
 
9
21
  const getArcPath = (props) => {
10
22
  const { cx, cy, r, startAngle, endAngle, closedPath } = props;
@@ -48,10 +60,10 @@ const evaluateProps = (props) => {
48
60
  return assign({}, props, { ariaLabel, desc, id, style, tabIndex });
49
61
  };
50
62
 
51
- const Arc = (props) => {
63
+ export const Arc = (props: ArcProps) => {
52
64
  props = evaluateProps(props);
53
65
 
54
- return React.cloneElement(props.pathComponent, {
66
+ return React.cloneElement(props.pathComponent!, {
55
67
  ...props.events,
56
68
  "aria-label": props.ariaLabel,
57
69
  d: getArcPath(props),
@@ -83,5 +95,3 @@ Arc.defaultProps = {
83
95
  role: "presentation",
84
96
  shapeRendering: "auto"
85
97
  };
86
-
87
- export default Arc;
@@ -3,8 +3,20 @@ import PropTypes from "prop-types";
3
3
  import { assign } from "lodash";
4
4
  import * as Helpers from "../victory-util/helpers";
5
5
  import * as CommonProps from "../victory-util/common-props";
6
- import Rect from "./rect";
7
- import Circle from "./circle";
6
+ import { Rect } from "./rect";
7
+ import { Circle } from "./circle";
8
+ import { VictoryCommonPrimitiveProps } from "../victory-util/types";
9
+
10
+ export interface BackgroundProps extends VictoryCommonPrimitiveProps {
11
+ circleComponent?: React.ReactElement;
12
+ height?: number;
13
+ rectComponent?: React.ReactElement;
14
+ rx?: number;
15
+ ry?: number;
16
+ width?: number;
17
+ x?: number;
18
+ y?: number;
19
+ }
8
20
 
9
21
  const evaluateProps = (props) => {
10
22
  /**
@@ -16,11 +28,11 @@ const evaluateProps = (props) => {
16
28
  return assign({}, props, { id });
17
29
  };
18
30
 
19
- const Background = (props) => {
31
+ export const Background = (props: BackgroundProps) => {
20
32
  props = evaluateProps(props);
21
33
 
22
34
  return props.polar
23
- ? React.cloneElement(props.circleComponent, {
35
+ ? React.cloneElement(props.circleComponent!, {
24
36
  ...props.events,
25
37
  style: props.style,
26
38
  role: props.role,
@@ -30,7 +42,7 @@ const Background = (props) => {
30
42
  r: props.height,
31
43
  className: props.className
32
44
  })
33
- : React.cloneElement(props.rectComponent, {
45
+ : React.cloneElement(props.rectComponent!, {
34
46
  ...props.events,
35
47
  style: props.style,
36
48
  role: props.role,
@@ -63,5 +75,3 @@ Background.defaultProps = {
63
75
  role: "presentation",
64
76
  shapeRendering: "auto"
65
77
  };
66
-
67
- export default Background;
@@ -3,7 +3,16 @@ import PropTypes from "prop-types";
3
3
  import * as Helpers from "../victory-util/helpers";
4
4
  import { assign } from "lodash";
5
5
  import * as CommonProps from "../victory-util/common-props";
6
- import Rect from "./rect";
6
+ import { Rect } from "./rect";
7
+ import { VictoryCommonPrimitiveProps } from "../victory-util/types";
8
+
9
+ export interface BorderProps extends VictoryCommonPrimitiveProps {
10
+ width?: number;
11
+ height?: number;
12
+ rectComponent?: React.ReactElement;
13
+ x?: number;
14
+ y?: number;
15
+ }
7
16
 
8
17
  const evaluateProps = (props) => {
9
18
  /**
@@ -26,10 +35,10 @@ const evaluateProps = (props) => {
26
35
  return assign({}, props, { ariaLabel, desc, id, style, tabIndex });
27
36
  };
28
37
 
29
- const Border = (props) => {
38
+ export const Border = (props: BorderProps) => {
30
39
  props = evaluateProps(props);
31
40
 
32
- return React.cloneElement(props.rectComponent, {
41
+ return React.cloneElement(props.rectComponent!, {
33
42
  ...props.events,
34
43
  "aria-label": props.ariaLabel,
35
44
  style: props.style,
@@ -61,5 +70,3 @@ Border.defaultProps = {
61
70
  role: "presentation",
62
71
  shapeRendering: "auto"
63
72
  };
64
-
65
- export default Border;
@@ -1,15 +1,16 @@
1
1
  import React from "react";
2
+ import { VictoryPrimitiveShapeProps } from "./types";
2
3
 
3
- const Circle = (props) => {
4
+ export const Circle = (props: VictoryPrimitiveShapeProps) => {
4
5
  // eslint-disable-next-line react/prop-types
5
6
  const { desc, ...rest } = props;
6
7
  return desc ? (
8
+ // @ts-expect-error FIXME: "id cannot be a number"
7
9
  <circle vectorEffect="non-scaling-stroke" {...rest}>
8
10
  <desc>{desc}</desc>
9
11
  </circle>
10
12
  ) : (
13
+ // @ts-expect-error FIXME: "id cannot be a number"
11
14
  <circle vectorEffect="non-scaling-stroke" {...rest} />
12
15
  );
13
16
  };
14
-
15
- export default Circle;
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+ import { VictoryCommonPrimitiveProps } from "../victory-util/types";
4
+
5
+ export interface ClipPathProps extends VictoryCommonPrimitiveProps {
6
+ children?: React.ReactNode[] | React.ReactNode;
7
+ clipId?: number | string;
8
+ }
9
+
10
+ export const ClipPath = (props: ClipPathProps) => (
11
+ <defs>
12
+ {
13
+ // @ts-expect-error FIXME: "id cannot be a number"
14
+ <clipPath id={props.clipId}>{props.children}</clipPath>
15
+ }
16
+ </defs>
17
+ );
18
+
19
+ ClipPath.propTypes = {
20
+ children: PropTypes.oneOfType([
21
+ PropTypes.arrayOf(PropTypes.node),
22
+ PropTypes.node
23
+ ]),
24
+ clipId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
25
+ };
@@ -0,0 +1,14 @@
1
+ export * from "./arc";
2
+ export * from "./background";
3
+ export * from "./border";
4
+ export * from "./circle";
5
+ export * from "./clip-path";
6
+ export * from "./line";
7
+ export * from "./line-segment";
8
+ export * from "./path";
9
+ export * from "./point";
10
+ export * from "./rect";
11
+ export * from "./text";
12
+ export * from "./tspan";
13
+ export * from "./types";
14
+ export * from "./whisker";
@@ -3,7 +3,17 @@ import PropTypes from "prop-types";
3
3
  import * as Helpers from "../victory-util/helpers";
4
4
  import { assign } from "lodash";
5
5
  import * as CommonProps from "../victory-util/common-props";
6
- import Line from "./line";
6
+ import { Line } from "./line";
7
+ import { VictoryCommonPrimitiveProps } from "../victory-util/types";
8
+
9
+ export interface LineSegmentProps extends VictoryCommonPrimitiveProps {
10
+ datum?: any;
11
+ lineComponent?: React.ReactElement;
12
+ x1?: number;
13
+ x2?: number;
14
+ y1?: number;
15
+ y2?: number;
16
+ }
7
17
 
8
18
  const evaluateProps = (props) => {
9
19
  /**
@@ -26,10 +36,10 @@ const evaluateProps = (props) => {
26
36
  return assign({}, props, { ariaLabel, desc, id, style, tabIndex });
27
37
  };
28
38
 
29
- const LineSegment = (props) => {
39
+ export const LineSegment = (props: LineSegmentProps) => {
30
40
  props = evaluateProps(props);
31
41
 
32
- return React.cloneElement(props.lineComponent, {
42
+ return React.cloneElement(props.lineComponent!, {
33
43
  ...props.events,
34
44
  "aria-label": props.ariaLabel,
35
45
  style: props.style,
@@ -62,5 +72,3 @@ LineSegment.defaultProps = {
62
72
  role: "presentation",
63
73
  shapeRendering: "auto"
64
74
  };
65
-
66
- export default LineSegment;