billboard.js 3.12.0 → 3.12.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 (47) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +56 -32
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +9 -9
  5. package/dist/billboard.pkgd.js +223 -199
  6. package/dist/billboard.pkgd.min.js +16 -16
  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 +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2 -2
  20. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2 -2
  22. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2 -2
  24. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +2 -2
  25. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2 -2
  26. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +2 -2
  27. package/dist/theme/dark.css +1 -1
  28. package/dist/theme/dark.min.css +1 -1
  29. package/dist/theme/datalab.css +1 -1
  30. package/dist/theme/datalab.min.css +1 -1
  31. package/dist/theme/graph.css +1 -1
  32. package/dist/theme/graph.min.css +1 -1
  33. package/dist/theme/insight.css +1 -1
  34. package/dist/theme/insight.min.css +1 -1
  35. package/dist/theme/modern.css +1 -1
  36. package/dist/theme/modern.min.css +1 -1
  37. package/dist-esm/billboard.js +70 -34
  38. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  39. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
  40. package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
  41. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  42. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  43. package/package.json +7 -7
  44. package/src/ChartInternal/data/load.ts +3 -0
  45. package/src/ChartInternal/shape/funnel.ts +49 -25
  46. package/src/ChartInternal/shape/treemap.ts +19 -10
  47. package/types/types.d.ts +1 -0
