billboard.js 3.11.3 → 3.12.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 (177) hide show
  1. package/README.md +1 -5
  2. package/dist/billboard.css +13 -1
  3. package/dist/billboard.js +19672 -24210
  4. package/dist/billboard.min.css +2 -2
  5. package/dist/billboard.min.js +26 -3
  6. package/dist/billboard.pkgd.js +24515 -30430
  7. package/dist/billboard.pkgd.min.js +33 -3
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +77 -175
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -3
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +429 -1134
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
  12. package/dist/plugin/billboardjs-plugin-stanford.js +666 -1524
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +15 -3
  14. package/dist/plugin/billboardjs-plugin-tableview.js +503 -1175
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +30 -3
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +351 -1055
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -3
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1387 -1854
  19. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
  20. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2760 -3959
  21. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3504 -5057
  23. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2906 -4072
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +3076 -4506
  27. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
  28. package/dist/theme/dark.css +12 -1
  29. package/dist/theme/dark.min.css +2 -2
  30. package/dist/theme/datalab.css +12 -1
  31. package/dist/theme/datalab.min.css +2 -2
  32. package/dist/theme/graph.css +12 -1
  33. package/dist/theme/graph.min.css +2 -2
  34. package/dist/theme/insight.css +12 -1
  35. package/dist/theme/insight.min.css +2 -2
  36. package/dist/theme/modern.css +12 -1
  37. package/dist/theme/modern.min.css +3 -4
  38. package/dist-esm/billboard.js +9297 -8527
  39. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +20 -27
  40. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +155 -149
  41. package/dist-esm/plugin/billboardjs-plugin-stanford.js +302 -289
  42. package/dist-esm/plugin/billboardjs-plugin-tableview.js +236 -236
  43. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +41 -43
  44. package/package.json +29 -49
  45. package/src/Chart/api/axis.ts +6 -13
  46. package/src/Chart/api/chart.ts +12 -11
  47. package/src/Chart/api/data.ts +8 -7
  48. package/src/Chart/api/export.ts +28 -21
  49. package/src/Chart/api/flow.ts +4 -2
  50. package/src/Chart/api/grid.ts +1 -5
  51. package/src/Chart/api/load.ts +2 -2
  52. package/src/Chart/api/regions.ts +29 -5
  53. package/src/Chart/api/selection.ts +2 -2
  54. package/src/Chart/api/show.ts +2 -3
  55. package/src/Chart/api/subchart.ts +2 -2
  56. package/src/Chart/api/tooltip.ts +8 -9
  57. package/src/Chart/api/x.ts +2 -2
  58. package/src/Chart/api/zoom.ts +2 -2
  59. package/src/ChartInternal/Axis/Axis.ts +119 -44
  60. package/src/ChartInternal/Axis/AxisRenderer.ts +53 -38
  61. package/src/ChartInternal/Axis/AxisRendererHelper.ts +2 -2
  62. package/src/ChartInternal/ChartInternal.ts +87 -55
  63. package/src/ChartInternal/data/IData.ts +31 -31
  64. package/src/ChartInternal/data/convert.helper.ts +66 -68
  65. package/src/ChartInternal/data/convert.ts +11 -11
  66. package/src/ChartInternal/data/data.ts +51 -27
  67. package/src/ChartInternal/data/load.ts +7 -6
  68. package/src/ChartInternal/interactions/drag.ts +2 -1
  69. package/src/ChartInternal/interactions/eventrect.ts +84 -32
  70. package/src/ChartInternal/interactions/flow.ts +14 -4
  71. package/src/ChartInternal/interactions/interaction.ts +51 -22
  72. package/src/ChartInternal/interactions/subchart.ts +27 -25
  73. package/src/ChartInternal/interactions/zoom.ts +29 -18
  74. package/src/ChartInternal/internals/category.ts +1 -1
  75. package/src/ChartInternal/internals/class.ts +6 -6
  76. package/src/ChartInternal/internals/clip.ts +8 -4
  77. package/src/ChartInternal/internals/color.ts +70 -42
  78. package/src/ChartInternal/internals/domain.ts +59 -28
  79. package/src/ChartInternal/internals/format.ts +5 -5
  80. package/src/ChartInternal/internals/grid.ts +131 -47
  81. package/src/ChartInternal/internals/legend.ts +93 -61
  82. package/src/ChartInternal/internals/redraw.ts +6 -2
  83. package/src/ChartInternal/internals/region.ts +5 -3
  84. package/src/ChartInternal/internals/scale.ts +28 -15
  85. package/src/ChartInternal/internals/selection.ts +14 -13
  86. package/src/ChartInternal/internals/size.axis.ts +18 -10
  87. package/src/ChartInternal/internals/size.ts +98 -67
  88. package/src/ChartInternal/internals/style.ts +21 -19
  89. package/src/ChartInternal/internals/text.ts +79 -43
  90. package/src/ChartInternal/internals/title.ts +2 -2
  91. package/src/ChartInternal/internals/tooltip.ts +78 -32
  92. package/src/ChartInternal/internals/transform.ts +4 -4
  93. package/src/ChartInternal/internals/type.ts +17 -12
  94. package/src/ChartInternal/shape/arc.ts +78 -44
  95. package/src/ChartInternal/shape/area.ts +19 -22
  96. package/src/ChartInternal/shape/bar.ts +41 -31
  97. package/src/ChartInternal/shape/bubble.ts +5 -5
  98. package/src/ChartInternal/shape/candlestick.ts +15 -13
  99. package/src/ChartInternal/shape/funnel.ts +317 -0
  100. package/src/ChartInternal/shape/gauge.ts +16 -9
  101. package/src/ChartInternal/shape/line.ts +62 -46
  102. package/src/ChartInternal/shape/point.common.ts +1 -4
  103. package/src/ChartInternal/shape/point.ts +54 -34
  104. package/src/ChartInternal/shape/polar.ts +4 -2
  105. package/src/ChartInternal/shape/radar.ts +40 -22
  106. package/src/ChartInternal/shape/shape.ts +84 -58
  107. package/src/ChartInternal/shape/treemap.ts +31 -20
  108. package/src/Plugin/bubblecompare/index.ts +1 -3
  109. package/src/Plugin/sparkline/index.ts +3 -4
  110. package/src/Plugin/stanford/ColorScale.ts +3 -2
  111. package/src/Plugin/stanford/Elements.ts +15 -6
  112. package/src/Plugin/stanford/Options.ts +5 -5
  113. package/src/Plugin/stanford/index.ts +13 -9
  114. package/src/Plugin/tableview/Options.ts +1 -1
  115. package/src/Plugin/tableview/const.ts +1 -4
  116. package/src/Plugin/tableview/index.ts +11 -9
  117. package/src/Plugin/textoverlap/index.ts +4 -6
  118. package/src/config/Options/Options.ts +3 -3
  119. package/src/config/Options/axis/axis.ts +36 -0
  120. package/src/config/Options/axis/x.ts +34 -14
  121. package/src/config/Options/axis/y.ts +13 -13
  122. package/src/config/Options/axis/y2.ts +23 -10
  123. package/src/config/Options/common/color.ts +4 -4
  124. package/src/config/Options/common/grid.ts +4 -4
  125. package/src/config/Options/common/legend.ts +12 -13
  126. package/src/config/Options/common/main.ts +23 -23
  127. package/src/config/Options/common/point.ts +17 -18
  128. package/src/config/Options/common/title.ts +2 -2
  129. package/src/config/Options/common/tooltip.ts +13 -11
  130. package/src/config/Options/data/axis.ts +2 -2
  131. package/src/config/Options/data/data.ts +48 -45
  132. package/src/config/Options/interaction/interaction.ts +1 -1
  133. package/src/config/Options/interaction/subchart.ts +2 -2
  134. package/src/config/Options/interaction/zoom.ts +9 -9
  135. package/src/config/Options/shape/arc.ts +10 -13
  136. package/src/config/Options/shape/area.ts +5 -7
  137. package/src/config/Options/shape/bar.ts +8 -10
  138. package/src/config/Options/shape/bubble.ts +1 -1
  139. package/src/config/Options/shape/candlestick.ts +2 -2
  140. package/src/config/Options/shape/donut.ts +4 -4
  141. package/src/config/Options/shape/funnel.ts +38 -0
  142. package/src/config/Options/shape/gauge.ts +6 -6
  143. package/src/config/Options/shape/line.ts +3 -3
  144. package/src/config/Options/shape/pie.ts +5 -5
  145. package/src/config/Options/shape/polar.ts +3 -3
  146. package/src/config/Options/shape/radar.ts +2 -2
  147. package/src/config/Options/shape/scatter.ts +1 -1
  148. package/src/config/Options/shape/treemap.ts +1 -1
  149. package/src/config/Store/Element.ts +8 -5
  150. package/src/config/Store/State.ts +20 -13
  151. package/src/config/classes.ts +14 -4
  152. package/src/config/config.ts +1 -1
  153. package/src/config/const.ts +2 -0
  154. package/src/config/resolver/axis.ts +4 -4
  155. package/src/config/resolver/interaction.ts +3 -7
  156. package/src/config/resolver/shape.ts +17 -12
  157. package/src/core.ts +2 -3
  158. package/src/index.esm.ts +3 -6
  159. package/src/index.ts +2 -2
  160. package/src/module/Cache.ts +2 -3
  161. package/src/module/browser.ts +15 -10
  162. package/src/module/error.ts +9 -8
  163. package/src/module/generator.ts +3 -5
  164. package/src/module/util.ts +62 -39
  165. package/src/module/worker.ts +14 -11
  166. package/src/scss/billboard.scss +18 -0
  167. package/src/scss/theme/dark.scss +17 -0
  168. package/src/scss/theme/datalab.scss +17 -0
  169. package/src/scss/theme/graph.scss +17 -0
  170. package/src/scss/theme/insight.scss +17 -0
  171. package/src/scss/theme/modern.scss +17 -0
  172. package/types/axis.d.ts +17 -0
  173. package/types/bb.d.ts +1 -0
  174. package/types/index.d.ts +1 -0
  175. package/types/options.d.ts +9 -0
  176. package/types/options.shape.d.ts +26 -1
  177. package/types/types.d.ts +1 -0
