billboard.js 3.14.0 → 3.14.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 +85 -47
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +9 -9
  5. package/dist/billboard.pkgd.js +1626 -948
  6. package/dist/billboard.pkgd.min.js +16 -16
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +3 -3
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +10 -4
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +10 -4
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +10 -4
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +4 -4
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +10 -4
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1607 -967
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -5
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +1615 -969
  20. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -7
  21. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +1616 -970
  22. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +15 -15
  23. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1617 -971
  24. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +8 -8
  25. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +1618 -972
  26. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -7
  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 +97 -58
  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 +20 -20
  44. package/src/ChartInternal/Axis/Axis.ts +23 -0
  45. package/src/ChartInternal/data/data.ts +4 -3
  46. package/src/ChartInternal/interactions/eventrect.ts +1 -4
  47. package/src/ChartInternal/interactions/subchart.ts +2 -25
  48. package/src/ChartInternal/interactions/zoom.ts +21 -0
  49. package/src/ChartInternal/internals/tooltip.ts +29 -20
  50. package/src/ChartInternal/shape/point.ts +7 -6
  51. package/src/config/Options/axis/x.ts +2 -1
  52. package/src/module/util.ts +10 -2
  53. package/types/axis.d.ts +2 -2
@@ -106,6 +106,29 @@ class Axis {
106
106
  return type;
107
107
  }
108
108
 
