billboard.js 4.1.0-next.2 → 4.1.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 (233) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +268 -107
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +16 -16
  5. package/dist/billboard.pkgd.js +3198 -1755
  6. package/dist/billboard.pkgd.min.js +23 -23
  7. package/dist/billboard.react.js +28 -49
  8. package/dist/billboard.react.min.js +2 -2
  9. package/dist/billboard.worker.js +1 -1
  10. package/dist/plugin/billboardjs-plugin-bubblecompare.js +14 -31
  11. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-sparkline.js +14 -31
  13. package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
  14. package/dist/plugin/billboardjs-plugin-stanford.js +21 -35
  15. package/dist/plugin/billboardjs-plugin-stanford.min.js +7 -7
  16. package/dist/plugin/billboardjs-plugin-tableview.js +15 -30
  17. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  18. package/dist/plugin/billboardjs-plugin-textoverlap.js +15 -30
  19. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  20. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2959 -1684
  21. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +8 -8
  22. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2960 -1685
  23. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
  24. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2961 -1686
  25. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -18
  26. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2962 -1687
  27. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
  28. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2963 -1688
  29. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
  30. package/dist/theme/dark.css +1 -1
  31. package/dist/theme/dark.min.css +1 -1
  32. package/dist/theme/datalab.css +1 -1
  33. package/dist/theme/datalab.min.css +1 -1
  34. package/dist/theme/graph.css +1 -1
  35. package/dist/theme/graph.min.css +1 -1
  36. package/dist/theme/insight.css +1 -1
  37. package/dist/theme/insight.min.css +1 -1
  38. package/dist/theme/modern.css +1 -1
  39. package/dist/theme/modern.min.css +1 -1
  40. package/dist-esm/Chart/Chart.js +1 -1
  41. package/dist-esm/Chart/api/axis.js +1 -1
  42. package/dist-esm/Chart/api/category.js +1 -1
  43. package/dist-esm/Chart/api/chart.js +9 -7
  44. package/dist-esm/Chart/api/color.js +1 -1
  45. package/dist-esm/Chart/api/data.js +3 -3
  46. package/dist-esm/Chart/api/export.js +1 -1
  47. package/dist-esm/Chart/api/flow.js +1 -1
  48. package/dist-esm/Chart/api/focus.js +1 -1
  49. package/dist-esm/Chart/api/grid.js +1 -1
  50. package/dist-esm/Chart/api/group.js +1 -1
  51. package/dist-esm/Chart/api/legend.js +1 -1
  52. package/dist-esm/Chart/api/load.js +1 -1
  53. package/dist-esm/Chart/api/regions.js +1 -1
  54. package/dist-esm/Chart/api/selection.js +1 -1
  55. package/dist-esm/Chart/api/show.js +1 -1
  56. package/dist-esm/Chart/api/stubs.js +1 -1
  57. package/dist-esm/Chart/api/subchart.js +1 -1
  58. package/dist-esm/Chart/api/tooltip.js +1 -1
  59. package/dist-esm/Chart/api/x.js +11 -9
  60. package/dist-esm/Chart/api/zoom.js +8 -7
  61. package/dist-esm/ChartInternal/Axis/Axis.js +7 -6
  62. package/dist-esm/ChartInternal/Axis/AxisRenderer.js +1 -1
  63. package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +1 -1
  64. package/dist-esm/ChartInternal/ChartInternal.js +32 -8
  65. package/dist-esm/ChartInternal/data/convert.helper.js +7 -5
  66. package/dist-esm/ChartInternal/data/convert.js +1 -1
  67. package/dist-esm/ChartInternal/data/data.js +64 -33
  68. package/dist-esm/ChartInternal/data/load.js +1 -1
  69. package/dist-esm/ChartInternal/interactions/drag.js +1 -1
  70. package/dist-esm/ChartInternal/interactions/eventrect.js +1 -1
  71. package/dist-esm/ChartInternal/interactions/flow.js +17 -15
  72. package/dist-esm/ChartInternal/interactions/interaction.js +1 -1
  73. package/dist-esm/ChartInternal/interactions/subchart.js +8 -6
  74. package/dist-esm/ChartInternal/interactions/zoom.js +8 -6
  75. package/dist-esm/ChartInternal/internals/category.js +1 -1
  76. package/dist-esm/ChartInternal/internals/class.js +1 -1
  77. package/dist-esm/ChartInternal/internals/clip.js +1 -1
  78. package/dist-esm/ChartInternal/internals/color.js +1 -1
  79. package/dist-esm/ChartInternal/internals/domain.js +13 -9
  80. package/dist-esm/ChartInternal/internals/format.js +5 -3
  81. package/dist-esm/ChartInternal/internals/grid.js +5 -4
  82. package/dist-esm/ChartInternal/internals/legend.js +8 -7
  83. package/dist-esm/ChartInternal/internals/redraw.js +2 -2
  84. package/dist-esm/ChartInternal/internals/region.js +1 -1
  85. package/dist-esm/ChartInternal/internals/scale.js +1 -1
  86. package/dist-esm/ChartInternal/internals/selection.js +1 -1
  87. package/dist-esm/ChartInternal/internals/size.axis.js +1 -1
  88. package/dist-esm/ChartInternal/internals/size.js +56 -10
  89. package/dist-esm/ChartInternal/internals/style.js +1 -1
  90. package/dist-esm/ChartInternal/internals/subchart.util.js +1 -1
  91. package/dist-esm/ChartInternal/internals/text.arc.js +1 -1
  92. package/dist-esm/ChartInternal/internals/text.js +12 -9
  93. package/dist-esm/ChartInternal/internals/text.util.js +4 -4
  94. package/dist-esm/ChartInternal/internals/title.js +3 -2
  95. package/dist-esm/ChartInternal/internals/tooltip.js +25 -20
  96. package/dist-esm/ChartInternal/internals/transform.js +1 -1
  97. package/dist-esm/ChartInternal/internals/type.js +1 -1
  98. package/dist-esm/ChartInternal/shape/arc.js +3 -2
  99. package/dist-esm/ChartInternal/shape/area.js +3 -2
  100. package/dist-esm/ChartInternal/shape/bar.js +1 -1
  101. package/dist-esm/ChartInternal/shape/bubble.js +1 -1
  102. package/dist-esm/ChartInternal/shape/candlestick.js +1 -1
  103. package/dist-esm/ChartInternal/shape/core/barRadius.js +1 -1
  104. package/dist-esm/ChartInternal/shape/core/bubble.js +1 -1
  105. package/dist-esm/ChartInternal/shape/core/candlestick.js +1 -1
  106. package/dist-esm/ChartInternal/shape/core/dataRegion.js +1 -1
  107. package/dist-esm/ChartInternal/shape/core/geometry.js +1 -1
  108. package/dist-esm/ChartInternal/shape/core/path.js +1 -1
  109. package/dist-esm/ChartInternal/shape/core/point.js +1 -1
  110. package/dist-esm/ChartInternal/shape/core/treemap.js +3 -2
  111. package/dist-esm/ChartInternal/shape/funnel.js +1 -1
  112. package/dist-esm/ChartInternal/shape/gauge.js +1 -1
  113. package/dist-esm/ChartInternal/shape/line.js +3 -2
  114. package/dist-esm/ChartInternal/shape/point.js +1 -1
  115. package/dist-esm/ChartInternal/shape/polar.js +1 -1
  116. package/dist-esm/ChartInternal/shape/radar.js +1 -1
  117. package/dist-esm/ChartInternal/shape/shape.js +3 -2
  118. package/dist-esm/ChartInternal/shape/treemap.js +1 -1
  119. package/dist-esm/canvas/CanvasAxisRenderer.js +27 -21
  120. package/dist-esm/canvas/CanvasEngine.js +1 -1
  121. package/dist-esm/canvas/CanvasPainter.js +1 -1
  122. package/dist-esm/canvas/CanvasRenderer.js +1 -1
  123. package/dist-esm/canvas/CanvasTheme.js +7 -8
  124. package/dist-esm/canvas/HitDetector.js +1 -1
  125. package/dist-esm/canvas/axisTicks.js +3 -2
  126. package/dist-esm/canvas/classes.js +1 -1
  127. package/dist-esm/canvas/color.js +1 -1
  128. package/dist-esm/canvas/geometry.js +1 -1
  129. package/dist-esm/canvas/labels.js +4 -4
  130. package/dist-esm/canvas/pointPattern.js +1 -1
  131. package/dist-esm/canvas/util.js +1 -1
  132. package/dist-esm/config/Options/Options.js +1 -1
  133. package/dist-esm/config/Options/axis/axis.js +1 -1
  134. package/dist-esm/config/Options/axis/x.js +1 -1
  135. package/dist-esm/config/Options/axis/y.js +1 -1
  136. package/dist-esm/config/Options/axis/y2.js +1 -13
  137. package/dist-esm/config/Options/common/boost.js +1 -1
  138. package/dist-esm/config/Options/common/color.js +1 -1
  139. package/dist-esm/config/Options/common/grid.js +1 -1
  140. package/dist-esm/config/Options/common/legend.js +1 -1
  141. package/dist-esm/config/Options/common/main.js +44 -2
  142. package/dist-esm/config/Options/common/point.js +1 -1
  143. package/dist-esm/config/Options/common/title.js +1 -1
  144. package/dist-esm/config/Options/common/tooltip.js +1 -1
  145. package/dist-esm/config/Options/data/axis.js +1 -1
  146. package/dist-esm/config/Options/data/data.js +1 -1
  147. package/dist-esm/config/Options/data/selection.js +1 -1
  148. package/dist-esm/config/Options/interaction/interaction.js +1 -1
  149. package/dist-esm/config/Options/interaction/subchart.js +1 -1
  150. package/dist-esm/config/Options/interaction/zoom.js +1 -1
  151. package/dist-esm/config/Options/shape/arc.js +1 -1
  152. package/dist-esm/config/Options/shape/area.js +1 -1
  153. package/dist-esm/config/Options/shape/bar.js +1 -1
  154. package/dist-esm/config/Options/shape/bubble.js +1 -1
  155. package/dist-esm/config/Options/shape/candlestick.js +1 -1
  156. package/dist-esm/config/Options/shape/donut.js +1 -1
  157. package/dist-esm/config/Options/shape/funnel.js +1 -1
  158. package/dist-esm/config/Options/shape/gauge.js +1 -1
  159. package/dist-esm/config/Options/shape/line.js +1 -1
  160. package/dist-esm/config/Options/shape/pie.js +1 -1
  161. package/dist-esm/config/Options/shape/polar.js +1 -1
  162. package/dist-esm/config/Options/shape/radar.js +1 -1
  163. package/dist-esm/config/Options/shape/scatter.js +1 -1
  164. package/dist-esm/config/Options/shape/spline.js +1 -1
  165. package/dist-esm/config/Options/shape/treemap.js +1 -1
  166. package/dist-esm/config/Store/Element.js +1 -1
  167. package/dist-esm/config/Store/State.js +4 -1
  168. package/dist-esm/config/Store/Store.js +1 -1
  169. package/dist-esm/config/classes.js +1 -1
  170. package/dist-esm/config/config.js +1 -1
  171. package/dist-esm/config/const.js +1 -1
  172. package/dist-esm/config/resolver/axis.core.js +1 -1
  173. package/dist-esm/config/resolver/axis.js +1 -1
  174. package/dist-esm/config/resolver/canvas.js +17 -12
  175. package/dist-esm/config/resolver/canvasShape.js +1 -1
  176. package/dist-esm/config/resolver/category.js +1 -1
  177. package/dist-esm/config/resolver/export.js +1 -1
  178. package/dist-esm/config/resolver/flow.js +1 -1
  179. package/dist-esm/config/resolver/grid.js +1 -1
  180. package/dist-esm/config/resolver/interaction/selection.js +1 -1
  181. package/dist-esm/config/resolver/interaction/subchart.js +1 -1
  182. package/dist-esm/config/resolver/interaction/zoom.js +1 -1
  183. package/dist-esm/config/resolver/regions.js +1 -1
  184. package/dist-esm/config/resolver/shape/arc.helpers.js +1 -1
  185. package/dist-esm/config/resolver/shape/area.js +1 -1
  186. package/dist-esm/config/resolver/shape/axis.helpers.js +1 -1
  187. package/dist-esm/config/resolver/shape/bar.js +1 -1
  188. package/dist-esm/config/resolver/shape/bubble.js +1 -1
  189. package/dist-esm/config/resolver/shape/candlestick.js +1 -1
  190. package/dist-esm/config/resolver/shape/donut.js +1 -1
  191. package/dist-esm/config/resolver/shape/funnel.js +1 -1
  192. package/dist-esm/config/resolver/shape/gauge.js +1 -1
  193. package/dist-esm/config/resolver/shape/line.js +1 -1
  194. package/dist-esm/config/resolver/shape/pie.js +1 -1
  195. package/dist-esm/config/resolver/shape/polar.js +1 -1
  196. package/dist-esm/config/resolver/shape/radar.js +1 -1
  197. package/dist-esm/config/resolver/shape/scatter.js +1 -1
  198. package/dist-esm/config/resolver/shape/treemap.js +1 -1
  199. package/dist-esm/core.js +5 -4
  200. package/dist-esm/index.canvas.js +1 -1
  201. package/dist-esm/index.esm.js +1 -1
  202. package/dist-esm/module/Cache.js +2 -2
  203. package/dist-esm/module/browser.js +2 -2
  204. package/dist-esm/module/dsv.js +1 -1
  205. package/dist-esm/module/error.js +1 -1
  206. package/dist-esm/module/generator.js +16 -3
  207. package/dist-esm/module/sanitize.js +1 -1
  208. package/dist-esm/module/util/brush.js +1 -1
  209. package/dist-esm/module/util/dom.js +9 -7
  210. package/dist-esm/module/util/object.js +1 -1
  211. package/dist-esm/module/util/type-checks.js +1 -1
  212. package/dist-esm/module/worker.js +1 -1
  213. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  214. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -40
  215. package/dist-esm/plugin/billboardjs-plugin-stanford.js +4 -41
  216. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  217. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  218. package/dist-esm/react/index.js +1 -1
  219. package/package.json +36 -36
  220. package/src/Chart/api/chart.ts +1 -0
  221. package/src/Chart/api/data.ts +5 -3
  222. package/src/ChartInternal/ChartInternal.ts +72 -25
  223. package/src/ChartInternal/data/data.ts +68 -34
  224. package/src/ChartInternal/internals/redraw.ts +8 -1
  225. package/src/ChartInternal/internals/size.ts +99 -2
  226. package/src/config/Options/axis/y2.ts +0 -13
  227. package/src/config/Options/common/main.ts +43 -1
  228. package/src/config/Store/State.ts +4 -0
  229. package/src/config/const.ts +4 -0
  230. package/src/config/resolver/canvas.ts +3 -0
  231. package/src/module/Cache.ts +1 -1
  232. package/src/module/generator.ts +27 -2
  233. package/types/options.d.ts +38 -0
