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.
- package/CHANGELOG.md +6 -0
- package/dist/victory-core.js +4371 -5749
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.js +9 -15
- package/es/victory-animation/util.js +28 -47
- package/es/victory-animation/victory-animation.js +51 -67
- package/es/victory-clip-container/victory-clip-container.js +153 -229
- package/es/victory-container/victory-container.js +157 -216
- package/es/victory-label/victory-label.js +246 -323
- package/es/victory-portal/portal-context.js +1 -2
- package/es/victory-portal/portal.js +30 -76
- package/es/victory-portal/victory-portal.js +47 -104
- package/es/victory-primitives/arc.js +44 -47
- package/es/victory-primitives/background.js +14 -17
- package/es/victory-primitives/border.js +20 -24
- package/es/victory-primitives/circle.js +13 -27
- package/es/victory-primitives/clip-path.js +3 -7
- package/es/victory-primitives/line-segment.js +20 -24
- package/es/victory-primitives/line.js +13 -27
- package/es/victory-primitives/path.js +13 -27
- package/es/victory-primitives/point.js +36 -40
- package/es/victory-primitives/rect.js +13 -27
- package/es/victory-primitives/text.js +15 -28
- package/es/victory-primitives/tspan.js +13 -26
- package/es/victory-primitives/whisker.js +43 -47
- package/es/victory-theme/grayscale.js +22 -22
- package/es/victory-theme/material.js +46 -46
- package/es/victory-theme/victory-theme.js +3 -3
- package/es/victory-transition/victory-transition.js +126 -206
- package/es/victory-util/add-events.js +263 -374
- package/es/victory-util/axis.js +126 -222
- package/es/victory-util/collection.js +13 -41
- package/es/victory-util/data.js +159 -214
- package/es/victory-util/default-transitions.js +33 -51
- package/es/victory-util/domain.js +122 -171
- package/es/victory-util/events.js +168 -258
- package/es/victory-util/helpers.js +153 -178
- package/es/victory-util/hooks/use-animation-state.js +61 -99
- package/es/victory-util/hooks/use-previous-props.js +2 -2
- package/es/victory-util/immutable.js +6 -8
- package/es/victory-util/label-helpers.js +128 -130
- package/es/victory-util/line-helpers.js +29 -41
- package/es/victory-util/log.js +1 -1
- package/es/victory-util/point-path-helpers.js +89 -49
- package/es/victory-util/scale.js +24 -42
- package/es/victory-util/selection.js +39 -40
- package/es/victory-util/style.js +8 -13
- package/es/victory-util/textsize.js +80 -154
- package/es/victory-util/timer-context.js +2 -2
- package/es/victory-util/timer.js +40 -76
- package/es/victory-util/transitions.js +110 -150
- package/es/victory-util/type-helpers.js +2 -3
- package/es/victory-util/user-props.js +24 -49
- package/es/victory-util/wrapper.js +184 -247
- package/lib/index.js +0 -30
- package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
- package/lib/victory-animation/util.js +28 -63
- package/lib/victory-animation/victory-animation.js +54 -83
- package/lib/victory-clip-container/victory-clip-container.js +156 -243
- package/lib/victory-container/victory-container.js +160 -232
- package/lib/victory-label/victory-label.js +248 -344
- package/lib/victory-portal/portal-context.js +1 -6
- package/lib/victory-portal/portal.js +31 -81
- package/lib/victory-portal/victory-portal.js +50 -116
- package/lib/victory-primitives/arc.js +48 -57
- package/lib/victory-primitives/background.js +16 -28
- package/lib/victory-primitives/border.js +22 -34
- package/lib/victory-primitives/circle.js +16 -36
- package/lib/victory-primitives/clip-path.js +3 -11
- package/lib/victory-primitives/index.js +0 -28
- package/lib/victory-primitives/line-segment.js +22 -34
- package/lib/victory-primitives/line.js +16 -36
- package/lib/victory-primitives/path.js +16 -36
- package/lib/victory-primitives/point.js +38 -52
- package/lib/victory-primitives/rect.js +16 -36
- package/lib/victory-primitives/text.js +15 -33
- package/lib/victory-primitives/tspan.js +13 -31
- package/lib/victory-primitives/whisker.js +45 -57
- package/lib/victory-theme/grayscale.js +23 -24
- package/lib/victory-theme/material.js +47 -48
- package/lib/victory-theme/victory-theme.js +2 -7
- package/lib/victory-transition/victory-transition.js +129 -224
- package/lib/victory-util/add-events.js +263 -380
- package/lib/victory-util/axis.js +128 -241
- package/lib/victory-util/collection.js +13 -50
- package/lib/victory-util/data.js +160 -239
- package/lib/victory-util/default-transitions.js +33 -54
- package/lib/victory-util/domain.js +123 -193
- package/lib/victory-util/events.js +167 -274
- package/lib/victory-util/helpers.js +156 -207
- package/lib/victory-util/hooks/index.js +0 -2
- package/lib/victory-util/hooks/use-animation-state.js +63 -113
- package/lib/victory-util/hooks/use-previous-props.js +2 -7
- package/lib/victory-util/immutable.js +6 -18
- package/lib/victory-util/index.js +2 -51
- package/lib/victory-util/label-helpers.js +130 -141
- package/lib/victory-util/line-helpers.js +31 -49
- package/lib/victory-util/log.js +1 -2
- package/lib/victory-util/point-path-helpers.js +91 -63
- package/lib/victory-util/scale.js +26 -57
- package/lib/victory-util/selection.js +41 -49
- package/lib/victory-util/style.js +8 -16
- package/lib/victory-util/textsize.js +80 -157
- package/lib/victory-util/timer-context.js +2 -8
- package/lib/victory-util/timer.js +40 -76
- package/lib/victory-util/transitions.js +110 -152
- package/lib/victory-util/type-helpers.js +2 -9
- package/lib/victory-util/user-props.js +25 -59
- package/lib/victory-util/wrapper.js +186 -281
- 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
|
-
|
|
15
|
+
const defaultStyles = {
|
|
34
16
|
fill: "#252525",
|
|
35
17
|
fontSize: 14,
|
|
36
18
|
fontFamily: "'Gill Sans', 'Gill Sans MT', 'Seravek', '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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
115
|
-
|
|
81
|
+
return props.backgroundPadding.map(backgroundPadding => {
|
|
82
|
+
const padding = Helpers.evaluateProp(backgroundPadding, props);
|
|
116
83
|
return Helpers.getPadding({
|
|
117
|
-
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
|
|
90
|
+
padding
|
|
125
91
|
});
|
|
126
92
|
};
|
|
127
|
-
|
|
128
|
-
|
|
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(
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
257
|
-
|
|
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
|
-
|
|
263
|
-
|
|
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
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
306
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
|
332
|
-
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
|
|
263
|
+
y,
|
|
336
264
|
fontSize: current.fontSize,
|
|
337
265
|
dy: childDy
|
|
338
266
|
};
|
|
339
267
|
});
|
|
340
|
-
return textElements.map(
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
key:
|
|
351
|
-
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
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
text
|
|
320
|
+
const text = getContent(props.text, props);
|
|
321
|
+
const style = getStyles(props.style, Object.assign({}, props, {
|
|
322
|
+
text
|
|
399
323
|
}));
|
|
400
|
-
|
|
401
|
-
text
|
|
402
|
-
style
|
|
324
|
+
const backgroundStyle = getBackgroundStyles(props.backgroundStyle, Object.assign({}, props, {
|
|
325
|
+
text,
|
|
326
|
+
style
|
|
403
327
|
}));
|
|
404
|
-
|
|
405
|
-
text
|
|
406
|
-
style
|
|
407
|
-
backgroundStyle
|
|
328
|
+
const backgroundPadding = getBackgroundPadding(Object.assign({}, props, {
|
|
329
|
+
text,
|
|
330
|
+
style,
|
|
331
|
+
backgroundStyle
|
|
408
332
|
}));
|
|
409
|
-
|
|
333
|
+
const id = Helpers.evaluateProp(props.id, props);
|
|
410
334
|
return Object.assign({}, props, {
|
|
411
|
-
backgroundStyle
|
|
412
|
-
backgroundPadding
|
|
413
|
-
style
|
|
414
|
-
text
|
|
415
|
-
id
|
|
335
|
+
backgroundStyle,
|
|
336
|
+
backgroundPadding,
|
|
337
|
+
style,
|
|
338
|
+
text,
|
|
339
|
+
id
|
|
416
340
|
});
|
|
417
341
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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
|
|
433
|
-
lineHeight
|
|
434
|
-
direction
|
|
435
|
-
textAnchor
|
|
436
|
-
verticalAnchor
|
|
437
|
-
dx
|
|
438
|
-
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
|
|
441
|
-
x
|
|
442
|
-
y
|
|
363
|
+
transform,
|
|
364
|
+
x,
|
|
365
|
+
y
|
|
443
366
|
});
|
|
444
367
|
};
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
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
|
-
|
|
471
|
-
direction
|
|
472
|
-
dx
|
|
473
|
-
x
|
|
392
|
+
key: "text",
|
|
393
|
+
...events,
|
|
394
|
+
direction,
|
|
395
|
+
dx,
|
|
396
|
+
x,
|
|
474
397
|
y: y + dy,
|
|
475
|
-
transform
|
|
476
|
-
className
|
|
477
|
-
title
|
|
398
|
+
transform,
|
|
399
|
+
className,
|
|
400
|
+
title,
|
|
478
401
|
desc: Helpers.evaluateProp(desc, calculatedProps),
|
|
479
402
|
tabIndex: Helpers.evaluateProp(tabIndex, calculatedProps),
|
|
480
|
-
id
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
key:
|
|
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
|
|
510
|
-
|
|
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
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
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
|
-
|
|
538
|
-
|
|
462
|
+
const label = renderLabel(calculatedProps, tspanValues);
|
|
539
463
|
if (props.backgroundStyle) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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";
|