@zsherman/charts 0.0.0-stage → 0.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 (180) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +373 -0
  3. package/README.md +13 -2
  4. package/THIRD_PARTY_NOTICES.md +33 -0
  5. package/dist/dom/bar-list/bar-list.js +386 -0
  6. package/dist/dom/bar-list/bar-list.styles.js +171 -0
  7. package/dist/dom/bar-list/index.js +1 -0
  8. package/dist/dom/chart/chart.js +716 -0
  9. package/dist/dom/chart/chart.styles.js +165 -0
  10. package/dist/dom/chart/index.js +1 -0
  11. package/dist/dom/chart-grid/chart-grid.js +67 -0
  12. package/dist/dom/chart-grid/index.js +1 -0
  13. package/dist/dom/donut/donut.js +565 -0
  14. package/dist/dom/donut/donut.styles.js +111 -0
  15. package/dist/dom/donut/index.js +1 -0
  16. package/dist/dom/heat-graph/calendar.js +118 -0
  17. package/dist/dom/heat-graph/heat-graph.js +423 -0
  18. package/dist/dom/heat-graph/heat-graph.styles.js +168 -0
  19. package/dist/dom/heat-graph/index.js +1 -0
  20. package/dist/dom/heat-matrix/heat-matrix.js +346 -0
  21. package/dist/dom/heat-matrix/heat-matrix.styles.js +155 -0
  22. package/dist/dom/heat-matrix/index.js +1 -0
  23. package/dist/dom/heat-matrix/model.js +41 -0
  24. package/dist/dom/index.js +13 -0
  25. package/dist/dom/internal/colors.js +44 -0
  26. package/dist/dom/internal/floating-tip.js +83 -0
  27. package/dist/dom/internal/format.js +43 -0
  28. package/dist/dom/internal/grid-context.js +5 -0
  29. package/dist/dom/internal/hidden.styles.js +16 -0
  30. package/dist/dom/internal/legend.js +112 -0
  31. package/dist/dom/internal/legend.styles.js +108 -0
  32. package/dist/dom/internal/markers.js +101 -0
  33. package/dist/dom/internal/options.js +300 -0
  34. package/dist/dom/internal/place.js +27 -0
  35. package/dist/dom/internal/scheme-watch.js +73 -0
  36. package/dist/dom/internal/share.js +28 -0
  37. package/dist/dom/internal/types.js +0 -0
  38. package/dist/dom/row-chart/index.js +1 -0
  39. package/dist/dom/row-chart/model.js +59 -0
  40. package/dist/dom/row-chart/row-chart.js +691 -0
  41. package/dist/dom/row-chart/row-chart.styles.js +242 -0
  42. package/dist/dom/segmented-bar/index.js +1 -0
  43. package/dist/dom/segmented-bar/segmented-bar.js +280 -0
  44. package/dist/dom/segmented-bar/segmented-bar.styles.js +88 -0
  45. package/dist/dom/sparkline/index.js +1 -0
  46. package/dist/dom/sparkline/sparkline.js +145 -0
  47. package/dist/dom/stacked-histogram/histogram.js +137 -0
  48. package/dist/dom/stacked-histogram/index.js +1 -0
  49. package/dist/dom/stacked-histogram/stacked-histogram.js +761 -0
  50. package/dist/dom/stacked-histogram/stacked-histogram.styles.js +211 -0
  51. package/dist/dom/state-timeline/index.js +1 -0
  52. package/dist/dom/state-timeline/model.js +166 -0
  53. package/dist/dom/state-timeline/state-timeline.js +729 -0
  54. package/dist/dom/state-timeline/state-timeline.styles.js +171 -0
  55. package/dist/dom/status-history/index.js +1 -0
  56. package/dist/dom/status-history/status-history.js +542 -0
  57. package/dist/dom/status-history/status-history.styles.js +171 -0
  58. package/dist/solid/bar-list/bar-list.jsx +139 -0
  59. package/dist/solid/bar-list/bar-list.styles.jsx +171 -0
  60. package/dist/solid/bar-list/index.jsx +1 -0
  61. package/dist/solid/chart/chart.jsx +454 -0
  62. package/dist/solid/chart/chart.styles.jsx +165 -0
  63. package/dist/solid/chart/index.jsx +1 -0
  64. package/dist/solid/chart-grid/chart-grid.jsx +46 -0
  65. package/dist/solid/chart-grid/index.jsx +1 -0
  66. package/dist/solid/donut/donut.jsx +291 -0
  67. package/dist/solid/donut/donut.styles.jsx +111 -0
  68. package/dist/solid/donut/index.jsx +1 -0
  69. package/dist/solid/heat-graph/calendar.jsx +118 -0
  70. package/dist/solid/heat-graph/heat-graph.jsx +228 -0
  71. package/dist/solid/heat-graph/heat-graph.styles.jsx +168 -0
  72. package/dist/solid/heat-graph/index.jsx +1 -0
  73. package/dist/solid/heat-matrix/heat-matrix.jsx +165 -0
  74. package/dist/solid/heat-matrix/heat-matrix.styles.jsx +155 -0
  75. package/dist/solid/heat-matrix/index.jsx +1 -0
  76. package/dist/solid/heat-matrix/model.jsx +41 -0
  77. package/dist/solid/index.jsx +13 -0
  78. package/dist/solid/internal/colors.jsx +44 -0
  79. package/dist/solid/internal/floating-tip.jsx +68 -0
  80. package/dist/solid/internal/format.jsx +43 -0
  81. package/dist/solid/internal/grid-context.jsx +5 -0
  82. package/dist/solid/internal/hidden.styles.jsx +16 -0
  83. package/dist/solid/internal/legend.jsx +35 -0
  84. package/dist/solid/internal/legend.styles.jsx +108 -0
  85. package/dist/solid/internal/markers.jsx +101 -0
  86. package/dist/solid/internal/options.jsx +300 -0
  87. package/dist/solid/internal/place.jsx +27 -0
  88. package/dist/solid/internal/scheme-watch.jsx +73 -0
  89. package/dist/solid/internal/share.jsx +28 -0
  90. package/dist/solid/internal/types.jsx +0 -0
  91. package/dist/solid/row-chart/index.jsx +1 -0
  92. package/dist/solid/row-chart/model.jsx +59 -0
  93. package/dist/solid/row-chart/row-chart.jsx +312 -0
  94. package/dist/solid/row-chart/row-chart.styles.jsx +242 -0
  95. package/dist/solid/segmented-bar/index.jsx +1 -0
  96. package/dist/solid/segmented-bar/segmented-bar.jsx +125 -0
  97. package/dist/solid/segmented-bar/segmented-bar.styles.jsx +88 -0
  98. package/dist/solid/sparkline/index.jsx +1 -0
  99. package/dist/solid/sparkline/sparkline.jsx +88 -0
  100. package/dist/solid/stacked-histogram/histogram.jsx +137 -0
  101. package/dist/solid/stacked-histogram/index.jsx +1 -0
  102. package/dist/solid/stacked-histogram/stacked-histogram.jsx +381 -0
  103. package/dist/solid/stacked-histogram/stacked-histogram.styles.jsx +211 -0
  104. package/dist/solid/state-timeline/index.jsx +1 -0
  105. package/dist/solid/state-timeline/model.jsx +166 -0
  106. package/dist/solid/state-timeline/state-timeline.jsx +387 -0
  107. package/dist/solid/state-timeline/state-timeline.styles.jsx +171 -0
  108. package/dist/solid/status-history/index.jsx +1 -0
  109. package/dist/solid/status-history/status-history.jsx +279 -0
  110. package/dist/solid/status-history/status-history.styles.jsx +171 -0
  111. package/dist/styles.css +1 -0
  112. package/dist/types/bar-list/bar-list.d.ts +91 -0
  113. package/dist/types/bar-list/bar-list.styles.d.ts +148 -0
  114. package/dist/types/bar-list/index.d.ts +3 -0
  115. package/dist/types/chart/chart.d.ts +98 -0
  116. package/dist/types/chart/chart.styles.d.ts +145 -0
  117. package/dist/types/chart/index.d.ts +3 -0
  118. package/dist/types/chart-grid/chart-grid.d.ts +35 -0
  119. package/dist/types/chart-grid/index.d.ts +2 -0
  120. package/dist/types/donut/donut.d.ts +124 -0
  121. package/dist/types/donut/donut.styles.d.ts +96 -0
  122. package/dist/types/donut/index.d.ts +3 -0
  123. package/dist/types/heat-graph/calendar.d.ts +61 -0
  124. package/dist/types/heat-graph/heat-graph.d.ts +82 -0
  125. package/dist/types/heat-graph/heat-graph.styles.d.ts +141 -0
  126. package/dist/types/heat-graph/index.d.ts +4 -0
  127. package/dist/types/heat-matrix/heat-matrix.d.ts +65 -0
  128. package/dist/types/heat-matrix/heat-matrix.styles.d.ts +135 -0
  129. package/dist/types/heat-matrix/index.d.ts +3 -0
  130. package/dist/types/heat-matrix/model.d.ts +15 -0
  131. package/dist/types/index.d.ts +12 -0
  132. package/dist/types/internal/colors.d.ts +22 -0
  133. package/dist/types/internal/floating-tip.d.ts +15 -0
  134. package/dist/types/internal/format.d.ts +7 -0
  135. package/dist/types/internal/grid-context.d.ts +9 -0
  136. package/dist/types/internal/hidden.styles.d.ts +15 -0
  137. package/dist/types/internal/legend.d.ts +18 -0
  138. package/dist/types/internal/legend.styles.d.ts +96 -0
  139. package/dist/types/internal/markers.d.ts +16 -0
  140. package/dist/types/internal/options.d.ts +59 -0
  141. package/dist/types/internal/place.d.ts +20 -0
  142. package/dist/types/internal/scheme-watch.d.ts +12 -0
  143. package/dist/types/internal/share.d.ts +19 -0
  144. package/dist/types/internal/types.d.ts +163 -0
  145. package/dist/types/row-chart/index.d.ts +4 -0
  146. package/dist/types/row-chart/model.d.ts +50 -0
  147. package/dist/types/row-chart/row-chart.d.ts +148 -0
  148. package/dist/types/row-chart/row-chart.styles.d.ts +216 -0
  149. package/dist/types/segmented-bar/index.d.ts +3 -0
  150. package/dist/types/segmented-bar/segmented-bar.d.ts +65 -0
  151. package/dist/types/segmented-bar/segmented-bar.styles.d.ts +75 -0
  152. package/dist/types/sparkline/index.d.ts +3 -0
  153. package/dist/types/sparkline/sparkline.d.ts +38 -0
  154. package/dist/types/stacked-histogram/histogram.d.ts +48 -0
  155. package/dist/types/stacked-histogram/index.d.ts +4 -0
  156. package/dist/types/stacked-histogram/stacked-histogram.d.ts +73 -0
  157. package/dist/types/stacked-histogram/stacked-histogram.styles.d.ts +187 -0
  158. package/dist/types/state-timeline/index.d.ts +3 -0
  159. package/dist/types/state-timeline/model.d.ts +63 -0
  160. package/dist/types/state-timeline/state-timeline.d.ts +108 -0
  161. package/dist/types/state-timeline/state-timeline.styles.d.ts +151 -0
  162. package/dist/types/status-history/index.d.ts +3 -0
  163. package/dist/types/status-history/status-history.d.ts +72 -0
  164. package/dist/types/status-history/status-history.styles.d.ts +150 -0
  165. package/docs/api.json +1346 -0
  166. package/docs/bar-list.md +190 -0
  167. package/docs/chart-grid.md +77 -0
  168. package/docs/chart.md +355 -0
  169. package/docs/donut.md +182 -0
  170. package/docs/heat-graph.md +121 -0
  171. package/docs/heat-matrix.md +108 -0
  172. package/docs/llms.txt +68 -0
  173. package/docs/row-chart.md +193 -0
  174. package/docs/search-index.json +291 -0
  175. package/docs/segmented-bar.md +128 -0
  176. package/docs/sparkline.md +82 -0
  177. package/docs/stacked-histogram.md +123 -0
  178. package/docs/state-timeline.md +141 -0
  179. package/docs/status-history.md +121 -0
  180. package/package.json +104 -4
