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.
@@ -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
- var getPosition = function (props, width) {
23
- var x = props.x,
24
- x0 = props.x0,
25
- y = props.y,
26
- y0 = props.y0,
27
- horizontal = props.horizontal;
28
- var alignment = props.alignment || "middle";
29
- var size = alignment === "middle" ? width / 2 : width;
30
- var sign = horizontal ? -1 : 1;
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: 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: y0,
25
+ y0,
45
26
  y1: y
46
27
  };
47
28
  };
48
-
49
- var getAngle = function (props, index) {
50
- var data = props.data,
51
- scale = props.scale;
52
- var x = data[index]._x1 === undefined ? "_x" : "_x1";
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
- var getAngularWidth = function (props, width) {
57
- var scale = props.scale;
58
- var range = scale.y.range();
59
- var r = Math.max.apply(Math, _toConsumableArray(range));
60
- var angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
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
- export var getCustomBarPath = function (props, width) {
69
- var getPath = props.getPath;
70
-
49
+ export const getCustomBarPath = (props, width) => {
50
+ const {
51
+ getPath
52
+ } = props;
71
53
  if (typeof getPath === "function") {
72
- var propsWithCalculatedValues = _objectSpread(_objectSpread({}, props), getPosition(props, width));
73
-
54
+ const propsWithCalculatedValues = {
55
+ ...props,
56
+ ...getPosition(props, width)
57
+ };
74
58
  return getPath(propsWithCalculatedValues);
75
59
  }
76
60
  };
77
-
78
- var getStartAngle = function (props, index) {
79
- var data = props.data,
80
- scale = props.scale,
81
- alignment = props.alignment;
82
- var currentAngle = getAngle(props, index);
83
- var angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
84
- var previousAngle = index === 0 ? getAngle(props, data.length - 1) - Math.PI * 2 : getAngle(props, index - 1);
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
- var getEndAngle = function (props, index) {
96
- var data = props.data,
97
- scale = props.scale,
98
- alignment = props.alignment;
99
- var currentAngle = getAngle(props, index);
100
- var angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
101
- var lastAngle = scale.x.range()[1] === 2 * Math.PI ? getAngle(props, 0) + Math.PI * 2 : scale.x.range()[1];
102
- var nextAngle = index === data.length - 1 ? getAngle(props, 0) + Math.PI * 2 : getAngle(props, index + 1);
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
- var mapPointsToPath = function (coords, cornerRadius, direction) {
114
- var topLeftPath = "".concat(cornerRadius.topLeft, " ").concat(cornerRadius.topLeft, " ").concat(direction);
115
- var topRightPath = "".concat(cornerRadius.topRight, " ").concat(cornerRadius.topRight, " ").concat(direction);
116
- var bottomLeftPath = "".concat(cornerRadius.bottomLeft, " ").concat(cornerRadius.bottomLeft, " ").concat(direction);
117
- var bottomRightPath = "".concat(cornerRadius.bottomRight, " ").concat(cornerRadius.bottomRight, " ").concat(direction);
118
- var commands = ["M", "A ".concat(bottomLeftPath, ","), "L", "A ".concat(topLeftPath, ","), "L", "A ".concat(topRightPath, ","), "L", "A ".concat(bottomRightPath, ",")];
119
- var path = commands.reduce(function (acc, command, i) {
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
- var getVerticalBarPoints = function (position, sign, cr) {
126
- var x0 = position.x0,
127
- x1 = position.x1,
128
- y0 = position.y0,
129
- y1 = position.y1; // eslint-disable-next-line max-statements, max-len
130
-
131
- var getHalfPoints = function (side) {
132
- var isLeft = side === "Left";
133
- var signL = isLeft ? 1 : -1;
134
- var x = isLeft ? x0 : x1;
135
- var bottomPoint = {
136
- x: x + signL * cr["bottom".concat(side)],
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
- var bottomMiddlePoint = {
140
- x: x,
141
- y: y0 - sign * cr["bottom".concat(side)]
120
+ let bottomMiddlePoint = {
121
+ x,
122
+ y: y0 - sign * cr[`bottom${side}`]
142
123
  };
143
- var topMiddlePoint = {
144
- x: x,
145
- y: y1 + sign * cr["top".concat(side)]
124
+ let topMiddlePoint = {
125
+ x,
126
+ y: y1 + sign * cr[`top${side}`]
146
127
  };
147
- var topPoint = {
148
- x: x + signL * cr["top".concat(side)],
128
+ let topPoint = {
129
+ x: x + signL * cr[`top${side}`],
149
130
  y: y1
150
131
  };
151
- var hasIntersection = sign === 1 ? y0 - cr["bottom".concat(side)] < y1 + cr["top".concat(side)] : y0 + cr["bottom".concat(side)] > y1 - cr["top".concat(side)];
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
- var topCenter = point(x + signL * cr["top".concat(side)], y1 + sign * cr["top".concat(side)]);
155
- var topCircle = circle(topCenter, cr["top".concat(side)]);
156
- var bottomCenter = point(x + signL * cr["bottom".concat(side)], y0 - sign * cr["bottom".concat(side)]);
157
- var bottomCircle = circle(bottomCenter, cr["bottom".concat(side)]);
158
- var circleIntersection = topCircle.intersection(bottomCircle);
159
- var hasArcIntersection = circleIntersection.length > 0;
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
- var arcIntersection = circleIntersection[isLeft ? 0 : 1];
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
- var hasBottomLineTopArcIntersection = cr["top".concat(side)] > cr["bottom".concat(side)];
173
-
151
+ const hasBottomLineTopArcIntersection = cr[`top${side}`] > cr[`bottom${side}`];
174
152
  if (hasBottomLineTopArcIntersection) {
175
- var newX = topCircle.solveX(y0)[isLeft ? 0 : 1];
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
- var _newX = bottomCircle.solveX(y1)[isLeft ? 0 : 1];
167
+ const newX = bottomCircle.solveX(y1)[isLeft ? 0 : 1];
190
168
  bottomMiddlePoint = {
191
- x: _newX,
169
+ x: newX,
192
170
  y: y1
193
171
  };
194
172
  topMiddlePoint = {
195
- x: _newX,
173
+ x: newX,
196
174
  y: y1
197
175
  };
198
176
  topPoint = {
199
- x: _newX,
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
- var getHorizontalBarPoints = function (position, sign, cr) {
214
- var y0 = position.y0,
215
- y1 = position.y1;
216
- var x0 = position.x0 < position.x1 ? position.x0 : position.x1;
217
- var x1 = position.x0 < position.x1 ? position.x1 : position.x0; // eslint-disable-next-line max-statements, max-len
218
-
219
- var getHalfPoints = function (side) {
220
- var isTop = side === "top";
221
- var signL = isTop ? -1 : 1;
222
- var y = isTop ? y1 : y0;
223
- var leftPoint = {
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["".concat(side, "Left")]
203
+ y: y - signL * cr[`${side}Left`]
226
204
  };
227
- var leftMiddlePoint = {
228
- x: x0 + cr["".concat(side, "Left")],
229
- y: y
205
+ let leftMiddlePoint = {
206
+ x: x0 + cr[`${side}Left`],
207
+ y
230
208
  };
231
- var rightMiddlePoint = {
232
- x: x1 - cr["".concat(side, "Right")],
233
- y: y
209
+ let rightMiddlePoint = {
210
+ x: x1 - cr[`${side}Right`],
211
+ y
234
212
  };
235
- var rightPoint = {
213
+ let rightPoint = {
236
214
  x: x1,
237
- y: y - signL * cr["".concat(side, "Right")]
215
+ y: y - signL * cr[`${side}Right`]
238
216
  };
239
- var hasIntersection = leftMiddlePoint.x > rightMiddlePoint.x;
240
-
217
+ const hasIntersection = leftMiddlePoint.x > rightMiddlePoint.x;
241
218
  if (hasIntersection) {
242
- var leftCenter = point(x0 + cr["".concat(side, "Left")], y - signL * cr["".concat(side, "Left")]);
243
- var leftCircle = circle(leftCenter, cr["".concat(side, "Left")]);
244
- var rightCenter = point(x1 - cr["".concat(side, "Right")], y - signL * cr["".concat(side, "Right")]);
245
- var rightCircle = circle(rightCenter, cr["".concat(side, "Right")]);
246
- var circleIntersection = leftCircle.intersection(rightCircle);
247
- var hasArcIntersection = circleIntersection.length > 0;
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
- var arcIntersection = circleIntersection[sign > 0 ? 1 : 0];
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
- var hasLeftLineRightArcIntersection = cr["".concat(side, "Right")] > cr["".concat(side, "Left")];
261
-
236
+ const hasLeftLineRightArcIntersection = cr[`${side}Right`] > cr[`${side}Left`];
262
237
  if (hasLeftLineRightArcIntersection) {
263
- var newY = rightCircle.solveY(x0)[isTop ? 0 : 1];
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
- var _newY = leftCircle.solveY(x1)[isTop ? 0 : 1];
252
+ const newY = leftCircle.solveY(x1)[isTop ? 0 : 1];
278
253
  rightPoint = {
279
254
  x: x1,
280
- y: _newY
255
+ y: newY
281
256
  };
282
257
  rightMiddlePoint = {
283
258
  x: x1,
284
- y: _newY
259
+ y: newY
285
260
  };
286
261
  leftMiddlePoint = {
287
262
  x: x1,
288
- y: _newY
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
- var topPoints = getHalfPoints("top");
298
- var bottomPoints = getHalfPoints("bottom");
299
- return [bottomPoints[1], bottomPoints[0]].concat(_toConsumableArray(topPoints), [// eslint-disable-next-line no-magic-numbers
300
- bottomPoints[3], bottomPoints[2]]);
301
- }; // eslint-disable-next-line max-params
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
- }; // eslint-disable-next-line max-params
284
+ };
311
285
 
312
- export var getHorizontalBarPath = function (props, width, cornerRadius) {
313
- var position = getPosition(props, width);
314
- var sign = position.x0 < position.x1 ? 1 : -1;
315
- var direction = "0 0 1";
316
- var cr = {
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
- var points = getHorizontalBarPoints(position, sign, cr);
297
+ const points = getHorizontalBarPoints(position, sign, cr);
323
298
  return mapPointsToPath(points, cr, direction);
324
299
  };
325
- export var getVerticalPolarBarPath = function (props, cornerRadius) {
326
- var datum = props.datum,
327
- scale = props.scale,
328
- index = props.index,
329
- alignment = props.alignment,
330
- style = props.style;
331
- var r1 = scale.y(datum._y0 || 0);
332
- var r2 = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
333
- var currentAngle = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
334
- var start;
335
- var end;
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
- var width = getAngularWidth(props, style.width);
339
- var size = alignment === "middle" ? width / 2 : width;
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
- var getPath = function (edge) {
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
- var getPathData = function (edge) {
353
- var rightPath = getPath("".concat(edge, "Right"));
354
- var rightMoves = rightPath.match(/[A-Z]/g) || [];
355
- var rightCoords = rightPath.split(/[A-Z]/).slice(1);
356
- var rightMiddle = rightMoves.indexOf("L");
357
- var leftPath = getPath("".concat(edge, "Left"));
358
- var leftMoves = leftPath.match(/[A-Z]/g) || [];
359
- var leftCoords = leftPath.split(/[A-Z]/).slice(1);
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: rightMoves,
363
- rightCoords: rightCoords,
364
- rightMiddle: rightMiddle,
365
- leftMoves: leftMoves,
366
- leftCoords: leftCoords,
367
- leftMiddle: leftMiddle
336
+ rightMoves,
337
+ rightCoords,
338
+ rightMiddle,
339
+ leftMoves,
340
+ leftCoords,
341
+ leftMiddle
368
342
  };
369
- }; // eslint-disable-next-line max-statements
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
- var isShort = function (middle) {
394
- return middle < 3;
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
- var defaultOffset = isShort(rightMiddle) ? leftMiddle : leftMiddle - 2;
371
+ const defaultOffset = isShort(rightMiddle) ? leftMiddle : leftMiddle - 2;
402
372
  leftOffset = isShort(leftMiddle) ? leftMiddle - 1 : defaultOffset;
403
373
  } else {
404
- var _defaultOffset = isShort(leftMiddle) ? 1 : 2;
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
- moves = [].concat(_toConsumableArray(rightMoves.slice(0, rightOffset)), _toConsumableArray(leftMoves.slice(leftOffset)));
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
- var middle = moves.indexOf("L");
414
- var subMoves = moves.slice(0, middle);
415
- var subCoords = coords.slice(0, middle);
416
- return subMoves.map(function (m, i) {
417
- return {
418
- command: m,
419
- coords: subCoords[i].split(",")
420
- };
421
- });
422
- }; // eslint-disable-next-line max-statements
423
-
424
-
425
- var getBottomPath = function () {
426
- var bottomRight = cornerRadius.bottomRight,
427
- bottomLeft = cornerRadius.bottomLeft;
428
- var arcLength = r1 * Math.abs(end - start);
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
- var isShort = function (m, middle) {
447
- return m.length - middle < 4;
448
- };
449
-
450
- var shortPath = bottomRight > bottomLeft ? isShort(rightMoves, rightMiddle) : isShort(leftMoves, leftMiddle); // eslint-disable-next-line no-magic-numbers
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
- var middle = moves.indexOf("L");
458
- var subMoves = moves.slice(middle, -1);
459
- var subCoords = coords.slice(middle, -1);
460
- return subMoves.map(function (m, i) {
461
- return {
462
- command: m,
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
- var topPath = getTopPath();
469
- var bottomPath = getBottomPath();
470
- var moves = [].concat(_toConsumableArray(topPath), _toConsumableArray(bottomPath));
471
- var path = moves.reduce(function (memo, move) {
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 var getBarPath = function (props, width, cornerRadius) {
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 var getPolarBarPath = function (props, cornerRadius) {
438
+ export const getPolarBarPath = (props, cornerRadius) => {
484
439
  // TODO Radial bars
485
440
  return getVerticalPolarBarPath(props, cornerRadius);
486
441
  };