billboard.js 3.6.3 → 3.7.0-next.2

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.
Files changed (91) hide show
  1. package/dist/billboard.css +6 -1
  2. package/dist/billboard.js +1704 -843
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +3819 -2263
  6. package/dist/billboard.pkgd.min.js +6 -3
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +62 -23
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +62 -23
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +48 -14
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +48 -14
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +1087 -1031
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +1171 -1112
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +1222 -1169
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +1159 -1105
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +1365 -1319
  22. package/dist/theme/datalab.css +6 -1
  23. package/dist/theme/datalab.min.css +2 -2
  24. package/dist/theme/graph.css +6 -1
  25. package/dist/theme/graph.min.css +2 -2
  26. package/dist/theme/insight.css +6 -1
  27. package/dist/theme/insight.min.css +2 -2
  28. package/dist-esm/billboard.js +942 -277
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -5
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -9
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +10 -9
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +4 -8
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +3 -5
  34. package/package.json +44 -38
  35. package/src/Chart/api/chart.ts +13 -4
  36. package/src/Chart/api/export.ts +159 -14
  37. package/src/Chart/api/legend.ts +1 -0
  38. package/src/Chart/api/load.ts +1 -0
  39. package/src/Chart/api/tooltip.ts +11 -2
  40. package/src/ChartInternal/Axis/Axis.ts +1 -1
  41. package/src/ChartInternal/ChartInternal.ts +35 -25
  42. package/src/ChartInternal/data/IData.ts +9 -0
  43. package/src/ChartInternal/data/convert.helper.ts +35 -21
  44. package/src/ChartInternal/data/data.ts +26 -5
  45. package/src/ChartInternal/data/load.ts +3 -0
  46. package/src/ChartInternal/interactions/interaction.ts +42 -33
  47. package/src/ChartInternal/internals/class.ts +3 -4
  48. package/src/ChartInternal/internals/clip.ts +13 -10
  49. package/src/ChartInternal/internals/domain.ts +11 -4
  50. package/src/ChartInternal/internals/format.ts +1 -1
  51. package/src/ChartInternal/internals/grid.ts +1 -1
  52. package/src/ChartInternal/internals/legend.ts +3 -2
  53. package/src/ChartInternal/internals/redraw.ts +12 -5
  54. package/src/ChartInternal/internals/scale.ts +7 -2
  55. package/src/ChartInternal/internals/size.ts +41 -26
  56. package/src/ChartInternal/internals/text.ts +60 -32
  57. package/src/ChartInternal/internals/tooltip.ts +12 -8
  58. package/src/ChartInternal/internals/transform.ts +2 -2
  59. package/src/ChartInternal/internals/type.ts +6 -1
  60. package/src/ChartInternal/shape/arc.ts +145 -68
  61. package/src/ChartInternal/shape/area.ts +3 -0
  62. package/src/ChartInternal/shape/bar.ts +4 -1
  63. package/src/ChartInternal/shape/line.ts +12 -15
  64. package/src/ChartInternal/shape/radar.ts +2 -2
  65. package/src/ChartInternal/shape/shape.ts +10 -5
  66. package/src/ChartInternal/shape/treemap.ts +293 -0
  67. package/src/config/Options/common/tooltip.ts +11 -8
  68. package/src/config/Options/data/data.ts +6 -3
  69. package/src/config/Options/shape/arc.ts +47 -0
  70. package/src/config/Options/shape/gauge.ts +2 -2
  71. package/src/config/Options/shape/pie.ts +1 -1
  72. package/src/config/Options/shape/polar.ts +1 -1
  73. package/src/config/Options/shape/radar.ts +1 -1
  74. package/src/config/Options/shape/spline.ts +1 -1
  75. package/src/config/Options/shape/treemap.ts +53 -0
  76. package/src/config/Store/State.ts +1 -0
  77. package/src/config/classes.ts +7 -0
  78. package/src/config/const.ts +4 -2
  79. package/src/config/resolver/shape.ts +22 -5
  80. package/src/index.esm.ts +2 -1
  81. package/src/module/util.ts +1 -1
  82. package/src/scss/billboard.scss +6 -0
  83. package/src/scss/theme/datalab.scss +6 -0
  84. package/src/scss/theme/graph.scss +6 -0
  85. package/src/scss/theme/insight.scss +6 -0
  86. package/types/bb.d.ts +1 -0
  87. package/types/chart.d.ts +7 -0
  88. package/types/index.d.ts +1 -0
  89. package/types/options.d.ts +42 -624
  90. package/types/options.shape.d.ts +664 -0
  91. package/types/types.d.ts +4 -3
