@n1kname/charts 0.9.0 → 0.9.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/drawn.mjs +20 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/charts",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
package/src/drawn.mjs CHANGED
@@ -5,6 +5,11 @@
5
5
  // on a page that asks for it (data-chart-motion="update" on an ancestor). `after` runs after every
6
6
  // drawing, such as attaching the pointer, which a new SVG needs again.
7
7
  //
8
+ // While the page is still arriving (a view transition, as with page-change.css, is running), the
9
+ // first drawing waits for it to finish: drawing a chart takes the frames the nav pill needs to
10
+ // glide. Called again meanwhile, it keeps the newest figures for that drawing. Returns the first
11
+ // drawing's svg, or a promise of it while that waits; a later call returns nothing.
12
+ //
8
13
  // import { drawn } from '@n1kname/charts/drawn';
9
14
  // drawn(box, (width) => Plot.plot({ style, ...bars({ ...spec, pointer: false }, width) }), {
10
15
  // key: (m) => m.slice(5, 7),
@@ -20,6 +25,20 @@ export const drawn = (box, plot, { key, after } = {}) => {
20
25
  const state = known ?? { width: box.clientWidth };
21
26
  state.plot = plot;
22
27
  state.after = after;
28
+ if (state.waiting) {
29
+ state.key = key;
30
+ return state.waiting;
31
+ }
32
+ const arriving = !known && document.activeViewTransition;
33
+ if (arriving) {
34
+ boxes.set(box, state);
35
+ state.key = key;
36
+ state.waiting = arriving.finished.catch(() => {}).then(() => {
37
+ boxes.delete(box);
38
+ return drawn(box, state.plot, { key: state.key, after: state.after });
39
+ });
40
+ return state.waiting;
41
+ }
23
42
  const render = () => {
24
43
  const svg = state.plot(box.clientWidth);
25
44
  svg.setAttribute('aria-hidden', 'true');
@@ -47,4 +66,5 @@ export const drawn = (box, plot, { key, after } = {}) => {
47
66
  render();
48
67
  }
49
68
  }).observe(box);
69
+ return svg;
50
70
  };