billboard.js 3.2.0 → 3.3.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 (79) hide show
  1. package/dist/billboard.css +2 -3
  2. package/dist/billboard.js +422 -147
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +5645 -3320
  6. package/dist/billboard.pkgd.min.js +3 -3
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.d.ts +7 -0
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.d.ts +7 -0
  11. package/dist/plugin/billboardjs-plugin-sparkline.js +19 -14
  12. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-stanford.d.ts +7 -0
  14. package/dist/plugin/billboardjs-plugin-stanford.js +17 -12
  15. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-tableview.d.ts +7 -0
  17. package/dist/plugin/billboardjs-plugin-tableview.js +19 -14
  18. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  19. package/dist/plugin/billboardjs-plugin-textoverlap.d.ts +7 -0
  20. package/dist/plugin/billboardjs-plugin-textoverlap.js +17 -12
  21. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +5061 -3202
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +5087 -3223
  24. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +5086 -3222
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +5080 -3216
  26. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +5079 -3215
  27. package/dist/theme/datalab.css +2 -2
  28. package/dist/theme/datalab.min.css +2 -2
  29. package/dist/theme/graph.css +2 -2
  30. package/dist/theme/graph.min.css +2 -2
  31. package/dist/theme/insight.css +2 -2
  32. package/dist/theme/insight.min.css +2 -2
  33. package/dist-esm/billboard.js +723 -484
  34. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.d.ts +7 -0
  35. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  36. package/dist-esm/plugin/billboardjs-plugin-sparkline.d.ts +7 -0
  37. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +8 -8
  38. package/dist-esm/plugin/billboardjs-plugin-stanford.d.ts +7 -0
  39. package/dist-esm/plugin/billboardjs-plugin-stanford.js +15 -15
  40. package/dist-esm/plugin/billboardjs-plugin-tableview.d.ts +7 -0
  41. package/dist-esm/plugin/billboardjs-plugin-tableview.js +6 -6
  42. package/dist-esm/plugin/billboardjs-plugin-textoverlap.d.ts +7 -0
  43. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +4 -4
  44. package/package.json +60 -60
  45. package/src/Chart/api/data.ts +3 -4
  46. package/src/ChartInternal/Axis/Axis.ts +15 -9
  47. package/src/ChartInternal/ChartInternal.ts +11 -2
  48. package/src/ChartInternal/data/IData.ts +9 -0
  49. package/src/ChartInternal/data/convert.ts +1 -1
  50. package/src/ChartInternal/data/data.ts +29 -12
  51. package/src/ChartInternal/internals/domain.ts +31 -31
  52. package/src/ChartInternal/internals/legend.ts +2 -1
  53. package/src/ChartInternal/internals/redraw.ts +2 -2
  54. package/src/ChartInternal/internals/scale.ts +3 -2
  55. package/src/ChartInternal/internals/size.ts +32 -1
  56. package/src/ChartInternal/internals/text.ts +4 -4
  57. package/src/ChartInternal/internals/tooltip.ts +4 -0
  58. package/src/ChartInternal/shape/arc.ts +3 -5
  59. package/src/ChartInternal/shape/bar.ts +89 -34
  60. package/src/ChartInternal/shape/radar.ts +2 -0
  61. package/src/ChartInternal/shape/shape.ts +72 -11
  62. package/src/Plugin/sparkline/index.ts +2 -2
  63. package/src/Plugin/tableview/index.ts +1 -1
  64. package/src/config/Options/axis/x.ts +27 -7
  65. package/src/config/Options/axis/y.ts +24 -3
  66. package/src/config/Options/axis/y2.ts +24 -3
  67. package/src/config/Options/common/main.ts +11 -1
  68. package/src/config/Options/data/data.ts +25 -3
  69. package/src/config/Options/shape/bar.ts +9 -2
  70. package/src/module/util.ts +19 -20
  71. package/src/scss/billboard.scss +1 -13
  72. package/src/scss/theme/datalab.scss +1 -7
  73. package/src/scss/theme/graph.scss +1 -2
  74. package/src/scss/theme/insight.scss +1 -2
  75. package/types/axis.d.ts +18 -4
  76. package/types/options.d.ts +43 -36
  77. package/types/plugin/tableview/index.d.ts +3 -3
  78. package/types/plugin/tableview/options.d.ts +1 -1
  79. package/types/types.d.ts +9 -6
