billboard.js 3.4.0-next.1 → 3.4.1

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/README.md +7 -3
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +167 -58
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +237 -81
  7. package/dist/billboard.pkgd.min.js +2 -2
  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.js +12 -7
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +12 -7
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +12 -7
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +12 -7
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2 -2
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +58 -21
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +80 -28
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +58 -21
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +58 -21
  23. package/dist/theme/datalab.css +1 -1
  24. package/dist/theme/datalab.min.css +1 -1
  25. package/dist/theme/graph.css +1 -1
  26. package/dist/theme/graph.min.css +1 -1
  27. package/dist/theme/insight.css +1 -1
  28. package/dist/theme/insight.min.css +1 -1
  29. package/dist-esm/billboard.js +142 -52
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +7 -4
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  35. package/package.json +17 -17
  36. package/src/Chart/api/axis.ts +90 -25
  37. package/src/ChartInternal/ChartInternal.ts +25 -11
  38. package/src/ChartInternal/interactions/flow.ts +1 -1
  39. package/src/ChartInternal/shape/arc.ts +1 -1
  40. package/src/ChartInternal/shape/bar.ts +1 -1
  41. package/src/ChartInternal/shape/point.ts +8 -3
  42. package/src/config/Options/common/main.ts +19 -2
  43. package/src/module/generator.ts +19 -5
  44. package/src/module/util.ts +6 -3
  45. package/types/chart.d.ts +8 -8
  46. package/types/options.d.ts +7 -2
  47. package/types/types.d.ts +2 -0
@@ -2,7 +2,18 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {isValue, isDefined, isObjectType} from "../../module/util";
5
+ import {isValue, isDefined, isObjectType, isNumber} from "../../module/util";
6
+
7
+ type AxisOption = {
8
+ x?: number | false;
9
+ y?: number | false;
10
+ y2?: number | false;
11
+ } | number | false;
12
+
13
+ type RangeAxisOption = {
14
+ min? : AxisOption;
15
+ max?: AxisOption;
16
+ };
6
17
 
7
18
  /**
8
19
  * Set the min/max value
@@ -11,20 +22,28 @@ import {isValue, isDefined, isObjectType} from "../../module/util";
11
22
  * @param {object} value Value to be set
12
23
  * @private
13
24
  */
