victory-bar 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-bar.js +3872 -5045
- package/dist/victory-bar.min.js +1 -1
- package/es/bar-helper-methods.js +24 -33
- package/es/bar.js +40 -43
- package/es/geometry-helper-methods.js +93 -100
- package/es/helper-methods.js +96 -102
- package/es/path-helper-methods.js +260 -305
- package/es/victory-bar.js +65 -114
- package/lib/bar-helper-methods.js +24 -42
- package/lib/bar.js +43 -58
- package/lib/geometry-helper-methods.js +93 -103
- package/lib/helper-methods.js +96 -114
- package/lib/index.js +0 -7
- package/lib/path-helper-methods.js +262 -321
- package/lib/victory-bar.js +65 -122
- package/package.json +3 -3
|
@@ -4,116 +4,106 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.point = exports.circle = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* A point in the 2d plane
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new Error("Division by 0 error");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return point(this.x / n, this.y / n);
|
|
37
|
-
},
|
|
38
|
-
equals: function (p1) {
|
|
39
|
-
return this.x === p1.x && this.y === p1.y;
|
|
10
|
+
const point = (x, y) => ({
|
|
11
|
+
x,
|
|
12
|
+
y,
|
|
13
|
+
distance(p1) {
|
|
14
|
+
return Math.sqrt(Math.pow(this.x - p1.x, 2) + Math.pow(this.y - p1.y, 2));
|
|
15
|
+
},
|
|
16
|
+
// vector addition in 2d plane
|
|
17
|
+
add(p1) {
|
|
18
|
+
return point(this.x + p1.x, this.y + p1.y);
|
|
19
|
+
},
|
|
20
|
+
// vector subtraction in 2d
|
|
21
|
+
// returns p0 - p1
|
|
22
|
+
subtract(p1) {
|
|
23
|
+
return point(this.x - p1.x, this.y - p1.y);
|
|
24
|
+
},
|
|
25
|
+
// multiply a 2d point by a scalar
|
|
26
|
+
scalarMult(n) {
|
|
27
|
+
return point(this.x * n, this.y * n);
|
|
28
|
+
},
|
|
29
|
+
scalarDivide(n) {
|
|
30
|
+
if (n === 0) {
|
|
31
|
+
throw new Error("Division by 0 error");
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
33
|
+
return point(this.x / n, this.y / n);
|
|
34
|
+
},
|
|
35
|
+
equals(p1) {
|
|
36
|
+
return this.x === p1.x && this.y === p1.y;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
44
39
|
exports.point = point;
|
|
45
|
-
|
|
46
40
|
/**
|
|
47
41
|
* A circle in the 2d plane
|
|
48
42
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (d > r0 + r1) {
|
|
61
|
-
return false; // separate circles
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (d < Math.abs(r0 - r1)) {
|
|
65
|
-
return false; // one circle contains another
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return true;
|
|
69
|
-
},
|
|
70
|
-
equals: function (circle1) {
|
|
71
|
-
var P0 = this.center;
|
|
72
|
-
var P1 = circle1.center;
|
|
73
|
-
var r0 = this.radius;
|
|
74
|
-
var r1 = circle1.radius;
|
|
75
|
-
return r0 === r1 && P0.equals(P1);
|
|
76
|
-
},
|
|
77
|
-
// Source: http://paulbourke.net/geometry/circlesphere/
|
|
78
|
-
// "Intersection of two circles" by Paul Bourke
|
|
79
|
-
// Left-most point is returned as 0th element of array
|
|
80
|
-
// Right-most point is returned as 1st elemennt of array
|
|
81
|
-
intersection: function (circle1) {
|
|
82
|
-
// eslint-disable-line max-statements
|
|
83
|
-
var P0 = this.center;
|
|
84
|
-
var P1 = circle1.center;
|
|
85
|
-
var r0 = this.radius;
|
|
86
|
-
var r1 = circle1.radius;
|
|
87
|
-
var d = P0.distance(P1);
|
|
88
|
-
|
|
89
|
-
if (!this.hasIntersection(circle1) || this.equals(circle1)) {
|
|
90
|
-
return [];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
var a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d);
|
|
94
|
-
var h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2));
|
|
95
|
-
var P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d));
|
|
96
|
-
var x0 = P0.x,
|
|
97
|
-
y0 = P0.y;
|
|
98
|
-
var x1 = P1.x,
|
|
99
|
-
y1 = P1.y;
|
|
100
|
-
var x2 = P2.x,
|
|
101
|
-
y2 = P2.y;
|
|
102
|
-
var P3s = [point(x2 - h * (y1 - y0) / d, y2 + h * (x1 - x0) / d), point(x2 + h * (y1 - y0) / d, y2 - h * (x1 - x0) / d)];
|
|
103
|
-
P3s.sort(function (Point1, Point2) {
|
|
104
|
-
return Point1.x - Point2.x;
|
|
105
|
-
});
|
|
106
|
-
return P3s;
|
|
107
|
-
},
|
|
108
|
-
solveX: function (y) {
|
|
109
|
-
var sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2));
|
|
110
|
-
return [this.center.x - sqrt, this.center.x + sqrt];
|
|
111
|
-
},
|
|
112
|
-
solveY: function (x) {
|
|
113
|
-
var sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2));
|
|
114
|
-
return [this.center.y - sqrt, this.center.y + sqrt];
|
|
43
|
+
const circle = (center, radius) => ({
|
|
44
|
+
center,
|
|
45
|
+
radius,
|
|
46
|
+
hasIntersection(circle1) {
|
|
47
|
+
const P0 = this.center;
|
|
48
|
+
const P1 = circle1.center;
|
|
49
|
+
const r0 = this.radius;
|
|
50
|
+
const r1 = circle1.radius;
|
|
51
|
+
const d = P0.distance(P1);
|
|
52
|
+
if (d > r0 + r1) {
|
|
53
|
+
return false; // separate circles
|
|
115
54
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
55
|
+
if (d < Math.abs(r0 - r1)) {
|
|
56
|
+
return false; // one circle contains another
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
equals(circle1) {
|
|
61
|
+
const P0 = this.center;
|
|
62
|
+
const P1 = circle1.center;
|
|
63
|
+
const r0 = this.radius;
|
|
64
|
+
const r1 = circle1.radius;
|
|
65
|
+
return r0 === r1 && P0.equals(P1);
|
|
66
|
+
},
|
|
67
|
+
// Source: http://paulbourke.net/geometry/circlesphere/
|
|
68
|
+
// "Intersection of two circles" by Paul Bourke
|
|
69
|
+
// Left-most point is returned as 0th element of array
|
|
70
|
+
// Right-most point is returned as 1st elemennt of array
|
|
71
|
+
intersection(circle1) {
|
|
72
|
+
// eslint-disable-line max-statements
|
|
73
|
+
const P0 = this.center;
|
|
74
|
+
const P1 = circle1.center;
|
|
75
|
+
const r0 = this.radius;
|
|
76
|
+
const r1 = circle1.radius;
|
|
77
|
+
const d = P0.distance(P1);
|
|
78
|
+
if (!this.hasIntersection(circle1) || this.equals(circle1)) {
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
const a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d);
|
|
82
|
+
const h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2));
|
|
83
|
+
const P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d));
|
|
84
|
+
const {
|
|
85
|
+
x: x0,
|
|
86
|
+
y: y0
|
|
87
|
+
} = P0;
|
|
88
|
+
const {
|
|
89
|
+
x: x1,
|
|
90
|
+
y: y1
|
|
91
|
+
} = P1;
|
|
92
|
+
const {
|
|
93
|
+
x: x2,
|
|
94
|
+
y: y2
|
|
95
|
+
} = P2;
|
|
96
|
+
const P3s = [point(x2 - h * (y1 - y0) / d, y2 + h * (x1 - x0) / d), point(x2 + h * (y1 - y0) / d, y2 - h * (x1 - x0) / d)];
|
|
97
|
+
P3s.sort((Point1, Point2) => Point1.x - Point2.x);
|
|
98
|
+
return P3s;
|
|
99
|
+
},
|
|
100
|
+
solveX(y) {
|
|
101
|
+
const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2));
|
|
102
|
+
return [this.center.x - sqrt, this.center.x + sqrt];
|
|
103
|
+
},
|
|
104
|
+
solveY(x) {
|
|
105
|
+
const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2));
|
|
106
|
+
return [this.center.y - sqrt, this.center.y + sqrt];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
119
109
|
exports.circle = circle;
|
package/lib/helper-methods.js
CHANGED
|
@@ -4,157 +4,139 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBaseProps = exports.getBarPosition = void 0;
|
|
7
|
-
|
|
8
7
|
var _victoryCore = require("victory-core");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var minY = _victoryCore.Collection.getMinValue(props.domain[axis]);
|
|
16
|
-
|
|
17
|
-
var maxY = _victoryCore.Collection.getMaxValue(props.domain[axis]);
|
|
18
|
-
|
|
8
|
+
const getBarPosition = (props, datum) => {
|
|
9
|
+
const getDefaultMin = axis => {
|
|
10
|
+
const defaultZero = _victoryCore.Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
|
|
11
|
+
let defaultMin = defaultZero;
|
|
12
|
+
const minY = _victoryCore.Collection.getMinValue(props.domain[axis]);
|
|
13
|
+
const maxY = _victoryCore.Collection.getMaxValue(props.domain[axis]);
|
|
19
14
|
if (minY < 0 && maxY <= 0) {
|
|
20
15
|
defaultMin = maxY;
|
|
21
16
|
} else if (minY >= 0 && maxY > 0) {
|
|
22
17
|
defaultMin = minY;
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
return datum["_".concat(axis)] instanceof Date ? new Date(defaultMin) : defaultMin;
|
|
19
|
+
return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin;
|
|
26
20
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
|
|
31
|
-
|
|
21
|
+
const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
|
|
22
|
+
const _x0 = datum._x0 !== undefined ? datum._x0 : getDefaultMin("x");
|
|
32
23
|
return _victoryCore.Helpers.scalePoint(props, Object.assign({}, datum, {
|
|
33
|
-
_y0
|
|
34
|
-
_x0
|
|
24
|
+
_y0,
|
|
25
|
+
_x0
|
|
35
26
|
}));
|
|
36
27
|
};
|
|
37
|
-
|
|
38
28
|
exports.getBarPosition = getBarPosition;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var range = props.range || {
|
|
29
|
+
const getCalculatedValues = props => {
|
|
30
|
+
const {
|
|
31
|
+
polar
|
|
32
|
+
} = props;
|
|
33
|
+
const defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "bar");
|
|
34
|
+
const style = !props.disableInlineStyles ? _victoryCore.Helpers.getStyles(props.style, defaultStyles) : {};
|
|
35
|
+
const range = props.range || {
|
|
47
36
|
x: _victoryCore.Helpers.getRange(props, "x"),
|
|
48
37
|
y: _victoryCore.Helpers.getRange(props, "y")
|
|
49
38
|
};
|
|
50
|
-
|
|
39
|
+
const domain = {
|
|
51
40
|
x: _victoryCore.Domain.getDomainWithZero(props, "x"),
|
|
52
41
|
y: _victoryCore.Domain.getDomainWithZero(props, "y")
|
|
53
42
|
};
|
|
54
|
-
|
|
43
|
+
const scale = {
|
|
55
44
|
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
|
|
56
45
|
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
|
|
57
46
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var data = _victoryCore.Data.getData(props);
|
|
61
|
-
|
|
47
|
+
const origin = polar ? props.origin || _victoryCore.Helpers.getPolarOrigin(props) : undefined;
|
|
48
|
+
let data = _victoryCore.Data.getData(props);
|
|
62
49
|
data = _victoryCore.Data.formatDataFromDomain(data, domain, 0);
|
|
63
50
|
return {
|
|
64
|
-
style
|
|
65
|
-
data
|
|
66
|
-
scale
|
|
67
|
-
domain
|
|
68
|
-
origin
|
|
51
|
+
style,
|
|
52
|
+
data,
|
|
53
|
+
scale,
|
|
54
|
+
domain,
|
|
55
|
+
origin
|
|
69
56
|
};
|
|
70
57
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
58
|
+
const getBaseProps = (initialProps, fallbackProps) => {
|
|
59
|
+
const modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "bar");
|
|
60
|
+
const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
61
|
+
const {
|
|
62
|
+
alignment,
|
|
63
|
+
barRatio,
|
|
64
|
+
cornerRadius,
|
|
65
|
+
data,
|
|
66
|
+
disableInlineStyles,
|
|
67
|
+
domain,
|
|
68
|
+
events,
|
|
69
|
+
height,
|
|
70
|
+
horizontal,
|
|
71
|
+
origin,
|
|
72
|
+
padding,
|
|
73
|
+
polar,
|
|
74
|
+
scale,
|
|
75
|
+
sharedEvents,
|
|
76
|
+
standalone,
|
|
77
|
+
style,
|
|
78
|
+
theme,
|
|
79
|
+
width,
|
|
80
|
+
labels,
|
|
81
|
+
name,
|
|
82
|
+
barWidth,
|
|
83
|
+
getPath
|
|
84
|
+
} = props;
|
|
85
|
+
const initialChildProps = {
|
|
99
86
|
parent: {
|
|
100
|
-
horizontal
|
|
101
|
-
domain
|
|
102
|
-
scale
|
|
103
|
-
width
|
|
104
|
-
height
|
|
105
|
-
data
|
|
106
|
-
standalone
|
|
107
|
-
name
|
|
108
|
-
theme
|
|
109
|
-
polar
|
|
110
|
-
origin
|
|
111
|
-
padding
|
|
87
|
+
horizontal,
|
|
88
|
+
domain,
|
|
89
|
+
scale,
|
|
90
|
+
width,
|
|
91
|
+
height,
|
|
92
|
+
data,
|
|
93
|
+
standalone,
|
|
94
|
+
name,
|
|
95
|
+
theme,
|
|
96
|
+
polar,
|
|
97
|
+
origin,
|
|
98
|
+
padding,
|
|
112
99
|
style: style.parent
|
|
113
100
|
}
|
|
114
101
|
};
|
|
115
|
-
return data.reduce(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
scale: scale,
|
|
102
|
+
return data.reduce((childProps, datum, index) => {
|
|
103
|
+
const eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
|
|
104
|
+
const {
|
|
105
|
+
x,
|
|
106
|
+
y,
|
|
107
|
+
y0,
|
|
108
|
+
x0
|
|
109
|
+
} = getBarPosition(props, datum);
|
|
110
|
+
const dataProps = {
|
|
111
|
+
alignment,
|
|
112
|
+
barRatio,
|
|
113
|
+
barWidth,
|
|
114
|
+
cornerRadius,
|
|
115
|
+
data,
|
|
116
|
+
datum,
|
|
117
|
+
disableInlineStyles,
|
|
118
|
+
getPath,
|
|
119
|
+
horizontal,
|
|
120
|
+
index,
|
|
121
|
+
polar,
|
|
122
|
+
origin,
|
|
123
|
+
scale,
|
|
138
124
|
style: style.data,
|
|
139
|
-
width
|
|
140
|
-
height
|
|
141
|
-
x
|
|
142
|
-
y
|
|
143
|
-
y0
|
|
144
|
-
x0
|
|
125
|
+
width,
|
|
126
|
+
height,
|
|
127
|
+
x,
|
|
128
|
+
y,
|
|
129
|
+
y0,
|
|
130
|
+
x0
|
|
145
131
|
};
|
|
146
132
|
childProps[eventKey] = {
|
|
147
133
|
data: dataProps
|
|
148
134
|
};
|
|
149
|
-
|
|
150
|
-
var text = _victoryCore.LabelHelpers.getText(props, datum, index);
|
|
151
|
-
|
|
135
|
+
const text = _victoryCore.LabelHelpers.getText(props, datum, index);
|
|
152
136
|
if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
|
|
153
137
|
childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
|
|
154
138
|
}
|
|
155
|
-
|
|
156
139
|
return childProps;
|
|
157
140
|
}, initialChildProps);
|
|
158
141
|
};
|
|
159
|
-
|
|
160
142
|
exports.getBaseProps = getBaseProps;
|
package/lib/index.js
CHANGED
|
@@ -75,9 +75,7 @@ Object.defineProperty(exports, "getVerticalPolarBarPath", {
|
|
|
75
75
|
return _pathHelperMethods.getVerticalPolarBarPath;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
-
|
|
79
78
|
var _victoryBar = require("./victory-bar");
|
|
80
|
-
|
|
81
79
|
Object.keys(_victoryBar).forEach(function (key) {
|
|
82
80
|
if (key === "default" || key === "__esModule") return;
|
|
83
81
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -89,9 +87,7 @@ Object.keys(_victoryBar).forEach(function (key) {
|
|
|
89
87
|
}
|
|
90
88
|
});
|
|
91
89
|
});
|
|
92
|
-
|
|
93
90
|
var _bar = require("./bar");
|
|
94
|
-
|
|
95
91
|
Object.keys(_bar).forEach(function (key) {
|
|
96
92
|
if (key === "default" || key === "__esModule") return;
|
|
97
93
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -103,9 +99,6 @@ Object.keys(_bar).forEach(function (key) {
|
|
|
103
99
|
}
|
|
104
100
|
});
|
|
105
101
|
});
|
|
106
|
-
|
|
107
102
|
var _helperMethods = require("./helper-methods");
|
|
108
|
-
|
|
109
103
|
var _pathHelperMethods = require("./path-helper-methods");
|
|
110
|
-
|
|
111
104
|
var _barHelperMethods = require("./bar-helper-methods");
|