@@ -106,7 +106,8 @@ export default {
106
106
  const {$el} = this;
107
107
 
108
108
  $el.main.select(`.${$COMMON.chart}`).append("g")
109
- .attr("class", $TEXT.chartTexts);
109
+ .attr("class", $TEXT.chartTexts)
110
+ .style("pointer-events", $el.treemap ? "none" : null);
110
111
  },
111
112
 
112
113
  /**
@@ -120,9 +121,10 @@ export default {
120
121
  const classTexts = $$.getClass("texts", "id");
121
122
 
122
123
  const classFocus = $$.classFocus.bind($$);
123
- const mainTextUpdate = $$.$el.main.select(`.${$TEXT.chartTexts}`).selectAll(`.${$TEXT.chartText}`)
124
+ const mainTextUpdate = $$.$el.main.select(`.${$TEXT.chartTexts}`)
125
+ .selectAll(`.${$TEXT.chartText}`)
124
126
  .data(targets)
125
- .attr("class", d => classChartText(d) + classFocus(d));
127
+ .attr("class", d => `${classChartText(d)}${classFocus(d)}`.trim());
126
128
 
127
129
  const mainTextEnter = mainTextUpdate.enter().append("g")
128
130
  .style("opacity", "0")
@@ -141,6 +143,7 @@ export default {
141
143
  const $$ = this;
142
144
  const {$el, $T, config} = $$;
143
145
  const classText = $$.getClass("text", "index");
146
+ const labelsCentered = config.data_labels.centered;
144
147
 
145
148
  const text = $el.main.selectAll(`.${$TEXT.texts}`)
146
149
  .selectAll(`.${$TEXT.text}`)
@@ -162,6 +165,8 @@ export default {
162
165
  const data = $$.getCandlestickData(d);
163
166
 
164
167
  isEndAnchor = !data?._isUp;
168
+ } else if ($$.isTreemapType(d)) {
169
+ return labelsCentered ? "middle" : "start";
165
170
  }
166
171
 
167
172
  return (config.axis_rotated ? (isEndAnchor ? "end" : "start") : "middle");
@@ -182,7 +187,8 @@ export default {
182
187
  }
183
188
  }
184
189
 
185
- value = $$.dataLabelFormat(d.id)(value, d.id, i, texts);
190
+ value = $$.isTreemapType(d) ? $$.treemapDataLabelFormat(d)(node) :
191
+ $$.dataLabelFormat(d.id)(value, d.id, i, texts);
186
192
 
187
193
  if (isNumber(value)) {
188
194
  this.textContent = value;
@@ -196,7 +202,8 @@ export default {
196
202
  const $$ = this;
197
203
  const {config} = $$;
198
204
  const labelColors = config.data_labels_colors;
199
- const defaultColor = $$.isArcType(d) && !$$.isRadarType(d) ? null : $$.color(d);
205
+ const defaultColor = ($$.isArcType(d) && !$$.isRadarType(d)) || $$.isTreemapType(d) ?
206
+ null : $$.color(d);
200
207
  let color;
201
208
 
202
209
  if (isString(labelColors)) {
@@ -257,21 +264,23 @@ export default {
257
264
  */