@@ -2,12 +2,12 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {area as d3Area} from "d3-shape";
6
5
  import {select as d3Select} from "d3-selection";
6
+ import {area as d3Area} from "d3-shape";
7
+ import {d3Selection} from "../../../types";
7
8
  import {$AREA, $CIRCLE, $LINE} from "../../config/classes";
8
9
  import {getRandom} from "../../module/util";
9
10
  import type {IData, IDataRow} from "../data/IData";
10
- import {d3Selection} from "../../../types";
11
11
 
12
12
  type Indices = {[key: string | "__max__"]: number};
13
13
 
@@ -30,8 +30,7 @@ export default {
30
30
  updateAreaColor(d: IDataRow): string {
31
31
  const $$ = this;
32
32
 
33
- return $$.config.area_linearGradient ?
34
- $$.getGradienColortUrl(d.id) : $$.color(d);
33
+ return $$.config.area_linearGradient ? $$.getGradienColortUrl(d.id) : $$.color(d);
35
34
  },
36
35
 
37
36
  /**
@@ -79,14 +78,15 @@ export default {
79
78
  */
80
79
  redrawArea(drawFn: Function, withTransition?: boolean, isSub = false): d3Selection[] {
81
80
  const $$ = this;
82
- const {area} = (isSub ? this.$el.subchart : this.$el);
81
+ const {area} = isSub ? this.$el.subchart : this.$el;
83
82
  const {orgAreaOpacity} = $$.state;
84
83
 
85
84
  return [
86
85
  $$.$T(area, withTransition, getRandom())
87
86
  .attr("d", drawFn)
88
87
  .style("fill", $$.updateAreaColor.bind($$))
89
- .style("opacity", d => String($$.isAreaRangeType(d) ? orgAreaOpacity / 1.75 : orgAreaOpacity))
88
+ .style("opacity",
89
+ d => String($$.isAreaRangeType(d) ? orgAreaOpacity / 1.75 : orgAreaOpacity))
90
90
  ];
91
91
  },
92
92
 
@@ -107,18 +107,12 @@ export default {
107
107
  const yScale = $$.getYScaleById.bind($$);
108
108
 
109
109
  const xValue = d => (isSub ? $$.subxx : $$.xx).call($$, d);
110
- const value0 = (d, i) => ($$.isGrouped(d.id) ?
111
- getPoints(d, i)[0][1] :
112
- yScale(d.id, isSub)(
113
- $$.isAreaRangeType(d) ?
114
- $$.getRangedData(d, "high") : $$.getShapeYMin(d.id)
115
- ));
116
- const value1 = (d, i) => ($$.isGrouped(d.id) ?
117
- getPoints(d, i)[1][1] :
118
- yScale(d.id, isSub)(
119
- $$.isAreaRangeType(d) ?
120
- $$.getRangedData(d, "low") : d.value
121
- ));
110
+ const value0 = (d, i) => ($$.isGrouped(d.id) ? getPoints(d, i)[0][1] : yScale(d.id, isSub)(
111
+ $$.isAreaRangeType(d) ? $$.getRangedData(d, "high") : $$.getShapeYMin(d.id)
112
+ ));
113
+ const value1 = (d, i) => ($$.isGrouped(d.id) ? getPoints(d, i)[1][1] : yScale(d.id, isSub)(
114
+ $$.isAreaRangeType(d) ? $$.getRangedData(d, "low") : d.value
115
+ ));
122
116
 
123
117
  return d => {
124
118
  let values = lineConnectNull ? $$.filterRemoveNull(d.values) : d.values;
@@ -162,7 +156,8 @@ export default {
162
156
  },
163
157
 
164
158
  generateGetAreaPoints(
165
- areaIndices: Indices, isSub?: boolean
159
+ areaIndices: Indices,
160
+ isSub?: boolean
166
161
  ): (d: IDataRow, i: number) => [number, number][] {
167
162
  // partial duplication of generateGetBarPoints
168
163
  const $$ = this;
@@ -180,9 +175,11 @@ export default {
180
175
  let posY = y(d);
181
176
 
182
177
  // fix posY not to overflow opposite quadrant
183
- if (config.axis_rotated && (
184
- (value > 0 && posY < y0) || (value < 0 && y0 < posY)
185
- )) {
178
+ if (
179
+ config.axis_rotated && (
180
+ (value > 0 && posY < y0) || (value < 0 && y0 < posY)
181
+ )
182
+ ) {
186
183
  posY = y0;
187
184
  }
188
185
 
@@ -16,9 +16,7 @@ export default {
16
16
 
17
17
  $el.bar = $el.main.select(`.${$COMMON.chart}`);
18
18
 
19
- $el.bar = config.bar_front ?
20
- $el.bar.append("g") :
21
- $el.bar.insert("g", ":first-child");
19
+ $el.bar = config.bar_front ? $el.bar.append("g") : $el.bar.insert("g", ":first-child");
22
20
 
23
21
  $el.bar
24
22
  .attr("class", $BAR.chartBars)
@@ -26,9 +24,11 @@ export default {
26
24
 
27
25
  // set clip-path attribute when condition meet
28
26
  // https://github.com/naver/billboard.js/issues/2421
29
- if (config.clipPath === false && (
30
- config.bar_radius || config.bar_radius_ratio
31
- )) {
27
+ if (
28
+ config.clipPath === false && (
29
+ config.bar_radius || config.bar_radius_ratio
30
+ )
31
+ ) {
32
32
  $el.bar.attr("clip-path", clip.pathXAxis.replace(/#[^)]*/, `#${clip.id}`));
33
33
  }
34
34
  },
@@ -110,8 +110,7 @@ export default {
110
110
  const $$ = this;
111
111
  const fn = $$.getStylePropValue($$.color);
112
112
 
113
- return $$.config.bar_linearGradient ?
114
- $$.getGradienColortUrl(d.id) : (fn ? fn(d) : null);
113
+ return $$.config.bar_linearGradient ? $$.getGradienColortUrl(d.id) : (fn ? fn(d) : null);
115
114
  },
116
115
 
117
116
  /**
@@ -124,7 +123,7 @@ export default {
124
123
  */
125
124
  redrawBar(drawFn, withTransition?: boolean, isSub = false) {
126
125
  const $$ = this;
127
- const {bar} = (isSub ? $$.$el.subchart : $$.$el);
126
+ const {bar} = isSub ? $$.$el.subchart : $$.$el;
128
127
 
129
128
  return [
130
129
  $$.$T(bar, withTransition, getRandom())
@@ -141,15 +140,15 @@ export default {
141
140
  *
142
141
  * When gropus given as:
143
142
  * groups: [
144
- * ["data1", "data2"],
145
- * ["data3", "data4"]
146
- * ],
143
+ * ["data1", "data2"],
144
+ * ["data3", "data4"]
145
+ * ],
147
146
  *
148
147
  * Will be rendered as:
149
148
  * data1 data3 data1 data3
150
- * data2 data4 data2 data4
151
- * -------------------------
152
- * 0 1
149
+ * data2 data4 data2 data4
150
+ * -------------------------
151
+ * 0 1
153
152
  * @param {boolean} isSub If is for subchart
154
153
  * @returns {Function}
155
154
  * @private
@@ -163,10 +162,9 @@ export default {
163
162
  const barRadiusRatio = config.bar_radius_ratio;
164
163
 
165
164
  // get the bar radius
166
- const getRadius = isNumber(barRadius) && barRadius > 0 ?
167
- () => barRadius : (
168
- isNumber(barRadiusRatio) ? w => w * barRadiusRatio : null
169
- );
165
+ const getRadius = isNumber(barRadius) && barRadius > 0 ? () => barRadius : (
166
+ isNumber(barRadiusRatio) ? w => w * barRadiusRatio : null
167
+ );
170
168
 
171
169
  return (d: IDataRow, i: number) => {
172
170
  // 4 points that make a bar
@@ -195,7 +193,9 @@ export default {
195
193
  const arc = `a${radius},${radius} ${isNegative ? `1 0 0` : `0 0 1`} `;
196
194
 
197
195
  pathRadius[+!isRotated] = `${arc}${radius},${radius}`;
198
- pathRadius[+isRotated] = `${arc}${[-radius, radius][isRotated ? "sort" : "reverse"]()}`;
196
+ pathRadius[+isRotated] = `${arc}${
197
+ [-radius, radius][isRotated ? "sort" : "reverse"]()
198
+ }`;
199
199
 
200
200
  isNegative && pathRadius.reverse();
201
201
  }
@@ -203,8 +203,12 @@ export default {
203
203
  // path string data shouldn't be containing new line chars
204
204
  // https://github.com/naver/billboard.js/issues/530
205
205
  const path = isRotated ?
206
- `H${points[1][indexX] + (isNegative ? radius : -radius)} ${pathRadius[0]}V${points[2][indexY] - radius} ${pathRadius[1]}H${points[3][indexX]}` :
207
- `V${points[1][indexY] + (isNegative ? -radius : radius)} ${pathRadius[0]}H${points[2][indexX] - radius} ${pathRadius[1]}V${points[3][indexY]}`;
206
+ `H${points[1][indexX] + (isNegative ? radius : -radius)} ${pathRadius[0]}V${
207
+ points[2][indexY] - radius
208
+ } ${pathRadius[1]}H${points[3][indexX]}` :
209
+ `V${points[1][indexY] + (isNegative ? -radius : radius)} ${pathRadius[0]}H${
210
+ points[2][indexX] - radius
211
+ } ${pathRadius[1]}V${points[3][indexY]}`;
208
212
 
209
213
  return `M${points[0][indexX]},${points[0][indexY]}${path}z`;
210
214
  };
@@ -237,10 +241,13 @@ export default {
237
241
 
238
242
  // Get sorted Ids. Filter positive or negative values Ids from given value
239
243
  const sortedIds = sortedList
240
- .map(v => v.values.filter(
241
- v2 => v2.index === index && (
242
- isNumber(value) && value > 0 ? v2.value > 0 : v2.value < 0
243
- ))[0]
244
+ .map(v =>
245
+ v.values.filter(
246
+ v2 =>
247
+ v2.index === index && (
248
+ isNumber(value) && value > 0 ? v2.value > 0 : v2.value < 0
249
+ )
250
+ )[0]
244
251
  )
245
252
  .filter(Boolean)
246
253
  .map(v => v.id);
@@ -256,7 +263,8 @@ export default {
256
263
  * @returns {Array} Array of coordinate points
257
264
  * @private
258
265
  */
259
- generateGetBarPoints(barIndices, isSub?: boolean): (d: IDataRow, i: number) => [number, number][] {
266
+ generateGetBarPoints(barIndices,
267
+ isSub?: boolean): (d: IDataRow, i: number) => [number, number][] {
260
268
  const $$ = this;
261
269
  const {config} = $$;
262
270
  const axis = isSub ? $$.axis.subX : $$.axis.x;
@@ -278,14 +286,16 @@ export default {
278
286
  let posY = barY(d);
279
287
 
280
288
  // fix posY not to overflow opposite quadrant
281
- if (config.axis_rotated && !isInverted && (
282
- (value > 0 && posY < y0) || (value < 0 && y0 < posY)
283
- )) {
289
+ if (
290
+ config.axis_rotated && !isInverted && (
291
+ (value > 0 && posY < y0) || (value < 0 && y0 < posY)
292
+ )
293
+ ) {
284
294
  posY = y0;
285
295
  }
286
296
 
287
297
  if (!$$.isBarRangeType(d)) {
288
- posY -= (y0 - offset);
298
+ posY -= y0 - offset;
289
299
  }
290
300
 
291
301
  const startPosX = posX + width;
@@ -55,13 +55,13 @@ export default {
55
55
  }
56
56
 
57
57
  const max = getMinMax("max", $$.getMinMaxData().max.map(d => (
58
- $$.isBubbleZType(d) ?
59
- $$.getBubbleZData(d.value, "y") : (
60
- isObject(d.value) ? d.value.mid : d.value
61
- )
58
+ $$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "y") : (
59
+ isObject(d.value) ? d.value.mid : d.value
60
+ )
62
61
  )));
63
62
  const maxArea = maxR * maxR * Math.PI;
64
- const area = ($$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "z") : d.value) * (maxArea / max);
63
+ const area = ($$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "z") : d.value) *
64
+ (maxArea / max);
65
65
 
66
66
  return Math.sqrt(area / Math.PI);
67
67
  },
@@ -125,17 +125,19 @@ export default {
125
125
 
126
126
  // set line position
127
127
  const line = g.select("line");
128
- const pos = isRotated ? {
129
- x1: points[2][1],
130
- x2: points[2][2],
131
- y1: points[2][0],
132
- y2: points[2][0]
133
- } : {
134
- x1: points[2][0],
135
- x2: points[2][0],
136
- y1: points[2][1],
137
- y2: points[2][2]
138
- };
128
+ const pos = isRotated ?
129
+ {
130
+ x1: points[2][1],
131
+ x2: points[2][2],
132
+ y1: points[2][0],
133
+ y2: points[2][0]
134
+ } :
135
+ {
136
+ x1: points[2][0],
137
+ x2: points[2][0],
138
+ y1: points[2][1],
139
+ y2: points[2][2]
140
+ };
139
141
 
140
142
  for (const x in pos) {
141
143
  line.attr(x, pos[x]);
@@ -184,7 +186,7 @@ export default {
184
186
  low: y(value.low)
185
187
  };
186
188
 
187
- posY.start -= (y0 - offset);
189
+ posY.start -= y0 - offset;
188
190
 
189
191
  points = [
190
192
  [posX.start, posY.start],
@@ -209,7 +211,7 @@ export default {
209
211
  redrawCandlestick(drawFn, withTransition?: boolean, isSub = false) {
210
212
  const $$ = this;
211
213
  const {$el, $T} = $$;
212
- const {candlestick} = (isSub ? $el.subchart : $el);
214
+ const {candlestick} = isSub ? $el.subchart : $el;
213
215
  const rand = getRandom(true);
214
216
 
215
217
  return [
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ import {select as d3Select} from "d3-selection";
6
+ import {$COMMON, $FUNNEL} from "../../config/classes";
7
+ import {isObject} from "../../module/util";
8
+ import type {IData, IDataRow, IFunnelData} from "../data/IData";
9
+
10
+ type TSize = { [key in "width" | "height" | "top" | "left"]: number };
11
+ type TSizeCurrent = Pick<TSize, "width" | "height">;
12
+
13
+ /**
14
+ * Get current size value
15
+ * @param {boolean} checkNeck Determine if container width to not be less than neck width
16
+ * @returns {object} size object
17
+ * @private
18
+ */
19
+ function getSize(checkNeck = false): TSize {
20
+ const $$ = this;
21
+ const {config, state: {current: {width, height}}} = $$;
22
+ const padding = $$.getCurrentPadding();
23
+
24
+ const size = {
25
+ width: width - (padding.left + padding.right),
26
+ height: height - (config.legend_show ? $$.getLegendHeight() + 10 : 0) -
27
+ (padding.top + padding.bottom),
28
+ ...padding
29
+ };
30
+
31
+ // determine if container width to not be less than neck width
32
+ if (checkNeck) {
33
+ const {width: neckWidth} = getNecklSize.call($$, {
34
+ width: size.width,
35
+ height: size.height
36
+ });
37
+
38
+ // prevent funnel width from being less than neck width
39
+ if (size.width < neckWidth) {
40
+ size.width = neckWidth;
41
+ }
42
+ }
43
+
44
+ return size;
45
+ }
46
+
47
+ /**
48
+ * Return neck size in pixels
49
+ * @param {object} current Current size object
50
+ * @returns {object} size object
51
+ * @private
52
+ */
53
+ function getNecklSize(current: TSizeCurrent) {
54
+ const $$ = this;
55
+ const {config} = $$;
56
+ let width = config.funnel_neck_width;
57
+ let height = config.funnel_neck_height;
58
+
59
+ [width, height] = [width, height].map((v, i) => {
60
+ let size = v;
61
+
62
+ if (isObject(v)) {
63
+ size = current[i ? "height" : "width"] * v.ratio;
64
+ }
65
+
66
+ return size;
67
+ });
68
+
69
+ return {
70
+ width,
71
+ height
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Get coordinate points
77
+ * @param {Array} d Data object
78
+ * @returns {Array} Coordinate points
79
+ * @private
80
+ */
81
+ function getCoord(d: IFunnelData[]) {
82
+ const $$ = this;
83
+ const {top, width} = getSize.call($$, true);
84
+ const coords: number[][][] = [];
85
+
86
+ d.forEach((d, i) => {
87
+ const {ratio} = d;
88
+ const y = i > 0 ? coords[i - 1][2][1] : top;
89
+
90
+ // (M)(4) ------------> (1)
91
+ // ˄ |
92
+ // | |
93
+ // | ˅
94
+ // (3) <-------------- (2)
95
+ coords.push(d.coords = [
96
+ [0, y], // M
97
+ [width, y], // 1
98
+ [width, i > 0 ? ratio + y : ratio + top], // 2
99
+ [0, i > 0 ? ratio + y : ratio + top], // 3
100
+ [0, y] // 4
101
+ ]);
102
+ });
103
+
104
+ return coords;
105
+ }
106
+
107
+ /**
108
+ * Get neck path
109
+ * @returns {string} path
110
+ * @private
111
+ */
112
+ function getNeckPath() {
113
+ const $$ = this;
114
+ const {width, height, top, left} = getSize.call($$, true);
115
+ const neck = getNecklSize.call($$, {width, height});
116
+
117
+ const rightX = (width + neck.width) / 2;
118
+ const leftX = (width - neck.width) / 2;
119
+ const bodyHeigth = height - neck.height;
120
+
121
+ const coords = [
122
+ [0 + left, 0 + top], // M
123
+ [width + left, 0 + top], // 1
124
+ [rightX, bodyHeigth], // 2
125
+ [rightX, height + top], // 3
126
+ [leftX, height + top], // 4
127
+ [leftX, bodyHeigth], // 5
128
+ [0 + left, 0 + top] // 6
129
+ ];
130
+
131
+ return `M${coords.join("L")}z`;
132
+ }
133
+
134
+ /**
135
+ * Get funnel data
136
+ * @param {object} d data object
137
+ * @returns {Array}
138
+ * @private
139
+ */
140
+ function getFunnelData(d: IData[]): IFunnelData[] {
141
+ const $$ = this;
142
+ const {config} = $$;
143
+ const data: IFunnelData[] = d.map(d => ({
144
+ id: d.id,
145
+ value: d.values.reduce((a, b) => a + <number>b.value, 0)
146
+ }));
147
+
148
+ if (config.data_order) {
149
+ data.sort($$.getSortCompareFn.bind($$)(true));
150
+ }
151
+
152
+ return updateRatio.call($$, data);
153
+ }
154
+
155
+ /**
156
+ * Update ratio value
157
+ * @param {Array} data Data object
158
+ * @returns {Array} Updated data object
159
+ * @private
160
+ */
161
+ function updateRatio(data) {
162
+ const $$ = this;
163
+ const {height} = getSize.call($$);
164
+ const total = $$.getTotalDataSum(true);
165
+
166
+ data.forEach(d => {
167
+ // ratio = shape's height
168
+ d.ratio = (d.value / total) * height;
169
+ });
170
+
171
+ return data;
172
+ }
173
+
174
+ export default {
175
+ /**
176
+ * Initialize polar
177
+ * @private
178
+ */
179
+ initFunnel(): void {
180
+ const $$ = this;
181
+ const {$el} = $$;
182
+
183
+ $el.funnel = $el.main.select(`.${$COMMON.chart}`)
184
+ .append("g")
185
+ .classed($FUNNEL.chartFunnels, true);
186
+
187
+ // define background to prevent shape overflow
188
+ $el.funnel.background = $el.funnel.append("path")
189
+ .classed($FUNNEL.funnelBackground, true);
190
+
191
+ $$.bindFunnelEvent();
192
+ },
193
+
194
+ /**
195
+ * Bind events
196
+ * @private
197
+ */
198
+ bindFunnelEvent(): void {
199
+ const $$ = this;
200
+ const {$el: {funnel}, config, state} = $$;
201
+ const getTarget = event => {
202
+ const target = event.isTrusted ? event.target : state.eventReceiver.rect?.node();
203
+ let data;
204
+
205
+ if (/^path$/i.test(target.tagName)) {
206
+ state.event = event;
207
+ data = d3Select(target).datum();
208
+ }
209
+
210
+ return data;
211
+ };
212
+
213
+ if (config.interaction_enabled) {
214
+ const isTouch = state.inputType === "touch";
215
+
216
+ funnel
217
+ .on(isTouch ? "touchstart" : "mouseover mousemove", event => {
218
+ const data = getTarget(event);
219
+
220
+ if (data) {
221
+ $$.showTooltip([data], event.target);
222
+ /^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
223
+ }
224
+ })
225
+ .on(isTouch ? "touchend" : "mouseout", event => {
226
+ const data = getTarget(event);
227
+
228
+ $$.hideTooltip();
229
+ $$.setOverOut(false, data);
230
+ });
231
+ }
232
+ },
233
+
234
+ /**
235
+ * Update polar based on given data array
236
+ * @param {object} t Data object
237
+ * @private
238
+ */
239
+ updateTargetsForFunnel(t: IData[]): void {
240
+ const $$ = this;
241
+ const {$el: {funnel}} = $$;
242
+ const classChartFunnel = $$.getChartClass("Funnel");
243
+ const classFunnel = $$.getClass("funnel", true);
244
+
245
+ if (!funnel) {
246
+ $$.initFunnel();
247
+ }
248
+
249
+ const targets = getFunnelData.call($$, t.filter($$.isFunnelType.bind($$)));
250
+
251
+ const mainFunnelUpdate = funnel
252
+ .selectAll(`.${$FUNNEL.chartFunnel}`)
253
+ .data(targets);
254
+
255
+ mainFunnelUpdate.exit().remove();
256
+
257
+ const mainFunnelEnter = mainFunnelUpdate
258
+ .enter()
259
+ .insert("g", `.${$FUNNEL.funnelBackground}`);
260
+
261
+ mainFunnelEnter
262
+ .append("path");
263
+
264
+ funnel.path = mainFunnelEnter
265
+ .merge(mainFunnelUpdate)
266
+ .attr("class", d => classChartFunnel(d))
267
+ .select("path")
268
+ .attr("class", classFunnel)
269
+ .style("opacity", "0")
270
+ .style("fill", $$.color);
271
+ },
272
+
273
+ /**
274
+ * Generate treemap coordinate points data
275
+ * @returns {Array} Array of coordinate points
276
+ * @private
277
+ */
278
+ generateGetFunnelPoints(): (d: IDataRow) => [number, number][] {
279
+ const $$ = this;
280
+ const {$el: {funnel}} = $$;
281
+ const targets = $$.filterTargetsToShow(funnel.path);
282
+ const points = {};
283
+ let accumulatedHeight = getSize.call($$).top ?? 0;
284
+
285
+ targets.each((d, i) => {
286
+ points[d.id] = [
287
+ [0, accumulatedHeight],
288
+ [0, accumulatedHeight += (targets?.[i] ?? d).ratio]
289
+ ];
290
+ });
291
+
292
+ return d => points[d.id];
293
+ },
294
+
295
+ /**
296
+ * Called whenever redraw happens
297
+ * @private
298
+ */
299
+ redrawFunnel(): void {
300
+ const $$ = this;
301
+ const {$T, $el: {funnel}} = $$;
302
+ const targets = $$.filterTargetsToShow(funnel.path);
303
+ const coords = getCoord.call($$, updateRatio.call($$, targets.data()));
304
+
305
+ // set neck path
306
+ const neckPath = getNeckPath.bind($$)();
307
+
308
+ funnel.attr("clip-path", `path('${neckPath}')`);
309
+ funnel.background.attr("d", neckPath);
310
+
311
+ $T(targets)
312
+ .attr("d", (d, i) => `M${coords[i].join("L")}z`)
313
+ .style("opacity", "1");
314
+
315
+ funnel.selectAll("g").style("opacity", null);
316
+ }
317
+ };
@@ -10,7 +10,7 @@ export default {
10
10
  initGauge(): void {
11
11
  const $$ = this;
12
12
  const {config, $el: {arcs}} = $$;
13
- const appendText = (className = <null|string>null, value = "") => {
13
+ const appendText = (className = <null | string>null, value = "") => {
14
14
  arcs.append("text")
15
15
  .attr("class", className)
16
16
  .style("text-anchor", "middle")
@@ -42,12 +42,15 @@ export default {
42
42
 
43
43
  // to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
44
44
  const max = hasMultiGauge ?
45
- $$.getMinMaxData().max[0].value : $$.getTotalDataSum(state.rendered);
45
+ $$.getMinMaxData().max[0].value :
46
+ $$.getTotalDataSum(state.rendered);
46
47
 
47
48
  // if gauge_max less than max, make max to max value
48
- if (!config.gauge_enforceMinMax && (
49
- max + config.gauge_min * (config.gauge_min > 0 ? -1 : 1) > config.gauge_max
50
- )) {
49
+ if (
50
+ !config.gauge_enforceMinMax && (
51
+ max + config.gauge_min * (config.gauge_min > 0 ? -1 : 1) > config.gauge_max
52
+ )
53
+ ) {
51
54
  config.gauge_max = max - config.gauge_min;
52
55
  }
53
56
  },
@@ -63,11 +66,13 @@ export default {
63
66
 
64
67
  const mainArcLabelLine = arcLabelLines.enter()
65
68
  .append("rect")
66
- .attr("class", d => `${$ARC.arcLabelLine} ${$COMMON.target} ${$COMMON.target}-${d.data.id}`)
69
+ .attr("class",
70
+ d => `${$ARC.arcLabelLine} ${$COMMON.target} ${$COMMON.target}-${d.data.id}`)
67
71
  .merge(arcLabelLines);
68
72
 
69
73
  mainArcLabelLine
70
- .style("fill", d => ($$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data)))
74
+ .style("fill",
75
+ d => ($$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data)))
71
76
  .style("display", config.gauge_label_show ? null : "none")
72
77
  .each(function(d) {
73
78
  let lineLength = 0;
@@ -78,11 +83,13 @@ export default {
78
83
 
79
84
  if (hiddenTargetIds.indexOf(d.data.id) < 0) {
80
85
  const updated = $$.updateAngle(d);
81
- const innerLineLength = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length *
86
+ const innerLineLength = state.gaugeArcWidth /
87
+ $$.filterTargetsToShow($$.data.targets).length *
82
88
  (updated.index + 1);
83
89
  const lineAngle = updated.endAngle - Math.PI / 2;
84
90
  const arcInnerRadius = state.radius - innerLineLength;
85
- const linePositioningAngle = lineAngle - (arcInnerRadius === 0 ? 0 : (1 / arcInnerRadius));
91
+ const linePositioningAngle = lineAngle -
92
+ (arcInnerRadius === 0 ? 0 : (1 / arcInnerRadius));
86
93
 
87
94
  lineLength = state.radiusExpanded - state.radius + innerLineLength;
88
95
  x = Math.cos(linePositioningAngle) * arcInnerRadius;