billboard.js 3.3.3 → 3.4.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 (69) hide show
  1. package/dist/billboard.css +19 -14
  2. package/dist/billboard.js +504 -112
  3. package/dist/billboard.min.css +2 -2
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +550 -126
  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 +34 -18
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +34 -18
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +29 -15
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +29 -15
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +80 -32
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +80 -32
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +75 -29
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +75 -29
  22. package/dist/theme/datalab.css +24 -20
  23. package/dist/theme/datalab.min.css +2 -2
  24. package/dist/theme/graph.css +24 -20
  25. package/dist/theme/graph.min.css +2 -2
  26. package/dist/theme/insight.css +24 -20
  27. package/dist/theme/insight.min.css +2 -2
  28. package/dist-esm/billboard.js +446 -99
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -5
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +8 -7
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  34. package/package.json +21 -21
  35. package/src/Chart/api/axis.ts +90 -25
  36. package/src/Chart/api/focus.ts +3 -2
  37. package/src/ChartInternal/Axis/Axis.ts +8 -6
  38. package/src/ChartInternal/ChartInternal.ts +48 -23
  39. package/src/ChartInternal/data/data.ts +1 -1
  40. package/src/ChartInternal/interactions/flow.ts +1 -1
  41. package/src/ChartInternal/internals/color.ts +4 -3
  42. package/src/ChartInternal/internals/format.ts +5 -1
  43. package/src/ChartInternal/internals/redraw.ts +3 -0
  44. package/src/ChartInternal/internals/text.ts +1 -1
  45. package/src/ChartInternal/internals/transform.ts +4 -1
  46. package/src/ChartInternal/internals/type.ts +5 -0
  47. package/src/ChartInternal/shape/arc.ts +41 -17
  48. package/src/ChartInternal/shape/bar.ts +1 -1
  49. package/src/ChartInternal/shape/point.ts +6 -3
  50. package/src/ChartInternal/shape/polar.ts +132 -0
  51. package/src/ChartInternal/shape/radar.ts +4 -4
  52. package/src/config/Options/common/main.ts +19 -2
  53. package/src/config/Options/data/data.ts +3 -0
  54. package/src/config/Options/shape/polar.ts +81 -0
  55. package/src/config/classes.ts +6 -3
  56. package/src/config/const.ts +3 -0
  57. package/src/config/resolver/shape.ts +4 -0
  58. package/src/core.ts +1 -0
  59. package/src/index.esm.ts +1 -0
  60. package/src/module/generator.ts +19 -5
  61. package/src/module/util.ts +22 -9
  62. package/src/scss/billboard.scss +13 -0
  63. package/src/scss/theme/datalab.scss +13 -0
  64. package/src/scss/theme/graph.scss +13 -0
  65. package/src/scss/theme/insight.scss +13 -0
  66. package/types/bb.d.ts +1 -0
  67. package/types/chart.d.ts +8 -8
  68. package/types/options.d.ts +79 -2
  69. package/types/types.d.ts +2 -0
@@ -24,6 +24,7 @@ import shapeGauge from "../../ChartInternal/shape/gauge";
24
24
  import shapeBubble from "../../ChartInternal/shape/bubble";
25
25
  import shapeLine from "../../ChartInternal/shape/line";
26
26
  import shapePoint from "../../ChartInternal/shape/point";
27
+ import shapePolar from "../../ChartInternal/shape/polar";
27
28
  import shapeRadar from "../../ChartInternal/shape/radar";
28
29
 
29
30
  // Options
@@ -40,6 +41,7 @@ import optSpline from "../Options/shape/spline";
40
41
  import optDonut from "../Options/shape/donut";
41
42
  import optGauge from "../Options/shape/gauge";
42
43
  import optPie from "../Options/shape/pie";
44
+ import optPolar from "../Options/shape/polar";
43
45
  import optRadar from "../Options/shape/radar";
44
46
 
