billboard.js 3.11.1 → 3.11.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 (53) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +183 -111
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +183 -111
  6. package/dist/billboard.pkgd.min.js +2 -2
  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 +164 -115
  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 +1 -1
  44. package/src/ChartInternal/ChartInternal.ts +2 -2
  45. package/src/ChartInternal/data/data.ts +1 -1
  46. package/src/ChartInternal/data/load.ts +7 -1
  47. package/src/ChartInternal/internals/redraw.ts +2 -1
  48. package/src/ChartInternal/shape/point.common.ts +134 -0
  49. package/src/ChartInternal/shape/point.ts +3 -95
  50. package/src/ChartInternal/shape/shape.ts +1 -1
  51. package/src/config/Store/State.ts +1 -1
  52. package/src/config/resolver/axis.ts +4 -4
  53. package/src/config/resolver/shape.ts +22 -10
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.11.1
8
+ * @version 3.11.2
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -121,7 +121,7 @@ var Plugin = /** @class */ (function () {
121
121
  delete _this[key];
122
122
  });
123
123
  };
124
- Plugin.version = "3.11.1";
124
+ Plugin.version = "3.11.2";
125
125
  return Plugin;
126
126
  }());
127
127
  var Plugin$1 = Plugin;
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.11.1
8
+ * @version 3.11.2
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -269,7 +269,7 @@ var Plugin = /** @class */ (function () {
269
269
  delete _this[key];
270
270
  });
271
271
  };
272
- Plugin.version = "3.11.1";
272
+ Plugin.version = "3.11.2";
273
273
  return Plugin;
274
274
  }());
275
275
  var Plugin$1 = Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billboard.js",
3
- "version": "3.11.1",
3
+ "version": "3.11.2",
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",
@@ -281,7 +281,7 @@ export default class ChartInternal {
281
281
  config.subchart_show = false;
282
282
  }
283
283
 