@@ -82,7 +82,7 @@ export default {
82
82
  * @returns {number} index number
83
83
  * @private
84
84
  */
85
- getIndexByX(x, basedX: (string|Date)[]): number {
85
+ getIndexByX(x: Date|number|string, basedX: (Date|number|string)[]): number {
86
86
  const $$ = this;
87
87
 
88
88
  return basedX ?
@@ -154,7 +154,7 @@ export default {
154
154
  .map(t => $$.addName($$.getValueOnIndex(t.values, index)));
155
155
 
156
156
  if (filterNull) {
157
- value = value.filter(v => isValue(v.value));
157
+ value = value.filter(v => v && "value" in v && isValue(v.value));
158
158
  }
159
159
 
160
160
  return value;
@@ -412,7 +412,7 @@ export default {
412
412
  return target;
413
413
  },
414
414
 
415
- mapToIds(targets) {
415
+ mapToIds(targets): string[] {
416
416
  return targets.map(d => d.id);
417
417
  },
418
418
 
@@ -586,6 +586,7 @@ export default {
586
586
 
587
587
  /**
588
588
  * Sort targets data
589
+ * Note: For stacked bar, will sort from the total sum of data series, not for each stacked bar
589
590
  * @param {Array} targetsValue Target value
590
591
  * @returns {Array}
591
592
  * @private
@@ -617,9 +618,9 @@ export default {
617
618
  if (orderAsc || orderDesc) {
618
619
  const reducer = (p, c) => p + Math.abs(c.value);
619
620
 
620
- fn = (t1, t2) => {
621
- const t1Sum = t1.values.reduce(reducer, 0);
622
- const t2Sum = t2.values.reduce(reducer, 0);
621
+ fn = (t1: IData | IDataRow, t2: IData | IDataRow) => {
622
+ const t1Sum = "values" in t1 ? t1.values.reduce(reducer, 0) : t1.value;
623
+ const t2Sum = "values" in t2 ? t2.values.reduce(reducer, 0) : t2.value;
623
624
 
624
625
  return isArc ?
625
626
  (orderAsc ? t1Sum - t2Sum : t2Sum - t1Sum) :
@@ -743,20 +744,23 @@ export default {
743
744
  let minDist = config.point_sensitivity;
744
745
  let closest;
745
746
 
746
- // find mouseovering bar
747
+ // find mouseovering bar/candlestick
748
+ // https://github.com/naver/billboard.js/issues/2434
747
749
  data
748
- .filter(v => $$.isBarType(v.id))
750
+ .filter(v => $$.isBarType(v.id) || $$.isCandlestickType(v.id))
749
751
  .forEach(v => {
750
- const shape = main.select(`.${CLASS.bars}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.bar}-${v.index}`).node();
752
+ const selector = $$.isBarType(v.id) ?
753
+ `.${CLASS.chartBar}.${CLASS.target}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.bar}-${v.index}` :
754
+ `.${CLASS.chartCandlestick}.${CLASS.target}${$$.getTargetSelectorSuffix(v.id)} .${CLASS.candlestick}-${v.index} path`;
751
755
 
752
- if (!closest && $$.isWithinBar(shape)) {
756
+ if (!closest && $$.isWithinBar(main.select(selector).node())) {
753
757
  closest = v;
754
758
  }
755
759
  });
756
760
 
757
- // find closest point from non-bar
761
+ // find closest point from non-bar/candlestick
758
762
  data
759
- .filter(v => !$$.isBarType(v.id))
763
+ .filter(v => !$$.isBarType(v.id) && !$$.isCandlestickType(v.id))
760
764
  .forEach(v => {
761
765
  const d = $$.dist(v, pos);
762
766
 
@@ -983,6 +987,19 @@ export default {
983
987
  );
984
988
  },
985
989
 
990
+ /**
991
+ * Determine if bar has ranged data
992
+ * @param {Array} d data value
993
+ * @returns {boolean}
994
+ * @private
995
+ */
996
+ isBarRangeType(d): boolean {
997
+ const $$ = this;
998
+ const {value} = d;
999
+
1000
+ return $$.isBarType(d) && isArray(value) && value.length === 2 && value.every(v => isNumber(v));
1001
+ },
1002
+
986
1003
  /**
987
1004
  * Get data object by id
988
1005
  * @param {string} id data id
@@ -19,41 +19,39 @@ export default {
19
19
  if (dataGroups.length > 0) {
20
20
  const hasValue = $$[`has${isMin ? "Negative" : "Positive"}ValueInTargets`](targets);
21
21
 
22
- for (let j = 0, idsInGroup; (idsInGroup = dataGroups[j]); j++) {
22
+ dataGroups.forEach(groupIds => {
23
23
  // Determine baseId
24
- idsInGroup = idsInGroup.filter(v => ids.indexOf(v) >= 0);
24
+ const idsInGroup = groupIds
25
+ .filter(v => ids.indexOf(v) >= 0);
25
26
 
26
- if (idsInGroup.length === 0) {
27
- continue;
28
- }
29
-
30
- const baseId = idsInGroup[0];
31
- const baseAxisId = axis.getId(baseId);
27
+ if (idsInGroup.length) {
28
+ const baseId = idsInGroup[0];
29
+ const baseAxisId = axis.getId(baseId);
32
30
 
33
- // Initialize base value. Set to 0 if not match with the condition
34
- if (hasValue && ys[baseId]) {
35
- ys[baseId] = ys[baseId].map(v => (
36
- (isMin ? v < 0 : v > 0) ? v : 0
37
- ));
38
- }
39
-
40
- for (let k = 1, id; (id = idsInGroup[k]); k++) {
41
- if (!ys[id]) {
42
- continue;
31
+ // Initialize base value. Set to 0 if not match with the condition
32
+ if (hasValue && ys[baseId]) {
33
+ ys[baseId] = ys[baseId]
34
+ .map(v => ((isMin ? v < 0 : v > 0) ? v : 0));
43
35
  }
44
36
 
45
- const axisId = axis.getId(id);
46
-
47
- ys[id].forEach((v, i) => {
48
- const val = +v;
49
- const meetCondition = isMin ? val > 0 : val < 0;
50
-
51
- if (axisId === baseAxisId && !(hasValue && meetCondition)) {
52
- ys[baseId][i] += val;
53
- }
54
- });
37
+ idsInGroup
38
+ .filter((v, i) => i > 0)
39
+ .forEach(id => {
40
+ if (ys[id]) {
41
+ const axisId = axis.getId(id);
42
+
43
+ ys[id].forEach((v, i) => {
44
+ const val = +v;
45
+ const meetCondition = isMin ? val > 0 : val < 0;
46
+
47
+ if (axisId === baseAxisId && !(hasValue && meetCondition)) {
48
+ ys[baseId][i] += val;
49
+ }
50
+ });
51
+ }
52
+ });
55
53
  }
56
- }
54
+ });
57
55
  }
58
56
 
59
57
  return getMinMax(type, Object.keys(ys).map(key => getMinMax(type, ys[key])));
@@ -147,7 +145,7 @@ export default {
147
145
  }
148
146
 
149
147
  const domainLength = Math.abs(yDomainMax - yDomainMin);
150
- const padding = {top: domainLength * 0.1, bottom: domainLength * 0.1};
148
+ let padding = {top: domainLength * 0.1, bottom: domainLength * 0.1};
151
149
 
152
150
  if (isDefined(center)) {
153
151
  const yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax));
@@ -173,6 +171,8 @@ export default {
173
171
  });
174
172
  }
175
173
 
174
+ padding = $$.getResettedPadding(padding);
175
+
176
176
  // if padding is set, the domain will be updated relative the current domain value
177
177
  // ex) $$.height=300, padding.top=150, domainLength=4 --> domain=6
178
178
  const p = config[`${pfx}_padding`];
@@ -235,7 +235,7 @@ export default {
235
235
 
236
236
  defaultValue = maxDataCount > 1 ? (diff / (maxDataCount - 1)) / 2 : 0.5;
237
237
  } else {
238
- defaultValue = diff * 0.01;
238
+ defaultValue = $$.getResettedPadding(diff * 0.01);
239
239
  }
240
240
 
241
241
  let {left = defaultValue, right = defaultValue} = isNumber(padding) ?
@@ -622,8 +622,9 @@ export default {
622
622
  .attr("href", (data, idx, selection) => {
623
623
  const node = selection[idx];
624
624
  const nodeName = node.nodeName.toLowerCase();
625
+ const id = $$.getTargetSelectorSuffix(data);
625
626
 
626
- return nodeName === "use" ? `#${state.datetimeId}-point-${data}` : undefined;
627
+ return nodeName === "use" ? `#${state.datetimeId}-point${id}` : undefined;
627
628
  });
628
629
  } else {
629
630
  l.append("line")
@@ -16,8 +16,7 @@ export default {
16
16
  state.redrawing = true;
17
17
 
18
18
  const targetsToShow = $$.filterTargetsToShow($$.data.targets);
19
- const initializing = options.initializing;
20
- const flow = options.flow;
19
+ const {flow, initializing} = options;
21
20
  const wth = $$.getWithOption(options);
22
21
  const duration = wth.Transition ? config.transition_duration : 0;
23
22
  const durationForExit = wth.TransitionForExit ? duration : 0;
@@ -247,6 +246,7 @@ export default {
247
246
  redrawWithoutRescale() {
248
247
  this.redraw({
249
248
  withY: false,
249
+ withLegend: true,
250
250
  withSubchart: false,
251
251
  withEventRect: false,
252
252
  withTransitionForAxis: false
@@ -146,10 +146,11 @@ export default {
146
146
 
147
147
  if (hasAxis) {
148
148
  const isRotated = config.axis_rotated;
149
+ const resettedPadding = $$.getResettedPadding(1);
149
150
 
150
151
  // update edges
151
152
  const min = {
152
- x: isRotated ? 1 : 0,
153
+ x: isRotated ? resettedPadding : 0,
153
154
  y: isRotated ? 0 : height,
154
155
  subX: isRotated ? 1 : 0,
155
156
  subY: isRotated ? 0 : height2
@@ -157,7 +158,7 @@ export default {
157
158
 
158
159
  const max = {
159
160
  x: isRotated ? height : width,
160
- y: isRotated ? width : 1,
161
+ y: isRotated ? width : resettedPadding,
161
162
  subX: isRotated ? height : width,
162
163
  subY: isRotated ? width2 : 1
163
164
  };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import {document} from "../../module/browser";
6
6
  import CLASS from "../../config/classes";
7
- import {isValue, ceil10, capitalize} from "../../module/util";
7
+ import {isValue, ceil10, capitalize, isNumber, isEmpty} from "../../module/util";
8
8
 
9
9
  export default {
10
10
  /**
@@ -232,6 +232,35 @@ export default {
232
232
  }
233
233
  },
234
234
 
235
+ /**
236
+ * Get resetted padding values when 'padding=false' option is set
237
+ * https://github.com/naver/billboard.js/issues/2367
238
+ * @param {number|object} v Padding values to be resetted
239
+ * @returns {number|object} Padding value
240
+ * @private
241
+ */
242
+ getResettedPadding<T = number | {[key: string]: string;}>(v: T): T {
243
+ const $$ = this;
244
+ const {config} = $$;
245
+ const isNum = isNumber(v);
246
+ let p = isNum ? 0 : {};
247
+
248
+ if (config.padding === false) {
249
+ !isNum && Object.keys(v).forEach(key => {
250
+ // when data.lables=true, do not reset top padding
251
+ p[key] = (
252
+ !isEmpty(config.data_labels) &&
253
+ config.data_labels !== false &&
254
+ key === "top"
255
+ ) ? v[key] : 0;
256
+ });
257
+ } else {
258
+ p = v;
259
+ }
260
+
261
+ return p as T;
262
+ },
263
+
235
264
  /**
236
265
  * Update size values
237
266
  * @param {boolean} isInit If is called at initialization
@@ -275,6 +304,8 @@ export default {
275
304
  left: hasArc ? 0 : $$.getCurrentPaddingLeft()
276
305
  };
277
306
 
307
+ state.margin = $$.getResettedPadding(state.margin);
308
+
278
309
  // for subchart
279
310
  state.margin2 = isRotated ? {
280
311
  top: state.margin.top,
@@ -91,7 +91,7 @@ export default {
91
91
  })
92
92
  .style("fill", $$.updateTextColor.bind($$))
93
93
  .style("fill-opacity", "0")
94
- .each(function(d, i, j) {
94
+ .each(function(d, i, texts) {
95
95
  const node = d3Select(this);
96
96
  let {value} = d;
97
97
 
@@ -105,7 +105,7 @@ export default {
105
105
  }
106
106
  }
107
107
 
108
- value = $$.dataLabelFormat(d.id)(value, d.id, i, j);
108
+ value = $$.dataLabelFormat(d.id)(value, d.id, i, texts);
109
109
 
110
110
  if (isNumber(value)) {
111
111
  this.textContent = value;
@@ -339,9 +339,9 @@ export default {
339
339
  let xPos = points[0][0];
340
340
 
341
341
 
342
- if ($$.hasType("candlestick")) {
342
+ if ($$.isCandlestickType(d)) {
343
343
  if (isRotated) {
344
- xPos = $$.getCandlestickData(d)._isUp ?
344
+ xPos = $$.getCandlestickData(d)?._isUp ?
345
345
  points[2][2] + 4 : points[2][1] - 4;
346
346
  } else {
347
347
  xPos += (points[1][0] - xPos) / 2;
@@ -203,6 +203,10 @@ export default {
203
203
  ));
204
204
 
205
205
  value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
206
+ } else if ($$.isBarRangeType(row)) {
207
+ const [start, end] = row.value;
208
+
209
+ value = `${valueFormat(start)} ~ ${valueFormat(end)}`;
206
210
  }
207
211
 
208
212
  if (value !== undefined) {
@@ -536,11 +536,7 @@ export default {
536
536
  .attr("class", CLASS[hasGauge ? "chartArcsGaugeTitle" : "chartArcsTitle"])
537
537
  .style("text-anchor", "middle");
538
538
 
539
- if (hasGauge) {
540
- text
541
- .attr("dy", "-0.3em")
542
- .style("font-size", "27px");
543
- }
539
+ hasGauge && text.attr("dy", "-0.3em");
544
540
 
545
541
  setTextValue(text, title, hasGauge ? undefined : [-0.6, 1.35], true);
546
542
  }
@@ -799,6 +795,8 @@ export default {
799
795
  return;
800
796
  }
801
797
 
798
+ state.event = event;
799
+
802
800
  const eventArc = getEventArc(event);
803
801
  const datum: any = eventArc.datum();
804
802
  const updated = (datum?.data && datum.data.id) ? $$.updateAngle(datum) : null;
@@ -2,20 +2,32 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
+ import {DataRow} from "../../../types/types";
5
6
  import CLASS from "../../config/classes";
6
- import {getPointer, getRandom, getRectSegList, isNumber} from "../../module/util";
7
+ import {getRandom, isNumber} from "../../module/util";
8
+ import {IDataRow} from "../data/IData";
9
+
10
+ type BarTypeDataRow = DataRow<number | number[]>;
7
11
 
8
12
  export default {
9
13
  initBar(): void {
10
- const {$el} = this;
14
+ const {$el, config, state: {clip}} = this;
11
15
 
12
16
  $el.bar = $el.main.select(`.${CLASS.chart}`)
13
17
  // should positioned at the beginning of the shape node to not overlap others
14
18
  .insert("g", ":first-child")
15
19
  .attr("class", CLASS.chartBars);
20
+
21
+ // set clip-path attribute when condition meet
22
+ // https://github.com/naver/billboard.js/issues/2421
23
+ if (config.clipPath === false && (
24
+ config.bar_radius || config.bar_radius_ratio
25
+ )) {
26
+ $el.bar.attr("clip-path", clip.pathXAxis.replace(/#[^)]*/, `#${clip.id}`));
27
+ }
16
28
  },
17
29
 
18
- updateTargetsForBar(targets): void {
30
+ updateTargetsForBar(targets: BarTypeDataRow[]): void {
19
31
  const $$ = this;
20
32
  const {config, $el} = $$;
21
33
  const classChartBar = $$.getChartClass("Bar");
@@ -32,7 +44,7 @@ export default {
32
44
  .data(
33
45
  // remove
34
46
  targets.filter(
35
- v => !v.values.every(d => !isNumber(d.value))
47
+ v => v.values.some(d => (isNumber(d.value) || $$.isBarRangeType(d)))
36
48
  )
37
49
  )
38
50
  .attr("class", d => classChartBar(d) + classFocus(d));
@@ -78,7 +90,7 @@ export default {
78
90
 
79
91
  /**
80
92
  * Redraw function
81
- * @param {Function} drawFn Retuned functino from .generateDrawCandlestick()
93
+ * @param {Function} drawFn Retuned function from .getDrawShape() => .generateDrawBar()
82
94
  * @param {boolean} withTransition With or without transition
83
95
  * @param {boolean} isSub Subchart draw
84
96
  * @returns {Array}
@@ -89,18 +101,37 @@ export default {
89
101
 
90
102
  return [
91
103
  $$.$T(bar, withTransition, getRandom())
92
- .attr("d", d => isNumber(d.value) && drawFn(d))
104
+ .attr("d", d => (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d))
93
105
  .style("fill", this.color)
94
106
  .style("opacity", null)
95
107
  ];
96
108
  },
97
109
 
98
- generateDrawBar(barIndices, isSub?: boolean): Function {
110
+ /**
111
+ * Generate draw function
112
+ * @param {object} barIndices data order within x axis.
113
+ * barIndices ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
114
+ *
115
+ * When gropus given as:
116
+ * groups: [
117
+ * ["data1", "data2"],
118
+ * ["data3", "data4"]
119
+ * ],
120
+ *
121
+ * Will be rendered as:
122
+ * data1 data3 data1 data3
123
+ * data2 data4 data2 data4
124
+ * -------------------------
125
+ * 0 1
126
+ * @param {boolean} isSub If is for subchart
127
+ * @returns {Function}
128
+ * @private
129
+ */
130
+ generateDrawBar(barIndices, isSub?: boolean): (d: IDataRow, i: number) => string {
99
131
  const $$ = this;
100
132
  const {config} = $$;
101
133
  const getPoints = $$.generateGetBarPoints(barIndices, isSub);
102
134
  const isRotated = config.axis_rotated;
103
- const isGrouped = config.data_groups.length;
104
135
  const barRadius = config.bar_radius;
105
136
  const barRadiusRatio = config.bar_radius_ratio;
106
137
 
@@ -110,7 +141,7 @@ export default {
110
141
  isNumber(barRadiusRatio) ? w => w * barRadiusRatio : null
111
142
  );
112
143
 
113
- return (d, i) => {
144
+ return (d: IDataRow, i: number) => {
114
145
  // 4 points that make a bar
115
146
  const points = getPoints(d, i);
116
147
 
@@ -122,7 +153,11 @@ export default {
122
153
  const pathRadius = ["", ""];
123
154
  let radius = 0;
124
155
 
125
- if (getRadius && !isGrouped) {
156
+ const isGrouped = $$.isGrouped(d.id);
157
+ const hasRadius = d.value !== 0 && getRadius;
158
+ const isRadiusData = hasRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
159
+
160
+ if (hasRadius && (!isGrouped || isRadiusData)) {
126
161
  const index = isRotated ? indexY : indexX;
127
162
  const barW = points[2][index] - points[0][index];
128
163
 
@@ -146,7 +181,46 @@ export default {
146
181
  };
147
182
  },
148
183
 
149
- generateGetBarPoints(barIndices, isSub?: boolean): Function {
184
+ /**
185
+ * Determine if given stacking bar data is radius type
186
+ * @param {Object} d Data row
187
+ * @returns {boolean}
188
+ */
189
+ isStackingRadiusData(d: IDataRow): boolean {
190
+ const $$ = this;
191
+ const {config, data} = $$;
192
+ const {id, index, value} = d;
193
+
194
+ // Find same grouped ids
195
+ const keys = config.data_groups.find(v => v.indexOf(id) > -1);
196
+
197
+ // Get sorted list
198
+ const sortedList = $$.orderTargets(
199
+ $$.filterTargetsToShow(data.targets.filter($$.isBarType, $$))
200
+ ).filter(v => keys.indexOf(v.id) > -1);
201
+
202
+ // Get sorted Ids. Filter positive or negative values Ids from given value
203
+ const sortedIds = sortedList
204
+ .map(v => v.values.filter(
205
+ v2 => v2.index === index && (
206
+ value > 0 ? v2.value > 0 : v2.value < 0
207
+ ))[0]
208
+ )
209
+ .filter(Boolean)
210
+ .map(v => v.id);
211
+
212
+ // If the given id stays in the last position, then radius should be applied.
213
+ return value !== 0 && (sortedIds.indexOf(id) === sortedIds.length - 1);
214
+ },
215
+
216
+ /**
217
+ * Generate bar coordinate points data
218
+ * @param {object} barIndices Data order within x axis.
219
+ * @param {boolean} isSub If is for subchart
220
+ * @returns {Array} Array of coordinate points
221
+ * @private
222
+ */
223
+ generateGetBarPoints(barIndices, isSub?: boolean): (d: IDataRow, i: number) => [number, number][] {
150
224
  const $$ = this;
151
225
  const {config} = $$;
152
226
  const axis = isSub ? $$.axis.subX : $$.axis.x;
@@ -157,7 +231,7 @@ export default {
157
231
  const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
158
232
  const yScale = $$.getYScaleById.bind($$);
159
233
 
160
- return (d, i) => {
234
+ return (d: IDataRow, i: number) => {
161
235
  const y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
162
236
  const offset = barOffset(d, i) || y0; // offset is for stacked bar chart
163
237
  const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
@@ -171,7 +245,9 @@ export default {
171
245
  posY = y0;
172
246
  }
173
247
 
174
- posY -= (y0 - offset);
248
+ if (!$$.isBarRangeType(d)) {
249
+ posY -= (y0 - offset);
250
+ }
175
251
 
176
252
  const startPosX = posX + width;
177
253
 
@@ -183,26 +259,5 @@ export default {
183
259
  [startPosX, offset]
184
260
  ];
185
261
  };
186
- },
187
-
188
- isWithinBar(that): boolean {
189
- const mouse = getPointer(this.state.event, that);
190
- const list = getRectSegList(that);
191
- const [seg0, seg1] = list;
192
- const x = Math.min(seg0.x, seg1.x);
193
- const y = Math.min(seg0.y, seg1.y);
194
- const offset = this.config.bar_sensitivity;
195
- const {width, height} = that.getBBox();
196
- const sx = x - offset;
197
- const ex = x + width + offset;
198
- const sy = y + height + offset;
199
- const ey = y - offset;
200
-
201
- const isWithin = sx < mouse[0] &&
202
- mouse[0] < ex &&
203
- ey < mouse[1] &&
204
- mouse[1] < sy;
205
-
206
- return isWithin;
207
262
  }
208
263
  };
@@ -314,6 +314,8 @@ export default {
314
314
  return d && Object.keys(d).length === 1 ? d.index : undefined;
315
315
  };
316
316
  const hide = event => {
317
+ state.event = event;
318
+
317
319
  const index = getIndex(event);
318
320
  const noIndex = isUndefined(index);
319
321