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