@@ -36,8 +36,30 @@ export default {
36
36
 
37
37
  getCurrentHeight(): number {
38
38
  const $$ = this;
39
- const {config} = $$;
40
- const h = config.size_height || $$.getParentHeight();
39
+ const {config, state, $el} = $$;
40
+ let h = config.size_height;
41
+
42
+ if (!h) {
43
+ // The min-height reserved for the canvas surface is this element's own
44
+ // output. Measuring with it in place makes it the floor of every later
45
+ // measurement, so the chart could never shrink vertically.
46
+ const chartNode = state.isCanvasMode ? $el.chart?.node() : null;
47
+ const minHeight = chartNode?.style.minHeight;
48
+
49
+ minHeight && (chartNode.style.minHeight = "");
50
+ h = $$.getParentHeight();
51
+ minHeight && (chartNode.style.minHeight = minHeight);
52
+
53
+ // Without a height of its own, the container collapses onto the canvas,
54
+ // which is drawn shorter than the chart by the bottom legend's room. The
55
+ // legend is positioned absolutely, so it adds nothing back: keep that room.
56
+ const surface = chartNode ? parseFloat($$.canvasEngine?.canvas.style.height) || 0 : 0;
57
+ const reserve = state.current.height - surface;
58
+
59
+ if (reserve > 0 && Math.round(h) === Math.round(surface)) {
60
+ h += reserve;
61
+ }
62
+ }
41
63
 
42
64
  return h > 0 ? h : 320 / ($$.hasType("gauge") && !config.gauge_fullCircle ? 2 : 1);
43
65
  },
@@ -135,6 +157,78 @@ export default {
135
157
  return result;
136
158
  },
137
159
 
160
+ /**
161
+ * Stretch the rendered surface to the container's current size, without redrawing.
162
+ * Gives an immediate size feedback while the delayed resize is pending.
163
+ * The drawn content keeps its previous geometry until the redraw takes place.
164
+ * @private
165
+ */
166
+ previewResize(): void {
167
+ const $$ = this;
168
+ const {state, $el} = $$;
169
+ const {current} = state;
170
+ const width = $$.getCurrentWidth();
171
+ const height = $$.getCurrentHeight();
172
+
173
+ if (
174
+ !width || !height || !current.width || !current.height ||
175
+ (width === current.width && height === current.height)
176
+ ) {
177
+ return;
178
+ }
179
+
180
+ if (state.isCanvasMode) {
181
+ const canvas = $$.canvasEngine?.canvas;
182
+
183
+ if (!canvas) {
184
+ return;
185
+ }
186
+
187
+ // Bottom legend is a DOM node keeping its own height, so only the
188
+ // remaining surface stretches.
189
+ $el.chart.style("min-height", `${height}px`);
190
+ canvas.style.width = `${width}px`;
191
+ canvas.style.height = `${
192
+ Math.max(0, height - ($$.getCanvasBottomLegendHeight?.() ?? 0))
193
+ }px`;
194
+ } else if ($el.svg) {
195
+ // viewBox of the drawn size + the new size as the layout box stretches the
196
+ // rendering exactly to the container. Pointer coordinates stay correct, as
197
+ // the viewBox branches(hasViewBox) map them back through the CTM.
198
+ $el.svg
199
+ .attr("viewBox", `0 0 ${current.width} ${current.height}`)
200
+ .attr("preserveAspectRatio", "none")
201
+ .attr("width", width)
202
+ .attr("height", height);
203
+ } else {
204
+ return;
205
+ }
206
+
207
+ state.resizePreview = true;
208
+ },
209
+
210
+ /**
211
+ * Drop the stretched state set by previewResize(), to render on exact pixels again.
212
+ * @private
213
+ */
214
+ clearResizePreview(): void {
215
+ const $$ = this;
216
+ const {config, state, $el} = $$;
217
+
218
+ if (!state.resizePreview) {
219
+ return;
220
+ }
221
+
222
+ state.resizePreview = false;
223
+
224
+ // canvas surfaces are restored by resizeCanvas()
225
+ if (!state.isCanvasMode && $el.svg && config.resize_auto !== "viewBox") {
226
+ $el.svg
227
+ .attr("viewBox", null)
228
+ .attr("preserveAspectRatio", null);
229
+ }
230
+ },
231
+
138
232
  updateDimension(withoutAxis?: boolean): void {
139
233
  const $$ = this;
140
234
  const {config, state: {hasAxis, isCanvasMode}, $el} = $$;
@@ -164,6 +258,9 @@ export default {
164
258
  return;
165
259
  }
166
260
 
261
+ // about to draw on exact pixels: drop any stretched state
262
+ $$.clearResizePreview();
263
+
167
264
  if (config.resize_auto === "viewBox") {
168
265
  svg
169
266
  .attr("viewBox", `0 0 ${current.width} ${current.height}`);
@@ -6,19 +6,6 @@
6
6
  * y2 Axis config options
7
7
  */
8
8
  export default {
9
- /**
10
- * Set clip-path attribute for y2 axis element
11
- * - **NOTE**: `clip-path` attribute for y2 Axis is set only when `axis.y2.inner` option is true.
12
- * @name axis․y2․clipPath
13
- * @memberof Options
14
- * @type {boolean}
15
- * @default true
16
- * @example
17
- * // don't set 'clip-path' attribute
18
- * clipPath: false
19
- */
20
- axis_y2_clipPath: true,
21
-
22
9
  /**
23
10
  * Show or hide y2 axis.
24
11
  * - **NOTE**:
@@ -168,12 +168,50 @@ export default {
168
168
  * - false: Disables automatic resize.
169
169
  * - "parent": Enables automatic resize when the parent node is resized.
170
170
  * - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
171
+ * - **NOTE:** `true` listens to the window's resize event, so a container resized by anything
172
+ * else(a splitter drag, a sibling element growing, a CSS resize handle) is not detected.
173
+ * Use `"parent"`, which observes the parent node itself, for those.
171
174
  * @property {boolean|number} [resize.timer=true] Set resize timer option.
172
175
  * - **NOTE:** Available options
173
176
  * - The resize function will be called using:
174
177
  * - true: `setTimeout()`
175
178
  * - false: `requestIdleCallback()`
176
179
  * - Given number(delay in ms) value, resize function will be triggered using `setTimeout()` with given delay.
180
+ * - **NOTE:** With `resize.live`, this no longer decides when the size is reflected(every
181
+ * animation frame does), but when the resize is treated as finished:
182
+ * - `onresize`/`onresized` are called then, as they are without it.
183
+ * - When the rendering is being stretched, this is also when it's redrawn to the exact
184
+ * size. The stretched rendering stays on screen for this long after the resize stops,
185
+ * so keep the delay short for charts large enough to be stretched.
186
+ * - When every frame is redrawn, the last frame already drew the final size, so the
187
+ * delayed call changes nothing on screen.
188
+ * @property {boolean} [resize.live=false] Follow the container size while resizing, instead of
189
+ * only when the delayed resize(`resize.timer`) runs.
190
+ * - **NOTE:** Applies only when `resize.auto` is `true` or `"parent"`.
191
+ * - **Strategy:** How the size is followed is measured, not configured. Two of them are used:
192
+ * - **Redraw**: while a resize redraw fits in one animation frame(16ms), the chart is
193
+ * redrawn on every frame, giving an exact rendering at every size.
194
+ * - **Stretch**: once a redraw misses that budget, the rendering is stretched to the new
195
+ * size for the rest of the resize, and redrawn when the resize settles. Stretching runs
196
+ * no redraw at all: for SVG the `viewBox` is set to the drawn size and the width/height
197
+ * attributes to the new one, and for canvas only the element's CSS box is resized, with
198
+ * the backing store left as is. The size keeps following the container at any data amount.
199
+ * - **Switching:** within a resize the strategy only goes from redraw to stretch, never back,
200
+ * so frames can't alternate between an exact and a stretched rendering. The measured time
201
+ * outlives the resize, so a chart already known to be expensive stretches from the first
202
+ * frame of the next one.
203
+ * - **While stretched:** text and stroke width are scaled with the box(SVG) and the drawn
204
+ * bitmap is upscaled(canvas). Interaction is unaffected, as pointer coordinates are mapped
205
+ * back through the element's transform. The redraw on settle restores the exact rendering.
206
+ * - **Cost:** resize redraws skip the shape data join and the axis tick measurement, so they
207
+ * are far cheaper than an initial render. A 5x1,000 line chart redraws in about 6ms(SVG)
208
+ * and 3ms(canvas), a 10x10,000 one in about 78ms and 53ms. Ordinary charts therefore redraw
209
+ * on every frame, and only the large ones fall back to stretching.
210
+ * - **Several charts on a page:** the budget is measured per chart, and charts don't know
211
+ * about each other. Eight charts of 2,000 points each spend about 75ms per frame together
212
+ * while each one measures about 9ms and keeps redrawing. Turn it on for the charts the user
213
+ * actually watches while resizing, rather than for every chart on a dense page.
214
+ * - `onrendered` is called on every redrawn frame while resizing, not once per resize.
177
215
  * @see [Demo: resize "parent"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeParent)
178
216
  * @see [Demo: resize "viewBox"](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeViewBox)
179
217
  * @example
@@ -193,11 +231,15 @@ export default {
193
231
  * timer: false,
194
232
  *
195
233
  * // set resize function will be triggered using `setTimeout()` with a delay of `100ms`.
196
- * timer: 100
234
+ * timer: 100,
235
+ *
236
+ * // follow the container size while resizing
237
+ * live: true
197
238
  * }
198
239
  */
199
240
  resize_auto: <boolean | "parent" | "viewBox">true,
200
241
  resize_timer: true,
242
+ resize_live: false,
201
243
 
202
244
  /**
203
245
  * Set a callback to execute when the chart is clicked.
@@ -162,6 +162,10 @@ export default class State {
162
162
  transiting: false,
163
163
  redrawing: false, // if redraw() is on process
164
164
  resizing: false, // resize event called
165
+ resizePreview: false, // rendered surface is stretched, pending an exact redraw
166
+ resizeRedrawTime: 0, // ms the last resize redraw took, decides resize.live strategy
167
+ // stretch instead of redrawing for the rest of this resize; null until decided
168
+ resizeLiveScale: <boolean | null>null,
165
169
  toggling: false, // legend toggle
166
170
  zooming: false,
167
171
  hasNegativeValue: false,
@@ -49,6 +49,10 @@ export const API_MODULE_NEEDED = {
49
49
  * Axis rendering constants shared by SVG and canvas renderers.
50
50
  * @private
51
51
  */
52
+ // A resize redraw costing more than one frame makes the whole drag stretch the
53
+ // rendering instead of redrawing it. 16ms is the budget of a 60fps frame.
54
+ export const RESIZE_FRAME_BUDGET = 16;
55
+
52
56
  export const AXIS_DEFAULT_TICK_COUNT = 10;
53
57
  export const AXIS_TICK_SIZE = 6;
54
58
  export const AXIS_TICK_PADDING = 3;
@@ -3208,6 +3208,9 @@ const canvasInternal = {
3208
3208
  const {config, state, $el} = $$;
3209
3209
  const container = $el.chart.node();
3210
3210
 
3211
+ // about to draw on exact pixels: drop any stretched state
3212
+ $$.clearResizePreview();
3213
+
3211
3214
  $el.chart.style("min-height", `${state.current.height}px`);
3212
3215
  $$.canvasEngine?.resize(state.current.width, $$.getCanvasSurfaceHeight());
3213
3216
  $$.canvasTheme?.reload(container, config.canvas_theme);
@@ -17,9 +17,9 @@ export const KEY = {
17
17
  dataMinMax: "$dataMinMax",
18
18
  dataTotalSum: "$dataTotalSum",
19
19
  dataTotalPerIndex: "$totalPerIndex",
20
+ visibleTotalPerIndex: "$visibleTotalPerIndex",
20
21
  domainMinMax: "$domainMinMax",
21
22
  filteredTargets: "$filteredTargets",
22
- filteredNullish: "$filteredNullish",
23
23
  svgLeft: "$svgLeft",
24
24
  valuesByX: "$valuesByX",
25
25
  legendItemTextBox: "legendItemTextBox",
@@ -3,7 +3,13 @@
3
3
  * billboard.js project is licensed under the MIT license
4
4
  */
5
5
  import type {d3Transition} from "../../types/types";
6
- import {cancelIdleCallback, requestIdleCallback, window} from "./browser";
6
+ import {
7
+ cancelAnimationFrame,
8
+ cancelIdleCallback,
9
+ requestAnimationFrame,
10
+ requestIdleCallback,
11
+ window
12
+ } from "./browser";
7
13
  import {isArray, isNumber, isTabVisible, runUntil} from "./util";
8
14
 
9
15
  const {setTimeout, clearTimeout} = window;
@@ -11,17 +17,29 @@ const {setTimeout, clearTimeout} = window;
11
17
  /**
12
18
  * Generate resize queue function
13
19
  * @param {boolean|number} option Resize option
20
+ * @param {()=>void} live Called on every resize event, throttled by animation frame.
21
+ * Used to reflect the size change before the delayed call takes place.
14
22
  * @returns {Fucntion}
15
23
  * @private
16
24
  */
17
- export function generateResize(option: boolean | number) {
25
+ export function generateResize(option: boolean | number, live?: Function) {
18
26
  const fn: Function[] = [];
19
27
  let timeout;
28
+ let rafId: number | null = null;
20
29
 
21
30
  const callResizeFn = function() {
22
31
  // Delay all resize functions call, to prevent unintended excessive call from resize event
23
32
  callResizeFn.clear();
24
33
 
34
+ // One pending frame at most: when the live call takes longer than a frame,
35
+ // events coalesce instead of piling up.
36
+ if (live && rafId === null) {
37
+ rafId = requestAnimationFrame(() => {
38
+ rafId = null;
39
+ live();
40
+ });
41
+ }
42
+
25
43
  if (option === false) {
26
44
  timeout = requestIdleCallback(() => {
27
45
  timeout = null;
@@ -42,6 +60,13 @@ export function generateResize(option: boolean | number) {
42
60
  }
43
61
  };
44
62
 
63
+ callResizeFn.clearLive = () => {
64
+ if (rafId !== null) {
65
+ cancelAnimationFrame(rafId);
66
+ rafId = null;
67
+ }
68
+ };
69
+
45
70
  callResizeFn.add = f => fn.push(f);
46
71
 
47
72
  callResizeFn.remove = f => {
@@ -209,6 +209,9 @@ export interface ChartOptions {
209
209
  * - false: Disables automatic resize.
210
210
  * - "parent": Enables automatic resize when the parent node is resized.
211
211
  * - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
212
+ * - **NOTE:** `true` listens to the window's resize event, so a container resized by anything else(a splitter drag,
213
+ * a sibling element growing, a CSS resize handle) is not detected. Use `"parent"`, which observes the parent node
214
+ * itself, for those.
212
215
  */
213
216
  auto?: boolean | "parent" | "viewBox";
214
217
 
@@ -217,8 +220,43 @@ export interface ChartOptions {
217
220
  * - **NOTE:**
218
221
  * - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
219
222
  * - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
223
+ * - **NOTE:** With `resize.live`, this no longer decides when the size is reflected(every animation frame does), but
224
+ * when the resize is treated as finished:
225
+ * - `onresize`/`onresized` are called then, as they are without it.
226
+ * - When the rendering is being stretched, this is also when it's redrawn to the exact size. The stretched
227
+ * rendering stays on screen for this long after the resize stops, so keep the delay short for charts large
228
+ * enough to be stretched.
229
+ * - When every frame is redrawn, the last frame already drew the final size, so the delayed call changes nothing
230
+ * on screen.
220
231
  */
221
232
  timer?: boolean | number;
233
+
234
+ /**
235
+ * Follow the container size while resizing, instead of only when the delayed resize(`resize.timer`) runs.
236
+ * - **NOTE:** Applies only when `resize.auto` is `true` or `"parent"`.
237
+ * - **Strategy:** How the size is followed is measured, not configured. Two of them are used:
238
+ * - **Redraw**: while a resize redraw fits in one animation frame(16ms), the chart is redrawn on every frame,
239
+ * giving an exact rendering at every size.
240
+ * - **Stretch**: once a redraw misses that budget, the rendering is stretched to the new size for the rest of
241
+ * the resize, and redrawn when the resize settles. Stretching runs no redraw at all: for SVG the `viewBox` is
242
+ * set to the drawn size and the width/height attributes to the new one, and for canvas only the element's CSS
243
+ * box is resized, with the backing store left as is.
244
+ * - **Switching:** within a resize the strategy only goes from redraw to stretch, never back, so frames can't
245
+ * alternate between an exact and a stretched rendering. The measured time outlives the resize, so a chart already
246
+ * known to be expensive stretches from the first frame of the next one.
247
+ * - **While stretched:** text and stroke width are scaled with the box(SVG) and the drawn bitmap is
248
+ * upscaled(canvas). Interaction is unaffected, as pointer coordinates are mapped back through the element's
249
+ * transform. The redraw on settle restores the exact rendering.
250
+ * - **Cost:** resize redraws skip the shape data join and the axis tick measurement, so they are far cheaper than an
251
+ * initial render. A 5x1,000 line chart redraws in about 6ms(SVG) and 3ms(canvas), a 10x10,000 one in about 78ms
252
+ * and 53ms. Ordinary charts therefore redraw on every frame, and only the large ones fall back to stretching.
253
+ * - **Several charts on a page:** the budget is measured per chart, and charts don't know about each other. Eight
254
+ * charts of 2,000 points each spend about 75ms per frame together while each one measures about 9ms and keeps
255
+ * redrawing. Turn it on for the charts the user actually watches while resizing, rather than for every chart on a
256
+ * dense page.
257
+ * - `onrendered` is called on every redrawn frame while resizing, not once per resize.
258
+ */
259
+ live?: boolean;
222
260
  };
223
261
 
224
262
  color?: {