billboard.js 3.10.2 → 3.10.3

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 (54) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +80 -65
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +192 -338
  6. package/dist/billboard.pkgd.min.js +4 -4
  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 +112 -273
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +113 -274
  20. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +114 -275
  22. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
  23. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +114 -275
  24. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +2 -2
  25. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +114 -275
  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 +60 -46
  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 +17 -17
  44. package/src/ChartInternal/Axis/Axis.ts +7 -4
  45. package/src/ChartInternal/data/data.ts +15 -9
  46. package/src/ChartInternal/internals/clip.ts +1 -2
  47. package/src/ChartInternal/internals/format.ts +15 -4
  48. package/src/ChartInternal/internals/size.axis.ts +4 -17
  49. package/src/ChartInternal/internals/size.ts +11 -5
  50. package/src/ChartInternal/internals/text.ts +3 -3
  51. package/src/ChartInternal/internals/tooltip.ts +2 -2
  52. package/src/ChartInternal/internals/transform.ts +1 -1
  53. package/src/ChartInternal/shape/arc.ts +1 -1
  54. package/src/ChartInternal/shape/shape.ts +2 -0
@@ -587,12 +587,13 @@ class Axis {
587
587
  const $$ = this.owner;
588
588
  const {config, state: {current}, $el: {svg, chart}} = $$;
589
589
  const currentTickMax = current.maxTickSize[id];
590
+ const configPrefix = `axis_${id}`;
590
591
  const max = {
591
592
  width: 0,
592
593
  height: 0
593
594
  };
594
595
 
595
- if (withoutRecompute || !config[`axis_${id}_show`] || (
596
+ if (withoutRecompute || !config[`${configPrefix}_show`] || (
596
597
  currentTickMax.width > 0 && $$.filterTargetsToShow().length === 0
597
598
  )) {
598
599
  return currentTickMax;
@@ -624,8 +625,9 @@ class Axis {
624
625
  }
625
626
 
626
627
  const axis = this.getAxis(id, scale, false, false, true);
627
- const tickCount = config[`axis_${id}_tick_count`];
628
- const tickValues = config[`axis_${id}_tick_values`];
628
+ const tickRotate = config[`${configPrefix}_tick_rotate`];
629
+ const tickCount = config[`${configPrefix}_tick_count`];
630
+ const tickValues = config[`${configPrefix}_tick_values`];
629
631
 
630
632
  // Make to generate the final tick text to be rendered
631
633
  // https://github.com/naver/billboard.js/issues/920
@@ -651,6 +653,7 @@ class Axis {
651
653
  axis.create(dummy);
652
654
 
653
655
  dummy.selectAll("text")
656
+ .attr("transform", isNumber(tickRotate) ? `rotate(${tickRotate})` : null)
654
657
  .each(function(d, i) {
655
658
  const {width, height} = this.getBoundingClientRect();
656
659
 
@@ -683,7 +686,7 @@ class Axis {
683
686
 
684
687
  if ((axis.isCategorized() || axis.isTimeSeries()) &&
685
688
  config.axis_x_tick_fit &&
686
- !config.axis_x_tick_culling &&
689
+ (!config.axis_x_tick_culling || isEmpty(config.axis_x_tick_culling)) &&
687
690
  !config.axis_x_tick_multiline &&
688
691
  positiveRotation
689
692
  ) {
@@ -899,14 +899,18 @@ export default {
899
899
  const value = d?.value;
900
900
 
901
901
  if (isArray(value)) {
902
- // @ts-ignore
903
- const index = {
904
- areaRange: ["high", "mid", "low"],
905
- candlestick: ["open", "high", "low", "close", "volume"]
906
- }[type].indexOf(key);
907
-
908
- return index >= 0 && value ? value[index] : undefined;
909
- } else if (value) {
902
+ if (type === "bar") {
903
+ return value.reduce((a, c) => c - a);
904
+ } else {
905
+ // @ts-ignore
906
+ const index = {
907
+ areaRange: ["high", "mid", "low"],
908
+ candlestick: ["open", "high", "low", "close", "volume"]
909
+ }[type].indexOf(key);
910
+
911
+ return index >= 0 && value ? value[index] : undefined;
912
+ }
913
+ } else if (value && key) {
910
914
  return value[key];
911
915
  }
912
916
 
@@ -992,7 +996,9 @@ export default {
992
996
  const max = yScale.domain().reduce((a, c) => c - a);
993
997
 
994
998
  // when all data are 0, return 0
995
- ratio = max === 0 ? 0 : Math.abs(d.value) / max;
999
+ ratio = max === 0 ? 0 : Math.abs(
1000
+ $$.getRangedData(d, null, type) / max
1001
+ );
996
1002
  } else if (type === "treemap") {
997
1003
  ratio /= $$.getTotalDataSum(true);
998
1004
  }
@@ -59,7 +59,6 @@ export default {
59
59
 
60
60
  // less than 20 is not enough to show the axis label 'outer' without legend
61
61
  const h = (isRotated ? (margin.top + height) + 10 : margin.bottom) + 20;
62
-
63
62
  const x = isRotated ? -(1 + left) : -(left - 1);
64
63
  const y = -15; // -Math.max(15, margin.top);
65
64
  const w = isRotated ? margin.left + 20 : width + 10 + left;
@@ -88,7 +87,7 @@ export default {
88
87
  (isRotated ? -(1 + left) : -(left - 1));
89
88
  const y = -(isRotated ? 20 : margin.top);
90
89
  const w = (isRotated ? width + 15 + left : margin.left + 20) + (isInner ? 20 : 0);
91
- const h = (isRotated ? margin.bottom + (config.padding?.mode === "fit" ? 10 : 0) : (margin.top + height)) + 10;
90
+ const h = (isRotated ? margin.bottom + 10 : (margin.top + height)) + 10;
92
91
 
93
92
  node
94
93
  .attr("x", x)
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {isValue, isFunction, isObjectType} from "../../module/util";
5
+ import {isArray, isValue, isFunction, isObjectType, isObject} from "../../module/util";
6
6
  import type {AxisType} from "../../../types/types";
7
7
 
8
8
  /**
@@ -50,8 +50,8 @@ export default {
50
50
  };
51
51
  },
52
52
 
53
- defaultValueFormat(v): number|string {
54
- return isValue(v) ? +v : "";
53
+ defaultValueFormat(v: number|number[]): number|string {
54
+ return isArray(v) ? v.join("~") : (isValue(v) ? +v : "");
55
55
  },
56
56
 
57
57
  defaultArcValueFormat(v, ratio): string {
@@ -65,7 +65,18 @@ export default {
65
65
  dataLabelFormat(targetId: string): Function {
66
66
  const $$ = this;
67
67
  const dataLabels = $$.config.data_labels;
68
- const defaultFormat = v => (isValue(v) ? +v : "");
68
+ const defaultFormat = v => {
69
+ const delimiter = "~";
70
+ let res = v;
71
+
72
+ if (isArray(v)) {
73
+ res = v.join(delimiter);
74
+ } else if (isObject(v)) {
75
+ res = Object.values(v).join(delimiter);
76
+ }
77
+
78
+ return res;
79
+ };
69
80
  let format = defaultFormat;
70
81
 
71
82
  // find format according to axis id
@@ -42,7 +42,7 @@ export default {
42
42
  getHorizontalAxisHeight(id: AxisType): number {
43
43
  const $$ = this;
44
44
  const {config, state} = $$;
45
- const {current, rotatedPadding, isLegendRight, isLegendInset} = state;
45
+ const {rotatedPadding, isLegendRight, isLegendInset} = state;
46
46
  const isRotated = config.axis_rotated;
47
47
  const isFitPadding = config.padding?.mode === "fit";
48
48
  const isInner = config[`axis_${id}_inner`];
@@ -70,21 +70,8 @@ export default {
70
70
  }
71
71
 
72
72
  const maxtickSize = $$.axis.getMaxTickSize(id);
73
- const rotate = $$.getAxisTickRotate(id);
74
-
75
- // Calculate x/y axis height when tick rotated
76
- if (
77
- ((id === "x" && !isRotated) || (/y2?/.test(id) && isRotated)) && rotate
78
- ) {
79
- h += maxtickSize.width *
80
- Math.cos(Math.PI * (90 - Math.abs(rotate)) / 180);
81
-
82
- if (!config.axis_x_tick_multiline && current.height) {
83
- if (h > current.height / 2) {
84
- h = current.height / 2;
85
- }
86
- }
87
- } else if (maxtickSize.height > defaultHeight && config.legend_show) {
73
+
74
+ if (maxtickSize.height > defaultHeight) {
88
75
  h += maxtickSize.height - defaultHeight;
89
76
  }
90
77
 
@@ -140,10 +127,10 @@ export default {
140
127
  }
141
128
 
142
129
  if ($el.svg &&
130
+ config.axis_x_tick_autorotate &&
143
131
  config.axis_x_tick_fit &&
144
132
  !config.axis_x_tick_multiline &&
145
133
  !config.axis_x_tick_culling &&
146
- config.axis_x_tick_autorotate &&
147
134
  allowedXAxisTypes
148
135
  ) {
149
136
  rotate = $$.needToRotateXAxisTickTexts() ?
@@ -169,10 +169,11 @@ export default {
169
169
  * Get padding by the direction.
170
170
  * @param {string} type "top" | "bottom" | "left" | "right"
171
171
  * @param {boolean} [withoutRecompute=false] If set true, do not recompute the padding value.
172
+ * @param {boolean} [withXAxisTickTextOverflow=false] If set true, calculate x axis tick text overflow.
172
173
  * @returns {number} padding value
173
174
  * @private
174
175
  */
175
- getCurrentPaddingByDirection(type: "top" | "bottom" | "left" | "right", withoutRecompute = false): number {
176
+ getCurrentPaddingByDirection(type: "top" | "bottom" | "left" | "right", withoutRecompute = false, withXAxisTickTextOverflow = false): number {
176
177
  const $$ = this;
177
178
  const {config, $el, state: {hasAxis}} = $$;
178
179
  const isRotated = config.axis_rotated;
@@ -219,6 +220,8 @@ export default {
219
220
  padding += isRotated ? (
220
221
  !isFitPadding && isUndefined(paddingOption) ? 10 : 2
221
222
  ) : !isAxisShow || isAxisInner ? (isFitPadding ? 2 : 1) : 0;
223
+
224
+ padding += withXAxisTickTextOverflow ? $$.axis.getXAxisTickTextY2Overflow(defaultPadding) : 0;
222
225
  } else if (type === "left" && isRotated && isUndefined(paddingOption)) {
223
226
  padding = !config.axis_x_show ?
224
227
  1 : (isFitPadding ? axisSize : Math.max(axisSize, 40));
@@ -238,10 +241,12 @@ export default {
238
241
  return padding + (axisSize * axesLen) - gap;
239
242
  },
240
243
 
241
- getCurrentPadding(): {top: number, bottom: number, left: number, right: number} {
244
+ getCurrentPadding(withXAxisTickTextOverflow = false): {
245
+ top: number, bottom: number, left: number, right: number
246
+ } {
242
247
  const $$ = this;
243
248
  const [top, bottom, left, right] = ["top", "bottom", "left", "right"]
244
- .map(v => $$.getCurrentPaddingByDirection(v));
249
+ .map(v => $$.getCurrentPaddingByDirection(v, null, withXAxisTickTextOverflow));
245
250
 
246
251
  return {top, bottom, left, right};
247
252
  },
@@ -299,7 +304,8 @@ export default {
299
304
  }
300
305
 
301
306
  const legendSize = {
302
- right: config.legend_show && state.isLegendRight ? $$.getLegendWidth() + 20 : 0,
307
+ right: config.legend_show && state.isLegendRight ?
308
+ $$.getLegendWidth() + (isFitPadding ? 0 : 20) : 0,
303
309
  bottom: !config.legend_show || state.isLegendRight || state.isLegendInset ? 0 : currLegend.height
304
310
  };
305
311
 
@@ -314,7 +320,7 @@ export default {
314
320
  const gaugeHeight = $$.hasType("gauge") && config.arc_needle_show &&
315
321
  !config.gauge_fullCircle && !config.gauge_label_show ? 10 : 0;
316
322
 
317
- const padding = $$.getCurrentPadding();
323
+ const padding = $$.getCurrentPadding(true);
318
324
 
319
325
  // for main
320
326
  state.margin = !isNonAxis && isRotated ? {
@@ -255,7 +255,7 @@ export default {
255
255
  * @returns {string|null}
256
256
  * @private
257
257
  */
258
- updateTextBacgroundColor(d: IDataRow | IArcData): string | null {
258
+ updateTextBackgroundColor(d: IDataRow | IArcData): string | null {
259
259
  const $$ = this;
260
260
  const {$el, config} = $$;
261
261
  const backgroundColor = config.data_labels_backgroundColors;
@@ -293,7 +293,7 @@ export default {
293
293
 
294
294
  $$.$el.text
295
295
  .style("fill", $$.getStylePropValue($$.updateTextColor))
296
- .attr("filter", $$.updateTextBacgroundColor.bind($$))
296
+ .attr("filter", $$.updateTextBackgroundColor.bind($$))
297
297
  .style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
298
298
  .each(function(d: IDataRow, i: number) {
299
299
  // do not apply transition for newly added text elements
@@ -410,7 +410,7 @@ export default {
410
410
  const rect = getBoundingRect(textElement);
411
411
 
412
412
  if (isBarType) {
413
- const isPositive = d.value >= 0;
413
+ const isPositive = $$.getRangedData(d, null, "bar") >= 0;
414
414
 
415
415
  if (isRotated) {
416
416
  const w = (
@@ -198,9 +198,9 @@ export default {
198
198
 
199
199
  value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
200
200
  } else if ($$.isBarRangeType(row)) {
201
- const {value: [start, end], id, index} = row;
201
+ const {value: rangeValue, id, index} = row;
202
202
 
203
- value = `${valueFormat(start, undefined, id, index)} ~ ${valueFormat(end, undefined, id, index)}`;
203
+ value = `${valueFormat(rangeValue, undefined, id, index)}`;
204
204
  } else {
205
205
  value = valueFormat(getRowValue(row), ...param);
206
206
  }
@@ -37,7 +37,7 @@ export default {
37
37
  y = isRotated ? state.height + padding : 0;
38
38
  } else if (target === "y2") {
39
39
  x = isRotated ? 0 : state.width + padding;
40
- y = isRotated ? 1 - padding : 0;
40
+ y = isRotated ? -padding - 1 : 0;
41
41
  } else if (target === "subX") {
42
42
  x = 0;
43
43
  y = isRotated ? 0 : state.height2;
@@ -440,7 +440,7 @@ export default {
440
440
  if ($$.shouldShowArcLabel()) {
441
441
  selection
442
442
  .style("fill", $$.updateTextColor.bind($$))
443
- .attr("filter", $$.updateTextBacgroundColor.bind($$))
443
+ .attr("filter", $$.updateTextBackgroundColor.bind($$))
444
444
  .each(function(d) {
445
445
  const node = d3Select(this);
446
446
  const updated = $$.updateAngle(d);
@@ -273,6 +273,8 @@ export default {
273
273
 
274
274
  if (isNumber(d)) {
275
275
  value = d;
276
+ } else if ($$.isAreaRangeType(d)) {
277
+ value = $$.getBaseValue(d, "mid");
276
278
  } else if (isStackNormalized) {
277
279
  value = $$.getRatio("index", d, true);
278
280
  } else if ($$.isBubbleZType(d)) {