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,176 +4,150 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getVerticalPolarBarPath = exports.getVerticalBarPath = exports.getPolarBarPath = exports.getHorizontalBarPath = exports.getCustomBarPath = exports.getBarPath = void 0;
|
|
7
|
-
|
|
8
7
|
var d3Shape = _interopRequireWildcard(require("victory-vendor/d3-shape"));
|
|
9
|
-
|
|
10
8
|
var _geometryHelperMethods = require("./geometry-helper-methods");
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
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."); }
|
|
25
|
-
|
|
26
|
-
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); }
|
|
27
|
-
|
|
28
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
29
|
-
|
|
30
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
31
|
-
|
|
32
|
-
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; }
|
|
33
|
-
|
|
34
|
-
var getPosition = function (props, width) {
|
|
35
|
-
var x = props.x,
|
|
36
|
-
x0 = props.x0,
|
|
37
|
-
y = props.y,
|
|
38
|
-
y0 = props.y0,
|
|
39
|
-
horizontal = props.horizontal;
|
|
40
|
-
var alignment = props.alignment || "middle";
|
|
41
|
-
var size = alignment === "middle" ? width / 2 : width;
|
|
42
|
-
var sign = horizontal ? -1 : 1;
|
|
43
|
-
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
const getPosition = (props, width) => {
|
|
12
|
+
const {
|
|
13
|
+
x,
|
|
14
|
+
x0,
|
|
15
|
+
y,
|
|
16
|
+
y0,
|
|
17
|
+
horizontal
|
|
18
|
+
} = props;
|
|
19
|
+
const alignment = props.alignment || "middle";
|
|
20
|
+
const size = alignment === "middle" ? width / 2 : width;
|
|
21
|
+
const sign = horizontal ? -1 : 1;
|
|
44
22
|
if (horizontal) {
|
|
45
23
|
return {
|
|
46
|
-
x0
|
|
24
|
+
x0,
|
|
47
25
|
x1: x,
|
|
48
26
|
y0: alignment === "start" ? y : y - sign * size,
|
|
49
27
|
y1: alignment === "end" ? y : y + sign * size
|
|
50
28
|
};
|
|
51
29
|
}
|
|
52
|
-
|
|
53
30
|
return {
|
|
54
31
|
x0: alignment === "start" ? x : x - sign * size,
|
|
55
32
|
x1: alignment === "end" ? x : x + sign * size,
|
|
56
|
-
y0
|
|
33
|
+
y0,
|
|
57
34
|
y1: y
|
|
58
35
|
};
|
|
59
36
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
37
|
+
const getAngle = (props, index) => {
|
|
38
|
+
const {
|
|
39
|
+
data,
|
|
40
|
+
scale
|
|
41
|
+
} = props;
|
|
42
|
+
const x = data[index]._x1 === undefined ? "_x" : "_x1";
|
|
65
43
|
return scale.x(data[index][x]);
|
|
66
44
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
const getAngularWidth = (props, width) => {
|
|
46
|
+
const {
|
|
47
|
+
scale
|
|
48
|
+
} = props;
|
|
49
|
+
const range = scale.y.range();
|
|
50
|
+
const r = Math.max(...range);
|
|
51
|
+
const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
|
|
73
52
|
return width / (2 * Math.PI * r) * angularRange;
|
|
74
53
|
};
|
|
75
|
-
|
|
76
|
-
var transformAngle = function (angle) {
|
|
54
|
+
const transformAngle = angle => {
|
|
77
55
|
return -1 * angle + Math.PI / 2;
|
|
78
56
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
57
|
+
const getCustomBarPath = (props, width) => {
|
|
58
|
+
const {
|
|
59
|
+
getPath
|
|
60
|
+
} = props;
|
|
83
61
|
if (typeof getPath === "function") {
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
const propsWithCalculatedValues = {
|
|
63
|
+
...props,
|
|
64
|
+
...getPosition(props, width)
|
|
65
|
+
};
|
|
86
66
|
return getPath(propsWithCalculatedValues);
|
|
87
67
|
}
|
|
88
68
|
};
|
|
89
|
-
|
|
90
69
|
exports.getCustomBarPath = getCustomBarPath;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
70
|
+
const getStartAngle = (props, index) => {
|
|
71
|
+
const {
|
|
72
|
+
data,
|
|
73
|
+
scale,
|
|
74
|
+
alignment
|
|
75
|
+
} = props;
|
|
76
|
+
const currentAngle = getAngle(props, index);
|
|
77
|
+
const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
|
|
78
|
+
const previousAngle = index === 0 ? getAngle(props, data.length - 1) - Math.PI * 2 : getAngle(props, index - 1);
|
|
100
79
|
if (index === 0 && angularRange < 2 * Math.PI) {
|
|
101
80
|
return scale.x.range()[0];
|
|
102
81
|
} else if (alignment === "start" || alignment === "end") {
|
|
103
82
|
return alignment === "start" ? previousAngle : currentAngle;
|
|
104
83
|
}
|
|
105
|
-
|
|
106
84
|
return (currentAngle + previousAngle) / 2;
|
|
107
85
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
86
|
+
const getEndAngle = (props, index) => {
|
|
87
|
+
const {
|
|
88
|
+
data,
|
|
89
|
+
scale,
|
|
90
|
+
alignment
|
|
91
|
+
} = props;
|
|
92
|
+
const currentAngle = getAngle(props, index);
|
|
93
|
+
const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
|
|
94
|
+
const lastAngle = scale.x.range()[1] === 2 * Math.PI ? getAngle(props, 0) + Math.PI * 2 : scale.x.range()[1];
|
|
95
|
+
const nextAngle = index === data.length - 1 ? getAngle(props, 0) + Math.PI * 2 : getAngle(props, index + 1);
|
|
118
96
|
if (index === data.length - 1 && angularRange < 2 * Math.PI) {
|
|
119
97
|
return lastAngle;
|
|
120
98
|
} else if (alignment === "start" || alignment === "end") {
|
|
121
99
|
return alignment === "start" ? currentAngle : nextAngle;
|
|
122
100
|
}
|
|
123
|
-
|
|
124
101
|
return (currentAngle + nextAngle) / 2;
|
|
125
102
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return "".concat(acc).concat(command, " ").concat(coords[i].x, ", ").concat(coords[i].y, " \n");
|
|
135
|
-
}, "");
|
|
136
|
-
return "".concat(path, " z");
|
|
103
|
+
const mapPointsToPath = (coords, cornerRadius, direction) => {
|
|
104
|
+
const topLeftPath = `${cornerRadius.topLeft} ${cornerRadius.topLeft} ${direction}`;
|
|
105
|
+
const topRightPath = `${cornerRadius.topRight} ${cornerRadius.topRight} ${direction}`;
|
|
106
|
+
const bottomLeftPath = `${cornerRadius.bottomLeft} ${cornerRadius.bottomLeft} ${direction}`;
|
|
107
|
+
const bottomRightPath = `${cornerRadius.bottomRight} ${cornerRadius.bottomRight} ${direction}`;
|
|
108
|
+
const commands = ["M", `A ${bottomLeftPath},`, "L", `A ${topLeftPath},`, "L", `A ${topRightPath},`, "L", `A ${bottomRightPath},`];
|
|
109
|
+
const path = commands.reduce((acc, command, i) => `${acc}${command} ${coords[i].x}, ${coords[i].y} \n`, "");
|
|
110
|
+
return `${path} z`;
|
|
137
111
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
const getVerticalBarPoints = (position, sign, cr) => {
|
|
113
|
+
const {
|
|
114
|
+
x0,
|
|
115
|
+
x1,
|
|
116
|
+
y0,
|
|
117
|
+
y1
|
|
118
|
+
} = position;
|
|
119
|
+
|
|
120
|
+
// eslint-disable-next-line max-statements, max-len
|
|
121
|
+
const getHalfPoints = side => {
|
|
122
|
+
const isLeft = side === "Left";
|
|
123
|
+
const signL = isLeft ? 1 : -1;
|
|
124
|
+
const x = isLeft ? x0 : x1;
|
|
125
|
+
let bottomPoint = {
|
|
126
|
+
x: x + signL * cr[`bottom${side}`],
|
|
151
127
|
y: y0
|
|
152
128
|
};
|
|
153
|
-
|
|
154
|
-
x
|
|
155
|
-
y: y0 - sign * cr[
|
|
129
|
+
let bottomMiddlePoint = {
|
|
130
|
+
x,
|
|
131
|
+
y: y0 - sign * cr[`bottom${side}`]
|
|
156
132
|
};
|
|
157
|
-
|
|
158
|
-
x
|
|
159
|
-
y: y1 + sign * cr[
|
|
133
|
+
let topMiddlePoint = {
|
|
134
|
+
x,
|
|
135
|
+
y: y1 + sign * cr[`top${side}`]
|
|
160
136
|
};
|
|
161
|
-
|
|
162
|
-
x: x + signL * cr[
|
|
137
|
+
let topPoint = {
|
|
138
|
+
x: x + signL * cr[`top${side}`],
|
|
163
139
|
y: y1
|
|
164
140
|
};
|
|
165
|
-
|
|
166
|
-
|
|
141
|
+
const hasIntersection = sign === 1 ? y0 - cr[`bottom${side}`] < y1 + cr[`top${side}`] : y0 + cr[`bottom${side}`] > y1 - cr[`top${side}`];
|
|
167
142
|
if (hasIntersection) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
143
|
+
const topCenter = (0, _geometryHelperMethods.point)(x + signL * cr[`top${side}`], y1 + sign * cr[`top${side}`]);
|
|
144
|
+
const topCircle = (0, _geometryHelperMethods.circle)(topCenter, cr[`top${side}`]);
|
|
145
|
+
const bottomCenter = (0, _geometryHelperMethods.point)(x + signL * cr[`bottom${side}`], y0 - sign * cr[`bottom${side}`]);
|
|
146
|
+
const bottomCircle = (0, _geometryHelperMethods.circle)(bottomCenter, cr[`bottom${side}`]);
|
|
147
|
+
const circleIntersection = topCircle.intersection(bottomCircle);
|
|
148
|
+
const hasArcIntersection = circleIntersection.length > 0;
|
|
175
149
|
if (hasArcIntersection) {
|
|
176
|
-
|
|
150
|
+
const arcIntersection = circleIntersection[isLeft ? 0 : 1];
|
|
177
151
|
bottomMiddlePoint = {
|
|
178
152
|
x: arcIntersection.x,
|
|
179
153
|
y: arcIntersection.y
|
|
@@ -183,10 +157,9 @@ var getVerticalBarPoints = function (position, sign, cr) {
|
|
|
183
157
|
y: arcIntersection.y
|
|
184
158
|
};
|
|
185
159
|
} else {
|
|
186
|
-
|
|
187
|
-
|
|
160
|
+
const hasBottomLineTopArcIntersection = cr[`top${side}`] > cr[`bottom${side}`];
|
|
188
161
|
if (hasBottomLineTopArcIntersection) {
|
|
189
|
-
|
|
162
|
+
const newX = topCircle.solveX(y0)[isLeft ? 0 : 1];
|
|
190
163
|
bottomPoint = {
|
|
191
164
|
x: newX,
|
|
192
165
|
y: y0
|
|
@@ -200,68 +173,66 @@ var getVerticalBarPoints = function (position, sign, cr) {
|
|
|
200
173
|
y: y0
|
|
201
174
|
};
|
|
202
175
|
} else {
|
|
203
|
-
|
|
176
|
+
const newX = bottomCircle.solveX(y1)[isLeft ? 0 : 1];
|
|
204
177
|
bottomMiddlePoint = {
|
|
205
|
-
x:
|
|
178
|
+
x: newX,
|
|
206
179
|
y: y1
|
|
207
180
|
};
|
|
208
181
|
topMiddlePoint = {
|
|
209
|
-
x:
|
|
182
|
+
x: newX,
|
|
210
183
|
y: y1
|
|
211
184
|
};
|
|
212
185
|
topPoint = {
|
|
213
|
-
x:
|
|
186
|
+
x: newX,
|
|
214
187
|
y: y1
|
|
215
188
|
};
|
|
216
189
|
}
|
|
217
190
|
}
|
|
218
191
|
}
|
|
219
|
-
|
|
220
|
-
var points = [bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint];
|
|
192
|
+
const points = [bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint];
|
|
221
193
|
return isLeft ? points : points.reverse();
|
|
222
194
|
};
|
|
223
|
-
|
|
224
195
|
return getHalfPoints("Left").concat(getHalfPoints("Right"));
|
|
225
196
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
197
|
+
const getHorizontalBarPoints = (position, sign, cr) => {
|
|
198
|
+
const {
|
|
199
|
+
y0,
|
|
200
|
+
y1
|
|
201
|
+
} = position;
|
|
202
|
+
const x0 = position.x0 < position.x1 ? position.x0 : position.x1;
|
|
203
|
+
const x1 = position.x0 < position.x1 ? position.x1 : position.x0;
|
|
204
|
+
|
|
205
|
+
// eslint-disable-next-line max-statements, max-len
|
|
206
|
+
const getHalfPoints = side => {
|
|
207
|
+
const isTop = side === "top";
|
|
208
|
+
const signL = isTop ? -1 : 1;
|
|
209
|
+
const y = isTop ? y1 : y0;
|
|
210
|
+
let leftPoint = {
|
|
238
211
|
x: x0,
|
|
239
|
-
y: y - signL * cr[
|
|
212
|
+
y: y - signL * cr[`${side}Left`]
|
|
240
213
|
};
|
|
241
|
-
|
|
242
|
-
x: x0 + cr[
|
|
243
|
-
y
|
|
214
|
+
let leftMiddlePoint = {
|
|
215
|
+
x: x0 + cr[`${side}Left`],
|
|
216
|
+
y
|
|
244
217
|
};
|
|
245
|
-
|
|
246
|
-
x: x1 - cr[
|
|
247
|
-
y
|
|
218
|
+
let rightMiddlePoint = {
|
|
219
|
+
x: x1 - cr[`${side}Right`],
|
|
220
|
+
y
|
|
248
221
|
};
|
|
249
|
-
|
|
222
|
+
let rightPoint = {
|
|
250
223
|
x: x1,
|
|
251
|
-
y: y - signL * cr[
|
|
224
|
+
y: y - signL * cr[`${side}Right`]
|
|
252
225
|
};
|
|
253
|
-
|
|
254
|
-
|
|
226
|
+
const hasIntersection = leftMiddlePoint.x > rightMiddlePoint.x;
|
|
255
227
|
if (hasIntersection) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
228
|
+
const leftCenter = (0, _geometryHelperMethods.point)(x0 + cr[`${side}Left`], y - signL * cr[`${side}Left`]);
|
|
229
|
+
const leftCircle = (0, _geometryHelperMethods.circle)(leftCenter, cr[`${side}Left`]);
|
|
230
|
+
const rightCenter = (0, _geometryHelperMethods.point)(x1 - cr[`${side}Right`], y - signL * cr[`${side}Right`]);
|
|
231
|
+
const rightCircle = (0, _geometryHelperMethods.circle)(rightCenter, cr[`${side}Right`]);
|
|
232
|
+
const circleIntersection = leftCircle.intersection(rightCircle);
|
|
233
|
+
const hasArcIntersection = circleIntersection.length > 0;
|
|
263
234
|
if (hasArcIntersection) {
|
|
264
|
-
|
|
235
|
+
const arcIntersection = circleIntersection[sign > 0 ? 1 : 0];
|
|
265
236
|
leftMiddlePoint = {
|
|
266
237
|
x: arcIntersection.x,
|
|
267
238
|
y: arcIntersection.y
|
|
@@ -271,10 +242,9 @@ var getHorizontalBarPoints = function (position, sign, cr) {
|
|
|
271
242
|
y: arcIntersection.y
|
|
272
243
|
};
|
|
273
244
|
} else {
|
|
274
|
-
|
|
275
|
-
|
|
245
|
+
const hasLeftLineRightArcIntersection = cr[`${side}Right`] > cr[`${side}Left`];
|
|
276
246
|
if (hasLeftLineRightArcIntersection) {
|
|
277
|
-
|
|
247
|
+
const newY = rightCircle.solveY(x0)[isTop ? 0 : 1];
|
|
278
248
|
leftPoint = {
|
|
279
249
|
x: x0,
|
|
280
250
|
y: newY
|
|
@@ -288,227 +258,198 @@ var getHorizontalBarPoints = function (position, sign, cr) {
|
|
|
288
258
|
y: newY
|
|
289
259
|
};
|
|
290
260
|
} else {
|
|
291
|
-
|
|
261
|
+
const newY = leftCircle.solveY(x1)[isTop ? 0 : 1];
|
|
292
262
|
rightPoint = {
|
|
293
263
|
x: x1,
|
|
294
|
-
y:
|
|
264
|
+
y: newY
|
|
295
265
|
};
|
|
296
266
|
rightMiddlePoint = {
|
|
297
267
|
x: x1,
|
|
298
|
-
y:
|
|
268
|
+
y: newY
|
|
299
269
|
};
|
|
300
270
|
leftMiddlePoint = {
|
|
301
271
|
x: x1,
|
|
302
|
-
y:
|
|
272
|
+
y: newY
|
|
303
273
|
};
|
|
304
274
|
}
|
|
305
275
|
}
|
|
306
276
|
}
|
|
307
|
-
|
|
308
277
|
return [leftPoint, leftMiddlePoint, rightMiddlePoint, rightPoint];
|
|
309
278
|
};
|
|
279
|
+
const topPoints = getHalfPoints("top");
|
|
280
|
+
const bottomPoints = getHalfPoints("bottom");
|
|
281
|
+
return [bottomPoints[1], bottomPoints[0], ...topPoints,
|
|
282
|
+
// eslint-disable-next-line no-magic-numbers
|
|
283
|
+
bottomPoints[3], bottomPoints[2]];
|
|
284
|
+
};
|
|
310
285
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
var getVerticalBarPath = function (props, width, cornerRadius) {
|
|
319
|
-
var position = getPosition(props, width);
|
|
320
|
-
var sign = position.y0 > position.y1 ? 1 : -1;
|
|
321
|
-
var direction = sign > 0 ? "0 0 1" : "0 0 0";
|
|
322
|
-
var points = getVerticalBarPoints(position, sign, cornerRadius);
|
|
286
|
+
// eslint-disable-next-line max-params
|
|
287
|
+
const getVerticalBarPath = (props, width, cornerRadius) => {
|
|
288
|
+
const position = getPosition(props, width);
|
|
289
|
+
const sign = position.y0 > position.y1 ? 1 : -1;
|
|
290
|
+
const direction = sign > 0 ? "0 0 1" : "0 0 0";
|
|
291
|
+
const points = getVerticalBarPoints(position, sign, cornerRadius);
|
|
323
292
|
return mapPointsToPath(points, cornerRadius, direction);
|
|
324
|
-
};
|
|
325
|
-
|
|
293
|
+
};
|
|
326
294
|
|
|
295
|
+
// eslint-disable-next-line max-params
|
|
327
296
|
exports.getVerticalBarPath = getVerticalBarPath;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
var cr = {
|
|
297
|
+
const getHorizontalBarPath = (props, width, cornerRadius) => {
|
|
298
|
+
const position = getPosition(props, width);
|
|
299
|
+
const sign = position.x0 < position.x1 ? 1 : -1;
|
|
300
|
+
const direction = "0 0 1";
|
|
301
|
+
const cr = {
|
|
334
302
|
topRight: sign > 0 ? cornerRadius.topLeft : cornerRadius.bottomLeft,
|
|
335
303
|
bottomRight: sign > 0 ? cornerRadius.topRight : cornerRadius.bottomRight,
|
|
336
304
|
bottomLeft: sign > 0 ? cornerRadius.bottomRight : cornerRadius.topRight,
|
|
337
305
|
topLeft: sign > 0 ? cornerRadius.bottomLeft : cornerRadius.topLeft
|
|
338
306
|
};
|
|
339
|
-
|
|
307
|
+
const points = getHorizontalBarPoints(position, sign, cr);
|
|
340
308
|
return mapPointsToPath(points, cr, direction);
|
|
341
309
|
};
|
|
342
|
-
|
|
343
310
|
exports.getHorizontalBarPath = getHorizontalBarPath;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
311
|
+
const getVerticalPolarBarPath = (props, cornerRadius) => {
|
|
312
|
+
const {
|
|
313
|
+
datum,
|
|
314
|
+
scale,
|
|
315
|
+
index,
|
|
316
|
+
alignment,
|
|
317
|
+
style
|
|
318
|
+
} = props;
|
|
319
|
+
const r1 = scale.y(datum._y0 || 0);
|
|
320
|
+
const r2 = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
|
|
321
|
+
const currentAngle = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
|
|
322
|
+
let start;
|
|
323
|
+
let end;
|
|
357
324
|
if (style.width) {
|
|
358
|
-
|
|
359
|
-
|
|
325
|
+
const width = getAngularWidth(props, style.width);
|
|
326
|
+
const size = alignment === "middle" ? width / 2 : width;
|
|
360
327
|
start = alignment === "start" ? currentAngle : currentAngle - size;
|
|
361
328
|
end = alignment === "end" ? currentAngle : currentAngle + size;
|
|
362
329
|
} else {
|
|
363
330
|
start = getStartAngle(props, Number(index));
|
|
364
331
|
end = getEndAngle(props, Number(index));
|
|
365
332
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
var pathFunction = d3Shape.arc().innerRadius(r1).outerRadius(r2).startAngle(transformAngle(start)).endAngle(transformAngle(end)).cornerRadius(cornerRadius[edge]);
|
|
333
|
+
const getPath = edge => {
|
|
334
|
+
const pathFunction = d3Shape.arc().innerRadius(r1).outerRadius(r2).startAngle(transformAngle(start)).endAngle(transformAngle(end)).cornerRadius(cornerRadius[edge]);
|
|
369
335
|
return pathFunction();
|
|
370
336
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
var leftMiddle = leftMoves.indexOf("L");
|
|
337
|
+
const getPathData = edge => {
|
|
338
|
+
const rightPath = getPath(`${edge}Right`);
|
|
339
|
+
const rightMoves = rightPath.match(/[A-Z]/g) || [];
|
|
340
|
+
const rightCoords = rightPath.split(/[A-Z]/).slice(1);
|
|
341
|
+
const rightMiddle = rightMoves.indexOf("L");
|
|
342
|
+
const leftPath = getPath(`${edge}Left`);
|
|
343
|
+
const leftMoves = leftPath.match(/[A-Z]/g) || [];
|
|
344
|
+
const leftCoords = leftPath.split(/[A-Z]/).slice(1);
|
|
345
|
+
const leftMiddle = leftMoves.indexOf("L");
|
|
381
346
|
return {
|
|
382
|
-
rightMoves
|
|
383
|
-
rightCoords
|
|
384
|
-
rightMiddle
|
|
385
|
-
leftMoves
|
|
386
|
-
leftCoords
|
|
387
|
-
leftMiddle
|
|
347
|
+
rightMoves,
|
|
348
|
+
rightCoords,
|
|
349
|
+
rightMiddle,
|
|
350
|
+
leftMoves,
|
|
351
|
+
leftCoords,
|
|
352
|
+
leftMiddle
|
|
388
353
|
};
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
var getTopPath = function () {
|
|
393
|
-
var topRight = cornerRadius.topRight,
|
|
394
|
-
topLeft = cornerRadius.topLeft;
|
|
395
|
-
var arcLength = r2 * Math.abs(end - start);
|
|
396
|
-
|
|
397
|
-
var _getPathData = getPathData("top"),
|
|
398
|
-
rightMoves = _getPathData.rightMoves,
|
|
399
|
-
rightCoords = _getPathData.rightCoords,
|
|
400
|
-
rightMiddle = _getPathData.rightMiddle,
|
|
401
|
-
leftMoves = _getPathData.leftMoves,
|
|
402
|
-
leftCoords = _getPathData.leftCoords,
|
|
403
|
-
leftMiddle = _getPathData.leftMiddle;
|
|
404
|
-
|
|
405
|
-
var moves;
|
|
406
|
-
var coords;
|
|
354
|
+
};
|
|
407
355
|
|
|
356
|
+
// eslint-disable-next-line max-statements
|
|
357
|
+
const getTopPath = () => {
|
|
358
|
+
const {
|
|
359
|
+
topRight,
|
|
360
|
+
topLeft
|
|
361
|
+
} = cornerRadius;
|
|
362
|
+
const arcLength = r2 * Math.abs(end - start);
|
|
363
|
+
const {
|
|
364
|
+
rightMoves,
|
|
365
|
+
rightCoords,
|
|
366
|
+
rightMiddle,
|
|
367
|
+
leftMoves,
|
|
368
|
+
leftCoords,
|
|
369
|
+
leftMiddle
|
|
370
|
+
} = getPathData("top");
|
|
371
|
+
let moves;
|
|
372
|
+
let coords;
|
|
408
373
|
if (topRight === topLeft || arcLength < 2 * topRight + 2 * topLeft) {
|
|
409
374
|
moves = topRight > topLeft ? rightMoves : leftMoves;
|
|
410
375
|
coords = topRight > topLeft ? rightCoords : leftCoords;
|
|
411
376
|
} else {
|
|
412
377
|
// eslint-disable-next-line no-magic-numbers
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
var rightOffset = topLeft > topRight && isShort(rightMiddle) ? 1 : 2;
|
|
418
|
-
var leftOffset;
|
|
419
|
-
|
|
378
|
+
const isShort = middle => middle < 3;
|
|
379
|
+
const rightOffset = topLeft > topRight && isShort(rightMiddle) ? 1 : 2;
|
|
380
|
+
let leftOffset;
|
|
420
381
|
if (topRight > topLeft) {
|
|
421
|
-
|
|
382
|
+
const defaultOffset = isShort(rightMiddle) ? leftMiddle : leftMiddle - 2;
|
|
422
383
|
leftOffset = isShort(leftMiddle) ? leftMiddle - 1 : defaultOffset;
|
|
423
384
|
} else {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
leftOffset = isShort(rightMiddle) ? _defaultOffset : leftMiddle - 2;
|
|
385
|
+
const defaultOffset = isShort(leftMiddle) ? 1 : 2;
|
|
386
|
+
leftOffset = isShort(rightMiddle) ? defaultOffset : leftMiddle - 2;
|
|
427
387
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
coords = [].concat(_toConsumableArray(rightCoords.slice(0, rightOffset)), _toConsumableArray(leftCoords.slice(leftOffset)));
|
|
388
|
+
moves = [...rightMoves.slice(0, rightOffset), ...leftMoves.slice(leftOffset)];
|
|
389
|
+
coords = [...rightCoords.slice(0, rightOffset), ...leftCoords.slice(leftOffset)];
|
|
431
390
|
}
|
|
391
|
+
const middle = moves.indexOf("L");
|
|
392
|
+
const subMoves = moves.slice(0, middle);
|
|
393
|
+
const subCoords = coords.slice(0, middle);
|
|
394
|
+
return subMoves.map((m, i) => ({
|
|
395
|
+
command: m,
|
|
396
|
+
coords: subCoords[i].split(",")
|
|
397
|
+
}));
|
|
398
|
+
};
|
|
432
399
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
var _getPathData2 = getPathData("bottom"),
|
|
451
|
-
rightMoves = _getPathData2.rightMoves,
|
|
452
|
-
rightCoords = _getPathData2.rightCoords,
|
|
453
|
-
rightMiddle = _getPathData2.rightMiddle,
|
|
454
|
-
leftMoves = _getPathData2.leftMoves,
|
|
455
|
-
leftCoords = _getPathData2.leftCoords,
|
|
456
|
-
leftMiddle = _getPathData2.leftMiddle;
|
|
457
|
-
|
|
458
|
-
var moves;
|
|
459
|
-
var coords;
|
|
460
|
-
|
|
400
|
+
// eslint-disable-next-line max-statements
|
|
401
|
+
const getBottomPath = () => {
|
|
402
|
+
const {
|
|
403
|
+
bottomRight,
|
|
404
|
+
bottomLeft
|
|
405
|
+
} = cornerRadius;
|
|
406
|
+
const arcLength = r1 * Math.abs(end - start);
|
|
407
|
+
const {
|
|
408
|
+
rightMoves,
|
|
409
|
+
rightCoords,
|
|
410
|
+
rightMiddle,
|
|
411
|
+
leftMoves,
|
|
412
|
+
leftCoords,
|
|
413
|
+
leftMiddle
|
|
414
|
+
} = getPathData("bottom");
|
|
415
|
+
let moves;
|
|
416
|
+
let coords;
|
|
461
417
|
if (bottomRight === bottomLeft || arcLength < 2 * bottomRight + 2 * bottomLeft) {
|
|
462
418
|
moves = bottomRight > bottomLeft ? rightMoves : leftMoves;
|
|
463
419
|
coords = bottomRight > bottomLeft ? rightCoords : leftCoords;
|
|
464
420
|
} else {
|
|
465
421
|
// eslint-disable-next-line no-magic-numbers
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
var rightOffset = shortPath ? -1 : -3;
|
|
473
|
-
moves = [].concat(_toConsumableArray(leftMoves.slice(0, leftMiddle + 2)), _toConsumableArray(rightMoves.slice(rightOffset)));
|
|
474
|
-
coords = [].concat(_toConsumableArray(leftCoords.slice(0, leftMiddle + 2)), _toConsumableArray(rightCoords.slice(rightOffset)));
|
|
422
|
+
const isShort = (m, middle) => m.length - middle < 4;
|
|
423
|
+
const shortPath = bottomRight > bottomLeft ? isShort(rightMoves, rightMiddle) : isShort(leftMoves, leftMiddle);
|
|
424
|
+
// eslint-disable-next-line no-magic-numbers
|
|
425
|
+
const rightOffset = shortPath ? -1 : -3;
|
|
426
|
+
moves = [...leftMoves.slice(0, leftMiddle + 2), ...rightMoves.slice(rightOffset)];
|
|
427
|
+
coords = [...leftCoords.slice(0, leftMiddle + 2), ...rightCoords.slice(rightOffset)];
|
|
475
428
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
coords: subCoords[i].split(",")
|
|
484
|
-
};
|
|
485
|
-
});
|
|
429
|
+
const middle = moves.indexOf("L");
|
|
430
|
+
const subMoves = moves.slice(middle, -1);
|
|
431
|
+
const subCoords = coords.slice(middle, -1);
|
|
432
|
+
return subMoves.map((m, i) => ({
|
|
433
|
+
command: m,
|
|
434
|
+
coords: subCoords[i].split(",")
|
|
435
|
+
}));
|
|
486
436
|
};
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
return "".concat(memo).concat(move.command, " ").concat(move.coords.join());
|
|
493
|
-
}, "");
|
|
494
|
-
return "".concat(path, " z");
|
|
437
|
+
const topPath = getTopPath();
|
|
438
|
+
const bottomPath = getBottomPath();
|
|
439
|
+
const moves = [...topPath, ...bottomPath];
|
|
440
|
+
const path = moves.reduce((memo, move) => `${memo}${move.command} ${move.coords.join()}`, "");
|
|
441
|
+
return `${path} z`;
|
|
495
442
|
};
|
|
496
|
-
|
|
497
443
|
exports.getVerticalPolarBarPath = getVerticalPolarBarPath;
|
|
498
|
-
|
|
499
|
-
var getBarPath = function (props, width, cornerRadius) {
|
|
444
|
+
const getBarPath = (props, width, cornerRadius) => {
|
|
500
445
|
if (props.getPath) {
|
|
501
446
|
return getCustomBarPath(props, width);
|
|
502
447
|
}
|
|
503
|
-
|
|
504
448
|
return props.horizontal ? getHorizontalBarPath(props, width, cornerRadius) : getVerticalBarPath(props, width, cornerRadius);
|
|
505
449
|
};
|
|
506
|
-
|
|
507
450
|
exports.getBarPath = getBarPath;
|
|
508
|
-
|
|
509
|
-
var getPolarBarPath = function (props, cornerRadius) {
|
|
451
|
+
const getPolarBarPath = (props, cornerRadius) => {
|
|
510
452
|
// TODO Radial bars
|
|
511
453
|
return getVerticalPolarBarPath(props, cornerRadius);
|
|
512
454
|
};
|
|
513
|
-
|
|
514
455
|
exports.getPolarBarPath = getPolarBarPath;
|