billboard.js 3.11.2 → 3.12.0-next.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 (171) hide show
  1. package/README.md +2 -6
  2. package/dist/billboard.css +5 -1
  3. package/dist/billboard.js +19431 -24292
  4. package/dist/billboard.min.css +2 -2
  5. package/dist/billboard.min.js +26 -3
  6. package/dist/billboard.pkgd.js +22301 -29057
  7. package/dist/billboard.pkgd.min.js +33 -3
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +77 -175
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -3
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +423 -1134
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
  12. package/dist/plugin/billboardjs-plugin-stanford.js +660 -1524
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +15 -3
  14. package/dist/plugin/billboardjs-plugin-tableview.js +503 -1175
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +30 -3
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +351 -1055
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -3
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +339 -1324
  19. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
  20. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +1701 -3424
  21. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
  22. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2385 -4462
  23. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
  24. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1783 -3467
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
  26. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2031 -3979
  27. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
  28. package/dist/theme/dark.css +5 -1
  29. package/dist/theme/dark.min.css +2 -2
  30. package/dist/theme/datalab.css +5 -1
  31. package/dist/theme/datalab.min.css +2 -2
  32. package/dist/theme/graph.css +5 -1
  33. package/dist/theme/graph.min.css +2 -2
  34. package/dist/theme/insight.css +5 -1
  35. package/dist/theme/insight.min.css +2 -2
  36. package/dist/theme/modern.css +5 -1
  37. package/dist/theme/modern.min.css +3 -4
  38. package/dist-esm/billboard.js +9051 -8666
  39. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +19 -25
  40. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +149 -148
  41. package/dist-esm/plugin/billboardjs-plugin-stanford.js +295 -286
  42. package/dist-esm/plugin/billboardjs-plugin-tableview.js +235 -234
  43. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +40 -41
  44. package/package.json +26 -46
  45. package/src/Chart/api/axis.ts +6 -13
  46. package/src/Chart/api/chart.ts +12 -11
  47. package/src/Chart/api/data.ts +8 -7
  48. package/src/Chart/api/export.ts +28 -21
  49. package/src/Chart/api/flow.ts +4 -2
  50. package/src/Chart/api/grid.ts +1 -5
  51. package/src/Chart/api/load.ts +2 -2
  52. package/src/Chart/api/regions.ts +29 -5
  53. package/src/Chart/api/selection.ts +2 -2
  54. package/src/Chart/api/show.ts +2 -3
  55. package/src/Chart/api/subchart.ts +2 -2
  56. package/src/Chart/api/tooltip.ts +5 -7
  57. package/src/Chart/api/x.ts +2 -2
  58. package/src/Chart/api/zoom.ts +2 -2
  59. package/src/ChartInternal/Axis/Axis.ts +119 -44
  60. package/src/ChartInternal/Axis/AxisRenderer.ts +53 -38
  61. package/src/ChartInternal/Axis/AxisRendererHelper.ts +2 -2
  62. package/src/ChartInternal/ChartInternal.ts +79 -51
  63. package/src/ChartInternal/data/IData.ts +22 -29
  64. package/src/ChartInternal/data/convert.helper.ts +66 -68
  65. package/src/ChartInternal/data/convert.ts +11 -11
  66. package/src/ChartInternal/data/data.ts +40 -23
  67. package/src/ChartInternal/data/load.ts +7 -6
  68. package/src/ChartInternal/interactions/drag.ts +2 -1
  69. package/src/ChartInternal/interactions/eventrect.ts +54 -25
  70. package/src/ChartInternal/interactions/flow.ts +14 -4
  71. package/src/ChartInternal/interactions/interaction.ts +34 -12
  72. package/src/ChartInternal/interactions/subchart.ts +27 -25
  73. package/src/ChartInternal/interactions/zoom.ts +29 -18
  74. package/src/ChartInternal/internals/category.ts +1 -1
  75. package/src/ChartInternal/internals/class.ts +5 -5
  76. package/src/ChartInternal/internals/clip.ts +9 -10
  77. package/src/ChartInternal/internals/color.ts +70 -42
  78. package/src/ChartInternal/internals/domain.ts +59 -28
  79. package/src/ChartInternal/internals/format.ts +5 -5
  80. package/src/ChartInternal/internals/grid.ts +130 -47
  81. package/src/ChartInternal/internals/legend.ts +99 -66
  82. package/src/ChartInternal/internals/redraw.ts +3 -2
  83. package/src/ChartInternal/internals/region.ts +5 -3
  84. package/src/ChartInternal/internals/scale.ts +28 -15
  85. package/src/ChartInternal/internals/selection.ts +14 -13
  86. package/src/ChartInternal/internals/size.axis.ts +18 -10
  87. package/src/ChartInternal/internals/size.ts +97 -66
  88. package/src/ChartInternal/internals/style.ts +21 -19
  89. package/src/ChartInternal/internals/text.ts +64 -39
  90. package/src/ChartInternal/internals/title.ts +2 -2
  91. package/src/ChartInternal/internals/tooltip.ts +83 -34
  92. package/src/ChartInternal/internals/transform.ts +2 -2
  93. package/src/ChartInternal/internals/type.ts +12 -12
  94. package/src/ChartInternal/shape/arc.ts +78 -44
  95. package/src/ChartInternal/shape/area.ts +19 -22
  96. package/src/ChartInternal/shape/bar.ts +41 -31
  97. package/src/ChartInternal/shape/bubble.ts +5 -5
  98. package/src/ChartInternal/shape/candlestick.ts +15 -13
  99. package/src/ChartInternal/shape/gauge.ts +16 -9
  100. package/src/ChartInternal/shape/line.ts +62 -46
  101. package/src/ChartInternal/shape/point.common.ts +1 -4
  102. package/src/ChartInternal/shape/point.ts +52 -32
  103. package/src/ChartInternal/shape/polar.ts +4 -2
  104. package/src/ChartInternal/shape/radar.ts +40 -22
  105. package/src/ChartInternal/shape/shape.ts +84 -58
  106. package/src/ChartInternal/shape/treemap.ts +29 -20
  107. package/src/Plugin/bubblecompare/index.ts +1 -3
  108. package/src/Plugin/sparkline/index.ts +3 -4
  109. package/src/Plugin/stanford/ColorScale.ts +3 -2
  110. package/src/Plugin/stanford/Elements.ts +15 -6
  111. package/src/Plugin/stanford/Options.ts +5 -5
  112. package/src/Plugin/stanford/index.ts +13 -9
  113. package/src/Plugin/tableview/Options.ts +1 -1
  114. package/src/Plugin/tableview/const.ts +1 -4
  115. package/src/Plugin/tableview/index.ts +11 -9
  116. package/src/Plugin/textoverlap/index.ts +4 -6
  117. package/src/config/Options/Options.ts +3 -3
  118. package/src/config/Options/axis/axis.ts +36 -0
  119. package/src/config/Options/axis/x.ts +12 -13
  120. package/src/config/Options/axis/y.ts +13 -13
  121. package/src/config/Options/axis/y2.ts +23 -10
  122. package/src/config/Options/common/color.ts +4 -4
  123. package/src/config/Options/common/grid.ts +4 -4
  124. package/src/config/Options/common/legend.ts +13 -14
  125. package/src/config/Options/common/main.ts +23 -23
  126. package/src/config/Options/common/point.ts +17 -18
  127. package/src/config/Options/common/title.ts +2 -2
  128. package/src/config/Options/common/tooltip.ts +13 -11
  129. package/src/config/Options/data/axis.ts +2 -2
  130. package/src/config/Options/data/data.ts +45 -45
  131. package/src/config/Options/interaction/interaction.ts +1 -1
  132. package/src/config/Options/interaction/subchart.ts +2 -2
  133. package/src/config/Options/interaction/zoom.ts +9 -9
  134. package/src/config/Options/shape/arc.ts +10 -13
  135. package/src/config/Options/shape/area.ts +5 -7
  136. package/src/config/Options/shape/bar.ts +8 -10
  137. package/src/config/Options/shape/bubble.ts +1 -1
  138. package/src/config/Options/shape/candlestick.ts +2 -2
  139. package/src/config/Options/shape/donut.ts +4 -4
  140. package/src/config/Options/shape/gauge.ts +6 -6
  141. package/src/config/Options/shape/line.ts +3 -3
  142. package/src/config/Options/shape/pie.ts +5 -5
  143. package/src/config/Options/shape/polar.ts +3 -3
  144. package/src/config/Options/shape/radar.ts +2 -2
  145. package/src/config/Options/shape/scatter.ts +1 -1
  146. package/src/config/Options/shape/treemap.ts +1 -1
  147. package/src/config/Store/Element.ts +8 -5
  148. package/src/config/Store/State.ts +19 -13
  149. package/src/config/classes.ts +6 -4
  150. package/src/config/config.ts +1 -1
  151. package/src/config/resolver/axis.ts +4 -4
  152. package/src/config/resolver/interaction.ts +3 -7
  153. package/src/config/resolver/shape.ts +11 -12
  154. package/src/core.ts +2 -3
  155. package/src/index.esm.ts +2 -6
  156. package/src/index.ts +2 -2
  157. package/src/module/Cache.ts +2 -3
  158. package/src/module/browser.ts +15 -10
  159. package/src/module/error.ts +9 -8
  160. package/src/module/generator.ts +3 -5
  161. package/src/module/util.ts +60 -37
  162. package/src/module/worker.ts +14 -11
  163. package/src/scss/billboard.scss +6 -0
  164. package/src/scss/theme/dark.scss +6 -0
  165. package/src/scss/theme/datalab.scss +6 -0
  166. package/src/scss/theme/graph.scss +6 -0
  167. package/src/scss/theme/insight.scss +6 -0
  168. package/src/scss/theme/modern.scss +6 -0
  169. package/types/axis.d.ts +7 -0
  170. package/types/options.d.ts +7 -0
  171. package/types/options.shape.d.ts +7 -0