258
265
  redrawText(getX, getY, forFlow?: boolean, withTransition?: boolean): true {
259
266
  const $$ = this;
260
- const {$T, axis, config} = $$;
267
+ const {$T, axis, config, state: {hasTreemap}} = $$;
261
268
  const t = <string>getRandom(true);
262
269
  const isRotated = config.axis_rotated;
263
270
  const angle = config.data_labels.rotate;
264
-
265
271
  const anchorString = getRotateAnchor(angle);
266
272
  const rotateString = angle ? `rotate(${angle})` : "";
267
273
 
274
+
275
+ // $$.meetsLabelThreshold(ratio,
276
+
268
277
  $$.$el.text
269
278
  .style("fill", $$.getStylePropValue($$.updateTextColor))
270
279
  .attr("filter", $$.updateTextBacgroundColor.bind($$))
271
280
  .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
272
281
  .each(function(d: IDataRow, i: number) {
273
282
  // do not apply transition for newly added text elements
274
- const node = $T(this, !!(withTransition && this.getAttribute("x")), t);
283
+ const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this, !!(withTransition && this.getAttribute("x")), t);
275
284
  const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
276
285
  let pos = {
277
286
  x: getX.bind(this)(d, i),
@@ -341,11 +350,13 @@ export default {
341
350
  */
342
351
  generateXYForText(indices, forX?: boolean): (d, i) => number {
343
352
  const $$ = this;
353
+ const {state: {hasRadar, hasTreemap}} = $$;
344
354
  const types = Object.keys(indices);
345
355
  const points = {};
346
356
  const getter = forX ? $$.getXForText : $$.getYForText;
347
357
 
348
- $$.hasType("radar") && types.push("radar");
358
+ hasRadar && types.push("radar");
359
+ hasTreemap && types.push("treemap");
349
360
 
350
361
  types.forEach(v => {
351
362
  points[v] = $$[`generateGet${capitalize(v)}Points`](indices[v], false);
@@ -355,7 +366,8 @@ export default {
355
366
  const type = ($$.isAreaType(d) && "area") ||
356
367
  ($$.isBarType(d) && "bar") ||
357
368
  ($$.isCandlestickType(d) && "candlestick") ||
358
- ($$.isRadarType(d) && "radar") || "line";
369
+ ($$.isRadarType(d) && "radar") ||
370
+ ($$.isTreemapType(d) && "treemap") || "line";
359
371
 
360
372
  return getter.call($$, points[type](d, i), d, this);
361
373
  };
@@ -366,34 +378,44 @@ export default {
366
378
  * @param {object} d Data object
367
379
  * @param {Array} points Data points position
368
380
  * @param {HTMLElement} textElement Data label text element
381
+ * @param {string} type 'x' or 'y'
369
382
  * @returns {number} Position value
370
383
  * @private
371
384
  */
372
- getCenteredTextPos(d, points, textElement): number {
385
+ getCenteredTextPos(d, points, textElement, type: "x" | "y"): number {
373
386
  const $$ = this;
374
387
  const {config} = $$;
375
388
  const isRotated = config.axis_rotated;
389
+ const isBarType = $$.isBarType(d);
390
+ const isTreemapType = $$.isTreemapType(d);
376
391
 
377
- if (config.data_labels.centered && $$.isBarType(d)) {
392
+ if (config.data_labels.centered && (isBarType || isTreemapType)) {
378
393
  const rect = getBoundingRect(textElement);
379
- const isPositive = d.value >= 0;
380
394
 
381
- if (isRotated) {
382
- const w = (
383
- isPositive ?
384
- points[1][1] - points[0][1] :
385
- points[0][1] - points[1][1]
386
- ) / 2 + (rect.width / 2);
395
+ if (isBarType) {
396
+ const isPositive = d.value >= 0;
387
397
 
388
- return isPositive ? -w - 3 : w + 2;
389
- } else {
390
- const h = (
391
- isPositive ?
392
- points[0][1] - points[1][1] :
393
- points[1][1] - points[0][1]
394
- ) / 2 + (rect.height / 2);
398
+ if (isRotated) {
399
+ const w = (
400
+ isPositive ?
401
+ points[1][1] - points[0][1] :
402
+ points[0][1] - points[1][1]
403
+ ) / 2 + (rect.width / 2);
404
+
405
+ return isPositive ? -w - 3 : w + 2;
406
+ } else {
407
+ const h = (
408
+ isPositive ?
409
+ points[0][1] - points[1][1] :
410
+ points[1][1] - points[0][1]
411
+ ) / 2 + (rect.height / 2);
395
412
 
396
- return isPositive ? h : -h - 2;
413
+ return isPositive ? h : -h - 2;
414
+ }
415
+ } else if (isTreemapType) {
416
+ return type === "x" ?
417
+ (points[1][0] - points[0][0]) / 2 :
418
+ (points[1][1] - points[0][1]) / 2 + (rect.height / 2);
397
419
  }
398
420
  }
399
421
 
@@ -425,6 +447,7 @@ export default {
425
447
  const $$ = this;
426
448
  const {config, state} = $$;
427
449
  const isRotated = config.axis_rotated;
450
+ const isTreemapType = $$.isTreemapType(d);
428
451
  let xPos = points[0][0];
429
452
 
430
453
  if ($$.isCandlestickType(d)) {
@@ -434,6 +457,8 @@ export default {
434
457
  } else {
435
458
  xPos += (points[1][0] - xPos) / 2;
436
459
  }
460
+ } else if (isTreemapType) {
461
+ xPos += config.data_labels.centered ? 0 : 5;
437
462
  } else {
438
463
  if (isRotated) {
439
464
  const padding = $$.isBarType(d) ? 4 : 6;
@@ -455,8 +480,8 @@ export default {
455
480
  }
456
481
  }
457
482
 
458
- if (isRotated) {
459
- xPos += $$.getCenteredTextPos(d, points, textElement);
483
+ if (isRotated || isTreemapType) {
484
+ xPos += $$.getCenteredTextPos(d, points, textElement, "x");
460
485
  }
461
486
 
462
487
  return xPos + $$.getTextPos(d.id, "x");
@@ -476,6 +501,7 @@ export default {
476
501
  const isRotated = config.axis_rotated;
477
502
  const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
478
503
  const isBarType = $$.isBarType(d);
504
+ const isTreemapType = $$.isTreemapType(d);
479
505
  const r = config.point_r;
480
506
  const rect = getBoundingRect(textElement);
481
507
  let {value} = d;
@@ -497,6 +523,8 @@ export default {
497
523
  yPos += 15 * (value._isUp ? 1 : -1);
498
524
  }
499
525
  }
526
+ } else if (isTreemapType) {
527
+ yPos = points[0][1] + (config.data_labels.centered ? 0 : rect.height + 5);
500
528
  } else {
501
529
  if (isRotated) {
502
530
  yPos = (points[0][0] + points[2][0] + rect.height * 0.6) / 2;
@@ -540,8 +568,8 @@ export default {
540
568
  }
541
569
  }
542
570
 
543
- if (!isRotated) {
544
- yPos += $$.getCenteredTextPos(d, points, textElement);
571
+ if (!isRotated || isTreemapType) {
572
+ yPos += $$.getCenteredTextPos(d, points, textElement, "y");
545
573
  }
546
574
 
547
575
  return yPos + $$.getTextPos(d.id, "y");
@@ -601,7 +629,7 @@ export default {
601
629
  * @returns {boolean}
602
630
  * @private
603
631
  */
604
- meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie" | "polar"): boolean {
632
+ meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie" | "polar" | "treemap"): boolean {
605
633
  const $$ = this;
606
634
  const {config} = $$;
607
635
  const threshold = config[`${type}_label_threshold`] || 0;
@@ -105,7 +105,7 @@ export default {
105
105
  */
106
106
  getTooltipContent(d, defaultTitleFormat, defaultValueFormat, color): string {
107
107
  const $$ = this;
108
- const {api, config, state} = $$;
108
+ const {api, config, state, $el} = $$;
109
109
 
110
110
  let [titleFormat, nameFormat, valueFormat] = ["title", "name", "value"].map(v => {
111
111
  const fn = config[`tooltip_format_${v}`];
@@ -116,7 +116,7 @@ export default {
116
116
  titleFormat = titleFormat || defaultTitleFormat;
117
117
  nameFormat = nameFormat || (name => name);
118
118
  valueFormat = valueFormat || (
119
- $$.isStackNormalized() ? (v, ratio) => `${(ratio * 100).toFixed(2)}%` : defaultValueFormat
119
+ state.hasTreemap || $$.isStackNormalized() ? (v, ratio) => `${(ratio * 100).toFixed(2)}%` : defaultValueFormat
120
120
  );
121
121
 
122
122
  const order = config.tooltip_order;
@@ -183,8 +183,9 @@ export default {
183
183
  });
184
184
  }
185
185
 
186
- if (!row.ratio && $$.$el.arcs) {
187
- row.ratio = $$.getRatio("arc", $$.$el.arcs.select(`path.${$ARC.arc}-${row.id}`).data()[0]);
186
+ if (!row.ratio && $el.arcs) {
187
+ param = ["arc", $$.$el.arcs.select(`path.${$ARC.arc}-${row.id}`).data()[0]];
188
+ row.ratio = $$.getRatio(...param);
188
189
  }
189
190
 
190
191
  param = [row.ratio, row.id, row.index, d];
@@ -271,6 +272,7 @@ export default {
271
272
  const {config, scale, state} = $$;
272
273
  const {width, height, current, isLegendRight, inputType, event} = state;
273
274
  const hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
275
+ const hasTreemap = state.hasTreemap;
274
276
  const svgLeft = $$.getSvgLeft(true);
275
277
  let chartRight = svgLeft + current.width - $$.getCurrentPaddingRight();
276
278
  const chartLeft = $$.getCurrentPaddingLeft(true);
@@ -285,7 +287,7 @@ export default {
285
287
  y += hasGauge ? height : height / 2;
286
288
  x += (width - (isLegendRight ? $$.getLegendWidth() : 0)) / 2;
287
289
  }
288
- } else {
290
+ } else if (!hasTreemap) {
289
291
  const dataScale = scale.x(dataToShow[0].x);
290
292
 
291
293
  if (config.axis_rotated) {
@@ -294,17 +296,19 @@ export default {
294
296
  chartRight -= svgLeft;
295
297
  } else {
296
298
  y -= 5;
297
- x = svgLeft + chartLeft + size + ($$.scale.zoom ? x : dataScale);
299
+ x = svgLeft + chartLeft + size + (scale.zoom ? x : dataScale);
298
300
  }
299
301
  }
300
302
 
301
303
  // when tooltip left + tWidth > chart's width
302
304
  if ((x + tWidth + 15) > chartRight) {
303
- x -= tWidth + chartLeft;
305
+ x -= tWidth + (hasTreemap ? 0 : chartLeft);
304
306
  }
305
307
 
306
308
  if (y + tHeight > current.height) {
307
- y -= hasGauge ? tHeight * 3 : tHeight + 30;
309
+ const gap = hasTreemap ? 0 : 30;
310
+
311
+ y -= hasGauge ? tHeight * 3 : tHeight + gap;
308
312
  }
309
313
 
310
314
  const pos = {top: y, left: x};
@@ -87,9 +87,9 @@ export default {
87
87
 
88
88
  transformAll(withTransition: boolean, transitions): void {
89
89
  const $$ = this;
90
- const {config, state: {hasAxis}, $el} = $$;
90
+ const {config, state: {hasAxis, hasTreemap}, $el} = $$;
91
91
 
92
- $$.transformMain(withTransition, transitions);
92
+ !hasTreemap && $$.transformMain(withTransition, transitions);
93
93
 
94
94
  hasAxis && config.subchart_show &&
95
95
  $$.transformContext(withTransition, transitions);
@@ -175,6 +175,10 @@ export default {
175
175
  return this.isTypeOf(d, "scatter");
176
176
  },
177
177
 
178
+ isTreemapType(d): boolean {
179
+ return this.isTypeOf(d, "treemap");
180
+ },
181
+
178
182
  isPieType(d): boolean {
179
183
  return this.isTypeOf(d, "pie");
180
184
  },
@@ -241,7 +245,8 @@ export default {
241
245
  this.isScatterType(d) ||
242
246
  this.isBubbleType(d) ||
243
247
  this.isCandlestickType(d) ||
244
- this.isRadarType(d) ? d.values.filter(v => isNumber(v.value) || Boolean(v.value)) : [];
248
+ this.isRadarType(d) ||
249
+ this.isTreemapType(d) ? d.values.filter(v => isNumber(v.value) || Boolean(v.value)) : [];
245
250
  },
246
251
 
247
252
  barLineBubbleData(d) {
@@ -12,7 +12,119 @@ import {document} from "../../module/browser";
12
12
  import {$ARC, $COMMON, $FOCUS, $GAUGE} from "../../config/classes";
13
13
  import {callFn, endall, isFunction, isNumber, isObject, isUndefined, setTextValue} from "../../module/util";
14
14
  import type {d3Selection} from "../../../types/types";
15
- import type {IArcData, IData} from "../data/IData";
15
+ import type {IArcData, IArcDataRow, IData} from "../data/IData";
16
+
17
+ /**
18
+ * Get radius functions
19
+ * @param {number} expandRate Expand rate number.
20
+ * - If 0, means for "normal" radius.
21
+ * - If > 0, means for "expanded" radius.
22
+ * @returns {object} radius functions
23
+ * @private
24
+ */
25
+ function getRadiusFn(expandRate = 0) {
26
+ const $$ = this;
27
+ const {config, state} = $$;
28
+ const hasMultiArcGauge = $$.hasMultiArcGauge();
29
+ const singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
30
+ const expandWidth = expandRate ? (
31
+ Math.min(
32
+ state.radiusExpanded * expandRate - state.radius,
33
+ singleArcWidth * 0.8 - (1 - expandRate) * 100
34
+ )) : 0;
35
+
36
+ return {
37
+ /**
38
+ * Getter of arc innerRadius value
39
+ * @param {IArcData} d Data object
40
+ * @returns {number} innerRadius value
41
+ * @private
42
+ */
43
+ inner(d: IArcData) {
44
+ const {innerRadius} = $$.getRadius(d);
45
+
46
+ return hasMultiArcGauge ?
47
+ state.radius - singleArcWidth * (d.index + 1) :
48
+ isNumber(innerRadius) ? innerRadius : 0;
49
+ },
50
+
51
+ /**
52
+ * Getter of arc outerRadius value
53
+ * @param {IArcData} d Data object
54
+ * @returns {number} outerRadius value
55
+ * @private
56
+ */
57
+ outer(d: IArcData) {
58
+ const {outerRadius} = $$.getRadius(d);
59
+ let radius: number;
60
+
61
+ if (hasMultiArcGauge) {
62
+ radius = state.radius - singleArcWidth * d.index + expandWidth;
63
+ } else if ($$.hasType("polar") && !expandRate) {
64
+ radius = $$.getPolarOuterRadius(d, outerRadius);
65
+ } else {
66
+ radius = outerRadius;
67
+
68
+ if (expandRate) {
69
+ let {radiusExpanded} = state;
70
+
71
+ if (state.radius !== outerRadius) {
72
+ radiusExpanded -= Math.abs(state.radius - outerRadius);
73
+ }
74
+
75
+ radius = radiusExpanded * expandRate;
76
+ }
77
+ }
78
+
79
+ return radius;
80
+ },
81
+
82
+ /**
83
+ * Getter of arc cornerRadius value
84
+ * @param {IArcData} d Data object
85
+ * @param {number} outerRadius outer radius value
86
+ * @returns {number} cornerRadius value
87
+ * @private
88
+ */
89
+ corner(d: IArcData, outerRadius): number {
90
+ const {
91
+ arc_cornerRadius_ratio: ratio = 0,
92
+ arc_cornerRadius: cornerRadius = 0
93
+ } = config;
94
+ const {data: {id}, value} = d;
95
+ let corner = 0;
96
+
97
+ if (ratio) {
98
+ corner = ratio * outerRadius;
99
+ } else {
100
+ corner = isNumber(cornerRadius) ?
101
+ cornerRadius : cornerRadius.call($$.api, id, value, outerRadius);
102
+ }
103
+
104
+ return corner;
105
+ }
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Get attrTween function to get interpolated value on transition
111
+ * @param {Function} fn Arc function to execute
112
+ * @returns {Function} attrTween function
113
+ * @private
114
+ */
115
+ function getAttrTweenFn(fn: (d: IArcData) => string) {
116
+ return function(d: IArcData): (t: number) => string {
117
+ const interpolate = d3Interpolate(this._current, d);
118
+
119
+ this._current = d;
120
+
121
+ return function(t: number): string {
122
+ const interpolated = interpolate(t);
123
+
124
+ return fn(interpolated);
125
+ };
126
+ };
127
+ }
16
128
 
17
129
  export default {
18
130
  initPie(): void {
@@ -192,42 +304,22 @@ export default {
192
304
 
193
305
  getSvgArc(): Function {
194
306
  const $$ = this;
195
- const {state} = $$;
196
- const singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
197
- const hasMultiArcGauge = $$.hasMultiArcGauge();
198
- const hasPolar = $$.hasType("polar");
307
+ const {inner, outer, corner} = getRadiusFn.call($$);
199
308
 
200
309
  const arc = d3Arc()
201
- .innerRadius((d: any) => {
202
- const {innerRadius} = $$.getRadius(d);
203
-
204
- return hasMultiArcGauge ?
205
- state.radius - singleArcWidth * (d.index + 1) :
206
- isNumber(innerRadius) ? innerRadius : 0;
207
- })
208
- .outerRadius((d: any) => {
209
- const {outerRadius} = $$.getRadius(d);
210
- let radius = outerRadius;
211
-
212
- if (hasMultiArcGauge) {
213
- radius = state.radius - singleArcWidth * d.index;
214
- } else if (hasPolar) {
215
- radius = $$.getPolarOuterRadius(d, outerRadius);
216
- }
217
-
218
- return radius;
219
- });
310
+ .innerRadius(inner)
311
+ .outerRadius(outer);
220
312
 
221
313
  const newArc = function(d, withoutUpdate) {
222
314
  let path: string | null = "M 0 0";
223
315
 
224
316
  if (d.value || d.data) {
225
- const updated = !withoutUpdate && $$.updateAngle(d);
317
+ const data = withoutUpdate ? d : $$.updateAngle(d) ?? null;
226
318
 
227
- if (withoutUpdate) {
228
- path = arc(d);
229
- } else if (updated) {
230
- path = arc(updated);
319
+ if (data) {
320
+ path = arc.cornerRadius(
321
+ corner(data, outer(data))
322
+ )(data);
231
323
  }
232
324
  }
233
325
 
@@ -240,45 +332,30 @@ export default {
240
332
  return newArc;
241
333
  },
242
334
 
243
- getSvgArcExpanded(rate?: number): Function {
335
+ /**
336
+ * Get expanded arc path function
337
+ * @param {number} rate Expand rate
338
+ * @returns {Function} Expanded arc path getter function
339
+ * @private
340
+ */
341
+ getSvgArcExpanded(rate = 1): (d: IArcData) => string {
244
342
  const $$ = this;
245
- const {state} = $$;
246
- const newRate = rate || 1;
247
- const singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
248
- const hasMultiArcGauge = $$.hasMultiArcGauge();
249
- const expandWidth = Math.min(state.radiusExpanded * newRate - state.radius,
250
- singleArcWidth * 0.8 - (1 - newRate) * 100
251
- );
343
+ const {inner, outer, corner} = getRadiusFn.call($$, rate);
252
344
 
253
345
  const arc = d3Arc()
254
- .innerRadius((d: any) => (
255
- hasMultiArcGauge ?
256
- state.radius - singleArcWidth * (d.index + 1) : $$.getRadius(d).innerRadius
257
- ))
258
- .outerRadius((d: any) => {
259
- let radius: number;
260
-
261
- if (hasMultiArcGauge) {
262
- radius = state.radius - singleArcWidth * d.index + expandWidth;
263
- } else {
264
- const {outerRadius} = $$.getRadius(d);
346
+ .innerRadius(inner)
347
+ .outerRadius(outer);
265
348
 
266
- let {radiusExpanded} = state;
267
-
268
- if (state.radius !== outerRadius) {
269
- radiusExpanded -= Math.abs(state.radius - outerRadius);
270
- }
271
-
272
- radius = radiusExpanded * newRate;
273
- }
274
-
275
- return radius;
276
- });
277
-
278
- return function(d) {
349
+ return (d: IArcData): string => {
279
350
  const updated = $$.updateAngle(d);
351
+ const outerR = outer(updated);
352
+ let cornerR = 0;
353
+
354
+ if (updated) {
355
+ cornerR = corner(updated, outerR);
356
+ }
280
357
 
281
- return updated ? arc(updated) : "M 0 0";
358
+ return updated ? <string>arc.cornerRadius(cornerR)(updated) : "M 0 0";
282
359
  };
283
360
  },
284
361
 
@@ -292,7 +369,7 @@ export default {
292
369
  * @returns {string} Translate attribute string
293
370
  * @private
294
371
  */
295
- transformForArcLabel(d): string {
372
+ transformForArcLabel(d: IArcData): string {
296
373
  const $$ = this;
297
374
  const {config, state: {radiusExpanded}} = $$;
298
375
 
@@ -337,9 +414,9 @@ export default {
337
414
  return translate;
338
415
  },
339
416
 
340
- convertToArcData(d): object {
417
+ convertToArcData(d: IArcData | IArcDataRow): object {
341
418
  return this.addName({
342
- id: d.data ? d.data.id : d.id,
419
+ id: "data" in d ? d.data.id : d.id,
343
420
  value: d.value,
344
421
  ratio: this.getRatio("arc", d),
345
422
  index: d.index,
@@ -408,10 +485,10 @@ export default {
408
485
  d3Select(this).selectAll("path")
409
486
  .transition()
410
487
  .duration(expandDuration)
411
- .attr("d", $$.svgArcExpanded)
488
+ .attrTween("d", getAttrTweenFn($$.svgArcExpanded.bind($$)))
412
489
  .transition()
413
490
  .duration(expandDuration * 2)
414
- .attr("d", svgArcExpandedSub);
491
+ .attrTween("d", getAttrTweenFn(svgArcExpandedSub.bind($$)));
415
492
  });
416
493
  },
417
494
 
@@ -429,7 +506,7 @@ export default {
429
506
  .selectAll("path")
430
507
  .transition()
431
508
  .duration(d => $$.getExpandConfig(d.data.id, "duration"))
432
- .attr("d", $$.svgArc);
509
+ .attrTween("d", getAttrTweenFn($$.svgArc.bind($$)));
433
510
 
434
511
  svg.selectAll(`${$ARC.arc}`)
435
512
  .style("opacity", null);
@@ -65,6 +65,9 @@ export default {
65
65
  .merge(area);
66
66
 
67
67
  area.style("opacity", state.orgAreaOpacity);
68
+
69
+ // calculate ratio if grouped data exists
70
+ $$.setRatioForGroupedData($root.area.data());
68
71
  },
69
72
 
70
73
  /**
@@ -41,7 +41,7 @@ export default {
41
41
  $$.initBar();
42
42
  }
43
43
 
44
- const mainBarUpdate = $$.$el.main.select(`.${$BAR.chartBars}`)
44
+ const mainBarUpdate = $el.main.select(`.${$BAR.chartBars}`)
45
45
  .selectAll(`.${$BAR.chartBar}`)
46
46
  .data(
47
47
  // remove
@@ -91,6 +91,9 @@ export default {
91
91
  .style("fill", $$.updateBarColor.bind($$))
92
92
  .merge(bar)
93
93
  .style("opacity", initialOpacity);
94
+
95
+ // calculate ratio if grouped data exists
96
+ $$.setRatioForGroupedData($root.bar.data());
94
97
  },
95
98
 
96
99
  /**