284
- if ($$.hasPointType()) {
284
+ if ($$.hasPointType() || $$.hasLegendDefsPoint?.()) {
285
285
  $$.point = $$.generatePoint();
286
286
  }
287
287
 
@@ -416,7 +416,7 @@ export default class ChartInternal {
416
416
  const hasColorPatterns = (isFunction(config.color_tiles) && $$.patterns);
417
417
 
418
418
  if (hasAxis || hasColorPatterns || hasPolar || hasTreemap ||
419
- config.data_labels_backgroundColors) {
419
+ config.data_labels_backgroundColors || $$.hasLegendDefsPoint?.()) {
420
420
  $el.defs = $el.svg.append("defs");
421
421
 
422
422
  if (hasAxis) {
@@ -451,7 +451,7 @@ export default {
451
451
  return this.state.hiddenLegendIds.indexOf(targetId) < 0;
452
452
  },
453
453
 
454
- filterTargetsToShow(targets) {
454
+ filterTargetsToShow(targets?) {
455
455
  const $$ = this;
456
456
 
457
457
  return (targets || $$.data.targets).filter(t => $$.isTargetToShow(t.id));
@@ -131,6 +131,7 @@ export default {
131
131
  unload(rawTargetIds, customDoneCb): void {
132
132
  const $$ = this;
133
133
  const {state, $el, $T} = $$;
134
+ const hasLegendDefsPoint = !!$$.hasLegendDefsPoint?.();
134
135
  let done = customDoneCb;
135
136
  let targetIds = rawTargetIds;
136
137
 
@@ -158,16 +159,21 @@ export default {
158
159
  .call(endall, done);
159
160
 
160
161
  targetIds.forEach(id => {
162
+ const suffixId = $$.getTargetSelectorSuffix(id);
163
+
161
164
  // Reset fadein for future load
162
165
  state.withoutFadeIn[id] = false;
163
166
 
164
167
  // Remove target's elements
165
168
  if ($el.legend) {
166
- $el.legend.selectAll(`.${$LEGEND.legendItem}${$$.getTargetSelectorSuffix(id)}`).remove();
169
+ $el.legend.selectAll(`.${$LEGEND.legendItem}${suffixId}`).remove();
167
170
  }
168
171
 
169
172
  // Remove target
170
173
  $$.data.targets = $$.data.targets.filter(t => t.id !== id);
174
+
175
+ // Remove custom point def element
176
+ hasLegendDefsPoint && $el.defs?.select(`#${$$.getDefsPointId(suffixId)}`).remove();
171
177
  });
172
178
 
173
179
  // since treemap uses different data types, it needs to be transformed
@@ -86,9 +86,10 @@ export default {
86
86
  treemap && $$.updateTreemap(durationForExit);
87
87
  }
88
88
 
89
- // @TODO: Axis & Radar type
90
89
  if (!state.resizing && !treemap && ($$.hasPointType() || state.hasRadar)) {
91
90
  $$.updateCircle();
91
+ } else if ($$.hasLegendDefsPoint?.()) {
92
+ $$.data.targets.forEach($$.point("create", this));
92
93
  }
93
94
 
94
95
  // text
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Copyright (c) 2017 ~ present NAVER Corp.
3
+ * billboard.js project is licensed under the MIT license
4
+ */
5
+ import {
6
+ namespaces as d3Namespaces,
7
+ select as d3Select
8
+ } from "d3-selection";
9
+ import {document} from "../../module/browser";
10
+ import {isFunction, isObjectType, notEmpty, toArray} from "../../module/util";
11
+
12
+ /**
13
+ * Check if point draw methods are valid
14
+ * @param {string} point point type
15
+ * @returns {boolean}
16
+ * @private
17
+ */
18
+ function hasValidPointDrawMethods(point: string): boolean {
19
+ return isObjectType(point) &&
20
+ isFunction(point.create) && isFunction(point.update);
21
+ }
22
+
23
+ /**
24
+ * Insert point info defs element
25
+ * @param {string} point Point element
26
+ * @param {string} id Point id
27
+ * @private
28
+ */
29
+ function insertPointInfoDefs(point: string, id: string): void {
30
+ const $$ = this;
31
+ const copyAttr = (from, target) => {
32
+ const attribs = from.attributes;
33
+
34
+ for (let i = 0, name; (name = attribs[i]); i++) {
35
+ name = name.name;
36
+ target.setAttribute(name, from.getAttribute(name));
37
+ }
38
+ };
39
+
40
+ const doc = new DOMParser().parseFromString(point, "image/svg+xml");
41
+ const node = doc.documentElement;
42
+ const clone = document.createElementNS(d3Namespaces.svg, node.nodeName.toLowerCase());
43
+
44
+ clone.id = id;
45
+ clone.style.fill = "inherit";
46
+ clone.style.stroke = "inherit";
47
+
48
+ copyAttr(node, clone);
49
+
50
+ if (node.childNodes?.length) {
51
+ const parent = d3Select(clone);
52
+
53
+ if ("innerHTML" in clone) {
54
+ parent.html(node.innerHTML);
55
+ } else {
56
+ toArray(node.childNodes).forEach(v => {
57
+ copyAttr(v, parent.append(v.tagName).node());
58
+ });
59
+ }
60
+ }
61
+
62
+ $$.$el.defs.node().appendChild(clone);
63
+ }
64
+
65
+ export default {
66
+ /**
67
+ * Check if point type option is valid
68
+ * @param {string} type point type
69
+ * @returns {boolean}
70
+ * @private
71
+ */
72
+ hasValidPointType(type?: string): boolean {
73
+ return /^(circle|rect(angle)?|polygon|ellipse|use)$/i.test(type || this.config.point_type);
74
+ },
75
+
76
+ /**
77
+ * Check if pattern point is set to be used on legend
78
+ * @returns {boolean}
79
+ * @private
80
+ */
81
+ hasLegendDefsPoint(): boolean {
82
+ const {config} = this;
83
+
84
+ return config.legend_show && config.point_pattern?.length && config.legend_usePoint;
85
+ },
86
+
87
+ getDefsPointId(id: string): string {
88
+ const {state: {datetimeId}} = this;
89
+
90
+ return `${datetimeId}-point${id}`;
91
+ },
92
+
93
+ /**
94
+ * Get generate point function
95
+ * @returns {Function}
96
+ * @private
97
+ */
98
+ generatePoint(): Function {
99
+ const $$ = this;
100
+ const {$el, config} = $$;
101
+ const ids: string[] = [];
102
+ const pattern = notEmpty(config.point_pattern) ? config.point_pattern : [config.point_type];
103
+
104
+ return function(method, context, ...args) {
105
+ return function(d) {
106
+ const id: string = $$.getTargetSelectorSuffix(d.id || d.data?.id || d);
107
+ const element = d3Select(this);
108
+
109
+ ids.indexOf(id) < 0 && ids.push(id);
110
+
111
+ let point = pattern[ids.indexOf(id) % pattern.length];
112
+
113
+ if ($$.hasValidPointType(point)) {
114
+ point = $$[point];
115
+ } else if (!hasValidPointDrawMethods(point || config.point_type)) {
116
+ const pointId = $$.getDefsPointId(id);
117
+ const defsPoint = $el.defs.select(`#${pointId}`);
118
+
119
+ if (defsPoint.size() < 1) {
120
+ insertPointInfoDefs.bind($$)(point, pointId);
121
+ }
122
+
123
+ if (method === "create") {
124
+ return $$.custom?.create.bind(context)(element, pointId, ...args);
125
+ } else if (method === "update") {
126
+ return $$.custom?.update.bind(context)(element, ...args);
127
+ }
128
+ }
129
+
130
+ return point[method]?.bind(context)(element, ...args);
131
+ };
132
+ };
133
+ }
134
+ };
@@ -2,30 +2,15 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {
6
- namespaces as d3Namespaces,
7
- select as d3Select
8
- } from "d3-selection";
9
- import type {d3Selection} from "../../../types/types";
5
+ import {select as d3Select} from "d3-selection";
10
6
  import {$CIRCLE, $COMMON, $SELECT} from "../../config/classes";
11
- import {document} from "../../module/browser";
7
+ import {getBoundingRect, getPointer, getRandom, isFunction, isObject, isUndefined, isValue} from "../../module/util";
8
+ import type {d3Selection} from "../../../types/types";
12
9
  import type {IDataPoint, IDataRow} from "../data/IData";
13
- import {getBoundingRect, getPointer, getRandom, isFunction, isObject, isObjectType, isUndefined, isValue, toArray, notEmpty} from "../../module/util";
14
10
 
15
11
  const getTransitionName = () => getRandom();
16
12
 
17
13
  export default {
18
- hasValidPointType(type?: string): boolean {
19
- return /^(circle|rect(angle)?|polygon|ellipse|use)$/i.test(type || this.config.point_type);
20
- },
21
-
22
- hasValidPointDrawMethods(type?: string): boolean {
23
- const pointType = type || this.config.point_type;
24
-
25
- return isObjectType(pointType) &&
26
- isFunction(pointType.create) && isFunction(pointType.update);
27
- },
28
-
29
14
  initialOpacityForCircle(d): string | number | null {
30
15
  const {config, state: {withoutFadeIn}} = this;
31
16
  let opacity = config.point_opacity;
@@ -410,46 +395,6 @@ export default {
410
395
  return sensitivity;
411
396
  },
412
397
 
413
- insertPointInfoDefs(point, id: string): void {
414
- const $$ = this;
415
- const copyAttr = (from, target) => {
416
- const attribs = from.attributes;
417
-
418
- for (let i = 0, name; (name = attribs[i]); i++) {
419
- name = name.name;
420
- target.setAttribute(name, from.getAttribute(name));
421
- }
422
- };
423
-
424
- const doc = new DOMParser().parseFromString(point, "image/svg+xml");
425
- const node = doc.documentElement;
426
- const clone = document.createElementNS(d3Namespaces.svg, node.nodeName.toLowerCase());
427
-
428
- clone.id = id;
429
- clone.style.fill = "inherit";
430
- clone.style.stroke = "inherit";
431
-
432
- copyAttr(node, clone);
433
-
434
- if (node.childNodes?.length) {
435
- const parent = d3Select(clone);
436
-
437
- if ("innerHTML" in clone) {
438
- parent.html(node.innerHTML);
439
- } else {
440
- toArray(node.childNodes).forEach(v => {
441
- copyAttr(v, parent.append(v.tagName).node());
442
- });
443
- }
444
- }
445
-
446
- $$.$el.defs.node().appendChild(clone);
447
- },
448
-
449
- pointFromDefs(id: string) {
450
- return this.$el.defs.select(`#${id}`);
451
- },
452
-
453
398
  updatePointClass(d) {
454
399
  const $$ = this;
455
400
  const {circle} = $$.$el;
@@ -504,43 +449,6 @@ export default {
504
449
  };
505
450
  },
506
451
 
507
- generatePoint(): Function {
508
- const $$ = this;
509
- const {config, state: {datetimeId}} = $$;
510
- const ids: string[] = [];
511
- const pattern = notEmpty(config.point_pattern) ? config.point_pattern : [config.point_type];
512
-
513
- return function(method, context, ...args) {
514
- return function(d) {
515
- const id: string = $$.getTargetSelectorSuffix(d.id || d.data?.id || d);
516
- const element = d3Select(this);
517
-
518
- ids.indexOf(id) < 0 && ids.push(id);
519
-
520
- let point = pattern[ids.indexOf(id) % pattern.length];
521
-
522
- if ($$.hasValidPointType(point)) {
523
- point = $$[point];
524
- } else if (!$$.hasValidPointDrawMethods(point)) {
525
- const pointId = `${datetimeId}-point${id}`;
526
- const pointFromDefs = $$.pointFromDefs(pointId);
527
-
528
- if (pointFromDefs.size() < 1) {
529
- $$.insertPointInfoDefs(point, pointId);
530
- }
531
-
532
- if (method === "create") {
533
- return $$.custom.create.bind(context)(element, pointId, ...args);
534
- } else if (method === "update") {
535
- return $$.custom.update.bind(context)(element, ...args);
536
- }
537
- }
538
-
539
- return point[method].bind(context)(element, ...args);
540
- };
541
- };
542
- },
543
-
544
452
  custom: {
545
453
  create(element, id, fillStyleFn) {
546
454
  return element.append("use")
@@ -425,7 +425,7 @@ export default {
425
425
  const maxDataCount = $$.getMaxDataCount();
426
426
  const isGrouped = type === "bar" && config.data_groups?.length;
427
427
  const configName = `${type}_width`;
428
- const {k} = $$.getZoomTransform();
428
+ const {k} = $$.getZoomTransform?.() ?? {k: 1};
429
429
  const xMinMax = <[number, number]>[
430
430
  config.axis_x_min ?? org.xDomain[0],
431
431
  config.axis_x_max ?? org.xDomain[1]
@@ -55,7 +55,7 @@ export default class State {
55
55
  dataMax: 0,
56
56
 
57
57
  maxTickSize: {
58
- x: {width: 0, height: 0, ticks: <number[]> [], clipPath: 0, domain: ""},
58
+ x: {width: 0, height: 0, ticks: <(number|string)[]> [], clipPath: 0, domain: ""},
59
59
  y: {width: 0, height: 0, domain: ""},
60
60
  y2: {width: 0, height: 0, domain: ""}
61
61
  },
@@ -39,7 +39,7 @@ export const api = [
39
39
  apiX
40
40
  ];
41
41
 
42
- export const internal = [
42
+ export const internal = {
43
43
  axis,
44
44
  clip,
45
45
  eventrect,
@@ -47,10 +47,10 @@ export const internal = [
47
47
  grid,
48
48
  region,
49
49
  sizeAxis,
50
- ];
50
+ };
51
51
 
52
- export const options = [
52
+ export const options = {
53
53
  optDataAxis,
54
54
  optAxis,
55
55
  optGrid,
56
- ];
56
+ };
@@ -23,6 +23,7 @@ import shapeCandlestick from "../../ChartInternal/shape/candlestick";
23
23
  import shapeGauge from "../../ChartInternal/shape/gauge";
24
24
  import shapeBubble from "../../ChartInternal/shape/bubble";
25
25
  import shapeLine from "../../ChartInternal/shape/line";
26
+ import shapePointCommon from "../../ChartInternal/shape/point.common";
26
27
  import shapePoint from "../../ChartInternal/shape/point";
27
28
  import shapePolar from "../../ChartInternal/shape/polar";
28
29
  import shapeRadar from "../../ChartInternal/shape/radar";
@@ -75,9 +76,9 @@ export {
75
76
  * @private
76
77
  */
77
78
  function extendAxis(module, option?): void {
78
- extend(ChartInternal.prototype, axisInternal.concat(module));
79
+ extend(ChartInternal.prototype, Object.values(axisInternal).concat(module));
79
80
  extend(Chart.prototype, axisAPI);
80
- Options.setOptions(axisOptions.concat(option || []));
81
+ Options.setOptions(Object.values(axisOptions).concat(option || []));
81
82
  }
82
83
 
83
84
  /**
@@ -87,7 +88,7 @@ function extendAxis(module, option?): void {
87
88
  * @private
88
89
  */
89
90
  function extendLine(module?, option?): void {
90
- extendAxis([shapePoint, shapeLine].concat(module || []));
91
+ extendAxis([shapePointCommon, shapePoint, shapeLine].concat(module || []));
91
92
  Options.setOptions([optPoint, optLine].concat(option || []));
92
93
  }
93
94
 
@@ -98,8 +99,8 @@ function extendLine(module?, option?): void {
98
99
  * @private
99
100
  */
100
101
  function extendArc(module?, option?): void {
101
- extend(ChartInternal.prototype, [shapeArc].concat(module || []));
102
- Options.setOptions(option);
102
+ extend(ChartInternal.prototype, [shapeArc, shapePointCommon].concat(module || []));
103
+ Options.setOptions([optPoint].concat(option || []));
103
104
  }
104
105
 
105
106
  // Area types
@@ -138,19 +139,30 @@ let polar = (): string => (
138
139
  extendArc([shapePolar], [optArc, optPolar]), (polar = () => TYPE.POLAR)()
139
140
  );
140
141
  let radar = (): string => (
141
- extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = () => TYPE.RADAR)()
142
+ extendArc(
143
+ [axisInternal.eventrect, shapePoint, shapeRadar],
144
+ [optPoint, optRadar, {axis_x_categories: axisOptions.optAxis.axis_x_categories}]
145
+ ), (radar = () => TYPE.RADAR)()
142
146
  );
143
147
 
144
148
  // Axis based types
145
- let bar = (): string => (extendAxis([shapeBar], optBar), (bar = () => TYPE.BAR)());
149
+ let bar = (): string => (
150
+ extendAxis([shapeBar, shapePointCommon], [optBar, optPoint]), (bar = () => TYPE.BAR)()
151
+ );
146
152
  let bubble = (): string => (
147
- extendAxis([shapePoint, shapeBubble], [optBubble, optPoint]), (bubble = () => TYPE.BUBBLE)()
153
+ extendAxis(
154
+ [shapePointCommon, shapePoint, shapeBubble], [optBubble, optPoint]
155
+ ), (bubble = () => TYPE.BUBBLE)()
148
156
  );
149
157
  let candlestick = (): string => (
150
- extendAxis([shapeCandlestick], [optCandlestick]), (candlestick = () => TYPE.CANDLESTICK)()
158
+ extendAxis(
159
+ [shapeCandlestick, shapePointCommon], [optCandlestick, optPoint]
160
+ ), (candlestick = () => TYPE.CANDLESTICK)()
151
161
  );
152
162
  let scatter = (): string => (
153
- extendAxis([shapePoint], [optPoint, optScatter]), (scatter = () => TYPE.SCATTER)()
163
+ extendAxis(
164
+ [shapePointCommon, shapePoint], [optPoint, optScatter]
165
+ ), (scatter = () => TYPE.SCATTER)()
154
166
  );
155
167
 
156
168
  // Non Axis based types