@@ -3,7 +3,11 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import {drag as d3Drag} from "d3-drag";
6
- import {zoomIdentity as d3ZoomIdentity, zoom as d3Zoom, zoomTransform as d3ZoomTransform} from "d3-zoom";
6
+ import {
7
+ zoom as d3Zoom,
8
+ zoomIdentity as d3ZoomIdentity,
9
+ zoomTransform as d3ZoomTransform
10
+ } from "d3-zoom";
7
11
  import {$COMMON, $ZOOM} from "../../config/classes";
8
12
  import {callFn, diffDomain, getPointer, isFunction} from "../../module/util";
9
13
 
@@ -79,7 +83,8 @@ export default {
79
83
  * @private
80
84
  */
81
85
  // @ts-ignore
82
- zoom.updateTransformScale = (transform: d3ZoomTransform, correctTransform: boolean): void => {
86
+ zoom.updateTransformScale = (transform: d3ZoomTransform,
87
+ correctTransform: boolean): void => {
83
88
  const isRotated = config.axis_rotated;
84
89
 
85
90
  // in case of resize, update range of orgXScale
@@ -102,7 +107,8 @@ export default {
102
107
  const tX = isRotated ? transform.x : t;
103
108
  const tY = isRotated ? t : transform.y;
104
109
 
105
- $$.$el.eventRect.property("__zoom", d3ZoomIdentity.translate(tX, tY).scale(transform.k));
110
+ $$.$el.eventRect.property("__zoom",
111
+ d3ZoomIdentity.translate(tX, tY).scale(transform.k));
106
112
  }
107
113
 
108
114
  if (!$$.state.xTickOffset) {
@@ -172,7 +178,8 @@ export default {
172
178
  if (
173
179
  !config.zoom_enabled ||
174
180
  $$.filterTargetsToShow($$.data.targets).length === 0 ||
175
- (!scale.zoom && sourceEvent?.type.indexOf("touch") > -1 && sourceEvent?.touches.length === 1)
181
+ (!scale.zoom && sourceEvent?.type.indexOf("touch") > -1 &&
182
+ sourceEvent?.touches.length === 1)
176
183
  ) {
177
184
  return;
178
185
  }
@@ -197,8 +204,8 @@ export default {
197
204
  // - when .unzoom() is called (event.transform === d3ZoomIdentity)
198
205
  const doTransition = config.transition_duration > 0 &&
199
206
  !config.subchart_show && (
200
- state.dragging || isUnZoom || !event.sourceEvent
201
- );
207
+ state.dragging || isUnZoom || !event.sourceEvent
208
+ );
202
209
 
203
210
  $$.redraw({
204
211
  withTransition: doTransition,
@@ -236,9 +243,11 @@ export default {
236
243
  }
237
244
 
238
245
  // if click, do nothing. otherwise, click interaction will be canceled.
239
- if (config.zoom_type === "drag" && (
240
- e && startEvent.clientX === e.clientX && startEvent.clientY === e.clientY
241
- )) {
246
+ if (
247
+ config.zoom_type === "drag" && (
248
+ e && startEvent.clientX === e.clientX && startEvent.clientY === e.clientY
249
+ )
250
+ ) {
242
251
  return;
243
252
  }
244
253
 
@@ -268,15 +277,17 @@ export default {
268
277
  const xDomain = subX.domain();
269
278
  const delta = 0.015; // arbitrary value
270
279
 
271
- const isfullyShown = $$.config.axis_x_inverted ? (
272
- zoomDomain[0] >= xDomain[0] || (zoomDomain[0] + delta) >= xDomain[0]
273
- ) && (
274
- xDomain[1] >= zoomDomain[1] || xDomain[1] >= (zoomDomain[1] + delta)
275
- ) : (
276
- zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]
277
- ) && (
278
- xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta)
279
- );
280
+ const isfullyShown = $$.config.axis_x_inverted ?
281
+ (
282
+ zoomDomain[0] >= xDomain[0] || (zoomDomain[0] + delta) >= xDomain[0]
283
+ ) && (
284
+ xDomain[1] >= zoomDomain[1] || xDomain[1] >= (zoomDomain[1] + delta)
285
+ ) :
286
+ (
287
+ zoomDomain[0] <= xDomain[0] || (zoomDomain[0] - delta) <= xDomain[0]
288
+ ) && (
289
+ xDomain[1] <= zoomDomain[1] || xDomain[1] <= (zoomDomain[1] - delta)
290
+ );
280
291
 
281
292
  // check if the zoomed chart is fully shown, then reset scale when zoom is out as initial
282
293
  if (force || isfullyShown) {
@@ -13,5 +13,5 @@ export default {
13
13
  const {axis_x_categories} = this.config;
14
14
 
15
15
  return axis_x_categories?.[i] ?? i;
16
- },
16
+ }
17
17
  };
@@ -94,14 +94,15 @@ export default {
94
94
  const target = this.getTargetSelectorSuffix(id);
95
95
 
96
96
  // select target & circle
97
- return `${prefix}.${CLASS.target + target} ${postfix}, ${prefix}.${CLASS.circles + target} ${postfix}`;
97
+ return `${prefix}.${CLASS.target + target} ${postfix}, ${prefix}.${
98
+ CLASS.circles + target
99
+ } ${postfix}`;
98
100
  },
99
101
 
100
102
  selectorTargets(idsValue, prefix: string): string[] | null {
101
103
  const ids = idsValue || [];
102
104
 
103
- return ids.length ?
104
- ids.map(id => this.selectorTarget(id, prefix)) : null;
105
+ return ids.length ? ids.map(id => this.selectorTarget(id, prefix)) : null;
105
106
  },
106
107
 
107
108
  selectorLegend(id: string): string {
@@ -109,7 +110,6 @@ export default {
109
110
  },
110
111
 
111
112
  selectorLegends(ids): string[] | null {
112
- return ids?.length ?
113
- ids.map(id => this.selectorLegend(id)) : null;
113
+ return ids?.length ? ids.map(id => this.selectorLegend(id)) : null;
114
114
  }
115
115
  };
@@ -2,7 +2,6 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {document, window} from "../../module/browser";
6
5
 
7
6
  export default {
8
7
  initClip(): void {
@@ -27,17 +26,15 @@ export default {
27
26
  const $$ = this;
28
27
  const {config} = $$;
29
28
 
30
- if ((!config.clipPath && /-clip$/.test(id)) ||
29
+ if (
30
+ (!config.clipPath && /-clip$/.test(id)) ||
31
31
  (!config.axis_x_clipPath && /-clip-xaxis$/.test(id)) ||
32
- (!config.axis_y_clipPath && /-clip-yaxis$/.test(id))) {
32
+ (!config.axis_y_clipPath && /-clip-yaxis$/.test(id))
33
+ ) {
33
34
  return null;
34
35
  }
35
36
 
36
- const isIE9 = window.navigator ?
37
- window.navigator.appVersion
38
- .toLowerCase().indexOf("msie 9.") >= 0 : false;
39
-
40
- return `url(${(isIE9 ? "" : document.URL.split("#")[0])}#${id})`;
37
+ return `url(#${id})`;
41
38
  },
42
39
 
43
40
  appendClip(parent, id: string): void {
@@ -83,7 +80,8 @@ export default {
83
80
  const left = Math.max(30, margin.left) - (isRotated ? 20 : 0);
84
81
  const isInner = config.axis_y_inner;
85
82
 
86
- const x = isInner && !isRotated ? (config.axis_y_label.text ? -20 : -1) :
83
+ const x = isInner && !isRotated ?
84
+ (config.axis_y_label.text ? -20 : -1) :
87
85
  (isRotated ? -(1 + left) : -(left - 1));
88
86
  const y = -(isRotated ? 20 : margin.top);
89
87
  const w = (isRotated ? width + 15 + left : margin.left + 20) + (isInner ? 20 : 0);
@@ -109,7 +107,8 @@ export default {
109
107
  clip.idXAxisTickTexts = clipId;
110
108
  }
111
109
 
112
- if (!config.axis_x_tick_multiline &&
110
+ if (
111
+ !config.axis_x_tick_multiline &&
113
112
  $$.getAxisTickRotate("x") &&
114
113
  newXAxisHeight !== xAxisHeight
115
114
  ) {
@@ -2,14 +2,14 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {select as d3Select} from "d3-selection";
6
5
  import {scaleOrdinal as d3ScaleOrdinal} from "d3-scale";
7
- import {document} from "../../module/browser";
6
+ import {select as d3Select} from "d3-selection";
7
+ import {d3Selection} from "../../../types";
8
8
  import {$ARC, $COLOR, $SHAPE} from "../../config/classes";
9
+ import {document} from "../../module/browser";
9
10
  import {KEY} from "../../module/Cache";
10
- import {notEmpty, isFunction, isObject, isString} from "../../module/util";
11
+ import {isFunction, isObject, isString, notEmpty} from "../../module/util";
11
12
  import type {IArcData, IDataRow} from "../data/IData";
12
- import {d3Selection} from "../../../types";
13
13
 
14
14
  /**
15
15
  * Set pattern's background color
@@ -72,7 +72,18 @@ function getColorFromCss(element: d3Selection): string[] {
72
72
 
73
73
  // Replacement of d3.schemeCategory10.
74
74
  // Contained differently depend on d3 version: v4(d3-scale), v5(d3-scale-chromatic)
75
- const schemeCategory10 = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"];
75
+ const schemeCategory10 = [
76
+ "#1f77b4",
77
+ "#ff7f0e",
78
+ "#2ca02c",
79
+ "#d62728",
80
+ "#9467bd",
81
+ "#8c564b",
82
+ "#e377c2",
83
+ "#7f7f7f",
84
+ "#bcbd22",
85
+ "#17becf"
86
+ ];
76
87
 
77
88
  export default {
78
89
  generateColor(): Function {
@@ -82,7 +93,8 @@ export default {
82
93
  const callback = config.data_color;
83
94
  const ids: string[] = [];
84
95
 
85
- let pattern = notEmpty(config.color_pattern) ? config.color_pattern :
96
+ let pattern = notEmpty(config.color_pattern) ?
97
+ config.color_pattern :
86
98
  d3ScaleOrdinal(getColorFromCss($el.chart) || schemeCategory10).range();
87
99
 
88
100
  const originalColorPattern = pattern;
@@ -114,24 +126,24 @@ export default {
114
126
  if (isFunction(colors[id])) {
115
127
  color = colors[id].bind($$.api)(d);
116
128
 
117
- // if specified, choose that color
129
+ // if specified, choose that color
118
130
  } else if (colors[id]) {
119
131
  color = colors[id];
120
132
 
121
- // if not specified, choose from pattern
133
+ // if not specified, choose from pattern
122
134
  } else {
123
135
  if (ids.indexOf(id) < 0) {
124
136
  ids.push(id);
125
137
  }
126
138
 
127
- color = isLine ? originalColorPattern[ids.indexOf(id) % originalColorPattern.length] :
139
+ color = isLine ?
140
+ originalColorPattern[ids.indexOf(id) % originalColorPattern.length] :
128
141
  pattern[ids.indexOf(id) % pattern.length];
129
142
 
130
143
  colors[id] = color;
131
144
  }
132
145
 
133
- return isFunction(callback) ?
134
- callback.bind($$.api)(color, d) : color;
146
+ return isFunction(callback) ? callback.bind($$.api)(color, d) : color;
135
147
  };
136
148
  },
137
149
 
@@ -143,52 +155,66 @@ export default {
143
155
  const asValue = threshold.unit === "value";
144
156
  const max = threshold.max || 100;
145
157
  const values = threshold.values &&
146
- threshold.values.length ? threshold.values : [];
147
-
148
- return notEmpty(threshold) ? function(value) {
149
- const v = asValue ? value : (value * 100 / max);
150
- let color = colors[colors.length - 1];
151
-
152
- for (let i = 0, l = values.length; i < l; i++) {
153
- if (v <= values[i]) {
154
- color = colors[i];
155
- break;
158
+ threshold.values.length ?
159
+ threshold.values :
160
+ [];
161
+
162
+ return notEmpty(threshold) ?
163
+ function(value) {
164
+ const v = asValue ? value : (value * 100 / max);
165
+ let color = colors[colors.length - 1];
166
+
167
+ for (let i = 0, l = values.length; i < l; i++) {
168
+ if (v <= values[i]) {
169
+ color = colors[i];
170
+ break;
171
+ }
156
172
  }
157
- }
158
173
 
159
- return color;
160
- } : null;
174
+ return color;
175
+ } :
176
+ null;
161
177
  },
162
178
 
163
179
  /**
164
180
  * Append data backgound color filter definition
165
- * @param {string} color Color string
181
+ * @param {string|object} color Color string
182
+ * @param {object} attr filter attribute
166
183
  * @private
167
184
  */
168
- generateDataLabelBackgroundColorFilter(color?: string): void {
185
+ generateTextBGColorFilter(color: string | object, attr = {
186
+ x: 0,
187
+ y: 0,
188
+ width: 1,
189
+ height: 1
190
+ }): void {
169
191
  const $$ = this;
170
- const {$el, config, state} = $$;
171
- const backgroundColors = color || config.data_labels_backgroundColors;
192
+ const {$el, state} = $$;
172
193
 
173
- if (backgroundColors) {
194
+ if (color) {
174
195
  let ids: string[] = [];
175
196
 
176
- if (isString(backgroundColors)) {
197
+ if (isString(color)) {
177
198
  ids.push("");
178
- } else if (isObject(backgroundColors)) {
179
- ids = Object.keys(backgroundColors);
199
+ } else if (isObject(color)) {
200
+ ids = Object.keys(color);
180
201
  }
181
202
 
182
203
  ids.forEach(v => {
183
- const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}${color ? $$.getTargetSelectorSuffix(color) : ""}`;
204
+ const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}${
205
+ isString(color) ? $$.getTargetSelectorSuffix(color) : ""
206
+ }`;
184
207
 
185
208
  $el.defs.append("filter")
186
- .attr("x", "0")
187
- .attr("y", "0")
188
- .attr("width", "1")
189
- .attr("height", "1")
209
+ .attr("x", attr.x)
210
+ .attr("y", attr.y)
211
+ .attr("width", attr.width)
212
+ .attr("height", attr.height)
190
213
  .attr("id", id)
191
- .html(`<feFlood flood-color="${v === "" ? backgroundColors : backgroundColors[v]}" /><feComposite in="SourceGraphic"/>`);
214
+ .html(
215
+ `<feFlood flood-color="${v === "" ? color : color[v]}" />
216
+ <feComposite in="SourceGraphic" />`
217
+ );
192
218
  });
193
219
  }
194
220
  },
@@ -221,8 +247,8 @@ export default {
221
247
  if ((radialGradient || supportedType) && defs.select(`#${id}`).empty()) {
222
248
  const color = $$.color(d);
223
249
  const gradient = {
224
- defs: <null|d3Selection>null,
225
- stops: <[number, string|Function|null, number][]>[]
250
+ defs: <null | d3Selection>null,
251
+ stops: <[number, string | Function | null, number][]>[]
226
252
  };
227
253
 
228
254
  if (radialGradient) {
@@ -256,9 +282,11 @@ export default {
256
282
  .attr("y2", y[1]);
257
283
  }
258
284
 
259
- gradient.stops.forEach((v: [number, string|Function|null, number]) => {
285
+ gradient.stops.forEach((v: [number, string | Function | null, number]) => {
260
286
  const [offset, stopColor, stopOpacity] = v;
261
- const colorValue = isFunction(stopColor) ? stopColor.bind($$.api)(d.id) : stopColor;
287
+ const colorValue = isFunction(stopColor) ?
288
+ stopColor.bind($$.api)(d.id) :
289
+ stopColor;
262
290
 
263
291
  gradient.defs && gradient.defs.append("stop")
264
292
  .attr("offset", offset)
@@ -3,8 +3,20 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import {TYPE, TYPE_BY_CATEGORY} from "../../config/const";
6
+ import {
7
+ brushEmpty,
8
+ diffDomain,
9
+ getBrushSelection,
10
+ getMinMax,
11
+ isDefined,
12
+ isNumber,
13
+ isObject,
14
+ isValue,
15
+ notEmpty,
16
+ parseDate,
17
+ sortValue
18
+ } from "../../module/util";
6
19
  import type {IData, TDomainRange} from "../data/IData";
7
- import {brushEmpty, getBrushSelection, getMinMax, isDefined, notEmpty, isValue, isObject, isNumber, diffDomain, parseDate, sortValue} from "../../module/util";
8
20
 
9
21
  export default {
10
22
  getYDomainMinMax(targets, type: "min" | "max"): number | Date | undefined {
@@ -88,8 +100,7 @@ export default {
88
100
  return scale[axisId].domain();
89
101
  } else {
90
102
  return axisId === "y2" ?
91
- scale.y.domain() :
92
- // When all data bounds to y2, y Axis domain is called prior y2.
103
+ scale.y.domain() : // When all data bounds to y2, y Axis domain is called prior y2.
93
104
  // So, it needs to call to get y2 domain here
94
105
  $$.getYDomain(targets, "y2", xDomain);
95
106
  }
@@ -114,15 +125,19 @@ export default {
114
125
 
115
126
  // MEMO: avoid inverting domain unexpectedly
116
127
  yDomainMin = isValue(yMin) ? yMin : (
117
- isValue(yMax) ? (
118
- yDomainMin <= yMax ? yDomainMin : yMax - 10
119
- ) : yDomainMin
128
+ isValue(yMax) ?
129
+ (
130
+ yDomainMin <= yMax ? yDomainMin : yMax - 10
131
+ ) :
132
+ yDomainMin
120
133
  );
121
134
 
122
135
  yDomainMax = isValue(yMax) ? yMax : (
123
- isValue(yMin) ? (
124
- yMin <= yDomainMax ? yDomainMax : yMin + 10
125
- ) : yDomainMax
136
+ isValue(yMin) ?
137
+ (
138
+ yMin <= yDomainMax ? yDomainMax : yMin + 10
139
+ ) :
140
+ yDomainMax
126
141
  );
127
142
 
128
143
  if (isNaN(yDomainMin)) { // set minimum to zero when not number
@@ -196,7 +211,8 @@ export default {
196
211
  isAllNegative && (padding.top = -yDomainMax);
197
212
  }
198
213
 
199
- const domain = isLog ? [yDomainMin, yDomainMax].map(v => (v < 0 ? 0 : v)) :
214
+ const domain = isLog ?
215
+ [yDomainMin, yDomainMax].map(v => (v < 0 ? 0 : v)) :
200
216
  [yDomainMin - padding.bottom, yDomainMax + padding.top];
201
217
 
202
218
  return isInverted ? domain.reverse() : domain;
@@ -205,14 +221,17 @@ export default {
205
221
  getXDomainMinMax(targets, type) {
206
222
  const $$ = this;
207
223
  const configValue = $$.config[`axis_x_${type}`];
208
- const dataValue = getMinMax(type, targets.map(t => getMinMax(type, t.values.map(v => v.x))));
224
+ const dataValue = getMinMax(type,
225
+ targets.map(t => getMinMax(type, t.values.map(v => v.x))));
209
226
  let value = isObject(configValue) ? configValue.value : configValue;
210
227
 
211
228
  value = isDefined(value) && $$.axis?.isTimeSeries() ? parseDate.bind(this)(value) : value;
212
229
 
213
- if (isObject(configValue) && configValue.fit && (
214
- (type === "min" && value < dataValue) || (type === "max" && value > dataValue)
215
- )) {
230
+ if (
231
+ isObject(configValue) && configValue.fit && (
232
+ (type === "min" && value < dataValue) || (type === "max" && value > dataValue)
233
+ )
234
+ ) {
216
235
  value = undefined;
217
236
  }
218
237
 
@@ -246,7 +265,8 @@ export default {
246
265
  }
247
266
 
248
267
  let {left = defaultValue, right = defaultValue} = isNumber(padding) ?
249
- {left: padding, right: padding} : padding;
268
+ {left: padding, right: padding} :
269
+ padding;
250
270
 
251
271
  // when the unit is pixel, convert pixels to axis scale value
252
272
  if (padding.unit === "px") {
@@ -274,7 +294,7 @@ export default {
274
294
  * @returns {Array} x Axis domain
275
295
  * @private
276
296
  */
277
- getXDomain(targets: IData[]): (Date|number)[] {
297
+ getXDomain(targets: IData[]): (Date | number)[] {
278
298
  const $$ = this;
279
299
  const {axis, config, scale: {x}} = $$;
280
300
  const isInverted = config.axis_x_inverted;
@@ -302,11 +322,15 @@ export default {
302
322
  }
303
323
 
304
324
  if (firstX || firstX === 0) {
305
- min = isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left;
325
+ min = isTimeSeries ?
326
+ new Date(firstX.getTime() - padding.left) :
327
+ firstX - padding.left;
306
328
  }
307
329
 
308
330
  if (lastX || lastX === 0) {
309
- max = isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right;
331
+ max = isTimeSeries ?
332
+ new Date(lastX.getTime() + padding.right) :
333
+ lastX + padding.right;
310
334
  }
311
335
  }
312
336
 
@@ -330,7 +354,8 @@ export default {
330
354
 
331
355
  if (withUpdateXDomain) {
332
356
  const domainValue = domain || (!$$.brush || brushEmpty($$)) ?
333
- org.xDomain : getBrushSelection($$).map(subX.invert);
357
+ org.xDomain :
358
+ getBrushSelection($$).map(subX.invert);
334
359
 
335
360
  x.domain(domainValue);
336
361
  // zoomEnabled && $$.zoom.updateScaleExtent();
@@ -411,7 +436,9 @@ export default {
411
436
  const isInverted = config.axis_x_inverted;
412
437
 
413
438
  // need to add offset to original value for 'category' type
414
- const domain = domainValue.map((v, i) => Number(v) + (i === 0 ? +isInverted : +!isInverted));
439
+ const domain = domainValue.map((v, i) =>
440
+ Number(v) + (i === 0 ? +isInverted : +!isInverted)
441
+ );
415
442
 
416
443
  return domain as T;
417
444
  }
@@ -427,7 +454,7 @@ export default {
427
454
  * @returns {number}
428
455
  * @private
429
456
  */
430
- convertPixelToScale(type: "x"|"y", pixels: number, domainLength: number): number {
457
+ convertPixelToScale(type: "x" | "y", pixels: number, domainLength: number): number {
431
458
  const $$ = this;
432
459
  const {config, state} = $$;
433
460
  const isRotated = config.axis_rotated;
@@ -461,13 +488,17 @@ export default {
461
488
  isInverted && target.reverse();
462
489
 
463
490
  if (target[0] < target[1]) {
464
- return domain.every((v, i) => (
465
- i === 0 ? (
466
- isInverted ? +v <= min : +v >= min
467
- ) : (
468
- isInverted ? +v >= max : +v <= max
469
- )
470
- ) && !(domain.every((v, i) => v === current[i])));
491
+ return domain.every((v, i) =>
492
+ (
493
+ i === 0 ?
494
+ (
495
+ isInverted ? +v <= min : +v >= min
496
+ ) :
497
+ (
498
+ isInverted ? +v >= max : +v <= max
499
+ )
500
+ ) && !(domain.every((v, i) => v === current[i]))
501
+ );
471
502
  }
472
503
  }
473
504
 
@@ -2,8 +2,8 @@
2
2
  * Copyright (c) 2017 ~ present NAVER Corp.
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
- import {isArray, isValue, isFunction, isObjectType, isObject} from "../../module/util";
6
5
  import type {AxisType} from "../../../types/types";
6
+ import {isArray, isFunction, isObject, isObjectType, isValue} from "../../module/util";
7
7
 
8
8
  /**
9
9
  * Get formatted
@@ -16,8 +16,7 @@ import type {AxisType} from "../../../types/types";
16
16
  function getFormat($$, typeValue: AxisType, v: number): number | string {
17
17
  const {config} = $$;
18
18
  const type = `axis_${typeValue}_tick_format`;
19
- const format = config[type] ?
20
- config[type] : $$.defaultValueFormat;
19
+ const format = config[type] ? config[type] : $$.defaultValueFormat;
21
20
 
22
21
  return format.call($$.api, v);
23
22
  }
@@ -50,7 +49,7 @@ export default {
50
49
  };
51
50
  },
52
51
 
53
- defaultValueFormat(v: number|number[]): number|string {
52
+ defaultValueFormat(v: number | number[]): number | string {
54
53
  return isArray(v) ? v.join("~") : (isValue(v) ? +v : "");
55
54
  },
56
55
 
@@ -85,7 +84,8 @@ export default {
85
84
  } else if (isObjectType(dataLabels.format)) {
86
85
  if (dataLabels.format[targetId]) {
87
86
  format = dataLabels.format[targetId] === true ?
88
- defaultFormat : dataLabels.format[targetId];
87
+ defaultFormat :
88
+ dataLabels.format[targetId];
89
89
  } else {
90
90
  format = () => "";
91
91
  }