victory-core 36.9.2 → 37.0.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 (110) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/victory-core.js +4371 -5749
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/victory-accessible-group/victory-accessible-group.js +9 -15
  5. package/es/victory-animation/util.js +28 -47
  6. package/es/victory-animation/victory-animation.js +51 -67
  7. package/es/victory-clip-container/victory-clip-container.js +153 -229
  8. package/es/victory-container/victory-container.js +157 -216
  9. package/es/victory-label/victory-label.js +246 -323
  10. package/es/victory-portal/portal-context.js +1 -2
  11. package/es/victory-portal/portal.js +30 -76
  12. package/es/victory-portal/victory-portal.js +47 -104
  13. package/es/victory-primitives/arc.js +44 -47
  14. package/es/victory-primitives/background.js +14 -17
  15. package/es/victory-primitives/border.js +20 -24
  16. package/es/victory-primitives/circle.js +13 -27
  17. package/es/victory-primitives/clip-path.js +3 -7
  18. package/es/victory-primitives/line-segment.js +20 -24
  19. package/es/victory-primitives/line.js +13 -27
  20. package/es/victory-primitives/path.js +13 -27
  21. package/es/victory-primitives/point.js +36 -40
  22. package/es/victory-primitives/rect.js +13 -27
  23. package/es/victory-primitives/text.js +15 -28
  24. package/es/victory-primitives/tspan.js +13 -26
  25. package/es/victory-primitives/whisker.js +43 -47
  26. package/es/victory-theme/grayscale.js +22 -22
  27. package/es/victory-theme/material.js +46 -46
  28. package/es/victory-theme/victory-theme.js +3 -3
  29. package/es/victory-transition/victory-transition.js +126 -206
  30. package/es/victory-util/add-events.js +263 -374
  31. package/es/victory-util/axis.js +126 -222
  32. package/es/victory-util/collection.js +13 -41
  33. package/es/victory-util/data.js +159 -214
  34. package/es/victory-util/default-transitions.js +33 -51
  35. package/es/victory-util/domain.js +122 -171
  36. package/es/victory-util/events.js +168 -258
  37. package/es/victory-util/helpers.js +153 -178
  38. package/es/victory-util/hooks/use-animation-state.js +61 -99
  39. package/es/victory-util/hooks/use-previous-props.js +2 -2
  40. package/es/victory-util/immutable.js +6 -8
  41. package/es/victory-util/label-helpers.js +128 -130
  42. package/es/victory-util/line-helpers.js +29 -41
  43. package/es/victory-util/log.js +1 -1
  44. package/es/victory-util/point-path-helpers.js +89 -49
  45. package/es/victory-util/scale.js +24 -42
  46. package/es/victory-util/selection.js +39 -40
  47. package/es/victory-util/style.js +8 -13
  48. package/es/victory-util/textsize.js +80 -154
  49. package/es/victory-util/timer-context.js +2 -2
  50. package/es/victory-util/timer.js +40 -76
  51. package/es/victory-util/transitions.js +110 -150
  52. package/es/victory-util/type-helpers.js +2 -3
  53. package/es/victory-util/user-props.js +24 -49
  54. package/es/victory-util/wrapper.js +184 -247
  55. package/lib/index.js +0 -30
  56. package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
  57. package/lib/victory-animation/util.js +28 -63
  58. package/lib/victory-animation/victory-animation.js +54 -83
  59. package/lib/victory-clip-container/victory-clip-container.js +156 -243
  60. package/lib/victory-container/victory-container.js +160 -232
  61. package/lib/victory-label/victory-label.js +248 -344
  62. package/lib/victory-portal/portal-context.js +1 -6
  63. package/lib/victory-portal/portal.js +31 -81
  64. package/lib/victory-portal/victory-portal.js +50 -116
  65. package/lib/victory-primitives/arc.js +48 -57
  66. package/lib/victory-primitives/background.js +16 -28
  67. package/lib/victory-primitives/border.js +22 -34
  68. package/lib/victory-primitives/circle.js +16 -36
  69. package/lib/victory-primitives/clip-path.js +3 -11
  70. package/lib/victory-primitives/index.js +0 -28
  71. package/lib/victory-primitives/line-segment.js +22 -34
  72. package/lib/victory-primitives/line.js +16 -36
  73. package/lib/victory-primitives/path.js +16 -36
  74. package/lib/victory-primitives/point.js +38 -52
  75. package/lib/victory-primitives/rect.js +16 -36
  76. package/lib/victory-primitives/text.js +15 -33
  77. package/lib/victory-primitives/tspan.js +13 -31
  78. package/lib/victory-primitives/whisker.js +45 -57
  79. package/lib/victory-theme/grayscale.js +23 -24
  80. package/lib/victory-theme/material.js +47 -48
  81. package/lib/victory-theme/victory-theme.js +2 -7
  82. package/lib/victory-transition/victory-transition.js +129 -224
  83. package/lib/victory-util/add-events.js +263 -380
  84. package/lib/victory-util/axis.js +128 -241
  85. package/lib/victory-util/collection.js +13 -50
  86. package/lib/victory-util/data.js +160 -239
  87. package/lib/victory-util/default-transitions.js +33 -54
  88. package/lib/victory-util/domain.js +123 -193
  89. package/lib/victory-util/events.js +167 -274
  90. package/lib/victory-util/helpers.js +156 -207
  91. package/lib/victory-util/hooks/index.js +0 -2
  92. package/lib/victory-util/hooks/use-animation-state.js +63 -113
  93. package/lib/victory-util/hooks/use-previous-props.js +2 -7
  94. package/lib/victory-util/immutable.js +6 -18
  95. package/lib/victory-util/index.js +2 -51
  96. package/lib/victory-util/label-helpers.js +130 -141
  97. package/lib/victory-util/line-helpers.js +31 -49
  98. package/lib/victory-util/log.js +1 -2
  99. package/lib/victory-util/point-path-helpers.js +91 -63
  100. package/lib/victory-util/scale.js +26 -57
  101. package/lib/victory-util/selection.js +41 -49
  102. package/lib/victory-util/style.js +8 -16
  103. package/lib/victory-util/textsize.js +80 -157
  104. package/lib/victory-util/timer-context.js +2 -8
  105. package/lib/victory-util/timer.js +40 -76
  106. package/lib/victory-util/transitions.js +110 -152
  107. package/lib/victory-util/type-helpers.js +2 -9
  108. package/lib/victory-util/user-props.js +25 -59
  109. package/lib/victory-util/wrapper.js +186 -281
  110. package/package.json +2 -2
