billboard.js 3.16.0-next.2 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +95 -91
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +8 -8
  5. package/dist/billboard.pkgd.js +95 -91
  6. package/dist/billboard.pkgd.min.js +13 -13
  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 +3 -3
  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 +128 -114
  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 +11 -11
  44. package/src/ChartInternal/ChartInternal.ts +51 -60
  45. package/src/ChartInternal/data/convert.ts +71 -45
  46. package/src/config/Options/axis/y2.ts +0 -13
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.16.0-next.2
8
+ * @version 3.16.0
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -204,7 +204,7 @@ var Plugin = /** @class */ (function () {
204
204
  delete _this[key];
205
205
  });
206
206
  };
207
- Plugin.version = "3.16.0-next.2";
207
+ Plugin.version = "3.16.0";
208
208
  return Plugin;
209
209
  }());
210
210
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billboard.js",
3
- "version": "3.16.0-next.2",
3
+ "version": "3.16.0",
4
4
  "description": "Re-usable easy interface JavaScript chart library, based on D3 v4+",
5
5
  "homepage": "https://naver.github.io/billboard.js/",
6
6
  "main": "dist/billboard.js",
@@ -107,7 +107,7 @@
107
107
  "@eslint/js": "^9.29.0",
108
108
  "@rollup/plugin-node-resolve": "^16.0.1",
109
109
  "@rollup/plugin-replace": "^6.0.2",
110
- "@rollup/plugin-typescript": "^12.1.2",
110
+ "@rollup/plugin-typescript": "^12.1.3",
111
111
  "@semantic-release/changelog": "^6.0.3",
112
112
  "@semantic-release/commit-analyzer": "^13.0.1",
113
113
  "@semantic-release/exec": "^7.1.0",
@@ -118,9 +118,9 @@
118
118
  "@testing-library/react": "^16.3.0",
119
119
  "@types/d3": "^7.4.3",
120
120
  "@types/sinon": "^17.0.4",
121
- "@vitest/browser": "^3.2.3",
122
- "@vitest/coverage-istanbul": "^3.2.3",
123
- "@vitest/ui": "^3.2.3",
121
+ "@vitest/browser": "^3.2.4",
122
+ "@vitest/coverage-istanbul": "^3.2.4",
123
+ "@vitest/ui": "^3.2.4",
124
124
  "better-docs": "^2.7.3",
125
125
  "clean-webpack-plugin": "^4.0.0",
126
126
  "cloc": "2.4.0-cloc",
@@ -136,15 +136,15 @@
136
136
  "dprint": "^0.50.0",
137
137
  "esbuild-loader": "^4.3.0",
138
138
  "eslint": "^9.29.0",
139
- "eslint-plugin-import": "^2.31.0",
140
- "eslint-plugin-jsdoc": "^51.0.1",
139
+ "eslint-plugin-import": "^2.32.0",
140
+ "eslint-plugin-jsdoc": "^51.2.3",
141
141
  "husky": "^9.1.7",
142
142
  "jsdoc": "^4.0.4",
143
143
  "lint-staged": "^16.1.2",
144
144
  "mini-css-extract-plugin": "^2.9.2",
145
- "playwright": "^1.53.0",
145
+ "playwright": "^1.53.1",
146
146
  "regenerator-runtime": "^0.14.1",
147
- "rollup": "^4.43.0",
147
+ "rollup": "^4.44.0",
148
148
  "rollup-plugin-delete": "^3.0.1",
149
149
  "sass": "^1.89.2",
150
150
  "sass-loader": "^16.0.5",
@@ -155,8 +155,8 @@
155
155
  "style-loader": "^4.0.0",
156
156
  "tslib": "^2.8.1",
157
157
  "typescript": "^5.8.3",
158
- "typescript-eslint": "^8.34.0",
159
- "vitest": "^3.2.3",
158
+ "typescript-eslint": "^8.35.0",
159
+ "vitest": "^3.2.4",
160
160
  "webpack": "^5.99.9",
161
161
  "webpack-bundle-analyzer": "^4.10.2",
162
162
  "webpack-clean": "^1.2.5",