109
+ /**
110
+ * Get extent value
111
+ * @returns {Array} default extent
112
+ * @private
113
+ */
114
+ public getExtent(): number[] {
115
+ const $$ = this.owner;
116
+ const {config, scale} = $$;
117
+ let extent = config.axis_x_extent;
118
+
119
+ if (extent) {
120
+ if (isFunction(extent)) {
121
+ extent = extent.bind($$.api)($$.getXDomain($$.data.targets), scale.subX);
122
+ } else if (this.isTimeSeries() && extent.every(isNaN)) {
123
+ const fn = parseDate.bind($$);
124
+
125
+ extent = extent.map(v => scale.subX(fn(v)));
126
+ }
127
+ }
128
+
129
+ return extent;
130
+ }
131
+
109
132
  init() {
110
133
  const $$ = this.owner;
111
134
  const {config, $el: {main, axis}, state: {clip}} = $$;
@@ -730,14 +730,15 @@ export default {
730
730
  event.changedTouches[0] :
731
731
  event;
732
732
 
733
- let point = isRotated ?
734
- e.clientY + scrollPos.y - rect.top :
735
- e.clientX + scrollPos.x - rect.left;
733
+ let point = isRotated ? e.clientY + scrollPos.y : e.clientX + scrollPos.x;
736
734
 
737
735
  if (hasViewBox($el.svg)) {
738
736
  const pos = [point, 0];
737
+
739
738
  isRotated && pos.reverse();
740
739
  point = getTransformCTM($el.svg.node(), ...pos)[isRotated ? "y" : "x"];
740
+ } else {
741
+ point -= isRotated ? rect.top : rect.left;
741
742
  }
742
743
 
743
744
  index = findIndex(
@@ -671,7 +671,6 @@ export default {
671
671
  clickHandlerForMultipleXS(ctx): void {
672
672
  const $$ = ctx;
673
673
  const {config, state} = $$;
674
- const pointSensitivity = config.point_sensitivity;
675
674
  const targetsToShow = $$.filterTargetsToShow($$.data.targets);
676
675
 
677
676
  if ($$.hasArcType(targetsToShow)) {
@@ -680,9 +679,7 @@ export default {
680
679
 
681
680
  const mouse = getPointer(state.event, this);
682
681
  const closest = $$.findClosestFromTargets(targetsToShow, mouse);
683
- const sensitivity = pointSensitivity === "radius" ? closest?.r : (
684
- isFunction(pointSensitivity) ? closest && pointSensitivity(closest) : pointSensitivity
685
- );
682
+ const sensitivity = $$.getPointSensitivity(closest);
686
683
 
687
684
  if (!closest) {
688
685
  return;
@@ -5,7 +5,7 @@
5
5
  import {brushSelection as d3BrushSelection, brushX as d3BrushX, brushY as d3BrushY} from "d3-brush";
6
6
  import {select as d3Select} from "d3-selection";
7
7
  import CLASS from "../../config/classes";
8
- import {brushEmpty, capitalize, isArray, isFunction, parseDate} from "../../module/util";
8
+ import {brushEmpty, capitalize, isArray} from "../../module/util";
9
9
 
10
10
  export default {
11
11
  /**
@@ -92,7 +92,7 @@ export default {
92
92
  // set the brush extent
93
93
  $$.brush.scale = function(scale) {
94
94
  const h = config.subchart_size_height;
95
- let extent = $$.getExtent();
95
+ let extent = $$.axis.getExtent();
96
96
 
97
97
  if (!extent && scale.range) {
98
98
  extent = [[0, 0], [scale.range()[1], h]];
@@ -373,28 +373,5 @@ export default {
373
373
 
374
374
  subchart.main.attr("transform", $$.getTranslate("context"));
375
375
  subXAxis.attr("transform", $$.getTranslate("subX"));
376
- },
377
-
378
- /**
379
- * Get extent value
380
- * @returns {Array} default extent
381
- * @private
382
- */
383
- getExtent(): number[] {
384
- const $$ = this;
385
- const {config, scale} = $$;
386
- let extent = config.axis_x_extent;
387
-
388
- if (extent) {
389
- if (isFunction(extent)) {
390
- extent = extent.bind($$.api)($$.getXDomain($$.data.targets), scale.subX);
391
- } else if ($$.axis.isTimeSeries() && extent.every(isNaN)) {
392
- const fn = parseDate.bind($$);
393
-
394
- extent = extent.map(v => scale.subX(fn(v)));
395
- }
396
- }
397
-
398
- return extent;
399
376
  }
400
377
  };
@@ -367,6 +367,7 @@ export default {
367
367
  let start = 0;
368
368
  let end = 0;
369
369
  let zoomRect;
370
+ let extent;
370
371
 
371
372
  const prop = {
372
373
  axis: isRotated ? "y" : "x",
@@ -377,6 +378,9 @@ export default {
377
378
  $$.zoomBehaviour = d3Drag()
378
379
  .clickDistance(4)
379
380
  .on("start", function(event) {
381
+ // get extent at first zooming, when is zoomed do not consider
382
+ extent = $$.scale.zoom ? null : $$.axis.getExtent();
383
+
380
384
  state.event = event;
381
385
  $$.setDragStatus(true);
382
386
  $$.unselectRect();
@@ -390,6 +394,15 @@ export default {
390
394
  }
391
395
 
392
396
  start = getPointer(event, this as SVGAElement)[prop.index];
397
+
398
+ if (extent) {
399
+ if (start < extent[0]) {
400
+ start = extent[0];
401
+ } else if (start > extent[1]) {
402
+ start = extent[1];
403
+ }
404
+ }
405
+
393
406
  end = start;
394
407
 
395
408
  zoomRect
@@ -401,6 +414,14 @@ export default {
401
414
  .on("drag", function(event) {
402
415
  end = getPointer(event, this as SVGAElement)[prop.index];
403
416
 
417
+ if (extent) {
418
+ if (end > extent[1]) {
419
+ end = extent[1];
420
+ } else if (end < extent[0]) {
421
+ end = extent[0];
422
+ }
423
+ }
424
+
404
425
  zoomRect
405
426
  .attr(prop.axis, Math.min(start, end))
406
427
  .attr(prop.attr, Math.abs(end - start));
@@ -362,16 +362,21 @@ export default {
362
362
  }
363
363
  },
364
364
 
365
+ /**
366
+ * Get tooltip position when svg has vieBox attribute
367
+ * @param {number} tWidth Tooltip width value
368
+ * @param {number} tHeight Tooltip height value
369
+ * @param {object} currPos Current event position value from SVG coordinate
370
+ * @returns {object} top, left value
371
+ */
365
372
  getTooltipPositionViewBox(tWidth: number, tHeight: number,
366
373
  currPos: {[key: string]: number}): {top: number, left: number} {
367
374
  const $$ = this;
368
- const {$el: {eventRect, main}, config, state} = $$;
375
+ const {$el: {eventRect, svg}, config, state} = $$;
369
376
 
370
377
  const isRotated = config.axis_rotated;
371
- const hasArcType = $$.hasArcType(undefined, ["radar"]) || state.hasFunnel ||
372
- state.hasTreemap;
373
- const target = (state.hasRadar ? main : eventRect)?.node() ?? state.event.target;
374
- const size = 38; // getTransformCTM($el.svg.node(), 10, 0, false).x;
378
+ const hasArcType = $$.hasArcType() || state.hasFunnel || state.hasTreemap;
379
+ const target = (hasArcType ? svg : eventRect)?.node() ?? state.event.target;
375
380
 
376
381
  let {x, y} = currPos;
377
382
 
@@ -380,25 +385,30 @@ export default {
380
385
  y = isRotated ? currPos.xAxis : y;
381
386
  }
382
387
 
383
- // currPos는 SVG 좌표계 기준으로 전달됨
388
+ // currPos value based on SVG coordinate
384
389
  const ctm = getTransformCTM(target, x, y, false);
390
+ const rect = target.getBoundingClientRect();
391
+ const size = getTransformCTM(target, 20, 0, false).x;
385
392
 
386
393
  let top = ctm.y;
387
- let left = ctm.x + size;
394
+ let left = ctm.x + (tWidth / 2) + size;
388
395
 
389
396
  if (hasArcType) {
390
- top += tHeight;
391
- left -= size; // (tWidth / 2);
397
+ if (state.hasFunnel || state.hasTreemap || state.hasRadar) {
398
+ left -= (tWidth / 2) + size;
399
+ top += tHeight;
400
+ } else {
401
+ top += rect.height / 2;
402
+ left += (rect.width / 2) - (tWidth - size);
403
+ }
392
404
  }
393
405
 
394
- const rect = (hasArcType ? main.node() : target).getBoundingClientRect();
395
-
396
- if (left + tWidth > rect.right) {
397
- left = rect.right - tWidth - size;
406
+ if (left + tWidth > rect.width) {
407
+ left = rect.width - tWidth - size;
398
408
  }
399
409
 
400
- if (top + tHeight > rect.bottom) {
401
- top -= tHeight + size;
410
+ if (top + tHeight > rect.height) {
411
+ top -= tHeight * 2;
402
412
  }
403
413
 
404
414
  return {
@@ -657,14 +667,13 @@ export default {
657
667
  $$.setExpand(idx, null, true);
658
668
  }
659
669
  }
660
-
661
- // for Arc & Treemap
662
- } else {
670
+ } else { // for Arc & Treemap
663
671
  const {clientX, clientY} = event;
664
672
 
665
673
  setTimeout(() => {
666
- let target = document.elementFromPoint(clientX, clientY);
667
- const data = d3Select(target).datum() as IArcData;
674
+ let target = [clientX, clientY].every(Number.isFinite) &&
675
+ document.elementFromPoint(clientX, clientY);
676
+ const data = target && d3Select(target).datum() as IArcData;
668
677
 
669
678
  if (data) {
670
679
  const d = $$.hasArcType() ?
@@ -374,13 +374,12 @@ export default {
374
374
  },
375
375
 
376
376
  isWithinCircle(node: SVGElement, r?: number): boolean {
377
- const {config, state} = this;
377
+ const {state} = this;
378
378
  const mouse = getPointer(state.event, node);
379
379
  const element = d3Select(node);
380
380
  const prefix = this.isCirclePoint(node) ? "c" : "";
381
- const sensitivity = config.point_sensitivity === "radius" ?
382
- node.getAttribute("r") :
383
- config.point_sensitivity;
381
+ const pointSensitivity = this.getPointSensitivity(element?.datum());
382
+
384
383
  let cx = +element.attr(`${prefix}x`);
385
384
  let cy = +element.attr(`${prefix}y`);
386
385
 
@@ -394,7 +393,7 @@ export default {
394
393
 
395
394
  return Math.sqrt(
396
395
  Math.pow(cx - mouse[0], 2) + Math.pow(cy - mouse[1], 2)
397
- ) < (r || sensitivity);
396
+ ) < (r || pointSensitivity);
398
397
  },
399
398
 
400
399
  /**
@@ -406,7 +405,9 @@ export default {
406
405
  const $$ = this;
407
406
  let sensitivity = $$.config.point_sensitivity;
408
407
 
409
- if (isFunction(sensitivity)) {
408
+ if (!d) {
409
+ return sensitivity;
410
+ } else if (isFunction(sensitivity)) {
410
411
  sensitivity = sensitivity.call($$.api, d);
411
412
  } else if (sensitivity === "radius") {
412
413
  sensitivity = d.r;
@@ -635,7 +635,8 @@ export default {
635
635
  axis_x_height: <number | undefined>undefined,
636
636
 
637
637
  /**
638
- * Set default extent for subchart and zoom. This can be an array or function that returns an array.
638
+ * Set extent for subchart and zoom(drag only). This can be an array or function that returns an array.
639
+ * - **NOTE:** Specifying value, will limit the zoom scope selection within.
639
640
  * @name axis․x․extent
640
641
  * @memberof Options
641
642
  * @type {Array|Function}
@@ -551,10 +551,18 @@ function getScrollPosition(node: HTMLElement) {
551
551
  function getTransformCTM(node: SVGGraphicsElement, x = 0, y = 0, inverse = true): DOMPoint {
552
552
  const point = new DOMPoint(x, y);
553
553
  const screen = <DOMMatrix>node.getScreenCTM();
554
-
555
- return point.matrixTransform(
554
+ const res = point.matrixTransform(
556
555
  inverse ? screen?.inverse() : screen
557
556
  );
557
+
558
+ if (inverse === false) {
559
+ const rect = node.getBoundingClientRect();
560
+
561
+ res.x -= rect.x;
562
+ res.y -= rect.y;
563
+ }
564
+
565
+ return res;
558
566
  }
559
567
 
560
568
  /**
package/types/axis.d.ts CHANGED
@@ -121,8 +121,8 @@ export interface xAxisConfiguration extends AxisConfigurationBase {
121
121
  height?: number;
122
122
 
123
123
  /**
124
- * Set default extent for subchart and zoom.
125
- * This can be an array or function that returns an array.
124
+ * Set extent for subchart and zoom(drag only). This can be an array or function that returns an array.
125
+ * - **NOTE:** Specifying value, will limit the zoom scope selection within.
126
126
  */
127
127
  extent?: Array<number|string> | (
128
128
  (