@@ -30,15 +30,19 @@ function getSize(checkNeck = false): TSize {
30
30
 
31
31
  // determine if container width to not be less than neck width
32
32
  if (checkNeck) {
33
- const {width: neckWidth} = getNecklSize.call($$, {
33
+ const {width: neckWidth, height: neckHeight} = getNecklSize.call($$, {
34
34
  width: size.width,
35
35
  height: size.height
36
36
  });
37
37
 
38
- // prevent funnel width from being less than neck width
38
+ // prevent neck size to not exceeed funnel size
39
39
  if (size.width < neckWidth) {
40
40
  size.width = neckWidth;
41
41
  }
42
+
43
+ if (size.height < neckHeight) {
44
+ size.height = neckHeight;
45
+ }
42
46
  }
43
47
 
44
48
  return size;
@@ -80,7 +84,7 @@ function getNecklSize(current: TSizeCurrent) {
80
84
  */
81
85
  function getCoord(d: IFunnelData[]) {
82
86
  const $$ = this;
83
- const {top, width} = getSize.call($$, true);
87
+ const {top, left, width} = getSize.call($$, true);
84
88
  const coords: number[][][] = [];
85
89
 
86
90
  d.forEach((d, i) => {
@@ -93,11 +97,11 @@ function getCoord(d: IFunnelData[]) {
93
97
  // | ˅
94
98
  // (3) <-------------- (2)
95
99
  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
100
+ [left, y], // M
101
+ [left + width, y], // 1
102
+ [left + width, i > 0 ? ratio + y : ratio + top], // 2
103
+ [left, i > 0 ? ratio + y : ratio + top], // 3
104
+ [left, y] // 4
101
105
  ]);
102
106
  });
103
107
 
@@ -105,29 +109,36 @@ function getCoord(d: IFunnelData[]) {
105
109
  }
106
110
 
107
111
  /**
108
- * Get neck path
112
+ * Get clip path
113
+ * @param {boolean} forBackground Determine if clip path for background
109
114
  * @returns {string} path
110
115
  * @private
111
116
  */
112
- function getNeckPath() {
117
+ function getClipPath(forBackground = false): string {
113
118
  const $$ = this;
114
119
  const {width, height, top, left} = getSize.call($$, true);
115
120
  const neck = getNecklSize.call($$, {width, height});
116
-
117
- const rightX = (width + neck.width) / 2;
118
121
  const leftX = (width - neck.width) / 2;
122
+ const rightX = (width + neck.width) / 2;
119
123
  const bodyHeigth = height - neck.height;
120
124
 
121
125
  const coords = [
122
- [0 + left, 0 + top], // M
123
- [width + left, 0 + top], // 1
126
+ [0, 0], // M
127
+ [width, 0], // 1
124
128
  [rightX, bodyHeigth], // 2
125
- [rightX, height + top], // 3
126
- [leftX, height + top], // 4
129
+ [rightX, height], // 3
130
+ [leftX, height], // 4
127
131
  [leftX, bodyHeigth], // 5
128
- [0 + left, 0 + top] // 6
132
+ [0, 0] // 6
129
133
  ];
130
134
 
135
+ if (forBackground) {
136
+ coords.forEach(d => {
137
+ d[0] += left;
138
+ d[1] += top;
139
+ });
140
+ }
141
+
131
142
  return `M${coords.join("L")}z`;
132
143
  }
133
144
 
@@ -158,7 +169,7 @@ function getFunnelData(d: IData[]): IFunnelData[] {
158
169
  * @returns {Array} Updated data object
159
170
  * @private
160
171
  */
161
- function updateRatio(data) {
172
+ function updateRatio(data: IFunnelData[]): IFunnelData[] {
162
173
  const $$ = this;
163
174
  const {height} = getSize.call($$);
164
175
  const total = $$.getTotalDataSum(true);
@@ -270,6 +281,19 @@ export default {
270
281
  .style("fill", $$.color);
271
282
  },
272
283
 
284
+ /**
285
+ * Update funnel path selection
286
+ * @param {object} targets Updated target data
287
+ * @private
288
+ */
289
+ updateFunnel(targets: IData[]): void {
290
+ const $$ = this;
291
+ const {$el: {funnel}} = $$;
292
+ const targetIds = targets.map(({id}) => id);
293
+
294
+ funnel.path = funnel.path.filter(d => targetIds.indexOf(d.id) >= 0);
295
+ },
296
+
273
297
  /**
274
298
  * Generate treemap coordinate points data
275
299
  * @returns {Array} Array of coordinate points
@@ -279,13 +303,15 @@ export default {
279
303
  const $$ = this;
280
304
  const {$el: {funnel}} = $$;
281
305
  const targets = $$.filterTargetsToShow(funnel.path);
306
+ const {top, left, right} = getSize.call($$);
307
+ const center = (left - right) / 2;
282
308
  const points = {};
283
- let accumulatedHeight = getSize.call($$).top ?? 0;
309
+ let accumulatedHeight = top ?? 0;
284
310
 
285
311
  targets.each((d, i) => {
286
312
  points[d.id] = [
287
- [0, accumulatedHeight],
288
- [0, accumulatedHeight += (targets?.[i] ?? d).ratio]
313
+ [center, accumulatedHeight],
314
+ [center, accumulatedHeight += (targets?.[i] ?? d).ratio]
289
315
  ];
290
316
  });
291
317
 
@@ -303,10 +329,8 @@ export default {
303
329
  const coords = getCoord.call($$, updateRatio.call($$, targets.data()));
304
330
 
305
331
  // set neck path
306
- const neckPath = getNeckPath.bind($$)();
307
-
308
- funnel.attr("clip-path", `path('${neckPath}')`);
309
- funnel.background.attr("d", neckPath);
332
+ funnel.attr("clip-path", `path('${getClipPath.bind($$)()}')`);
333
+ funnel.background.attr("d", getClipPath.call($$, true));
310
334
 
311
335
  $T(targets)
312
336
  .attr("d", (d, i) => `M${coords[i].join("L")}z`)
@@ -63,6 +63,24 @@ function convertDataToTreemapData(data: IData[]): ITreemapData[] {
63
63
  });
64
64
  }
65
65
 
66
+ /**
67
+ * Get hierarchy data
68
+ * @param {object} data Data object
69
+ * @returns {Array} Array of hierarchy data
70
+ * @private
71
+ */
72
+ function getHierachyData(data) {
73
+ const $$ = this;
74
+ const hierarchyData = d3Hierarchy(data).sum(d => d.value);
75
+ const sortFn = $$.getSortCompareFn(true);
76
+
77
+ return [
78
+ $$.treemap(
79
+ sortFn ? hierarchyData.sort(sortFn) : hierarchyData
80
+ )
81
+ ];
82
+ }
83
+
66
84
  export default {
67
85
  initTreemap(): void {
68
86
  const $$ = this;
@@ -80,15 +98,6 @@ export default {
80
98
  $$.treemap = d3Treemap()
81
99
  .tile($$.getTreemapTile());
82
100
 
83
- $$.treemapFn = data => {
84
- const hierarchyData = d3Hierarchy(data).sum(d => d.value);
85
- const sortFn = $$.getSortCompareFn(true);
86
-
87
- return $$.treemap(
88
- sortFn ? hierarchyData.sort(sortFn) : hierarchyData
89
- );
90
- };
91
-
92
101
  $el.defs
93
102
  .append("clipPath")
94
103
  .attr("id", clip.id)
@@ -198,7 +207,7 @@ export default {
198
207
  updateTargetsForTreemap(targets: IData): void {
199
208
  const $$ = this;
200
209
  const {$el: {treemap}} = $$;
201
- const treemapData = $$.treemapFn($$.getTreemapData(targets ?? $$.data.targets));
210
+ const treemapData = getHierachyData.call($$, $$.getTreemapData(targets ?? $$.data.targets));
202
211
 
203
212
  // using $el.treemap reference can alter data, so select treemap <g> again
204
213
  treemap.data(treemapData);
package/types/types.d.ts CHANGED
@@ -25,6 +25,7 @@ export type ChartTypes = "area"
25
25
  | "gauge"
26
26
  | "line"
27
27
  | "pie"
28
+ | "polar"
28
29
  | "radar"
29
30
  | "scatter"
30
31
  | "spline"