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,62 +1,50 @@
|
|
|
1
1
|
import * as d3Shape from "victory-vendor/d3-shape";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var y = d._y1 !== undefined ? d._y1 : d._y;
|
|
2
|
+
const defined = d => {
|
|
3
|
+
const y = d._y1 !== undefined ? d._y1 : d._y;
|
|
5
4
|
return y !== null && y !== undefined && d._y0 !== null;
|
|
6
5
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return function (d) {
|
|
10
|
-
return scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
11
|
-
};
|
|
6
|
+
const getXAccessor = scale => {
|
|
7
|
+
return d => scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
12
8
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return function (d) {
|
|
16
|
-
return scale.y(d._y1 !== undefined ? d._y1 : d._y);
|
|
17
|
-
};
|
|
9
|
+
const getYAccessor = scale => {
|
|
10
|
+
return d => scale.y(d._y1 !== undefined ? d._y1 : d._y);
|
|
18
11
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
12
|
+
const getAngleAccessor = scale => {
|
|
13
|
+
return d => {
|
|
14
|
+
const x = scale.x(d._x1 !== undefined ? d._x1 : d._x);
|
|
23
15
|
return -1 * x + Math.PI / 2;
|
|
24
16
|
};
|
|
25
17
|
};
|
|
26
|
-
|
|
27
|
-
var toNewName = function (interpolation) {
|
|
18
|
+
const toNewName = interpolation => {
|
|
28
19
|
// d3 shape changed the naming scheme for interpolators from "basis" -> "curveBasis" etc.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return "curve".concat(capitalize(interpolation));
|
|
20
|
+
const capitalize = s => s && s[0].toUpperCase() + s.slice(1);
|
|
21
|
+
return `curve${capitalize(interpolation)}`;
|
|
34
22
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return "".concat(toNewName(interpolation), "Closed");
|
|
23
|
+
const toNewNameClosed = interpolation => {
|
|
24
|
+
return `${toNewName(interpolation)}Closed`;
|
|
38
25
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
export const getInterpolationFunction = props => {
|
|
27
|
+
const {
|
|
28
|
+
interpolation
|
|
29
|
+
} = props;
|
|
43
30
|
if (typeof interpolation === "function") {
|
|
44
31
|
return interpolation;
|
|
45
32
|
}
|
|
46
|
-
|
|
47
33
|
if (typeof interpolation === "string") {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
const {
|
|
35
|
+
polar,
|
|
36
|
+
openCurve = !polar
|
|
37
|
+
} = props;
|
|
38
|
+
const interpolationName = !openCurve ? toNewNameClosed(interpolation) : toNewName(interpolation);
|
|
52
39
|
return d3Shape[interpolationName];
|
|
53
40
|
}
|
|
54
|
-
|
|
55
41
|
return d3Shape.curveLinear;
|
|
56
42
|
};
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
export const getLineFunction = props => {
|
|
44
|
+
const {
|
|
45
|
+
polar,
|
|
46
|
+
scale,
|
|
47
|
+
horizontal
|
|
48
|
+
} = props;
|
|
61
49
|
return polar ? d3Shape.lineRadial().defined(defined).curve(getInterpolationFunction(props)).angle(getAngleAccessor(scale)).radius(getYAccessor(scale)) : d3Shape.line().defined(defined).curve(getInterpolationFunction(props)).x(horizontal ? getYAccessor(scale) : getXAccessor(scale)).y(horizontal ? getXAccessor(scale) : getYAccessor(scale));
|
|
62
50
|
};
|
package/es/victory-util/log.js
CHANGED
|
@@ -1,71 +1,111 @@
|
|
|
1
1
|
/* eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2, 2.5, 3] }]*/
|
|
2
|
+
|
|
2
3
|
import * as Helpers from "./helpers";
|
|
3
4
|
export function circle(x, y, size) {
|
|
4
|
-
return
|
|
5
|
+
return `M ${x}, ${y}
|
|
6
|
+
m ${-size}, 0
|
|
7
|
+
a ${size}, ${size} 0 1,0 ${size * 2},0
|
|
8
|
+
a ${size}, ${size} 0 1,0 ${-size * 2},0`;
|
|
5
9
|
}
|
|
6
10
|
export function square(x, y, size) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const baseSize = 0.87 * size; // eslint-disable-line no-magic-numbers
|
|
12
|
+
const x0 = x - baseSize;
|
|
13
|
+
const y1 = y + baseSize;
|
|
14
|
+
const distance = x + baseSize - x0;
|
|
15
|
+
return `M ${x0}, ${y1}
|
|
16
|
+
h${distance}
|
|
17
|
+
v-${distance}
|
|
18
|
+
h-${distance}
|
|
19
|
+
z`;
|
|
13
20
|
}
|
|
14
21
|
export function diamond(x, y, size) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const baseSize = 0.87 * size; // eslint-disable-line no-magic-numbers
|
|
23
|
+
const length = Math.sqrt(2 * (baseSize * baseSize));
|
|
24
|
+
return `M ${x}, ${y + length}
|
|
25
|
+
l ${length}, -${length}
|
|
26
|
+
l -${length}, -${length}
|
|
27
|
+
l -${length}, ${length}
|
|
28
|
+
l ${length}, ${length}
|
|
29
|
+
z`;
|
|
19
30
|
}
|
|
20
31
|
export function triangleDown(x, y, size) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
32
|
+
const height = size / 2 * Math.sqrt(3);
|
|
33
|
+
const x0 = x - size;
|
|
34
|
+
const x1 = x + size;
|
|
35
|
+
const y0 = y - size;
|
|
36
|
+
const y1 = y + height;
|
|
37
|
+
return `M ${x0}, ${y0}
|
|
38
|
+
L ${x1}, ${y0}
|
|
39
|
+
L ${x}, ${y1}
|
|
40
|
+
z`;
|
|
27
41
|
}
|
|
28
42
|
export function triangleUp(x, y, size) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return
|
|
43
|
+
const height = size / 2 * Math.sqrt(3);
|
|
44
|
+
const x0 = x - size;
|
|
45
|
+
const x1 = x + size;
|
|
46
|
+
const y0 = y - height;
|
|
47
|
+
const y1 = y + size;
|
|
48
|
+
return `M ${x0}, ${y1}
|
|
49
|
+
L ${x1}, ${y1}
|
|
50
|
+
L ${x}, ${y0}
|
|
51
|
+
z`;
|
|
35
52
|
}
|
|
36
53
|
export function plus(x, y, size) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
const baseSize = 1.1 * size; // eslint-disable-line no-magic-numbers
|
|
55
|
+
const distance = baseSize / 1.5; // eslint-disable-line no-magic-numbers
|
|
56
|
+
return `
|
|
57
|
+
M ${x - distance / 2}, ${y + baseSize}
|
|
58
|
+
v-${distance}
|
|
59
|
+
h-${distance}
|
|
60
|
+
v-${distance}
|
|
61
|
+
h${distance}
|
|
62
|
+
v-${distance}
|
|
63
|
+
h${distance}
|
|
64
|
+
v${distance}
|
|
65
|
+
h${distance}
|
|
66
|
+
v${distance}
|
|
67
|
+
h-${distance}
|
|
68
|
+
v${distance}
|
|
69
|
+
z`;
|
|
42
70
|
}
|
|
43
71
|
export function cross(x, y, size) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
const baseSize = 0.8 * size; // eslint-disable-line no-magic-numbers
|
|
73
|
+
const distance = baseSize / 1.5; // eslint-disable-line no-magic-numbers
|
|
74
|
+
return `
|
|
75
|
+
M ${x - distance / 2}, ${y + baseSize + distance}
|
|
76
|
+
v-${distance * 2}
|
|
77
|
+
h-${distance}
|
|
78
|
+
v-${distance}
|
|
79
|
+
h${distance}
|
|
80
|
+
v-${distance}
|
|
81
|
+
h${distance}
|
|
82
|
+
v${distance}
|
|
83
|
+
h${distance}
|
|
84
|
+
v${distance}
|
|
85
|
+
h-${distance}
|
|
86
|
+
v${distance * 2}
|
|
87
|
+
z`;
|
|
49
88
|
}
|
|
50
89
|
export function minus(x, y, size) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
90
|
+
const baseSize = 1.1 * size; // eslint-disable-line no-magic-numbers
|
|
91
|
+
const lineHeight = baseSize - baseSize * 0.3; // eslint-disable-line no-magic-numbers
|
|
92
|
+
const x0 = x - baseSize;
|
|
93
|
+
const y1 = y + lineHeight / 2;
|
|
94
|
+
const distance = x + baseSize - x0;
|
|
95
|
+
return `M ${x0}, ${y1}
|
|
96
|
+
h${distance}
|
|
97
|
+
v-${lineHeight}
|
|
98
|
+
h-${distance}
|
|
99
|
+
z`;
|
|
59
100
|
}
|
|
60
101
|
export function star(x, y, size) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var angle = Math.PI / 5; // eslint-disable-line no-magic-numbers
|
|
102
|
+
const baseSize = 1.35 * size; // eslint-disable-line no-magic-numbers
|
|
103
|
+
const angle = Math.PI / 5; // eslint-disable-line no-magic-numbers
|
|
64
104
|
// eslint-disable-next-line no-magic-numbers
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
105
|
+
const starCoords = Helpers.range(10).map(index => {
|
|
106
|
+
const length = index % 2 === 0 ? baseSize : baseSize / 2;
|
|
107
|
+
return `${length * Math.sin(angle * (index + 1)) + x},
|
|
108
|
+
${length * Math.cos(angle * (index + 1)) + y}`;
|
|
69
109
|
});
|
|
70
|
-
return
|
|
110
|
+
return `M ${starCoords.join("L")} z`;
|
|
71
111
|
}
|
package/es/victory-util/scale.js
CHANGED
|
@@ -1,95 +1,79 @@
|
|
|
1
1
|
import _isPlainObject from "lodash/isPlainObject";
|
|
2
|
+
/* eslint-disable no-use-before-define */
|
|
2
3
|
import * as Helpers from "./helpers";
|
|
3
4
|
import * as Collection from "./collection";
|
|
4
5
|
import * as d3Scale from "victory-vendor/d3-scale";
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const supportedScaleStrings = ["linear", "time", "log", "sqrt"];
|
|
7
7
|
// Private Functions
|
|
8
|
+
|
|
8
9
|
function toNewName(scale) {
|
|
9
10
|
// d3 scale changed the naming scheme for scale from "linear" -> "scaleLinear" etc.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return "scale".concat(capitalize(scale));
|
|
11
|
+
const capitalize = s => s && s[0].toUpperCase() + s.slice(1);
|
|
12
|
+
return `scale${capitalize(scale)}`;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
export function validScale(scale) {
|
|
18
15
|
if (typeof scale === "function") {
|
|
19
16
|
return Helpers.isFunction(scale.copy) && Helpers.isFunction(scale.domain) && Helpers.isFunction(scale.range);
|
|
20
17
|
} else if (typeof scale === "string") {
|
|
21
18
|
return supportedScaleStrings.includes(scale);
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
return false;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
function isScaleDefined(props, axis) {
|
|
28
23
|
if (!props.scale) {
|
|
29
24
|
return false;
|
|
30
25
|
} else if (props.scale.x || props.scale.y) {
|
|
31
26
|
return !!props.scale[axis];
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
return true;
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
function getScaleTypeFromProps(props, axis) {
|
|
38
31
|
if (!isScaleDefined(props, axis)) {
|
|
39
32
|
return undefined;
|
|
40
33
|
}
|
|
41
|
-
|
|
42
|
-
var scale = props.scale[axis] || props.scale;
|
|
34
|
+
const scale = props.scale[axis] || props.scale;
|
|
43
35
|
return typeof scale === "string" ? scale : getType(scale);
|
|
44
36
|
}
|
|
45
|
-
|
|
46
37
|
function getScaleFromDomain(props, axis) {
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
let domain;
|
|
49
39
|
if (props.domain && props.domain[axis]) {
|
|
50
40
|
domain = props.domain[axis];
|
|
51
41
|
} else if (props.domain && Array.isArray(props.domain)) {
|
|
52
42
|
domain = props.domain;
|
|
53
43
|
}
|
|
54
|
-
|
|
55
44
|
if (!domain) {
|
|
56
45
|
return undefined;
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
return Collection.containsDates(domain) ? "time" : "linear";
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
function getScaleTypeFromData(props, axis) {
|
|
63
50
|
if (!props.data) {
|
|
64
51
|
return "linear";
|
|
65
52
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var processedData = _isPlainObject(accessor(datum)) ? accessor(datum)[axis] : accessor(datum);
|
|
53
|
+
const accessor = Helpers.createAccessor(props[axis]);
|
|
54
|
+
const axisData = props.data.map(datum => {
|
|
55
|
+
const processedData = _isPlainObject(accessor(datum)) ? accessor(datum)[axis] : accessor(datum);
|
|
70
56
|
return processedData !== undefined ? processedData : datum[axis];
|
|
71
57
|
});
|
|
72
58
|
return Collection.containsDates(axisData) ? "time" : "linear";
|
|
73
|
-
}
|
|
59
|
+
}
|
|
74
60
|
|
|
61
|
+
// Exported Functions
|
|
75
62
|
|
|
76
63
|
export function getScaleFromName(name) {
|
|
77
64
|
if (validScale(name)) {
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
const methodName = toNewName(name);
|
|
66
|
+
// @ts-expect-error scaleTime is not directly compatible with our D3Scale definition
|
|
80
67
|
return d3Scale[methodName]();
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
return d3Scale.scaleLinear();
|
|
84
70
|
}
|
|
85
71
|
export function getBaseScale(props, axis) {
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
const scale = getScaleFromProps(props, axis);
|
|
88
73
|
if (scale) {
|
|
89
74
|
return typeof scale === "string" ? getScaleFromName(scale) : scale;
|
|
90
75
|
}
|
|
91
|
-
|
|
92
|
-
var defaultScale = getScaleFromDomain(props, axis) || getScaleTypeFromData(props, axis);
|
|
76
|
+
const defaultScale = getScaleFromDomain(props, axis) || getScaleTypeFromData(props, axis);
|
|
93
77
|
return getScaleFromName(defaultScale);
|
|
94
78
|
}
|
|
95
79
|
export function getDefaultScale() {
|
|
@@ -99,28 +83,27 @@ export function getScaleFromProps(props, axis) {
|
|
|
99
83
|
if (!isScaleDefined(props, axis)) {
|
|
100
84
|
return undefined;
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
var scale = props.scale[axis] || props.scale;
|
|
104
|
-
|
|
86
|
+
const scale = props.scale[axis] || props.scale;
|
|
105
87
|
if (validScale(scale)) {
|
|
106
88
|
return Helpers.isFunction(scale) ? scale : getScaleFromName(scale);
|
|
107
89
|
}
|
|
108
|
-
|
|
109
90
|
return undefined;
|
|
110
91
|
}
|
|
111
92
|
export function getScaleType(props, axis) {
|
|
112
93
|
// if the scale was not given in props, it will be set to linear or time depending on data
|
|
113
94
|
return getScaleTypeFromProps(props, axis) || getScaleTypeFromData(props, axis);
|
|
114
|
-
}
|
|
115
|
-
// **Note**: Brittle because reliant on d3 internals.
|
|
95
|
+
}
|
|
116
96
|
|
|
117
|
-
|
|
97
|
+
// Ordered type inference off of function fields.
|
|
98
|
+
// **Note**: Brittle because reliant on d3 internals.
|
|
99
|
+
const DUCK_TYPES = [{
|
|
118
100
|
name: "quantile",
|
|
119
101
|
method: "quantiles"
|
|
120
102
|
}, {
|
|
121
103
|
name: "log",
|
|
122
104
|
method: "base"
|
|
123
|
-
}
|
|
105
|
+
}
|
|
106
|
+
// TODO(2214): Re-evaluate (1) duck typing approach, and (2) if duck typing,
|
|
124
107
|
// do we need a different approach? (Multiple keys? Stringifying functions?)
|
|
125
108
|
// https://github.com/FormidableLabs/victory/issues/2214
|
|
126
109
|
// Below are matches that don't seem to otherwise occur in Victory code base.
|
|
@@ -132,8 +115,7 @@ export function getType(scale) {
|
|
|
132
115
|
if (typeof scale === "string") {
|
|
133
116
|
return scale;
|
|
134
117
|
}
|
|
135
|
-
|
|
136
|
-
var scaleType = DUCK_TYPES.filter(function (type) {
|
|
118
|
+
const scaleType = DUCK_TYPES.filter(type => {
|
|
137
119
|
return scale[type.method] !== undefined;
|
|
138
120
|
})[0];
|
|
139
121
|
return scaleType ? scaleType.name : undefined;
|
|
@@ -1,41 +1,38 @@
|
|
|
1
1
|
import * as Collection from "./collection";
|
|
2
|
-
|
|
3
2
|
// Private Functions
|
|
3
|
+
|
|
4
4
|
function transformTarget(target, matrix, dimension) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const {
|
|
6
|
+
a,
|
|
7
|
+
d,
|
|
8
|
+
e,
|
|
9
|
+
f
|
|
10
|
+
} = matrix;
|
|
9
11
|
return dimension === "y" ? d * target + f : a * target + e;
|
|
10
12
|
}
|
|
11
|
-
|
|
12
13
|
function getTransformationMatrix(svg) {
|
|
13
14
|
return svg.getScreenCTM().inverse();
|
|
14
15
|
}
|
|
15
|
-
|
|
16
16
|
function isNativeTouchEvent(nativeEvent) {
|
|
17
17
|
return !!(nativeEvent && nativeEvent.identifier !== undefined);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
19
|
function isReactTouchEvent(evt) {
|
|
21
20
|
return evt.changedTouches && evt.changedTouches.length > 0;
|
|
22
|
-
}
|
|
21
|
+
}
|
|
23
22
|
|
|
23
|
+
// Exported Functions
|
|
24
24
|
|
|
25
25
|
export function getParentSVG(evt) {
|
|
26
26
|
if (isNativeTouchEvent(evt.nativeEvent)) {
|
|
27
27
|
// @ts-expect-error Seems like a superfluous check.
|
|
28
28
|
return undefined;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
var getParent = function (target) {
|
|
30
|
+
const getParent = target => {
|
|
32
31
|
if (target.nodeName === "svg") {
|
|
33
32
|
return target;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
return target.parentNode ? getParent(target.parentNode) : target;
|
|
37
35
|
};
|
|
38
|
-
|
|
39
36
|
return getParent(evt.target);
|
|
40
37
|
}
|
|
41
38
|
export function getSVGEventCoordinates(evt, svg) {
|
|
@@ -47,19 +44,20 @@ export function getSVGEventCoordinates(evt, svg) {
|
|
|
47
44
|
y: evt.nativeEvent.locationY
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var matrix = getTransformationMatrix(svg || getParentSVG(location));
|
|
47
|
+
const location = isReactTouchEvent(evt) ? evt.changedTouches[0] : evt;
|
|
48
|
+
const matrix = getTransformationMatrix(svg || getParentSVG(location));
|
|
53
49
|
return {
|
|
54
50
|
x: transformTarget(location.clientX, matrix, "x"),
|
|
55
51
|
y: transformTarget(location.clientY, matrix, "y")
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
54
|
export function getDomainCoordinates(props, domain) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
const {
|
|
56
|
+
horizontal
|
|
57
|
+
} = props;
|
|
58
|
+
const scale = props.scale;
|
|
59
|
+
// FIXME: add support for DomainTuple: [number, number]
|
|
60
|
+
const domainObj = domain || {
|
|
63
61
|
x: scale.x.domain(),
|
|
64
62
|
y: scale.y.domain()
|
|
65
63
|
};
|
|
@@ -67,45 +65,46 @@ export function getDomainCoordinates(props, domain) {
|
|
|
67
65
|
x: horizontal ? [scale.y(domainObj.y[0]), scale.y(domainObj.y[1])] : [scale.x(domainObj.x[0]), scale.x(domainObj.x[1])],
|
|
68
66
|
y: horizontal ? [scale.x(domainObj.x[0]), scale.x(domainObj.x[1])] : [scale.y(domainObj.y[0]), scale.y(domainObj.y[1])]
|
|
69
67
|
};
|
|
70
|
-
}
|
|
68
|
+
}
|
|
71
69
|
|
|
70
|
+
// eslint-disable-next-line max-params
|
|
72
71
|
export function getDataCoordinates(props, scale, x, y) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const {
|
|
73
|
+
polar,
|
|
74
|
+
horizontal
|
|
75
|
+
} = props;
|
|
76
76
|
if (!polar) {
|
|
77
77
|
return {
|
|
78
78
|
x: horizontal ? scale.x.invert(y) : scale.x.invert(x),
|
|
79
79
|
y: horizontal ? scale.y.invert(x) : scale.y.invert(y)
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
var origin = props.origin || {
|
|
82
|
+
const origin = props.origin || {
|
|
84
83
|
x: 0,
|
|
85
84
|
y: 0
|
|
86
85
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
const baseX = x - origin.x;
|
|
87
|
+
const baseY = y - origin.y;
|
|
88
|
+
const radius = Math.abs(baseX * Math.sqrt(1 + Math.pow(-baseY / baseX, 2)));
|
|
89
|
+
const angle = (-Math.atan2(baseY, baseX) + Math.PI * 2) % (Math.PI * 2);
|
|
91
90
|
return {
|
|
92
91
|
x: scale.x.invert(angle),
|
|
93
92
|
y: scale.y.invert(radius)
|
|
94
93
|
};
|
|
95
94
|
}
|
|
96
95
|
export function getBounds(props) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
const {
|
|
97
|
+
x1,
|
|
98
|
+
x2,
|
|
99
|
+
y1,
|
|
100
|
+
y2,
|
|
101
|
+
scale
|
|
102
|
+
} = props;
|
|
103
|
+
const point1 = getDataCoordinates(props, scale, x1, y1);
|
|
104
|
+
const point2 = getDataCoordinates(props, scale, x2, y2);
|
|
105
|
+
const makeBound = (a, b) => {
|
|
106
106
|
return [Collection.getMinValue([a, b]), Collection.getMaxValue([a, b])];
|
|
107
107
|
};
|
|
108
|
-
|
|
109
108
|
return {
|
|
110
109
|
x: makeBound(point1.x, point2.x),
|
|
111
110
|
y: makeBound(point1.y, point2.y)
|
package/es/victory-util/style.js
CHANGED
|
@@ -7,32 +7,28 @@
|
|
|
7
7
|
* @param {Object} obj An object of transform definitions.
|
|
8
8
|
* @returns {String} The generated transform string.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export const toTransformString = function (obj) {
|
|
11
11
|
for (var _len = arguments.length, more = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
12
12
|
more[_key - 1] = arguments[_key];
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
if (more.length > 0) {
|
|
16
|
-
return more.reduce(
|
|
15
|
+
return more.reduce((memo, currentObj) => {
|
|
17
16
|
return [memo, toTransformString(currentObj)].join(" ");
|
|
18
17
|
}, toTransformString(obj)).trim();
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
if (obj === undefined || obj === null || typeof obj === "string") {
|
|
22
20
|
return obj;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for (var key in obj) {
|
|
22
|
+
const transforms = [];
|
|
23
|
+
for (const key in obj) {
|
|
28
24
|
if (obj.hasOwnProperty(key)) {
|
|
29
|
-
|
|
30
|
-
transforms.push(
|
|
25
|
+
const value = obj[key];
|
|
26
|
+
transforms.push(`${key}(${value})`);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
|
-
|
|
34
29
|
return transforms.join(" ").trim();
|
|
35
30
|
};
|
|
31
|
+
|
|
36
32
|
/**
|
|
37
33
|
* Given the name of a color scale, getColorScale will return an array
|
|
38
34
|
* of 5 hex string values in that color scale. If no 'name' parameter
|
|
@@ -40,9 +36,8 @@ export var toTransformString = function (obj) {
|
|
|
40
36
|
* @param {String} name The name of the color scale to return (optional).
|
|
41
37
|
* @returns {Array} An array of 5 hex string values composing a color scale.
|
|
42
38
|
*/
|
|
43
|
-
|
|
44
39
|
export function getColorScale(name) {
|
|
45
|
-
|
|
40
|
+
const scales = {
|
|
46
41
|
grayscale: ["#cccccc", "#969696", "#636363", "#252525"],
|
|
47
42
|
qualitative: ["#334D5C", "#45B29D", "#EFC94C", "#E27A3F", "#DF5A49", "#4F7DA1", "#55DBC1", "#EFDA97", "#E2A37F", "#DF948A"],
|
|
48
43
|
heatmap: ["#428517", "#77D200", "#D6D305", "#EC8E19", "#C92B05"],
|