@@ -191,19 +191,20 @@ export default class ChartInternal {
191
191
  init(): void {
192
192
  const $$ = <any>this;
193
193
  const {config, state, $el} = $$;
194
- const useCssRule = config.boost_useCssRule;
194
+ const {boost_useCssRule, bindto} = config;
195
195
 
196
196
  checkModuleImport($$);
197
197
 
198
+ const hasArcType = $$.hasArcType();
198
199
  state.hasRadar = !state.hasAxis && $$.hasType("radar");
199
200
  state.hasFunnel = !state.hasAxis && $$.hasType("funnel");
200
201
  state.hasTreemap = !state.hasAxis && $$.hasType("treemap");
201
- state.hasAxis = !$$.hasArcType() && !state.hasFunnel && !state.hasTreemap;
202
+ state.hasAxis = !hasArcType && !state.hasFunnel && !state.hasTreemap;
202
203
 
203
204
  // datetime to be used for uniqueness
204
205
  state.datetimeId = `bb-${+new Date() * (getRandom() as number)}`;
205
206
 
206
- if (useCssRule) {
207
+ if (boost_useCssRule) {
207
208
  // append style element
208
209
  const styleEl = document.createElement("style");
209
210
 
@@ -220,28 +221,28 @@ export default class ChartInternal {
220
221
  $el.style = styleEl;
221
222
  }
222
223
 
223
- const bindto = {
224
- element: config.bindto,
224
+ const bindConfig = {
225
+ element: bindto,
225
226
  classname: "bb"
226
227
  };
227
228
 
228
- if (isObject(config.bindto)) {
229
- bindto.element = config.bindto.element || "#chart";
230
- bindto.classname = config.bindto.classname || bindto.classname;
229
+ if (isObject(bindto)) {
230
+ bindConfig.element = bindto.element || "#chart";
231
+ bindConfig.classname = bindto.classname || bindConfig.classname;
231
232
  }
232
233
 
233
234
  // select bind element
234
- $el.chart = isFunction(bindto.element.node) ?
235
- config.bindto.element :
236
- d3Select(bindto.element || []);
235
+ $el.chart = isFunction(bindConfig.element.node) ?
236
+ bindto.element :
237
+ d3Select(bindConfig.element || []);
237
238
 
238
239
  if ($el.chart.empty()) {
239
240
  $el.chart = d3Select(document.body.appendChild(document.createElement("div")));
240
241
  }
241
242
 
242
243
  $el.chart.html("")
243
- .classed(bindto.classname, true)
244
- .classed(state.datetimeId, useCssRule)
244
+ .classed(bindConfig.classname, true)
245
+ .classed(state.datetimeId, boost_useCssRule)
245
246
  .style("position", "relative");
246
247
 
247
248
  $$.initParams();
@@ -284,7 +285,6 @@ export default class ChartInternal {
284
285
  initParams(): void {
285
286
  const $$ = <any>this;
286
287
  const {config, format, state} = $$;
287
- const isRotated = config.axis_rotated;
288
288
 
289
289
  // color settings
290
290
  $$.color = $$.generateColor();
@@ -309,7 +309,7 @@ export default class ChartInternal {
309
309
  format.dataTime = config.data_xLocaltime ? d3TimeParse : d3UtcParse;
310
310
  format.axisTime = config.axis_x_localtime ? d3TimeFormat : d3UtcFormat;
311
311
 
312
- const isDragZoom = $$.config.zoom_enabled && $$.config.zoom_type === "drag";
312
+ const isDragZoom = config.zoom_enabled && config.zoom_type === "drag";
313
313
 
314
314
  format.defaultAxisTime = d => {
315
315
  const {x, zoom} = $$.scale;
@@ -329,17 +329,17 @@ export default class ChartInternal {
329
329
  };
330
330
  }
331
331
 
332
- state.isLegendRight = config.legend_position === "right";
333
- state.isLegendInset = config.legend_position === "inset";
332
+ const {legend_position, legend_inset_anchor, axis_rotated} = config;
334
333
 
335
- state.isLegendTop = config.legend_inset_anchor === "top-left" ||
336
- config.legend_inset_anchor === "top-right";
337
-
338
- state.isLegendLeft = config.legend_inset_anchor === "top-left" ||
339
- config.legend_inset_anchor === "bottom-left";
334
+ state.isLegendRight = legend_position === "right";
335
+ state.isLegendInset = legend_position === "inset";
336
+ state.isLegendTop = legend_inset_anchor === "top-left" ||
337
+ legend_inset_anchor === "top-right";
338
+ state.isLegendLeft = legend_inset_anchor === "top-left" ||
339
+ legend_inset_anchor === "bottom-left";
340
340
 
341
341
  state.rotatedPadding.top = $$.getResettedPadding(state.rotatedPadding.top);
342
- state.rotatedPadding.right = isRotated && !config.axis_x_show ? 0 : 30;
342
+ state.rotatedPadding.right = axis_rotated && !config.axis_x_show ? 0 : 30;
343
343
 
344
344
  state.inputType = convertInputType(
345
345
  config.interaction_inputType_mouse,
@@ -439,7 +439,7 @@ export default class ChartInternal {
439
439
  $el.defs = $el.svg.append("defs");
440
440
 
441
441
  if (hasAxis) {
442
- ["id", "idXAxis", "idYAxis", "idY2Axis", "idGrid"].forEach(v => {
442
+ ["id", "idXAxis", "idYAxis", "idGrid"].forEach(v => {
443
443
  $$.appendClip($el.defs, state.clip[v]);
444
444
  });
445
445
  }
@@ -560,25 +560,25 @@ export default class ChartInternal {
560
560
  shapes.push(shapes.shift() as string);
561
561
  }
562
562
 
563
- shapes.forEach(v => {
564
- const name = capitalize(v);
565
-
566
- if ((v === "line" && $$.hasTypeOf(name)) || $$.hasType(v)) {
563
+ for (const shape of shapes) {
564
+ const name = capitalize(shape);
565
+ if ((shape === "line" && $$.hasTypeOf(name)) || $$.hasType(shape)) {
567
566
  types.push(name);
568
567
  }
569
- });
568
+ }
570
569
  } else if (hasTreemap) {
571
570
  types.push("Treemap");
572
571
  } else if ($$.hasType("funnel")) {
573
572
  types.push("Funnel");
574
573
  } else {
575
574
  const hasPolar = $$.hasType("polar");
575
+ const hasGauge = $$.hasType("gauge");
576
576
 
577
577
  if (!hasRadar) {
578
578
  types.push("Arc", "Pie");
579
579
  }
580
580
 
581
- if ($$.hasType("gauge")) {
581
+ if (hasGauge) {
582
582
  types.push("Gauge");
583
583
  } else if (hasRadar) {
584
584
  types.push("Radar");
@@ -587,11 +587,13 @@ export default class ChartInternal {
587
587
  }
588
588
  }
589
589
 
590
- types.forEach(v => {
591
- $$[`init${v}`]();
592
- });
590
+ for (const type of types) {
591
+ $$[`init${type}`]();
592
+ }
593
593
 
594
- notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"]) && $$.initText();
594
+ if (notEmpty($$.config.data_labels) && !$$.hasArcType(null, ["radar"])) {
595
+ $$.initText();
596
+ }
595
597
  }
596
598
 
597
599
  /**
@@ -685,17 +687,16 @@ export default class ChartInternal {
685
687
  $$.updateTargetsForText(targets);
686
688
 
687
689
  if (hasAxis) {
688
- ["bar", "candlestick", "line"].forEach(v => {
689
- const name = capitalize(v);
690
-
691
- if ((v === "line" && $$.hasTypeOf(name)) || $$.hasType(v)) {
690
+ const shapes = ["bar", "candlestick", "line"];
691
+ for (const shape of shapes) {
692
+ const name = capitalize(shape);
693
+ if ((shape === "line" && $$.hasTypeOf(name)) || $$.hasType(shape)) {
692
694
  helper(name);
693
695
  }
694
- });
696
+ }
695
697
 
696
698
  // Sub Chart
697
- $$.updateTargetsForSubchart &&
698
- $$.updateTargetsForSubchart(targets);
699
+ $$.updateTargetsForSubchart?.(targets);
699
700
 
700
701
  // Arc, Polar, Radar
701
702
  } else if ($$.hasArcType(targets)) {
@@ -760,15 +761,10 @@ export default class ChartInternal {
760
761
  Y: true
761
762
  };
762
763
 
763
- Object.keys(withOptions).forEach(key => {
764
- let defVal = withOptions[key];
765
-
766
- if (isString(defVal)) {
767
- defVal = withOptions[defVal];
768
- }
769
-
770
- withOptions[key] = getOption(options, `with${key}`, defVal);
771
- });
764
+ for (const [key, defVal] of Object.entries(withOptions)) {
765
+ const value = isString(defVal) ? withOptions[defVal] : defVal;
766
+ withOptions[key] = getOption(options, `with${key}`, value);
767
+ }
772
768
 
773
769
  return withOptions;
774
770
  }
@@ -777,23 +773,19 @@ export default class ChartInternal {
777
773
  const $$ = <any>this;
778
774
  const {withoutFadeIn} = $$.state;
779
775
 
780
- const r = $$.getBaseValue(d) !== null &&
781
- withoutFadeIn[d.id] ?
782
- null :
783
- "0";
784
-
785
- return r;
776
+ return $$.getBaseValue(d) !== null && withoutFadeIn[d.id] ? null : "0";
786
777
  }
787
778
 
788
779
  bindResize(): void {
789
780
  const $$ = <any>this;
790
781
  const {$el, config, state} = $$;
791
782
  const resizeFunction = generateResize(config.resize_timer);
792
- const list: Function[] = [];
783
+ const {resize_auto} = config;
784
+ const list: (() => void)[] = [];
793
785
 
794
786
  list.push(() => callFn(config.onresize, $$.api));
795
787
 
796
- if (/^(true|parent)$/.test(config.resize_auto)) {
788
+ if (/^(true|parent)$/.test(resize_auto)) {
797
789
  list.push(() => {
798
790
  state.resizing = true;
799
791
 
@@ -814,11 +806,10 @@ export default class ChartInternal {
814
806
 
815
807
  // add resize functions
816
808
  list.forEach(v => resizeFunction.add(v));
817
-
818
809
  $$.resizeFunction = resizeFunction;
819
810
 
820
811
  // attach resize event
821
- if (config.resize_auto === "parent") {
812
+ if (resize_auto === "parent") {
822
813
  ($$.resizeFunction.resizeObserver = new ResizeObserver($$.resizeFunction.bind($$)))
823
814
  .observe($el.chart.node().parentNode);
824
815
  } else {
@@ -24,6 +24,60 @@ function getDataKeyForJson(keysParam, config) {
24
24
  return keys;
25
25
  }
26
26
 
27
+ /**
28
+ * Set `xs` for each id
29
+ * @param {string[]} ids Ids to set xs
30
+ * @param {object[]} data Data to set xs from
31
+ * @param {object} params Parameters for setting xs
32
+ * @param {boolean} params.appendXs Whether to append xs
33
+ * @param {string[]} params.xs X keys to set xs from
34
+ * @param {boolean} params.categorized Whether the axis is categorized
35
+ * @param {boolean} params.timeSeries Whether the axis is time series
36
+ * @param {boolean} params.customX Whether the x is custom
37
+ * @private
38
+ */
39
+ function setXS(
40
+ ids: string[],
41
+ data: {[key: string]: number | null}[],
42
+ params: {appendXs, xs, categorized: boolean, timeSeries: boolean, customX: boolean}
43
+ ): void {
44
+ const $$ = this;
45
+ const {config} = $$;
46
+ let xsData;
47
+
48
+ ids.forEach(id => {
49
+ const xKey = $$.getXKey(id);
50
+
51
+ if (params.customX || params.timeSeries) {
52
+ // if included in input data
53
+ if (params.xs.indexOf(xKey) >= 0) {
54
+ xsData = ((params.appendXs && $$.data.xs[id]) || [])
55
+ .concat(
56
+ data.map((d, i) => {
57
+ const rawX = isValue(d[xKey]);
58
+ return rawX ? $$.generateTargetX(rawX, id, i) : false;
59
+ }).filter(v => v !== false)
60
+ );
61
+ } else if (config.data_x) {
62
+ // if not included in input data, find from preloaded data of other id's x
63
+ xsData = this.getOtherTargetXs();
64
+ } else if (notEmpty(config.data_xs)) {
65
+ // if not included in input data, find from preloaded data
66
+ xsData = $$.getXValuesOfXKey(xKey, $$.data.targets);
67
+ }
68
+ // MEMO: if no x included, use same x of current will be used
69
+ } else {
70
+ xsData = data.map((d, i) => i);
71
+ }
72
+
73
+ if (xsData) {
74
+ $$.data.xs[id] = xsData;
75
+ } else {
76
+ throw new Error(`x is not defined for id = "${id}".`);
77
+ }
78
+ });
79
+ }
80
+
27
81
  /**
28
82
  * Data convert
29
83
  * @memberof ChartInternal
@@ -71,20 +125,17 @@ export default {
71
125
  }
72
126
  },
73
127
 
128
+ /**
129
+ * Convert data to targets
130
+ * @param {object[]} data Data to convert
131
+ * @param {boolean} appendXs Whether to append xs
132
+ * @returns {IData[]} Converted targets
133
+ * @private
134
+ */
74
135
  convertDataToTargets(data: {[key: string]: number | null}[], appendXs: boolean): IData[] {
75
136
  const $$ = this;
76
137
  const {axis, config, state} = $$;
77
138
  const chartType = config.data_type;
78
- let isCategorized = false;
79
- let isTimeSeries = false;
80
- let isCustomX = false;
81
-
82
- if (axis) {
83
- isCategorized = axis.isCategorized();
84
- isTimeSeries = axis.isTimeSeries();
85
- isCustomX = axis.isCustomX();
86
- }
87
-
88
139
  const dataKeys = Object.keys(data[0] || {});
89
140
 
90
141
  // Extract ids and xs from data keys to handle x and non-x values
@@ -100,48 +151,23 @@ export default {
100
151
  }, {ids: [] as string[], xs: [] as string[]}) :
101
152
  {ids: [], xs: []};
102
153
 
103
- let xsData;
154
+ const params = {
155
+ appendXs,
156
+ xs,
157
+ idConverter: config.data_idConverter.bind($$.api),
158
+ categorized: axis?.isCategorized(),
159
+ timeSeries: axis?.isTimeSeries(),
160
+ customX: axis?.isCustomX()
161
+ };
104
162
 
105
163
  // save x for update data by load when custom x and bb.x API
106
- ids.forEach(id => {
107
- const xKey = this.getXKey(id);
108
-
109
- if (isCustomX || isTimeSeries) {
110
- // if included in input data
111
- if (xs.indexOf(xKey) >= 0) {
112
- xsData = ((appendXs && $$.data.xs[id]) || [])
113
- .concat(
114
- data.map(d => d[xKey])
115
- .filter(isValue)
116
- .map((rawX, i) => $$.generateTargetX(rawX, id, i))
117
- );
118
- } else if (config.data_x) {
119
- // if not included in input data, find from preloaded data of other id's x
120
- xsData = this.getOtherTargetXs();
121
- } else if (notEmpty(config.data_xs)) {
122
- // if not included in input data, find from preloaded data
123
- xsData = $$.getXValuesOfXKey(xKey, $$.data.targets);
124
- }
125
- // MEMO: if no x included, use same x of current will be used
126
- } else {
127
- xsData = data.map((d, i) => i);
128
- }
129
-
130
- xsData && (this.data.xs[id] = xsData);
131
- });
132
-
133
- // check x is defined
134
- ids.forEach(id => {
135
- if (!this.data.xs[id]) {
136
- throw new Error(`x is not defined for id = "${id}".`);
137
- }
138
- });
164
+ setXS.bind($$)(ids, data, params);
139
165
 
140
166
  // convert to target
141
167
  const targets = ids.map((id, index) => {
142
168
  const convertedId = config.data_idConverter.bind($$.api)(id);
143
169
  const xKey = $$.getXKey(id);
144
- const isCategory = isCustomX && isCategorized;
170
+ const isCategory = params.customX && params.categorized;
145
171
  const hasCategory = isCategory && (() => {
146
172
  const categorySet = new Set(config.axis_x_categories);
147
173
  return data.every(v => categorySet.has(v.x));
@@ -6,19 +6,6 @@
6
6
  * y2 Axis config options
7
7
  */
8
8
  export default {
9
- /**
10
- * Set clip-path attribute for y2 axis element
11
- * - **NOTE**: `clip-path` attribute for y2 Axis is set only when `axis.y2.inner` option is true.
12
- * @name axis․y2․clipPath
13
- * @memberof Options
14
- * @type {boolean}
15
- * @default true
16
- * @example
17
- * // don't set 'clip-path' attribute
18
- * clipPath: false
19
- */
20
- axis_y2_clipPath: true,
21
-
22
9
  /**
23
10
  * Show or hide y2 axis.
24
11
  * - **NOTE**: