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