14
- function setMinMax($$, type: "min" | "max", value): void {
25
+ function setMinMax($$, type: "min" | "max", value: AxisOption): void {
15
26
  const {config} = $$;
16
- const axisX = `axis_x_${type}`;
17
- const axisY = `axis_y_${type}`;
18
- const axisY2 = `axis_y2_${type}`;
27
+ const helper = (key, value) => {
28
+ const v = isNumber(value) ? value : (
29
+ value === false ? undefined : null
30
+ );
31
+
32
+ if (v !== null) {
33
+ config[`axis_${key}_${type}`] = v;
34
+ }
35
+ };
19
36
 
20
37
  if (isDefined(value)) {
21
38
  if (isObjectType(value)) {
22
- isValue(value.x) && (config[axisX] = value.x);
23
- isValue(value.y) && (config[axisY] = value.y);
24
- isValue(value.y2) && (config[axisY2] = value.y2);
25
- } else {
26
- config[axisY] = value;
27
- config[axisY2] = value;
39
+ Object.keys(value).forEach(key => {
40
+ helper(key, value[key]);
41
+ });
42
+ } else if (isNumber(value) || value === false) {
43
+ // shorthand values affects only y and y2.
44
+ ["y", "y2"].forEach(key => {
45
+ helper(key, value);
46
+ });
28
47
  }
29
48
 
30
49
  $$.redraw({
@@ -111,8 +130,9 @@ const axis = {
111
130
  * @instance
112
131
  * @memberof Chart
113
132
  * @param {object} min If min is given, specified axis' min value will be updated.<br>
114
- * If no argument is given, the min values set on generating option for each axis will be returned.
115
- * If not set any min values on generation, it will return `undefined`.
133
+ * If no argument is given, the min values set on generating option for each axis will be returned.
134
+ * If not set any min values on generation, it will return `undefined`.<br>
135
+ * To unset specific axis max, set `false` to each of them.
116
136
  * @returns {object|undefined}
117
137
  * @example
118
138
  * // Update axis' min
@@ -121,12 +141,23 @@ const axis = {
121
141
  * y: 1000,
122
142
  * y2: 100
123
143
  * });
144
+ *
145
+ * // To unset specific axis min, set false to each of them.
146
+ * chart.axis.min({
147
+ * x: false,
148
+ * y: false,
149
+ * y2: false
150
+ * });
151
+ *
152
+ * // shorthand (only affects y and y2 axis)
153
+ * chart.axis.min(-50);
154
+ * chart.axis.min(false);
124
155
  */
125
- min: function(min?: number): object|void {
156
+ min: function(min?: AxisOption): object|void {
126
157
  const $$ = this.internal;
127
158
 
128
- return isValue(min) ?
129
- setMinMax($$, "min", min) :
159
+ return isValue(min) || min === false ?
160
+ setMinMax($$, "min", min as AxisOption) :
130
161
  getMinMax($$, "min");
131
162
  },
132
163
 
@@ -136,8 +167,9 @@ const axis = {
136
167
  * @instance
137
168
  * @memberof Chart
138
169
  * @param {object} max If max is given, specified axis' max value will be updated.<br>
139
- * If no argument is given, the max values set on generating option for each axis will be returned.
140
- * If not set any max values on generation, it will return `undefined`.
170
+ * If no argument is given, the max values set on generating option for each axis will be returned.
171
+ * If not set any max values on generation, it will return `undefined`.<br>
172
+ * To unset specific axis max, set `false` to each of them.
141
173
  * @returns {object|undefined}
142
174
  * @example
143
175
  * // Update axis' label
@@ -146,12 +178,23 @@ const axis = {
146
178
  * y: 1000,
147
179
  * y2: 10000
148
180
  * });
181
+ *
182
+ * // To unset specific axis max, set false to each of them.
183
+ * chart.axis.max({
184
+ * x: false,
185
+ * y: false,
186
+ * y2: false
187
+ * });
188
+ *
189
+ * // shorthand (only affects y and y2 axis)
190
+ * chart.axis.max(10);
191
+ * chart.axis.max(false);
149
192
  */
150
- max: function(max?: number): object|void {
193
+ max: function(max?: AxisOption): object|void {
151
194
  const $$ = this.internal;
152
195
 
153
- return arguments.length ?
154
- setMinMax($$, "max", max) :
196
+ return isValue(max) || max === false ?
197
+ setMinMax($$, "max", max as AxisOption) :
155
198
  getMinMax($$, "max");
156
199
  },
157
200
 
@@ -160,7 +203,9 @@ const axis = {
160
203
  * @function axis․range
161
204
  * @instance
162
205
  * @memberof Chart
163
- * @param {object} range If range is given, specified axis' min and max value will be updated. If no argument is given, the current min and max values for each axis will be returned.
206
+ * @param {object} range If range is given, specified axis' min and max value will be updated.
207
+ * If no argument is given, the current min and max values for each axis will be returned.<br>
208
+ * To unset specific axis max, set `false` to each of them.
164
209
  * @returns {object|undefined}
165
210
  * @example
166
211
  * // Update axis' label
@@ -176,13 +221,33 @@ const axis = {
176
221
  * y2: 10000
177
222
  * },
178
223
  * });
224
+ *
225
+ * // To unset specific axis max, set false to each of them.
226
+ * chart.axis.range({
227
+ * min: {
228
+ * x: false,
229
+ * y: false,
230
+ * y2: false
231
+ * },
232
+ * max: {
233
+ * x: false,
234
+ * y: false,
235
+ * y2: false
236
+ * },
237
+ * });
238
+ *
239
+ * // shorthand (only affects y and y2 axis)
240
+ * chart.axis.range({ min: -50, max: 1000 });
241
+ * chart.axis.range({ min: false, max: false });
179
242
  */
180
- range: function(range): object|void {
243
+ range: function(range: RangeAxisOption): object|void {
181
244
  const {axis} = this;
182
245
 
183
246
  if (arguments.length) {
184
- isDefined(range.max) && axis.max(range.max);
185
- isDefined(range.min) && axis.min(range.min);
247
+ const {min, max} = range;
248
+
249
+ isDefined(max) && axis.max(max);
250
+ isDefined(min) && axis.min(min);
186
251
  } else {
187
252
  return {
188
253
  max: axis.max(),
@@ -12,7 +12,7 @@ import {
12
12
  import {select as d3Select} from "d3-selection";
13
13
  import {d3Selection} from "../../types/types";
14
14
  import {checkModuleImport} from "../module/error";
15
- import {$COMMON, $TEXT} from "../config/classes";
15
+ import {$COMMON, $CIRCLE, $TEXT} from "../config/classes";
16
16
  import Store from "../config/Store/Store";
17
17
  import Options from "../config/Options/Options";
18
18
  import {document, window} from "../module/browser";
@@ -251,7 +251,7 @@ export default class ChartInternal {
251
251
 
252
252
  initParams(): void {
253
253
  const $$ = <any> this;
254
- const {config, format, state} = <any> $$;
254
+ const {config, format, state} = $$;
255
255
  const isRotated = config.axis_rotated;
256
256
 
257
257
  // datetime to be used for uniqueness
@@ -338,6 +338,7 @@ export default class ChartInternal {
338
338
  $$.mapToIds($$.data.targets) : config.data_hide
339
339
  );
340
340
  }
341
+
341
342
  if (config.legend_hide) {
342
343
  $$.addHiddenLegendIds(
343
344
  config.legend_hide === true ?
@@ -378,9 +379,12 @@ export default class ChartInternal {
378
379
 
379
380
  if (hasInteraction && state.inputType) {
380
381
  const isTouch = state.inputType === "touch";
382
+ const {onclick, onover, onout} = config;
381
383
 
382
- $el.svg.on(isTouch ? "touchstart" : "mouseenter", () => callFn(config.onover, $$.api))
383
- .on(isTouch ? "touchend" : "mouseleave", () => callFn(config.onout, $$.api));
384
+ $el.svg
385
+ .on("click", onclick?.bind($$.api) || null)
386
+ .on(isTouch ? "touchstart" : "mouseenter", onover?.bind($$.api) || null)
387
+ .on(isTouch ? "touchend" : "mouseleave", onout?.bind($$.api) || null);
384
388
  }
385
389
 
386
390
  config.svg_classname && $el.svg.attr("class", config.svg_classname);
@@ -638,24 +642,32 @@ export default class ChartInternal {
638
642
  helper(type);
639
643
  }
640
644
 
641
- // circle
642
- if ($$.hasType("bubble") || $$.hasType("scatter")) {
645
+ // Point types
646
+ const hasPointType = $$.hasType("bubble") || $$.hasType("scatter");
647
+
648
+ if (hasPointType) {
643
649
  $$.updateTargetForCircle?.();
644
650
  }
645
651
 
646
652
  // Fade-in each chart
647
- $$.showTargets();
653
+ $$.filterTargetsToShowAtInit(hasPointType);
648
654
  }
649
655
 
650
656
  /**
651
- * Display targeted elements
657
+ * Display targeted elements at initialization
658
+ * @param {boolean} hasPointType whether has point type(bubble, scatter) or not
652
659
  * @private
653
660
  */
654
- showTargets(): void {
661
+ filterTargetsToShowAtInit(hasPointType: boolean = false): void {
655
662
  const $$ = <any> this;
656
663
  const {$el: {svg}, $T} = $$;
664
+ let selector = `.${$COMMON.target}`;
657
665
 
658
- $T(svg.selectAll(`.${$COMMON.target}`)
666
+ if (hasPointType) {
667
+ selector += `, .${$CIRCLE.chartCircles} > .${$CIRCLE.circles}`;
668
+ }
669
+
670
+ $T(svg.selectAll(selector)
659
671
  .filter(d => $$.isTargetToShow(d.id))
660
672
  ).style("opacity", null);
661
673
  }
@@ -694,8 +706,10 @@ export default class ChartInternal {
694
706
  const $$ = <any> this;
695
707
  const {withoutFadeIn} = $$.state;
696
708
 
697
- return $$.getBaseValue(d) !== null &&
709
+ const r = $$.getBaseValue(d) !== null &&
698
710
  withoutFadeIn[d.id] ? null : "0";
711
+
712
+ return r;
699
713
  }
700
714
 
701
715
  bindResize(): void {
@@ -230,7 +230,7 @@ export default {
230
230
  } else {
231
231
  translateX = $$.axis.isTimeSeries() ?
232
232
  x(orgDomain[0]) - x(domain[0]) :
233
- x(flowStart.x) - x(flowEnd.x);
233
+ x(flowStart?.x || 0) - x(flowEnd.x);
234
234
  }
235
235
 
236
236
  const scaleX = (diffDomain(orgDomain) / diffDomain(domain));
@@ -288,7 +288,7 @@ export default {
288
288
 
289
289
  /**
290
290
  * Set transform attributes to arc label text
291
- * @param {Object} d Data object
291
+ * @param {object} d Data object
292
292
  * @returns {string} Translate attribute string
293
293
  * @private
294
294
  */
@@ -183,7 +183,7 @@ export default {
183
183
 
184
184
  /**
185
185
  * Determine if given stacking bar data is radius type
186
- * @param {Object} d Data row
186
+ * @param {object} d Data row
187
187
  * @returns {boolean}
188
188
  */
189
189
  isStackingRadiusData(d: IDataRow): boolean {
@@ -89,8 +89,7 @@ export default {
89
89
  const mainCircle = $el.main.select(`.${$CIRCLE.chartCircles}`)
90
90
  .style("pointer-events", "none")
91
91
  .selectAll(`.${$CIRCLE.circles}`)
92
- .data(targets)
93
- .attr("class", classCircles);
92
+ .data(targets);
94
93
 
95
94
  mainCircle.exit().remove();
96
95
  enterNode = mainCircle.enter();
@@ -102,7 +101,13 @@ export default {
102
101
 
103
102
  enterNode.append("g")
104
103
  .attr("class", classCircles)
105
- .style("cursor", d => (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null));
104
+ .style("cursor", d => (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null))
105
+ .style("opacity", function() {
106
+ const parent = d3Select(this.parentNode);
107
+
108
+ // if the parent node is .bb-chart-circles (bubble, scatter), initialize <g bb-circles> with opacity "0"
109
+ return parent.attr("class").indexOf($CIRCLE.chartCircles) > -1 ? "0" : null;
110
+ });
106
111
 
107
112
  // Update date for selected circles
108
113
  selectionEnabled && targets.forEach(t => {
@@ -151,6 +151,21 @@ export default {
151
151
  */
152
152
  resize_auto: true,
153
153
 
154
+ /**
155
+ * Set a callback to execute when the chart is clicked.
156
+ * @name onclick
157
+ * @memberof Options
158
+ * @type {Function}
159
+ * @default undefined
160
+ * @example
161
+ * onclick: function(event) {
162
+ * this; // chart instance itself
163
+ * event; // native event object
164
+ * ...
165
+ * }
166
+ */
167
+ onclick: <(() => void)|undefined> undefined,
168
+
154
169
  /**
155
170
  * Set a callback to execute when mouse/touch enters the chart.
156
171
  * @name onover
@@ -158,8 +173,9 @@ export default {
158
173
  * @type {Function}
159
174
  * @default undefined
160
175
  * @example
161
- * onover: function() {
176
+ * onover: function(event) {
162
177
  * this; // chart instance itself
178
+ * event; // native event object
163
179
  * ...
164
180
  * }
165
181
  */
@@ -172,8 +188,9 @@ export default {
172
188
  * @type {Function}
173
189
  * @default undefined
174
190
  * @example
175
- * onout: function() {
191
+ * onout: function(event) {
176
192
  * this; // chart instance itself
193
+ * event; // native event object
177
194
  * ...
178
195
  * }
179
196
  */
@@ -2,8 +2,9 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
+ import {d3Transition} from "../../types/types";
5
6
  import {window} from "./browser";
6
- import {isArray} from "./util";
7
+ import {isArray, isTabVisible} from "./util";
7
8
 
8
9
  const {setTimeout, clearTimeout} = window;
9
10
 
@@ -38,17 +39,24 @@ export function generateResize() {
38
39
  return callResizeFn;
39
40
  }
40
41
 
42
+ type Transition = boolean | d3Transition;
43
+
41
44
  /**
42
45
  * Generate transition queue function
43
46
  * @returns {Function}
44
47
  * @private
45
48
  */
46
49
  export function generateWait() {
47
- let transitionsToWait: any = [];
48
- const f = function(t, callback) {
50
+ let transitionsToWait: Transition[] = [];
51
+
52
+ // 'f' is called as selection.call(f, ...);
53
+ const f = function(selection: d3Transition, callback: Function) {
49
54
  let timer;
50
55
 
51
- // eslint-disable-next-line
56
+ /**
57
+ * Check if transition is complete
58
+ * @private
59
+ */
52
60
  function loop() {
53
61
  let done = 0;
54
62
 
@@ -58,6 +66,12 @@ export function generateWait() {
58
66
  continue;
59
67
  }
60
68
 
69
+ // when tab isn't visible exit loop
70
+ if (isTabVisible() === false) {
71
+ done = transitionsToWait.length;
72
+ break;
73
+ }
74
+
61
75
  try {
62
76
  t.transition();
63
77
  } catch (e) {
@@ -77,7 +91,7 @@ export function generateWait() {
77
91
  loop();
78
92
  };
79
93
 
80
- f.add = function(t) {
94
+ f.add = function(t: Transition | Transition[]) {
81
95
  isArray(t) ?
82
96
  (transitionsToWait = transitionsToWait.concat(t)) :
83
97
  transitionsToWait.push(t);
@@ -702,7 +702,9 @@ function parseDate(date: Date | string | number | any): Date {
702
702
  } else if (isString(date)) {
703
703
  const {config, format} = this;
704
704
 
705
- parsedDate = format.dataTime(config.data_xFormat)(date);
705
+ // if fails to parse, try by new Date()
706
+ // https://github.com/naver/billboard.js/issues/1714
707
+ parsedDate = format.dataTime(config.data_xFormat)(date) ?? new Date(date);
706
708
  } else if (isNumber(date) && !isNaN(date)) {
707
709
  parsedDate = new Date(+date);
708
710
  }
@@ -721,7 +723,7 @@ function parseDate(date: Date | string | number | any): Date {
721
723
  * @private
722
724
  */
723
725
  function isTabVisible(): boolean {
724
- return !document.hidden;
726
+ return document?.hidden === false || document?.visibilityState === "visible";
725
727
  }
726
728
 
727
729
  /**
@@ -766,5 +768,6 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
766
768
  const hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
767
769
  .some(v => matchMedia?.(`(${v})`).matches);
768
770
 
769
- return (hasMouse && "mouse") || (hasTouch && "touch") || null;
771
+ // fallback to 'mouse' if no input type is detected.
772
+ return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
770
773
  }
package/types/chart.d.ts CHANGED
@@ -177,16 +177,16 @@ export interface Chart {
177
177
  * Get and set axis min value.
178
178
  * @param min If min is given, specified axis' min value will be updated. If no argument is given, the current min values for each axis will be returned.
179
179
  */
180
- min(min?: number | { [key: string]: number }): number | {
181
- [key: string]: number | { fit?: boolean; value?: number; }
180
+ min(min?: number | false | { [key: string]: number }): number | {
181
+ [key: string]: number | undefined
182
182
  };
183
183
 
184
184
  /**
185
185
  * Get and set axis max value.
186
186
  * @param max If max is given, specified axis' max value will be updated. If no argument is given, the current max values for each axis will be returned.
187
187
  */
188
- max(max?: number | { [key: string]: number }): number | {
189
- [key: string]: number | { fit?: boolean; value?: number; }
188
+ max(max?: number | false | { [key: string]: number }): number | {
189
+ [key: string]: number | undefined
190
190
  };
191
191
 
192
192
  /**
@@ -194,11 +194,11 @@ export interface Chart {
194
194
  * @param range If range is given, specified axis' min and max value will be updated. If no argument is given, the current min and max values for each axis will be returned.
195
195
  */
196
196
  range(range?: {
197
- min?: number | { [key: string]: number };
198
- max?: number | { [key: string]: number };
197
+ min?: number | false | { [key: string]: number | false };
198
+ max?: number | false | { [key: string]: number | false };
199
199
  }): {
200
- min: number | { [key: string]: number };
201
- max: number | { [key: string]: number };
200
+ min: number | { [key: string]: number | undefined };
201
+ max: number | { [key: string]: number | undefined };
202
202
  };
203
203
  };
204
204
 
@@ -804,15 +804,20 @@ export interface ChartOptions {
804
804
  */
805
805
  onrendered?(this: Chart): void;
806
806
 
807
+ /**
808
+ * Set a callback to execute when the chart is clicked.
809
+ */
810
+ onclick?(this: Chart, event: Event): void;
811
+
807
812
  /**
808
813
  * Set a callback to execute when mouse/touch enters the chart.
809
814
  */
810
- onover?(this: Chart): void;
815
+ onover?(this: Chart, event: Event): void;
811
816
 
812
817
  /**
813
818
  * Set a callback to execute when mouse/touch leaves the chart.
814
819
  */
815
- onout?(this: Chart): void;
820
+ onout?(this: Chart, event: Event): void;
816
821
 
817
822
  /**
818
823
  * Set a callback to execute when user resizes the screen.
package/types/types.d.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import {Selection} from "d3-selection";
6
+ import {Transition} from "d3-transition";
6
7
 
7
8
  export type PrimitiveArray = Array<
8
9
  string | boolean | number | Date | null |
@@ -10,6 +11,7 @@ export type PrimitiveArray = Array<
10
11
  >;
11
12
  export type ArrayOrString = string[] | string;
12
13
  export type d3Selection = Selection<any, any, any, any>;
14
+ export type d3Transition = Transition<any, any, any, any>;
13
15
  export type ChartTypes = "area"
14
16
  | "area-line-range"
15
17
  | "area-spline"