@@ -1,24 +1,6 @@
1
1
  import _isEmpty from "lodash/isEmpty";
2
2
  import _defaults from "lodash/defaults";
3
-
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
-
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
-
8
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
-
10
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
-
12
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
-
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
-
16
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
-
18
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
-
20
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
21
-
3
+ /* eslint no-magic-numbers: ["error", { "ignore": [-0.5, 0.5, 0, 1, 2] }]*/
22
4
  import React from "react";
23
5
  import { VictoryPortal } from "../victory-portal/victory-portal";
24
6
  import { Rect } from "../victory-primitives/rect";
@@ -30,145 +12,111 @@ import * as Log from "../victory-util/log";
30
12
  import * as Style from "../victory-util/style";
31
13
  import * as TextSize from "../victory-util/textsize";
32
14
  import * as UserProps from "../victory-util/user-props";
33
- var defaultStyles = {
15
+ const defaultStyles = {
34
16
  fill: "#252525",
35
17
  fontSize: 14,
36
18
  fontFamily: "'Gill Sans', 'Gill Sans MT', 'Ser­avek', 'Trebuchet MS', sans-serif",
37
19
  stroke: "transparent"
38
20
  };
39
-
40
- var getPosition = function (props, dimension) {
21
+ const getPosition = (props, dimension) => {
41
22
  if (!props.datum) {
42
23
  return 0;
43
24
  }
44
-
45
- var scaledPoint = Helpers.scalePoint(props, props.datum);
25
+ const scaledPoint = Helpers.scalePoint(props, props.datum);
46
26
  return scaledPoint[dimension];
47
27
  };
48
-
49
- var getFontSize = function (style) {
50
- var baseSize = style && style.fontSize;
51
-
28
+ const getFontSize = style => {
29
+ const baseSize = style && style.fontSize;
52
30
  if (typeof baseSize === "number") {
53
31
  return baseSize;
54
32
  } else if (baseSize === undefined || baseSize === null) {
55
33
  return defaultStyles.fontSize;
56
34
  } else if (typeof baseSize === "string") {
57
- var fontSize = Number(baseSize.replace("px", ""));
58
-
35
+ const fontSize = Number(baseSize.replace("px", ""));
59
36
  if (!isNaN(fontSize)) {
60
37
  return fontSize;
61
38
  }
62
-
63
39
  Log.warn("fontSize should be expressed as a number of pixels");
64
40
  return defaultStyles.fontSize;
65
41
  }
66
-
67
42
  return defaultStyles.fontSize;
68
43
  };
69
-
70
- var getSingleValue = function (prop) {
71
- var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
44
+ const getSingleValue = function (prop, index) {
45
+ if (index === void 0) {
46
+ index = 0;
47
+ }
72
48
  return Array.isArray(prop) ? prop[index] || prop[0] : prop;
73
49
  };
74
-
75
- var shouldUseMultilineBackgrounds = function (props) {
76
- var backgroundStyle = props.backgroundStyle,
77
- backgroundPadding = props.backgroundPadding;
50
+ const shouldUseMultilineBackgrounds = props => {
51
+ const {
52
+ backgroundStyle,
53
+ backgroundPadding
54
+ } = props;
78
55
  return Array.isArray(backgroundStyle) && !_isEmpty(backgroundStyle) || Array.isArray(backgroundPadding) && !_isEmpty(backgroundPadding);
79
56
  };
80
-
81
- var getStyles = function (style, props) {
57
+ const getStyles = (style, props) => {
82
58
  if (props.disableInlineStyles) {
83
- var baseStyles = Helpers.evaluateStyle(style, props);
59
+ const baseStyles = Helpers.evaluateStyle(style, props);
84
60
  return {
85
61
  // Font size is necessary to calculate the y position of the label
86
62
  fontSize: getFontSize(baseStyles)
87
63
  };
88
64
  }
89
-
90
- var getSingleStyle = function (s) {
91
- var baseStyles = Helpers.evaluateStyle(s ? _defaults({}, s, defaultStyles) : defaultStyles, props);
65
+ const getSingleStyle = s => {
66
+ const baseStyles = Helpers.evaluateStyle(s ? _defaults({}, s, defaultStyles) : defaultStyles, props);
92
67
  return Object.assign({}, baseStyles, {
93
68
  fontSize: getFontSize(baseStyles)
94
69
  });
95
70
  };
96
-
97
- return Array.isArray(style) && !_isEmpty(style) ? style.map(function (s) {
98
- return getSingleStyle(s);
99
- }) : getSingleStyle(style);
71
+ return Array.isArray(style) && !_isEmpty(style) ? style.map(s => getSingleStyle(s)) : getSingleStyle(style);
100
72
  };
101
-
102
- var getBackgroundStyles = function (style, props) {
73
+ const getBackgroundStyles = (style, props) => {
103
74
  if (!style) {
104
75
  return undefined;
105
76
  }
106
-
107
- return Array.isArray(style) && !_isEmpty(style) ? style.map(function (s) {
108
- return Helpers.evaluateStyle(s, props);
109
- }) : Helpers.evaluateStyle(style, props);
77
+ return Array.isArray(style) && !_isEmpty(style) ? style.map(s => Helpers.evaluateStyle(s, props)) : Helpers.evaluateStyle(style, props);
110
78
  };
111
-
112
- var getBackgroundPadding = function (props) {
79
+ const getBackgroundPadding = props => {
113
80
  if (props.backgroundPadding && Array.isArray(props.backgroundPadding)) {
114
- return props.backgroundPadding.map(function (backgroundPadding) {
115
- var padding = Helpers.evaluateProp(backgroundPadding, props);
81
+ return props.backgroundPadding.map(backgroundPadding => {
82
+ const padding = Helpers.evaluateProp(backgroundPadding, props);
116
83
  return Helpers.getPadding({
117
- padding: padding
84
+ padding
118
85
  });
119
86
  });
120
87
  }
121
-
122
- var padding = Helpers.evaluateProp(props.backgroundPadding, props);
88
+ const padding = Helpers.evaluateProp(props.backgroundPadding, props);
123
89
  return Helpers.getPadding({
124
- padding: padding
90
+ padding
125
91
  });
126
92
  };
127
-
128
- var getLineHeight = function (props) {
129
- var lineHeight = Helpers.evaluateProp(props.lineHeight, props);
130
-
93
+ const getLineHeight = props => {
94
+ const lineHeight = Helpers.evaluateProp(props.lineHeight, props);
131
95
  if (Array.isArray(lineHeight)) {
132
96
  return _isEmpty(lineHeight) ? [1] : lineHeight;
133
97
  }
134
-
135
98
  return lineHeight;
136
99
  };
137
-
138
- var getContent = function (text, props) {
100
+ const getContent = (text, props) => {
139
101
  if (text === undefined || text === null) {
140
102
  return undefined;
141
103
  }
142
-
143
104
  if (Array.isArray(text)) {
144
- return text.map(function (line) {
145
- return Helpers.evaluateProp(line, props);
146
- });
105
+ return text.map(line => Helpers.evaluateProp(line, props));
147
106
  }
148
-
149
- var child = Helpers.evaluateProp(text, props);
150
-
107
+ const child = Helpers.evaluateProp(text, props);
151
108
  if (child === undefined || child === null) {
152
109
  return undefined;
153
110
  }
154
-
155
- return Array.isArray(child) ? child : "".concat(child).split("\n");
111
+ return Array.isArray(child) ? child : `${child}`.split("\n");
156
112
  };
157
-
158
- var getDy = function (props, verticalAnchor, lineHeight) {
159
- var dy = props.dy ? Helpers.evaluateProp(props.dy, props) : 0;
160
- var length = props.inline ? 1 : props.text.length;
161
- var capHeight = Helpers.evaluateProp(props.capHeight, props);
162
- var anchor = verticalAnchor ? Helpers.evaluateProp(verticalAnchor, props) : "middle";
163
-
164
- var fontSizes = _toConsumableArray(Array(length).keys()).map(function (i) {
165
- return getSingleValue(props.style, i).fontSize;
166
- });
167
-
168
- var lineHeights = _toConsumableArray(Array(length).keys()).map(function (i) {
169
- return getSingleValue(lineHeight, i);
170
- });
171
-
113
+ const getDy = (props, verticalAnchor, lineHeight) => {
114
+ const dy = props.dy ? Helpers.evaluateProp(props.dy, props) : 0;
115
+ const length = props.inline ? 1 : props.text.length;
116
+ const capHeight = Helpers.evaluateProp(props.capHeight, props);
117
+ const anchor = verticalAnchor ? Helpers.evaluateProp(verticalAnchor, props) : "middle";
118
+ const fontSizes = [...Array(length).keys()].map(i => getSingleValue(props.style, i).fontSize);
119
+ const lineHeights = [...Array(length).keys()].map(i => getSingleValue(lineHeight, i));
172
120
  if (anchor === "start") {
173
121
  return dy + (capHeight / 2 + lineHeights[0] / 2) * fontSizes[0];
174
122
  } else if (props.inline) {
@@ -176,314 +124,289 @@ var getDy = function (props, verticalAnchor, lineHeight) {
176
124
  } else if (length === 1) {
177
125
  return anchor === "end" ? dy + (capHeight / 2 + (0.5 - length) * lineHeights[0]) * fontSizes[0] : dy + (capHeight / 2 + (0.5 - length / 2) * lineHeights[0]) * fontSizes[0];
178
126
  }
179
-
180
- var allHeights = _toConsumableArray(Array(length).keys()).reduce(function (memo, i) {
127
+ const allHeights = [...Array(length).keys()].reduce((memo, i) => {
181
128
  return memo + (capHeight / 2 + (0.5 - length) * lineHeights[i]) * fontSizes[i] / length;
182
129
  }, 0);
183
-
184
130
  return anchor === "end" ? dy + allHeights : dy + allHeights / 2 + capHeight / 2 * lineHeights[length - 1] * fontSizes[length - 1];
185
131
  };
186
-
187
- var getTransform = function (props, x, y) {
188
- var polar = props.polar;
189
- var style = getSingleValue(props.style);
190
- var defaultAngle = polar ? LabelHelpers.getPolarAngle(props) : 0;
191
- var baseAngle = style.angle === undefined ? Helpers.evaluateProp(props.angle, props) : style.angle;
192
- var angle = baseAngle === undefined ? defaultAngle : baseAngle;
193
- var transform = props.transform || style.transform;
194
- var transformPart = transform && Helpers.evaluateProp(transform, props);
195
- var rotatePart = angle && {
132
+ const getTransform = (props, x, y) => {
133
+ const {
134
+ polar
135
+ } = props;
136
+ const style = getSingleValue(props.style);
137
+ const defaultAngle = polar ? LabelHelpers.getPolarAngle(props) : 0;
138
+ const baseAngle = style.angle === undefined ? Helpers.evaluateProp(props.angle, props) : style.angle;
139
+ const angle = baseAngle === undefined ? defaultAngle : baseAngle;
140
+ const transform = props.transform || style.transform;
141
+ const transformPart = transform && Helpers.evaluateProp(transform, props);
142
+ const rotatePart = angle && {
196
143
  rotate: [angle, x, y]
197
144
  };
198
145
  return transformPart || angle ? Style.toTransformString(transformPart, rotatePart) : undefined;
199
146
  };
200
-
201
- var getXCoordinate = function (calculatedProps, labelSizeWidth) {
202
- var direction = calculatedProps.direction,
203
- textAnchor = calculatedProps.textAnchor,
204
- x = calculatedProps.x,
205
- dx = calculatedProps.dx;
206
-
147
+ const getXCoordinate = (calculatedProps, labelSizeWidth) => {
148
+ const {
149
+ direction,
150
+ textAnchor,
151
+ x,
152
+ dx
153
+ } = calculatedProps;
207
154
  if (direction === "rtl") {
208
155
  return x - labelSizeWidth;
209
156
  }
210
-
211
157
  switch (textAnchor) {
212
158
  case "middle":
213
159
  return Math.round(x - labelSizeWidth / 2);
214
-
215
160
  case "end":
216
161
  return Math.round(x - labelSizeWidth);
217
-
218
162
  default:
219
163
  // start
220
164
  return x + (dx || 0);
221
165
  }
222
166
  };
223
-
224
- var getYCoordinate = function (calculatedProps, textHeight) {
225
- var verticalAnchor = calculatedProps.verticalAnchor,
226
- y = calculatedProps.y,
227
- _calculatedProps$orig = calculatedProps.originalDy,
228
- originalDy = _calculatedProps$orig === void 0 ? 0 : _calculatedProps$orig;
229
- var offset = y + originalDy;
230
-
167
+ const getYCoordinate = (calculatedProps, textHeight) => {
168
+ const {
169
+ verticalAnchor,
170
+ y,
171
+ originalDy = 0
172
+ } = calculatedProps;
173
+ const offset = y + originalDy;
231
174
  switch (verticalAnchor) {
232
175
  case "start":
233
176
  return Math.floor(offset);
234
-
235
177
  case "end":
236
178
  return Math.ceil(offset - textHeight);
237
-
238
179
  default:
239
180
  // middle
240
181
  return Math.floor(offset - textHeight / 2);
241
182
  }
242
183
  };
243
-
244
- var getFullBackground = function (calculatedProps, tspanValues) {
245
- var _calculatedProps$dx = calculatedProps.dx,
246
- dx = _calculatedProps$dx === void 0 ? 0 : _calculatedProps$dx,
247
- transform = calculatedProps.transform,
248
- backgroundComponent = calculatedProps.backgroundComponent,
249
- backgroundStyle = calculatedProps.backgroundStyle,
250
- inline = calculatedProps.inline,
251
- backgroundPadding = calculatedProps.backgroundPadding,
252
- capHeight = calculatedProps.capHeight;
253
- var textSizes = tspanValues.map(function (tspan) {
184
+ const getFullBackground = (calculatedProps, tspanValues) => {
185
+ const {
186
+ dx = 0,
187
+ transform,
188
+ backgroundComponent,
189
+ backgroundStyle,
190
+ inline,
191
+ backgroundPadding,
192
+ capHeight
193
+ } = calculatedProps;
194
+ const textSizes = tspanValues.map(tspan => {
254
195
  return tspan.textSize;
255
196
  });
256
- var height = inline ? Math.max.apply(Math, _toConsumableArray(textSizes.map(function (size) {
257
- return size.height;
258
- }))) : textSizes.reduce(function (memo, size, i) {
259
- var capHeightAdjustment = i ? 0 : capHeight / 2;
197
+ const height = inline ? Math.max(...textSizes.map(size => size.height)) : textSizes.reduce((memo, size, i) => {
198
+ const capHeightAdjustment = i ? 0 : capHeight / 2;
260
199
  return memo + size.height * (tspanValues[i].lineHeight - capHeightAdjustment);
261
200
  }, 0);
262
- var width = inline ? textSizes.reduce(function (memo, size, index) {
263
- var offset = index ? dx : 0;
201
+ const width = inline ? textSizes.reduce((memo, size, index) => {
202
+ const offset = index ? dx : 0;
264
203
  return memo + size.width + offset;
265
- }, 0) : Math.max.apply(Math, _toConsumableArray(textSizes.map(function (size) {
266
- return size.width;
267
- })));
268
- var xCoordinate = getXCoordinate(calculatedProps, width);
269
- var yCoordinate = getYCoordinate(calculatedProps, height);
270
- var backgroundProps = {
204
+ }, 0) : Math.max(...textSizes.map(size => size.width));
205
+ const xCoordinate = getXCoordinate(calculatedProps, width);
206
+ const yCoordinate = getYCoordinate(calculatedProps, height);
207
+ const backgroundProps = {
271
208
  key: "background",
272
209
  height: height + backgroundPadding.top + backgroundPadding.bottom,
273
210
  style: backgroundStyle,
274
- transform: transform,
211
+ transform,
275
212
  width: width + backgroundPadding.left + backgroundPadding.right,
276
213
  x: inline ? xCoordinate - backgroundPadding.left : xCoordinate + dx - backgroundPadding.left,
277
214
  y: yCoordinate
278
215
  };
279
216
  return /*#__PURE__*/React.cloneElement(backgroundComponent, _defaults({}, backgroundComponent.props, backgroundProps));
280
217
  };
281
-
282
- var getInlineXOffset = function (calculatedProps, textElements, index) {
283
- var textAnchor = calculatedProps.textAnchor;
284
- var widths = textElements.map(function (t) {
285
- return t.widthWithPadding;
286
- });
287
- var totalWidth = widths.reduce(function (memo, width) {
288
- return memo + width;
289
- }, 0);
290
- var centerOffset = -totalWidth / 2;
291
-
218
+ const getInlineXOffset = (calculatedProps, textElements, index) => {
219
+ const {
220
+ textAnchor
221
+ } = calculatedProps;
222
+ const widths = textElements.map(t => t.widthWithPadding);
223
+ const totalWidth = widths.reduce((memo, width) => memo + width, 0);
224
+ const centerOffset = -totalWidth / 2;
292
225
  switch (textAnchor) {
293
226
  case "start":
294
- return widths.reduce(function (memo, width, i) {
295
- return i < index ? memo + width : memo;
296
- }, 0);
297
-
227
+ return widths.reduce((memo, width, i) => i < index ? memo + width : memo, 0);
298
228
  case "end":
299
- return widths.reduce(function (memo, width, i) {
300
- return i > index ? memo - width : memo;
301
- }, 0);
302
-
229
+ return widths.reduce((memo, width, i) => i > index ? memo - width : memo, 0);
303
230
  default:
304
231
  // middle
305
- return widths.reduce(function (memo, width, i) {
306
- var offsetWidth = i < index ? width : 0;
232
+ return widths.reduce((memo, width, i) => {
233
+ const offsetWidth = i < index ? width : 0;
307
234
  return i === index ? memo + width / 2 : memo + offsetWidth;
308
235
  }, centerOffset);
309
236
  }
310
237
  };
311
-
312
- var getChildBackgrounds = function (calculatedProps, tspanValues) {
313
- var dy = calculatedProps.dy,
314
- dx = calculatedProps.dx,
315
- transform = calculatedProps.transform,
316
- backgroundStyle = calculatedProps.backgroundStyle,
317
- backgroundPadding = calculatedProps.backgroundPadding,
318
- backgroundComponent = calculatedProps.backgroundComponent,
319
- inline = calculatedProps.inline,
320
- y = calculatedProps.y;
321
- var textElements = tspanValues.map(function (current, i) {
322
- var previous = getSingleValue(tspanValues, i - 1);
323
- var labelSize = current.textSize;
324
- var totalLineHeight = current.fontSize * current.lineHeight;
325
- var textHeight = Math.ceil(totalLineHeight);
326
- var padding = getSingleValue(backgroundPadding, i);
327
- var prevPadding = getSingleValue(backgroundPadding, i - 1);
328
- var xOffset = inline ? dx || 0 : 0;
329
- var childDy = i && !inline ? previous.fontSize * previous.lineHeight + prevPadding.top + prevPadding.bottom : dy - totalLineHeight * 0.5 - (current.fontSize - current.capHeight);
238
+ const getChildBackgrounds = (calculatedProps, tspanValues) => {
239
+ const {
240
+ dy,
241
+ dx,
242
+ transform,
243
+ backgroundStyle,
244
+ backgroundPadding,
245
+ backgroundComponent,
246
+ inline,
247
+ y
248
+ } = calculatedProps;
249
+ const textElements = tspanValues.map((current, i) => {
250
+ const previous = getSingleValue(tspanValues, i - 1);
251
+ const labelSize = current.textSize;
252
+ const totalLineHeight = current.fontSize * current.lineHeight;
253
+ const textHeight = Math.ceil(totalLineHeight);
254
+ const padding = getSingleValue(backgroundPadding, i);
255
+ const prevPadding = getSingleValue(backgroundPadding, i - 1);
256
+ const xOffset = inline ? dx || 0 : 0;
257
+ const childDy = i && !inline ? previous.fontSize * previous.lineHeight + prevPadding.top + prevPadding.bottom : dy - totalLineHeight * 0.5 - (current.fontSize - current.capHeight);
330
258
  return {
331
- textHeight: textHeight,
332
- labelSize: labelSize,
259
+ textHeight,
260
+ labelSize,
333
261
  heightWithPadding: textHeight + padding.top + padding.bottom,
334
262
  widthWithPadding: labelSize.width + padding.left + padding.right + xOffset,
335
- y: y,
263
+ y,
336
264
  fontSize: current.fontSize,
337
265
  dy: childDy
338
266
  };
339
267
  });
340
- return textElements.map(function (textElement, i) {
341
- var xCoordinate = getXCoordinate(calculatedProps, textElement.labelSize.width);
342
- var yCoordinate = textElements.slice(0, i + 1).reduce(function (prev, curr) {
268
+ return textElements.map((textElement, i) => {
269
+ const xCoordinate = getXCoordinate(calculatedProps, textElement.labelSize.width);
270
+ const yCoordinate = textElements.slice(0, i + 1).reduce((prev, curr) => {
343
271
  return prev + curr.dy;
344
272
  }, y);
345
- var padding = getSingleValue(backgroundPadding, i);
346
- var height = textElement.heightWithPadding;
347
- var xCoord = inline ? getInlineXOffset(calculatedProps, textElements, i) + xCoordinate - padding.left : xCoordinate;
348
- var yCoord = inline ? getYCoordinate(calculatedProps, height) - padding.top : yCoordinate;
349
- var backgroundProps = {
350
- key: "tspan-background-".concat(i),
351
- height: height,
273
+ const padding = getSingleValue(backgroundPadding, i);
274
+ const height = textElement.heightWithPadding;
275
+ const xCoord = inline ? getInlineXOffset(calculatedProps, textElements, i) + xCoordinate - padding.left : xCoordinate;
276
+ const yCoord = inline ? getYCoordinate(calculatedProps, height) - padding.top : yCoordinate;
277
+ const backgroundProps = {
278
+ key: `tspan-background-${i}`,
279
+ height,
352
280
  style: getSingleValue(backgroundStyle, i),
353
281
  width: textElement.widthWithPadding,
354
- transform: transform,
282
+ transform,
355
283
  x: xCoord - padding.left,
356
284
  y: yCoord
357
285
  };
358
286
  return /*#__PURE__*/React.cloneElement(backgroundComponent, _defaults({}, backgroundComponent.props, backgroundProps));
359
287
  });
360
288
  };
361
-
362
- var getBackgroundElement = function (calculatedProps, tspanValues) {
289
+ const getBackgroundElement = (calculatedProps, tspanValues) => {
363
290
  return shouldUseMultilineBackgrounds(calculatedProps) ? getChildBackgrounds(calculatedProps, tspanValues) : getFullBackground(calculatedProps, tspanValues);
364
291
  };
365
-
366
- var calculateSpanDy = function (tspanValues, i, calculatedProps) {
367
- var current = getSingleValue(tspanValues, i);
368
- var previous = getSingleValue(tspanValues, i - 1);
369
- var previousHeight = previous.fontSize * previous.lineHeight;
370
- var currentHeight = current.fontSize * current.lineHeight;
371
- var previousCaps = previous.fontSize - previous.capHeight;
372
- var currentCaps = current.fontSize - current.capHeight;
373
- var textHeight = previousHeight - previous.fontSize / 2 + current.fontSize / 2 - previousHeight / 2 + currentHeight / 2 - currentCaps / 2 + previousCaps / 2;
292
+ const calculateSpanDy = (tspanValues, i, calculatedProps) => {
293
+ const current = getSingleValue(tspanValues, i);
294
+ const previous = getSingleValue(tspanValues, i - 1);
295
+ const previousHeight = previous.fontSize * previous.lineHeight;
296
+ const currentHeight = current.fontSize * current.lineHeight;
297
+ const previousCaps = previous.fontSize - previous.capHeight;
298
+ const currentCaps = current.fontSize - current.capHeight;
299
+ const textHeight = previousHeight - previous.fontSize / 2 + current.fontSize / 2 - previousHeight / 2 + currentHeight / 2 - currentCaps / 2 + previousCaps / 2;
374
300
  return shouldUseMultilineBackgrounds(calculatedProps) ? textHeight + current.backgroundPadding.top + previous.backgroundPadding.bottom : textHeight;
375
301
  };
376
-
377
- var getTSpanDy = function (tspanValues, calculatedProps, i) {
378
- var inline = calculatedProps.inline;
379
- var current = getSingleValue(tspanValues, i);
380
-
302
+ const getTSpanDy = (tspanValues, calculatedProps, i) => {
303
+ const {
304
+ inline
305
+ } = calculatedProps;
306
+ const current = getSingleValue(tspanValues, i);
381
307
  if (i && !inline) {
382
308
  return calculateSpanDy(tspanValues, i, calculatedProps);
383
309
  } else if (inline) {
384
310
  return i === 0 ? current.backgroundPadding.top : undefined;
385
311
  }
386
-
387
312
  return current.backgroundPadding.top;
388
313
  };
389
-
390
- var evaluateProps = function (props) {
314
+ const evaluateProps = props => {
391
315
  /* Potential evaluated props are
392
316
  1) text
393
317
  2) style
394
318
  3) everything else
395
319
  */
396
- var text = getContent(props.text, props);
397
- var style = getStyles(props.style, Object.assign({}, props, {
398
- text: text
320
+ const text = getContent(props.text, props);
321
+ const style = getStyles(props.style, Object.assign({}, props, {
322
+ text
399
323
  }));
400
- var backgroundStyle = getBackgroundStyles(props.backgroundStyle, Object.assign({}, props, {
401
- text: text,
402
- style: style
324
+ const backgroundStyle = getBackgroundStyles(props.backgroundStyle, Object.assign({}, props, {
325
+ text,
326
+ style
403
327
  }));
404
- var backgroundPadding = getBackgroundPadding(Object.assign({}, props, {
405
- text: text,
406
- style: style,
407
- backgroundStyle: backgroundStyle
328
+ const backgroundPadding = getBackgroundPadding(Object.assign({}, props, {
329
+ text,
330
+ style,
331
+ backgroundStyle
408
332
  }));
409
- var id = Helpers.evaluateProp(props.id, props);
333
+ const id = Helpers.evaluateProp(props.id, props);
410
334
  return Object.assign({}, props, {
411
- backgroundStyle: backgroundStyle,
412
- backgroundPadding: backgroundPadding,
413
- style: style,
414
- text: text,
415
- id: id
335
+ backgroundStyle,
336
+ backgroundPadding,
337
+ style,
338
+ text,
339
+ id
416
340
  });
417
341
  };
418
-
419
- var getCalculatedProps = function (props) {
420
- var ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
421
- var style = getSingleValue(props.style);
422
- var lineHeight = getLineHeight(props);
423
- var direction = props.direction ? Helpers.evaluateProp(props.direction, props) : "inherit";
424
- var textAnchor = props.textAnchor ? Helpers.evaluateProp(props.textAnchor, props) : style.textAnchor || "start";
425
- var verticalAnchor = props.verticalAnchor ? Helpers.evaluateProp(props.verticalAnchor, props) : style.verticalAnchor || "middle";
426
- var dx = props.dx ? Helpers.evaluateProp(props.dx, props) : 0;
427
- var dy = getDy(props, verticalAnchor, lineHeight);
428
- var x = props.x !== undefined ? props.x : getPosition(props, "x");
429
- var y = props.y !== undefined ? props.y : getPosition(props, "y");
430
- var transform = getTransform(props, x, y);
342
+ const getCalculatedProps = props => {
343
+ const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
344
+ const style = getSingleValue(props.style);
345
+ const lineHeight = getLineHeight(props);
346
+ const direction = props.direction ? Helpers.evaluateProp(props.direction, props) : "inherit";
347
+ const textAnchor = props.textAnchor ? Helpers.evaluateProp(props.textAnchor, props) : style.textAnchor || "start";
348
+ const verticalAnchor = props.verticalAnchor ? Helpers.evaluateProp(props.verticalAnchor, props) : style.verticalAnchor || "middle";
349
+ const dx = props.dx ? Helpers.evaluateProp(props.dx, props) : 0;
350
+ const dy = getDy(props, verticalAnchor, lineHeight);
351
+ const x = props.x !== undefined ? props.x : getPosition(props, "x");
352
+ const y = props.y !== undefined ? props.y : getPosition(props, "y");
353
+ const transform = getTransform(props, x, y);
431
354
  return Object.assign({}, props, {
432
- ariaLabel: ariaLabel,
433
- lineHeight: lineHeight,
434
- direction: direction,
435
- textAnchor: textAnchor,
436
- verticalAnchor: verticalAnchor,
437
- dx: dx,
438
- dy: dy,
355
+ ariaLabel,
356
+ lineHeight,
357
+ direction,
358
+ textAnchor,
359
+ verticalAnchor,
360
+ dx,
361
+ dy,
439
362
  originalDy: Helpers.evaluateProp(props.dy, props),
440
- transform: transform,
441
- x: x,
442
- y: y
363
+ transform,
364
+ x,
365
+ y
443
366
  });
444
367
  };
445
-
446
- var renderLabel = function (calculatedProps, tspanValues) {
447
- var ariaLabel = calculatedProps.ariaLabel,
448
- inline = calculatedProps.inline,
449
- className = calculatedProps.className,
450
- title = calculatedProps.title,
451
- events = calculatedProps.events,
452
- direction = calculatedProps.direction,
453
- text = calculatedProps.text,
454
- textAnchor = calculatedProps.textAnchor,
455
- dx = calculatedProps.dx,
456
- dy = calculatedProps.dy,
457
- transform = calculatedProps.transform,
458
- x = calculatedProps.x,
459
- y = calculatedProps.y,
460
- desc = calculatedProps.desc,
461
- id = calculatedProps.id,
462
- tabIndex = calculatedProps.tabIndex,
463
- tspanComponent = calculatedProps.tspanComponent,
464
- textComponent = calculatedProps.textComponent;
465
- var userProps = UserProps.getSafeUserProps(calculatedProps);
466
-
467
- var textProps = _objectSpread(_objectSpread({
368
+ const renderLabel = (calculatedProps, tspanValues) => {
369
+ const {
370
+ ariaLabel,
371
+ inline,
372
+ className,
373
+ title,
374
+ events,
375
+ direction,
376
+ text,
377
+ textAnchor,
378
+ dx,
379
+ dy,
380
+ transform,
381
+ x,
382
+ y,
383
+ desc,
384
+ id,
385
+ tabIndex,
386
+ tspanComponent,
387
+ textComponent
388
+ } = calculatedProps;
389
+ const userProps = UserProps.getSafeUserProps(calculatedProps);
390
+ const textProps = {
468
391
  "aria-label": ariaLabel,
469
- key: "text"
470
- }, events), {}, {
471
- direction: direction,
472
- dx: dx,
473
- x: x,
392
+ key: "text",
393
+ ...events,
394
+ direction,
395
+ dx,
396
+ x,
474
397
  y: y + dy,
475
- transform: transform,
476
- className: className,
477
- title: title,
398
+ transform,
399
+ className,
400
+ title,
478
401
  desc: Helpers.evaluateProp(desc, calculatedProps),
479
402
  tabIndex: Helpers.evaluateProp(tabIndex, calculatedProps),
480
- id: id
481
- }, userProps);
482
-
483
- var tspans = text.map(function (line, i) {
484
- var currentStyle = tspanValues[i].style;
485
- var tspanProps = {
486
- key: "".concat(id, "-key-").concat(i),
403
+ id,
404
+ ...userProps
405
+ };
406
+ const tspans = text.map((line, i) => {
407
+ const currentStyle = tspanValues[i].style;
408
+ const tspanProps = {
409
+ key: `${id}-key-${i}`,
487
410
  x: !inline ? x : undefined,
488
411
  dx: inline ? dx + tspanValues[i].backgroundPadding.left : dx,
489
412
  dy: getTSpanDy(tspanValues, calculatedProps, i),
@@ -495,8 +418,7 @@ var renderLabel = function (calculatedProps, tspanValues) {
495
418
  });
496
419
  return /*#__PURE__*/React.cloneElement(textComponent, textProps, tspans);
497
420
  };
498
-
499
- var defaultProps = {
421
+ const defaultProps = {
500
422
  backgroundComponent: /*#__PURE__*/React.createElement(Rect, null),
501
423
  groupComponent: /*#__PURE__*/React.createElement("g", null),
502
424
  direction: "inherit",
@@ -506,23 +428,26 @@ var defaultProps = {
506
428
  // Magic number from d3.
507
429
  lineHeight: 1
508
430
  };
509
- export var VictoryLabel = function (initialProps) {
510
- var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps));
511
-
431
+ export const VictoryLabel = initialProps => {
432
+ const props = evaluateProps({
433
+ ...defaultProps,
434
+ ...initialProps
435
+ });
512
436
  if (props.text === null || props.text === undefined) {
513
437
  return null;
514
438
  }
515
-
516
- var calculatedProps = getCalculatedProps(props);
517
- var text = calculatedProps.text,
518
- style = calculatedProps.style,
519
- capHeight = calculatedProps.capHeight,
520
- backgroundPadding = calculatedProps.backgroundPadding,
521
- lineHeight = calculatedProps.lineHeight;
522
- var tspanValues = text.map(function (line, i) {
523
- var currentStyle = getSingleValue(style, i);
524
- var capHeightPx = TextSize.convertLengthToPixels("".concat(capHeight, "em"), currentStyle.fontSize);
525
- var currentLineHeight = getSingleValue(lineHeight, i);
439
+ const calculatedProps = getCalculatedProps(props);
440
+ const {
441
+ text,
442
+ style,
443
+ capHeight,
444
+ backgroundPadding,
445
+ lineHeight
446
+ } = calculatedProps;
447
+ const tspanValues = text.map((line, i) => {
448
+ const currentStyle = getSingleValue(style, i);
449
+ const capHeightPx = TextSize.convertLengthToPixels(`${capHeight}em`, currentStyle.fontSize);
450
+ const currentLineHeight = getSingleValue(lineHeight, i);
526
451
  return {
527
452
  style: currentStyle,
528
453
  fontSize: currentStyle.fontSize || defaultStyles.fontSize,
@@ -534,15 +459,13 @@ export var VictoryLabel = function (initialProps) {
534
459
  backgroundPadding: getSingleValue(backgroundPadding, i)
535
460
  };
536
461
  });
537
- var label = renderLabel(calculatedProps, tspanValues);
538
-
462
+ const label = renderLabel(calculatedProps, tspanValues);
539
463
  if (props.backgroundStyle) {
540
- var backgroundElement = getBackgroundElement(calculatedProps, tspanValues);
541
- var children = [backgroundElement, label];
542
- var backgroundWithLabel = /*#__PURE__*/React.cloneElement(props.groupComponent, {}, children);
464
+ const backgroundElement = getBackgroundElement(calculatedProps, tspanValues);
465
+ const children = [backgroundElement, label];
466
+ const backgroundWithLabel = /*#__PURE__*/React.cloneElement(props.groupComponent, {}, children);
543
467
  return props.renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null, backgroundWithLabel) : backgroundWithLabel;
544
468
  }
545
-
546
469
  return props.renderInPortal ? /*#__PURE__*/React.createElement(VictoryPortal, null, label) : label;
547
470
  };
548
471
  VictoryLabel.displayName = "VictoryLabel";