45
47
  export {
@@ -55,6 +57,7 @@ export {
55
57
  gauge,
56
58
  line,
57
59
  pie,
60
+ polar,
58
61
  radar,
59
62
  scatter,
60
63
  spline,
@@ -121,6 +124,7 @@ let step = (): string => (extendLine(), (step = () => TYPE.STEP)());
121
124
  let donut = (): string => (extendArc(undefined, [optDonut]), (donut = () => TYPE.DONUT)());
122
125
  let gauge = (): string => (extendArc([shapeGauge], [optGauge]), (gauge = () => TYPE.GAUGE)());
123
126
  let pie = (): string => (extendArc(undefined, [optPie]), (pie = () => TYPE.PIE)());
127
+ let polar = (): string => (extendArc([shapePolar], [optPolar]), (polar = () => TYPE.POLAR)());
124
128
  let radar = (): string => (
125
129
  extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = () => TYPE.RADAR)()
126
130
  );
package/src/core.ts CHANGED
@@ -70,6 +70,7 @@ const bb = {
70
70
  * gauge,
71
71
  * line,
72
72
  * pie,
73
+ * polar,
73
74
  * radar,
74
75
  * scatter,
75
76
  * spline,
package/src/index.esm.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  gauge,
17
17
  line,
18
18
  pie,
19
+ polar,
19
20
  radar,
20
21
  scatter,
21
22
  spline,
@@ -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
  /**
@@ -732,28 +734,39 @@ function isTabVisible(): boolean {
732
734
  * @private
733
735
  */
734
736
  function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | null {
737
+ const {DocumentTouch, matchMedia, navigator} = window;
735
738
  let hasTouch = false;
736
739
 
737
740
  if (touch) {
738
741
  // Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
739
- if (window.navigator && "maxTouchPoints" in window.navigator) {
740
- hasTouch = window.navigator.maxTouchPoints > 0;
742
+ if (navigator && "maxTouchPoints" in navigator) {
743
+ hasTouch = navigator.maxTouchPoints > 0;
741
744
 
742
745
  // Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
743
746
  // On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
744
- } else if ("ontouchmove" in window || (window.DocumentTouch && document instanceof window.DocumentTouch)) {
747
+ } else if ("ontouchmove" in window || (DocumentTouch && document instanceof DocumentTouch)) {
745
748
  hasTouch = true;
746
749
  } else {
747
750
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
748
- const mQ = window.matchMedia && matchMedia("(pointer:coarse)");
751
+ if (matchMedia?.("(pointer:coarse)").matches) {
752
+ hasTouch = true;
753
+ } else {
754
+ // Only as a last resort, fall back to user agent sniffing
755
+ const UA = navigator.userAgent;
749
756
 
750
- if (mQ && mQ.media === "(pointer:coarse)") {
751
- hasTouch = !!mQ.matches;
757
+ hasTouch = (
758
+ /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
759
+ /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA)
760
+ );
752
761
  }
753
762
  }
754
763
  }
755
764
 
756
- const hasMouse = mouse && !hasTouch ? ("onmouseover" in window) : false;
765
+ // Check if agent has mouse using any-hover, touch devices (e.g iPad) with external mouse will return true as long as mouse is connected
766
+ // https://css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions/#aa-testing-the-capabilities-of-all-inputs
767
+ // Demo: https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/
768
+ const hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
769
+ .some(v => matchMedia?.(`(${v})`).matches);
757
770
 
758
771
  return (hasMouse && "mouse") || (hasTouch && "touch") || null;
759
772
  }
@@ -250,6 +250,19 @@ text.bb-chart-arcs-gauge-title {
250
250
  .bb-chart-arcs-gauge-min {
251
251
  fill: #777;
252
252
  }
253
+
254
+ /*-- Polar --*/
255
+ .bb-levels {
256
+ circle {
257
+ fill: none;
258
+ stroke: #848282;
259
+ stroke-width: .5px;
260
+ }
261
+
262
+ text {
263
+ fill: #848282;
264
+ }
265
+ }
253
266
  }
254
267
 
255
268
  /*-- Radar --*/
@@ -314,6 +314,19 @@ text.bb-chart-arcs-gauge-title {
314
314
  fill: #eaeaea;
315
315
  stroke-width: 0;
316
316
  }
317
+
318
+ /*-- Polar --*/
319
+ .bb-levels {
320
+ circle {
321
+ fill: none;
322
+ stroke: #848282;
323
+ stroke-width: .5px;
324
+ }
325
+
326
+ text {
327
+ fill: #848282;
328
+ }
329
+ }
317
330
  }
318
331
 
319
332
  .bb-chart-arc {
@@ -332,6 +332,19 @@ text.bb-chart-arcs-gauge-title {
332
332
  fill: #eaeaea;
333
333
  stroke-width: 0;
334
334
  }
335
+
336
+ /*-- Polar --*/
337
+ .bb-levels {
338
+ circle {
339
+ fill: none;
340
+ stroke: #848282;
341
+ stroke-width: .5px;
342
+ }
343
+
344
+ text {
345
+ fill: #848282;
346
+ }
347
+ }
335
348
  }
336
349
 
337
350
  .bb-chart-arc {
@@ -312,6 +312,19 @@ text.bb-chart-arcs-gauge-title {
312
312
  fill: #eaeaea;
313
313
  stroke-width: 0;
314
314
  }
315
+
316
+ /*-- Polar --*/
317
+ .bb-levels {
318
+ circle {
319
+ fill: none;
320
+ stroke: #848282;
321
+ stroke-width: .5px;
322
+ }
323
+
324
+ text {
325
+ fill: #848282;
326
+ }
327
+ }
315
328
  }
316
329
 
317
330
  .bb-chart-arc {
package/types/bb.d.ts CHANGED
@@ -45,6 +45,7 @@ export function donut(): "donut";
45
45
  export function gauge(): "gauge";
46
46
  export function line(): "line";
47
47
  export function pie(): "pie";
48
+ export function polar(): "polar";
48
49
  export function radar(): "radar";
49
50
  export function scatter(): "scatter";
50
51
  export function spline(): "spline";
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
 
@@ -461,6 +461,78 @@ export interface ChartOptions {
461
461
  }
462
462
  };
463
463
 
464
+ polar?: {
465
+ label?: {
466
+ /**
467
+ * Show or hide label on each polar piece.
468
+ */
469
+ show?: boolean;
470
+
471
+ /**
472
+ * Set threshold ratio to show/hide labels.
473
+ */
474
+ threshold?: number;
475
+
476
+ /**
477
+ * Set formatter for the label on each polar piece.
478
+ */
479
+ format?(this: Chart, value: number, ratio: number, id: string): string;
480
+
481
+ /**
482
+ * Set ratio of labels position.
483
+ */
484
+ ratio?: ((this: Chart, d: DataItem, radius: number, h: number) => void) | number
485
+ };
486
+ level?: {
487
+ /**
488
+ * Set the level depth.
489
+ */
490
+ depth?: number;
491
+
492
+ /**
493
+ * Set level max value.
494
+ */
495
+ max?: number;
496
+
497
+ /**
498
+ * Show or hide level.
499
+ */
500
+ show?: boolean;
501
+
502
+ text?: {
503
+ /**
504
+ * Set label text's background color.
505
+ */
506
+ backgroundColor?: string;
507
+
508
+ /**
509
+ * Set format function for the level value.
510
+ */
511
+ format?: (this: Chart, x: string) => string;
512
+
513
+ /**
514
+ * Show or hide level text.
515
+ */
516
+ show?: boolean;
517
+ }
518
+ };
519
+
520
+ /**
521
+ * Set padding between data.
522
+ */
523
+ padAngle?: number;
524
+
525
+ /**
526
+ * Sets the gap between pie arcs.
527
+ */
528
+ padding?: number;
529
+
530
+ /**
531
+ * Set starting angle where data draws.
532
+ */
533
+ startAngle?: number;
534
+ };
535
+
464
536
  pie?: {
465
537
  label?: {
466
538
  /**
@@ -732,15 +804,20 @@ export interface ChartOptions {
732
804
  */
733
805
  onrendered?(this: Chart): void;
734
806
 
807
+ /**
808
+ * Set a callback to execute when the chart is clicked.
809
+ */
810
+ onclick?(this: Chart, event: Event): void;
811
+
735
812
  /**
736
813
  * Set a callback to execute when mouse/touch enters the chart.
737
814
  */
738
- onover?(this: Chart): void;
815
+ onover?(this: Chart, event: Event): void;
739
816
 
740
817
  /**
741
818
  * Set a callback to execute when mouse/touch leaves the chart.
742
819
  */
743
- onout?(this: Chart): void;
820
+ onout?(this: Chart, event: Event): void;
744
821
 
745
822
  /**
746
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"