@@ -0,0 +1,27 @@
1
+ // src/internal/place.ts
2
+ /** Space between the anchor and the tooltip. */
3
+ const TIP_GAP = 12;
4
+ /** The tooltip keeps this far from the viewport's edges. */
5
+ const TIP_MARGIN = 8;
6
+ /**
7
+ * Where a tooltip's top-left corner goes, in viewport pixels: beside its anchor (after it, or before it
8
+ * when `before`), centred on it vertically. A side that would leave the viewport flips to the other; when
9
+ * neither fits it's clamped inside. Vertically it's clamped inside the viewport, so a tooltip at the top
10
+ * or the bottom of the screen slides along its anchor instead of being cut off.
11
+ */
12
+ function placeTip(anchor, tip, viewport, before) {
13
+ const after = anchor.x + 12;
14
+ const ahead = anchor.x - 12 - tip.width;
15
+ const fitsAfter = after + tip.width <= viewport.width - 8;
16
+ const fitsBefore = ahead >= 8;
17
+ let x = before ? fitsBefore || !fitsAfter ? ahead : after : fitsAfter || !fitsBefore ? after : ahead;
18
+ x = clamp(x, 8, viewport.width - 8 - tip.width);
19
+ const y = clamp(anchor.y - tip.height / 2, 8, viewport.height - 8 - tip.height);
20
+ return {
21
+ x: Math.round(x),
22
+ y: Math.round(y)
23
+ };
24
+ }
25
+ /** `value` inside `[min, max]`; `min` wins when the range is empty (a box wider than the viewport). */
26
+ const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
27
+ export { TIP_GAP, TIP_MARGIN, placeTip };
@@ -0,0 +1,73 @@
1
+ // src/internal/scheme-watch.ts
2
+ /** Tokens whose resolved values tell one scheme or theme from another. */
3
+ const SIGNALS = ["var(--sui-chart-1)", "var(--sui-text-muted)"];
4
+ const watchers = /* @__PURE__ */ new Set();
5
+ let pending = [];
6
+ let observer;
7
+ let media;
8
+ /** Each watcher's colors, resolved in one write pass and one read pass per token. */
9
+ function read(list) {
10
+ const out = list.map(() => "");
11
+ for (const css of SIGNALS) {
12
+ for (const w of list) {
13
+ w.probe.style.color = "";
14
+ w.probe.style.color = css;
15
+ }
16
+ list.forEach((w, i) => out[i] += `${getComputedStyle(w.probe).color} `);
17
+ }
18
+ return out;
19
+ }
20
+ function recheck(list) {
21
+ const live = list.filter((w) => watchers.has(w) && w.probe.isConnected);
22
+ const now = read(live);
23
+ live.forEach((w, i) => {
24
+ const seen = w.last;
25
+ w.last = now[i];
26
+ if (seen !== void 0 && seen !== now[i]) w.changed();
27
+ });
28
+ }
29
+ function bind() {
30
+ observer = new MutationObserver((records) => {
31
+ const targets = new Set(records.map((r) => r.target));
32
+ const hit = [...watchers].filter((w) => [...targets].some((t) => t.contains(w.probe)));
33
+ if (hit.length) recheck(hit);
34
+ });
35
+ observer.observe(document.documentElement, {
36
+ subtree: true,
37
+ attributes: true,
38
+ attributeFilter: ["data-color-scheme", "data-sui-theme"]
39
+ });
40
+ media = matchMedia("(prefers-color-scheme: dark)");
41
+ media.addEventListener("change", onMedia);
42
+ }
43
+ const onMedia = () => recheck([...watchers]);
44
+ function unbind() {
45
+ observer?.disconnect();
46
+ media?.removeEventListener("change", onMedia);
47
+ observer = media = void 0;
48
+ }
49
+ /**
50
+ * Calls `changed` when the colors `probe` resolves to change: its scheme or theme switched (an attribute on
51
+ * it or an ancestor, or the system preference). The first reading waits for a microtask, so charts mounting
52
+ * together are read together. Returns the cleanup.
53
+ */
54
+ function watchScheme(probe, changed) {
55
+ const w = {
56
+ probe,
57
+ last: void 0,
58
+ changed
59
+ };
60
+ if (!watchers.size) bind();
61
+ watchers.add(w);
62
+ pending.push(w);
63
+ if (pending.length === 1) queueMicrotask(() => {
64
+ const list = pending;
65
+ pending = [];
66
+ recheck(list);
67
+ });
68
+ return () => {
69
+ watchers.delete(w);
70
+ if (!watchers.size) unbind();
71
+ };
72
+ }
73
+ export { watchScheme };
@@ -0,0 +1,28 @@
1
+ // src/internal/share.ts
2
+ /**
3
+ * Part-to-whole helpers shared by Donut, Bar list and Segmented bar: what counts toward a total, a share
4
+ * written as a percent in the kit's locale, and the image's name written from the data. Plain functions, so
5
+ * each chart bundles only what it calls.
6
+ */
7
+ /** A value that counts toward a whole: a finite number above 0, else 0 (a missing or negative reading). */
8
+ const amount = (value) => value != null && Number.isFinite(value) && value > 0 ? value : 0;
9
+ /** A value's share of the total, 0 to 1 (0 when the total is 0). */
10
+ const shareOf = (value, total) => total > 0 ? amount(value) / total : 0;
11
+ /**
12
+ * A share (0 to 1) as a percent in the locale: one decimal under 10% ("4.2%"), whole above ("42%"), and
13
+ * "<0.1%" for a sliver that would otherwise read as nothing.
14
+ */
15
+ function shareFormat(locale) {
16
+ const whole = new Intl.NumberFormat(locale, {
17
+ style: "percent",
18
+ maximumFractionDigits: 0
19
+ });
20
+ const fine = new Intl.NumberFormat(locale, {
21
+ style: "percent",
22
+ maximumFractionDigits: 1
23
+ });
24
+ return (share) => share > 0 && share < .001 ? `<${fine.format(.001)}` : (share < .1 ? fine : whole).format(share);
25
+ }
26
+ /** The image's name, written from the data: "Revenue by region: EMEA 42%, Americas 35%, APAC 23%". */
27
+ const describe = (title, parts) => parts.length ? `${title}: ${parts.map((p) => `${p.label} ${p.share}`).join(", ")}` : title;
28
+ export { amount, describe, shareFormat, shareOf };
File without changes
@@ -0,0 +1 @@
1
+ export { RowChart } from "./row-chart.js";
@@ -0,0 +1,59 @@
1
+ import { amount, shareOf } from "../internal/share.js";
2
+ // src/row-chart/model.ts
3
+ /**
4
+ * RowChart's derivation: every row's bars as fractions of one shared scale, the text after each bar, the
5
+ * change from the first series, and each row's name in words. Plain functions of their input, no Solid.
6
+ */
7
+ function buildModel(input) {
8
+ const stacked = input.layout === "stacked";
9
+ const n = input.seriesCount;
10
+ const amounts = input.rows.map((r) => Array.from({ length: n }, (_v, i) => amount(r.values[i])));
11
+ let max = 0;
12
+ for (const a of amounts) max = Math.max(max, stacked ? sum(a) : Math.max(0, ...a));
13
+ if (input.max != null && Number.isFinite(input.max) && input.max > 0) max = input.max;
14
+ const scale = (v) => max > 0 ? Math.min(1, v / max) : 0;
15
+ return {
16
+ rows: input.rows.map((r, ri) => {
17
+ const values = amounts[ri];
18
+ const total = sum(values);
19
+ const first = r.values[0];
20
+ const bars = values.map((value, s) => {
21
+ const raw = r.values[s] ?? null;
22
+ const last = s === n - 1 && n > 1;
23
+ return {
24
+ series: s,
25
+ raw,
26
+ value,
27
+ fraction: scale(value),
28
+ text: raw == null ? "–" : input.format(value),
29
+ share: shareOf(value, total),
30
+ delta: !stacked && input.delta && last && raw != null && first != null && first > 0 ? (value - first) / first : void 0
31
+ };
32
+ });
33
+ const previous = input.rows[ri - 1];
34
+ return {
35
+ bars,
36
+ total,
37
+ fraction: scale(total),
38
+ groupStart: ri > 0 && (r.group ?? "") !== (previous?.group ?? "")
39
+ };
40
+ }),
41
+ max
42
+ };
43
+ }
44
+ const sum = (xs) => xs.reduce((a, b) => a + b, 0);
45
+ /** A change as a signed percent: "+54.9%", "−3.2%", "0%". */
46
+ function deltaFormat(locale) {
47
+ const fmt = new Intl.NumberFormat(locale, {
48
+ style: "percent",
49
+ maximumFractionDigits: 1,
50
+ signDisplay: "exceptZero"
51
+ });
52
+ return (d) => fmt.format(d);
53
+ }
54
+ /**
55
+ * A bar's length beside the text after it: the bar takes its fraction of the row's width less the room
56
+ * kept for the longest text, so the text always fits after the longest bar.
57
+ */
58
+ const barWidth = (fraction) => fraction > 0 ? `max(2px, calc((100% - var(--rc-text)) * ${fraction.toFixed(4)}))` : "0px";
59
+ export { barWidth, buildModel, deltaFormat };