@graphysdk/react 0.0.1 → 1.8.1-beta.1786025839240

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.
package/dist/index.mjs CHANGED
@@ -1,836 +1,22 @@
1
- import './index.css';
2
- import { jsx as s, jsxs as p, Fragment as C } from "react/jsx-runtime";
3
- import { useMotionValue as X, animate as ut, motion as _, useSpring as $, useReducedMotion as gt } from "motion/react";
4
- import { useState as Z, useEffect as w, useMemo as y, memo as k, useRef as O, useLayoutEffect as ht } from "react";
5
- import { DEFAULT_FONT_STYLE as pt, DEFAULT_FONT_WEIGHT as ft, CachedTextMeasurer as V, HeuristicTextMeasurer as yt, LayoutCompiler as mt, DEFAULT_COLOR_PALETTE as I, getStrokeWidth as J, createXValueReader as vt, getGroup as xt, getX as L, getYMin as q, GROUP_VARIABLES as Q, getY as T, getColor as R, getAlpha as F, getYMax as tt, getXMin as bt, getXMax as Lt, getSize as Tt, getStartAngle as Et, getEndAngle as At, getInnerRadius as _t, getOuterRadius as kt, compile as wt } from "@graphysdk/viz-engine";
6
- import St, { clsx as Ct } from "clsx";
7
- import { curveCatmullRom as It, curveLinear as Rt, area as Ft, line as et, arc as Dt } from "d3-shape";
8
- import { interpolatePath as Nt } from "d3-interpolate-path";
9
- import { assignInlineVars as Bt } from "@vanilla-extract/dynamic";
10
- typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.reactRenderer = "0.0.1");
11
- const Pt = /\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu, rt = "😀";
12
- class H {
13
- constructor() {
14
- this.emojiCorrections = /* @__PURE__ */ new Map(), this.currentFont = "";
15
- const r = new OffscreenCanvas(1, 1).getContext("2d");
16
- if (!r)
17
- throw new Error("Failed to create OffscreenCanvas 2D context");
18
- this.ctx = r;
19
- }
20
- /**
21
- * Creates a CanvasTextMeasurer after all declared `@font-face` fonts
22
- * have finished loading. This ensures measurements use the correct font
23
- * glyphs from the first call, avoiding stale cache entries.
24
- *
25
- * Falls back to immediate construction if `document.fonts` is unavailable
26
- * (e.g. non-browser environment).
27
- *
28
- * Note: document.fonts.ready still resolves even if some fonts fail to load.
29
- */
30
- static async create() {
31
- return typeof document < "u" && document.fonts && await document.fonts.ready, new H();
32
- }
33
- measureText(t, r) {
34
- const o = Gt(r);
35
- this.setFont(o);
36
- const { width: n, fontBoundingBoxAscent: a, fontBoundingBoxDescent: i } = this.ctx.measureText(t);
37
- let l = n;
38
- const c = Mt(t);
39
- if (c > 0) {
40
- const d = this.getEmojiCorrection(o);
41
- l -= d * c;
42
- }
43
- return {
44
- width: l,
45
- height: a + i,
46
- ascent: a,
47
- descent: i
48
- };
49
- }
50
- /**
51
- * Skip redundant `ctx.font` assignments
52
- * Setting the property triggers CSS font string parsing and font resolution.
53
- */
54
- setFont(t) {
55
- this.currentFont !== t && (this.ctx.font = t, this.currentFont = t);
56
- }
57
- /**
58
- * Computes the per-emoji width correction for a given font.
59
- * Measures the reference emoji in both Canvas and DOM, caches the difference.
60
- * Returns 0 if DOM is unavailable or the difference is negligible (< 0.5px).
61
- */
62
- getEmojiCorrection(t) {
63
- const r = this.emojiCorrections.get(t);
64
- if (r !== void 0) return r;
65
- this.setFont(t);
66
- const o = this.ctx.measureText(rt).width, n = Ot(t);
67
- let a = 0;
68
- if (n !== null) {
69
- const i = o - n;
70
- a = i > 0.5 ? i : 0;
71
- }
72
- return this.emojiCorrections.set(t, a), a;
73
- }
1
+ import { useMemo as e } from "react";
2
+ import { GraphProvider as n } from "@graphysdk/react-renderer";
3
+ import { updateSpec as i } from "@graphysdk/viz-engine";
4
+ import { jsx as o } from "react/jsx-runtime";
5
+ export * from "@graphysdk/react-renderer";
6
+ function a(r) {
7
+ const t = r.config.content;
8
+ return t?.isBrandMarkVisible !== void 0 || t?.brandMark?.enabled !== void 0 ? r : i(r, { config: { content: {
9
+ isBrandMarkVisible: !0,
10
+ brandMark: { enabled: !0 }
11
+ } } });
74
12
  }
75
- const Mt = (e) => {
76
- const t = e.match(Pt);
77
- return t ? t.length : 0;
78
- }, Ot = (e) => {
79
- const t = zt();
80
- return t ? (t.style.font = e, t.getBoundingClientRect().width) : null;
81
- };
82
- function Gt(e) {
83
- const t = e.style ?? pt, r = e.weight ?? ft;
84
- return `${t} ${r} ${e.size}px '${e.family}'`;
85
- }
86
- let b = null;
87
- const zt = () => typeof document > "u" ? null : (b || (b = document.createElement("span"), b.style.position = "absolute", b.style.visibility = "hidden", b.style.whiteSpace = "nowrap", b.style.left = "-9999px", b.textContent = rt, document.body.appendChild(b)), b), Wt = () => {
88
- const [e, t] = Z(null);
89
- return w(() => {
90
- let r = !1;
91
- const o = () => {
92
- r || t(Ht());
93
- };
94
- return (async () => {
95
- typeof document < "u" && document.fonts && await document.fonts.ready, o();
96
- })(), typeof document < "u" && document.fonts && document.fonts.addEventListener("loadingdone", o), () => {
97
- r = !0, typeof document < "u" && document.fonts && document.fonts.removeEventListener("loadingdone", o);
98
- };
99
- }, []), e;
100
- }, Ht = () => {
101
- try {
102
- return new V(new H());
103
- } catch {
104
- return new V(new yt());
105
- }
106
- }, Ut = 12, $t = "sans-serif", Vt = {
107
- family: $t,
108
- size: Ut
109
- }, jt = (e) => (t) => {
110
- if (!t.isVisible || t.ticks.length === 0) return 0;
111
- const r = t.position === "top" || t.position === "bottom", o = t.ticks.map((n) => e.measureText(String(n.value), Vt));
112
- return Math.max(...r ? o.map((n) => n.height) : o.map((n) => n.width));
113
- }, Yt = 20, Kt = () => () => Yt, Xt = 12, Zt = 8, Jt = 12, qt = "Inter", Qt = {
114
- family: qt,
115
- size: Jt
116
- }, te = Zt + Xt, ee = (e) => (t) => {
117
- if (t.items.length === 0) return 0;
118
- const r = t.position === "top" || t.position === "bottom", o = t.items.map((n) => e.measureText(String(n.value), Qt));
119
- return r ? Math.max(...o.map((n) => n.height)) : Math.max(...o.map((n) => n.width)) + te;
120
- }, re = ({ spec: e, containerSize: t, externalMeasurements: r }) => {
121
- const o = Wt(), n = y(() => o ? {
122
- measureAxis: jt(o),
123
- measureAxisLabel: Kt(),
124
- measureLegend: ee(o)
125
- } : null, [o]);
126
- return y(() => n ? new mt(n).compile({ guides: e.guides, containerSize: t, externalMeasurements: r }) : null, [e, t, r, n]);
127
- }, nt = !1, P = (e) => e.text !== void 0 ? e.text : e.content ? e.content.map(P).join("") : "";
128
- var ne = "_12eci1n0", G = "_1mf2q6u0";
129
- const oe = ({ ref: e, compiled: t, captionRect: r }) => {
130
- const { caption: o } = t.config.content;
131
- return o === null ? null : /* @__PURE__ */ s(
132
- "div",
133
- {
134
- ref: e,
135
- className: ne,
136
- style: {
137
- width: r.width
138
- },
139
- children: /* @__PURE__ */ s("p", { className: G, children: typeof o == "string" ? o : P(o) })
140
- }
141
- );
142
- };
143
- var ae = "_1q25vjj0";
144
- const ie = ({ ref: e, compiled: t, titleRect: r }) => {
145
- const { title: o, subtitle: n } = t.config.content;
146
- if (o === null && n === null) return null;
147
- const a = typeof o == "string" ? o : o !== null ? P(o) : "", i = typeof n == "string" ? n : n !== null ? P(n) : "";
148
- return /* @__PURE__ */ p(
149
- "div",
150
- {
151
- ref: e,
152
- className: ae,
153
- style: {
154
- width: r.width
155
- },
156
- children: [
157
- o !== null && /* @__PURE__ */ s("h1", { className: G, children: a }),
158
- n !== null && /* @__PURE__ */ s("p", { className: G, children: i })
159
- ]
160
- }
161
- );
162
- }, f = (e) => `${e * 100}%`;
163
- function S(e) {
164
- return 1 - e;
165
- }
166
- var se = "pr8m7u0", le = "pr8m7u1";
167
- const ce = 8, de = ({ legends: e }) => {
168
- const t = y(() => {
169
- const r = [];
170
- for (const o of e)
171
- for (const n of o.items) {
172
- if (n.normalizedY === null) continue;
173
- const a = typeof n.visual.color == "string" ? n.visual.color : void 0;
174
- r.push({
175
- key: `${String(n.value)}${a ? `-${a}` : ""}`,
176
- label: String(n.value),
177
- color: a,
178
- x: ce,
179
- y: f(S(n.normalizedY))
180
- });
181
- }
182
- return r;
183
- }, [e]);
184
- return t.length === 0 ? null : /* @__PURE__ */ s("div", { className: se, children: t.map((r) => /* @__PURE__ */ s("span", { className: le, style: { left: r.x, top: r.y, color: r.color }, children: r.label }, r.key)) });
185
- };
186
- var ue = "_2hq2f70", ge = "x9xdzb0", he = "x9xdzb1", pe = "x9xdzb2", fe = "x9xdzb3", ot = "x9xdzb4", ye = "x9xdzb5", me = "x9xdzb6";
187
- const ve = "#9ca3af", xe = ({ legends: e }) => e.length === 0 ? null : /* @__PURE__ */ s("div", { className: ge, children: e.map((t, r) => {
188
- const o = t.position === "left" || t.position === "right", n = t.aesthetics.includes("size");
189
- return /* @__PURE__ */ s(
190
- "div",
191
- {
192
- className: Ct(he, { [fe]: o, [pe]: !o }),
193
- children: n ? /* @__PURE__ */ s(Le, { legend: t }) : /* @__PURE__ */ s(be, { legend: t })
194
- },
195
- r
196
- );
197
- }) }), be = ({ legend: e }) => e.items.map((t) => /* @__PURE__ */ p("div", { className: ot, children: [
198
- /* @__PURE__ */ s("span", { className: ye, style: { backgroundColor: t.visual.color } }),
199
- /* @__PURE__ */ s("span", { children: String(t.value) })
200
- ] }, `${String(t.value)}${t.visual.color ? `-${t.visual.color}` : ""}`)), Le = ({ legend: e }) => {
201
- const t = e.items.map((r) => {
202
- const o = Number(r.visual.size);
203
- return {
204
- key: `${String(r.value)}-${o}`,
205
- label: String(r.value),
206
- color: typeof r.visual.color == "string" ? r.visual.color : void 0,
207
- sizeValue: o
208
- };
209
- }).filter((r) => Number.isFinite(r.sizeValue) && r.sizeValue > 0);
210
- return t.length === 0 ? null : t.map((r) => /* @__PURE__ */ p("div", { className: ot, children: [
211
- /* @__PURE__ */ s(
212
- "span",
213
- {
214
- className: me,
215
- style: {
216
- width: r.sizeValue,
217
- height: r.sizeValue,
218
- backgroundColor: r.color ?? ve
219
- }
220
- }
221
- ),
222
- /* @__PURE__ */ s("span", { children: r.label })
223
- ] }, r.key));
224
- }, Te = k(function({ legends: t, rects: r }) {
225
- const o = y(() => {
226
- const n = /* @__PURE__ */ new Map();
227
- for (const a of t) {
228
- const i = n.get(a.position);
229
- i ? i.push(a) : n.set(a.position, [a]);
230
- }
231
- return n;
232
- }, [t]);
233
- return /* @__PURE__ */ s(C, { children: Array.from(o, ([n, a]) => {
234
- const i = r[n];
235
- if (i == null) return null;
236
- const l = a.filter((d) => d.display === "pill"), c = a.filter((d) => d.display === "direct");
237
- return /* @__PURE__ */ p(
238
- "div",
239
- {
240
- className: ue,
241
- style: {
242
- left: i.x,
243
- top: i.y,
244
- width: i.width,
245
- height: i.height
246
- },
247
- children: [
248
- /* @__PURE__ */ s(xe, { legends: l }),
249
- /* @__PURE__ */ s(de, { legends: c })
250
- ]
251
- },
252
- n
253
- );
254
- }) });
255
- });
256
- var at = "wyi2w10";
257
- const Ee = ({ axisRects: e }) => /* @__PURE__ */ p(C, { children: [
258
- N("top", e.top),
259
- N("right", e.right),
260
- N("bottom", e.bottom),
261
- N("left", e.left)
262
- ] }), N = (e, t) => t ? /* @__PURE__ */ p("g", { transform: `translate(${t.x}, ${t.y})`, children: [
263
- nt,
264
- /* @__PURE__ */ p(
265
- "text",
266
- {
267
- className: at,
268
- x: t.width / 2,
269
- y: t.height / 2,
270
- textAnchor: "middle",
271
- dominantBaseline: "middle",
272
- children: [
273
- e,
274
- " axis"
275
- ]
276
- }
277
- )
278
- ] }, `axis-${e}`) : null, Ae = ({ axisLabelRects: e }) => /* @__PURE__ */ p(C, { children: [
279
- B("top", e.top),
280
- B("right", e.right),
281
- B("bottom", e.bottom),
282
- B("left", e.left)
283
- ] }), B = (e, t) => {
284
- if (!t) return null;
285
- const r = _e(e, t);
286
- return /* @__PURE__ */ p("g", { transform: `translate(${t.x}, ${t.y})`, children: [
287
- nt,
288
- /* @__PURE__ */ p("text", { className: at, ...r, children: [
289
- e,
290
- " axis label"
291
- ] })
292
- ] }, `axis-label-${e}`);
293
- }, _e = (e, t) => {
294
- const r = {
295
- x: t.width / 2,
296
- y: t.height / 2,
297
- textAnchor: "middle",
298
- dominantBaseline: "middle"
299
- };
300
- return e === "left" ? (r.x = 0, r.textAnchor = "start") : e === "right" && (r.x = t.width, r.textAnchor = "end"), r;
301
- }, ke = I[0], we = 0.3, Se = 1, E = {
302
- type: "spring",
303
- stiffness: 500,
304
- damping: 60,
305
- mass: 1
306
- }, Ce = I[0], Ie = 1, Re = 2, it = (e) => e === "catmull-rom" ? It : Rt, st = (e) => {
307
- switch (e) {
308
- case "dashed":
309
- return "8 4";
310
- case "dotted":
311
- return "2 2";
312
- case "solid":
313
- return;
314
- }
315
- }, lt = (e, t) => t.lineWidth !== "auto" ? t.lineWidth : J(e) ?? Re, D = (e, t, r) => {
316
- const o = vt(e, t);
317
- return (n) => {
318
- const a = xt(n) ?? "default", i = o(n);
319
- return `${r}-${a}${i !== null && i !== "" ? `-${i}` : ""}`;
320
- };
321
- }, z = (e, t) => {
322
- const r = X(e);
323
- return w(() => {
324
- const o = Nt(r.get(), e);
325
- ut(0, 1, {
326
- ...t,
327
- onUpdate: (n) => {
328
- const a = o(n);
329
- return r.set(a);
330
- }
331
- });
332
- }, [t, e, r]), r;
333
- };
334
- var M = "_1wf5x370";
335
- const Fe = k(function({ layer: t, isAnimated: r }) {
336
- const o = t.params, n = st(o.lineType), [a, i] = y(() => {
337
- const c = it(o.interpolate), d = (u) => S(tt(u) ?? T(u) ?? 0), g = Ft().x((u) => L(u) ?? 0).y0((u) => S(q(u) ?? 0)).y1(d).curve(c), h = et().x((u) => L(u) ?? 0).y(d).curve(c);
338
- if (o.missingValues === "gap") {
339
- const u = (v) => L(v) !== null && T(v) !== null;
340
- g.defined(u), h.defined(u);
341
- }
342
- return [h, g];
343
- }, [o.interpolate, o.missingValues]), l = y(() => {
344
- const c = D(t.data, t.mapping, t.index), d = [];
345
- return t.data.groupBy(Q.group).forEach((g) => {
346
- let h = [...g];
347
- o.missingValues === "connect" && (h = h.filter(
348
- (U) => L(U) !== null && T(U) !== null
349
- ));
350
- const u = i(h), v = a(h);
351
- if (!u || !v) return;
352
- const m = h[0];
353
- if (!m) return;
354
- const x = R(m) ?? ke, A = F(m), dt = lt(m, o);
355
- d.push({
356
- key: c(m),
357
- areaPath: u,
358
- linePath: v,
359
- color: x,
360
- fillOpacity: A ?? we,
361
- strokeWidth: dt,
362
- strokeOpacity: Se,
363
- strokeDasharray: n
364
- });
365
- }), d;
366
- }, [i, a, t.data, t.index, t.mapping, o, n]);
367
- return /* @__PURE__ */ s(
368
- "svg",
369
- {
370
- viewBox: "0 0 1 1",
371
- preserveAspectRatio: "none",
372
- width: "100%",
373
- height: "100%",
374
- "data-geom": "area",
375
- className: M,
376
- children: l.map((c) => /* @__PURE__ */ s(
377
- De,
378
- {
379
- areaPath: c.areaPath,
380
- linePath: c.linePath,
381
- color: c.color,
382
- fillOpacity: c.fillOpacity,
383
- strokeWidth: c.strokeWidth,
384
- strokeOpacity: c.strokeOpacity,
385
- strokeDasharray: c.strokeDasharray,
386
- isAnimated: r
387
- },
388
- c.key
389
- ))
390
- }
391
- );
392
- }), De = ({
393
- areaPath: e,
394
- linePath: t,
395
- color: r,
396
- fillOpacity: o,
397
- strokeWidth: n,
398
- strokeOpacity: a,
399
- strokeDasharray: i,
400
- isAnimated: l
401
- }) => l ? /* @__PURE__ */ s(
402
- Ne,
403
- {
404
- areaPath: e,
405
- linePath: t,
406
- color: r,
407
- fillOpacity: o,
408
- strokeWidth: n,
409
- strokeOpacity: a,
410
- strokeDasharray: i
411
- }
412
- ) : /* @__PURE__ */ p("g", { children: [
413
- /* @__PURE__ */ s("path", { d: e, fill: r, fillOpacity: o, stroke: "none" }),
414
- /* @__PURE__ */ s(
415
- "path",
416
- {
417
- d: t,
418
- fill: "none",
419
- stroke: r,
420
- strokeWidth: n,
421
- strokeOpacity: a,
422
- strokeDasharray: i,
423
- vectorEffect: "non-scaling-stroke"
424
- }
425
- )
426
- ] }), Ne = ({
427
- areaPath: e,
428
- linePath: t,
429
- color: r,
430
- fillOpacity: o,
431
- strokeWidth: n,
432
- strokeOpacity: a,
433
- strokeDasharray: i
434
- }) => {
435
- const l = z(e, E), c = z(t, E);
436
- return /* @__PURE__ */ p("g", { children: [
437
- /* @__PURE__ */ s(_.path, { d: l, fill: r, fillOpacity: o, stroke: "none" }),
438
- /* @__PURE__ */ s(
439
- _.path,
440
- {
441
- d: c,
442
- fill: "none",
443
- stroke: r,
444
- strokeWidth: n,
445
- strokeOpacity: a,
446
- strokeDasharray: i,
447
- vectorEffect: "non-scaling-stroke"
448
- }
449
- )
450
- ] });
451
- }, Be = I[0], Pe = 1, j = 4, Me = k(function({ layer: t, isAnimated: r }) {
452
- const o = y(() => {
453
- const n = D(t.data, t.mapping, t.index), a = [];
454
- for (const i of t.data) {
455
- const l = n(i), c = bt(i), d = Lt(i), g = q(i), h = tt(i) ?? T(i);
456
- if (c === null || d === null || g === null || h === null)
457
- continue;
458
- const u = R(i), v = F(i);
459
- let m = 1 - h, x = h - g;
460
- x < 0 && (m += x, x = -x), a.push({
461
- key: l,
462
- x: c,
463
- y: m,
464
- width: d - c,
465
- height: x,
466
- fill: u ?? Be,
467
- opacity: v ?? Pe
468
- });
469
- }
470
- return a;
471
- }, [t.data, t.index, t.mapping]);
472
- return /* @__PURE__ */ s(C, { children: o.map((n) => {
473
- const { key: a, ...i } = n;
474
- return /* @__PURE__ */ s(Oe, { ...i, isAnimated: r }, a);
475
- }) });
476
- }), Oe = ({ isAnimated: e, ...t }) => e ? /* @__PURE__ */ s(
477
- _.rect,
478
- {
479
- initial: !1,
480
- style: { transformBox: "view-box" },
481
- transition: E,
482
- fill: t.fill,
483
- opacity: t.opacity,
484
- rx: j,
485
- animate: {
486
- x: f(t.x),
487
- y: f(t.y),
488
- width: f(t.width),
489
- height: f(t.height),
490
- opacity: t.opacity
491
- }
492
- }
493
- ) : /* @__PURE__ */ s(
494
- "rect",
495
- {
496
- style: { transformBox: "view-box" },
497
- x: f(t.x),
498
- y: f(t.y),
499
- width: f(t.width),
500
- height: f(t.height),
501
- fill: t.fill,
502
- opacity: t.opacity,
503
- rx: j
504
- }
505
- ), Ge = k(function({ layer: t, isAnimated: r }) {
506
- const o = t.params, n = st(o.lineType), a = y(() => {
507
- const l = et().x((c) => L(c) ?? 0).y((c) => S(T(c) ?? 0)).curve(it(o.interpolate));
508
- return o.missingValues === "gap" && l.defined((c) => L(c) !== null && T(c) !== null), l;
509
- }, [o.interpolate, o.missingValues]), i = y(() => {
510
- const l = D(t.data, t.mapping, t.index), c = [];
511
- return t.data.groupBy(Q.group).forEach((d) => {
512
- let g = [...d];
513
- o.missingValues === "connect" && (g = g.filter(
514
- (A) => L(A) !== null && T(A) !== null
515
- ));
516
- const h = a(g);
517
- if (!h) return;
518
- const u = g[0];
519
- if (!u) return;
520
- const v = R(u) ?? Ce, m = F(u), x = lt(u, o);
521
- c.push({
522
- key: l(u),
523
- pathData: h,
524
- color: v,
525
- opacity: m ?? Ie,
526
- strokeWidth: x,
527
- strokeDasharray: n
528
- });
529
- }), c;
530
- }, [a, t.data, t.index, t.mapping, o, n]);
531
- return /* @__PURE__ */ s(
532
- "svg",
533
- {
534
- viewBox: "0 0 1 1",
535
- preserveAspectRatio: "none",
536
- width: "100%",
537
- height: "100%",
538
- "data-geom": "line",
539
- className: M,
540
- children: i.map((l) => /* @__PURE__ */ s(
541
- ze,
542
- {
543
- pathData: l.pathData,
544
- color: l.color,
545
- strokeWidth: l.strokeWidth,
546
- opacity: l.opacity,
547
- strokeDasharray: l.strokeDasharray,
548
- isAnimated: r
549
- },
550
- l.key
551
- ))
552
- }
553
- );
554
- }), ze = ({ pathData: e, color: t, strokeWidth: r, opacity: o, strokeDasharray: n, isAnimated: a }) => a ? /* @__PURE__ */ s(
555
- We,
556
- {
557
- pathData: e,
558
- color: t,
559
- strokeWidth: r,
560
- opacity: o,
561
- strokeDasharray: n
562
- }
563
- ) : /* @__PURE__ */ s(
564
- "path",
565
- {
566
- d: e,
567
- fill: "none",
568
- stroke: t,
569
- strokeWidth: r,
570
- opacity: o,
571
- strokeDasharray: n,
572
- vectorEffect: "non-scaling-stroke"
573
- }
574
- ), We = ({
575
- pathData: e,
576
- color: t,
577
- strokeWidth: r,
578
- opacity: o,
579
- strokeDasharray: n
580
- }) => {
581
- const a = z(e, E);
582
- return /* @__PURE__ */ s(
583
- _.path,
584
- {
585
- d: a,
586
- fill: "none",
587
- stroke: t,
588
- strokeWidth: r,
589
- opacity: o,
590
- strokeDasharray: n,
591
- vectorEffect: "non-scaling-stroke"
592
- }
593
- );
594
- }, He = I[0], Ue = 1, $e = 8, Ve = "#000000", je = 1, Ye = k(function({ layer: t, isAnimated: r }) {
595
- const o = y(() => {
596
- const n = D(t.data, t.mapping, t.index), a = [];
597
- for (const i of t.data) {
598
- const l = L(i), c = T(i);
599
- if (l === null || c === null)
600
- continue;
601
- const d = R(i), g = F(i), h = Tt(i), u = J(i);
602
- a.push({
603
- key: n(i),
604
- cx: l,
605
- cy: S(c),
606
- radius: (h ?? $e) / 2,
607
- fill: d ?? He,
608
- stroke: Ve,
609
- opacity: g ?? Ue,
610
- strokeWidth: u ?? je
611
- });
612
- }
613
- return a;
614
- }, [t.data, t.index, t.mapping]);
615
- return /* @__PURE__ */ s(C, { children: o.map((n) => r ? /* @__PURE__ */ s(
616
- _.circle,
617
- {
618
- initial: !1,
619
- transition: E,
620
- fill: n.fill,
621
- stroke: n.stroke,
622
- strokeWidth: n.strokeWidth,
623
- animate: {
624
- cx: f(n.cx),
625
- cy: f(n.cy),
626
- r: n.radius,
627
- opacity: n.opacity
628
- }
629
- },
630
- n.key
631
- ) : /* @__PURE__ */ s(
632
- "circle",
633
- {
634
- cx: f(n.cx),
635
- cy: f(n.cy),
636
- r: n.radius,
637
- fill: n.fill,
638
- opacity: n.opacity,
639
- stroke: n.stroke,
640
- strokeWidth: n.strokeWidth
641
- },
642
- n.key
643
- )) });
644
- }), Ke = I[0], Xe = 1, W = Dt(), Y = Math.PI * 2, Ze = k(function({
645
- layer: t,
646
- isAnimated: r
647
- }) {
648
- const o = O(!1);
649
- w(() => {
650
- o.current = !0;
651
- }, []);
652
- const n = y(() => {
653
- const a = D(t.data, t.mapping, t.index), i = [];
654
- for (const l of t.data) {
655
- const c = a(l), d = Et(l), g = At(l), h = _t(l), u = kt(l);
656
- d === null || g === null || h === null || u === null || i.push({
657
- key: c,
658
- startAngle: d,
659
- endAngle: g,
660
- innerRadius: h,
661
- outerRadius: u,
662
- fill: R(l) ?? Ke,
663
- opacity: F(l) ?? Xe
664
- });
665
- }
666
- return i;
667
- }, [t.data, t.index, t.mapping]);
668
- return /* @__PURE__ */ s(
669
- "svg",
670
- {
671
- viewBox: "-1 -1 2 2",
672
- preserveAspectRatio: "xMidYMid meet",
673
- width: "100%",
674
- height: "100%",
675
- "data-geom": "bar",
676
- className: M,
677
- children: n.map((a) => {
678
- if (r) {
679
- const { key: i, ...l } = a;
680
- return /* @__PURE__ */ s(Je, { isInitialRender: !o.current, ...l }, i);
681
- }
682
- return /* @__PURE__ */ s(
683
- "path",
684
- {
685
- d: W({
686
- startAngle: a.startAngle,
687
- endAngle: a.endAngle,
688
- innerRadius: a.innerRadius,
689
- outerRadius: a.outerRadius
690
- }) ?? void 0,
691
- fill: a.fill,
692
- opacity: a.opacity
693
- },
694
- a.key
695
- );
696
- })
697
- }
698
- );
699
- }), Je = ({
700
- startAngle: e,
701
- endAngle: t,
702
- innerRadius: r,
703
- outerRadius: o,
704
- fill: n,
705
- opacity: a,
706
- isInitialRender: i
707
- }) => {
708
- const l = i ? e : Y, c = i ? t : Y, d = $(l, E), g = $(c, E), h = X(
709
- W({ startAngle: l, endAngle: c, innerRadius: r, outerRadius: o }) ?? ""
710
- );
711
- return w(() => {
712
- d.set(e), g.set(t);
713
- }, [d, g, e, t]), w(() => {
714
- const u = () => {
715
- const x = d.get(), A = g.get();
716
- h.set(
717
- W({ startAngle: x, endAngle: A, innerRadius: r, outerRadius: o }) ?? ""
718
- );
719
- }, v = d.on("change", u), m = g.on("change", u);
720
- return () => {
721
- v(), m();
722
- };
723
- }, [d, g, r, o, h]), /* @__PURE__ */ s(_.path, { d: h, fill: n, opacity: a, transition: E });
724
- }, qe = ({ compiled: e, shouldAnimate: t, panelRect: r }) => /* @__PURE__ */ s("svg", { x: r.x, y: r.y, width: r.width, height: r.height, className: M, children: e.layers.map((o, n) => {
725
- const a = `layer-${n}`;
726
- switch (o.geom) {
727
- case "bar":
728
- return e.coordSystem.type === "polar" ? /* @__PURE__ */ s(Ze, { layer: o, isAnimated: t }, a) : /* @__PURE__ */ s(Me, { layer: o, isAnimated: t }, a);
729
- case "line":
730
- return /* @__PURE__ */ s(Ge, { layer: o, isAnimated: t }, a);
731
- case "area":
732
- return /* @__PURE__ */ s(Fe, { layer: o, isAnimated: t }, a);
733
- case "point":
734
- return /* @__PURE__ */ s(Ye, { layer: o, isAnimated: t }, a);
735
- default:
736
- return /* @__PURE__ */ p("text", { children: [
737
- o.geom,
738
- " not implemented"
739
- ] }, a);
740
- }
741
- }) });
742
- var Qe = "_1ymbsoj0";
743
- const ct = (e, t) => ({
744
- x: e.x - t.x,
745
- y: e.y - t.y,
746
- width: e.width,
747
- height: e.height
748
- }), K = (e, t) => {
749
- const r = {};
750
- for (const [o, n] of Object.entries(e))
751
- r[o] = ct(n, t);
752
- return r;
753
- }, tr = ({
754
- compiled: e,
755
- plotRect: t,
756
- panelRect: r,
757
- axisRects: o,
758
- axisLabelRects: n,
759
- shouldAnimate: a
760
- }) => {
761
- const i = ct(r, t), l = K(o, t), c = K(n, t);
762
- return /* @__PURE__ */ p(
763
- "svg",
764
- {
765
- className: Qe,
766
- width: t.width,
767
- height: t.height,
768
- style: { transform: `translate(${t.x}px, ${t.y}px)` },
769
- children: [
770
- /* @__PURE__ */ s(Ee, { axisRects: l }),
771
- /* @__PURE__ */ s(qe, { compiled: e, shouldAnimate: a, panelRect: i }),
772
- /* @__PURE__ */ s(Ae, { axisLabelRects: c })
773
- ]
774
- }
775
- );
776
- }, er = {
777
- titleSize: { width: 0, height: 0 },
778
- captionSize: { width: 0, height: 0 }
779
- }, rr = () => {
780
- const e = O(null), t = O(null), [r, o] = Z(er);
781
- return ht(() => {
782
- const n = () => {
783
- const i = e.current?.offsetHeight ?? 0, l = t.current?.offsetHeight ?? 0, c = e.current?.offsetWidth ?? 0, d = t.current?.offsetWidth ?? 0;
784
- o((g) => g.titleSize.height === i && g.captionSize.height === l && g.titleSize.width === c && g.captionSize.width === d ? g : {
785
- titleSize: { width: c, height: i },
786
- captionSize: { width: d, height: l }
787
- });
788
- };
789
- n();
790
- const a = new ResizeObserver(n);
791
- return e.current && a.observe(e.current), t.current && a.observe(t.current), () => a.disconnect();
792
- }, []), { titleRef: e, captionRef: t, measurements: r };
793
- };
794
- var nr = "znp3wr0";
795
- const pr = ({ spec: e, width: t, height: r, isAnimated: o }) => {
796
- const n = gt(), a = y(() => wt(e), [e]), { titleRef: i, captionRef: l, measurements: c } = rr(), d = re({
797
- spec: a,
798
- containerSize: { width: t, height: r },
799
- externalMeasurements: c
13
+ var c = (r) => {
14
+ const t = e(() => a(r.input), [r.input]);
15
+ return /* @__PURE__ */ o(n, {
16
+ ...r,
17
+ input: t
800
18
  });
801
- return d ? /* @__PURE__ */ p("div", { className: nr, style: { width: t, height: r }, children: [
802
- /* @__PURE__ */ s(ie, { ref: i, compiled: a, titleRect: d.title }),
803
- /* @__PURE__ */ s(
804
- tr,
805
- {
806
- compiled: a,
807
- plotRect: d.plot,
808
- panelRect: d.panel,
809
- axisRects: d.axes,
810
- axisLabelRects: d.axisLabels,
811
- shouldAnimate: o ?? !n
812
- }
813
- ),
814
- /* @__PURE__ */ s(oe, { ref: l, compiled: a, captionRect: d.caption }),
815
- /* @__PURE__ */ s(Te, { legends: a.guides.legends, rects: d.legends })
816
- ] }) : null;
817
- };
818
- var or = { white: "var(--graphy-white)", black: "var(--graphy-black)", transparent: "var(--graphy-transparent)", grey100: "var(--graphy-grey-100)", grey95: "var(--graphy-grey-95)", grey90: "var(--graphy-grey-90)", grey85: "var(--graphy-grey-85)", grey80: "var(--graphy-grey-80)", grey75: "var(--graphy-grey-75)", grey70: "var(--graphy-grey-70)", grey60: "var(--graphy-grey-60)", grey50: "var(--graphy-grey-50)", grey0: "var(--graphy-grey-0)", greyGradient80: "var(--graphy-grey-gradient-80)", green60: "var(--graphy-green-60)", green50: "var(--graphy-green-50)", red60: "var(--graphy-red-60)", red50: "var(--graphy-red-50)", amber70: "var(--graphy-amber-70)", amber50: "var(--graphy-amber-50)", amber40: "var(--graphy-amber-40)", amber30: "var(--graphy-amber-30)", blue80: "var(--graphy-blue-80)", blue60: "var(--graphy-blue-60)", purple50: "var(--graphy-purple-50)", purple30: "var(--graphy-purple-30)", brand: "var(--graphy-brand)", success: "var(--graphy-success)", warning: "var(--graphy-warning)", alert: "var(--graphy-alert)", textPrimary: "var(--graphy-text-primary)", textSecondary: "var(--graphy-text-secondary)", textDisabled: "var(--graphy-text-disabled)", iconPrimary: "var(--graphy-icon-primary)", iconSecondary: "var(--graphy-icon-secondary)", iconStickerBackground: "var(--graphy-icon-sticker-background)", border100: "var(--graphy-border-100)", border10: "var(--graphy-border-10)", sunkenBackground: "var(--graphy-sunken-background)", defaultBackground: "var(--graphy-default-background)", raisedBackground: "var(--graphy-raised-background)", overlayBackground: "var(--graphy-overlay-background)", overlayBorderGradient: "var(--graphy-overlay-border-gradient)", graphBackground: "var(--graphy-graph-background)", gridLineColor: "var(--graphy-grid-line-color)", hoverGuideLineColor: "var(--graphy-hover-guide-line-color)", originLineColor: "var(--graphy-origin-line-color)", targetLineColor: "var(--graphy-target-line-color)", targetLineMarkerColor: "var(--graphy-target-line-marker-color)", legendBackground: "var(--graphy-legend-background)", legendBorderColor: "var(--graphy-legend-border-color)", legendTextColor: "var(--graphy-legend-text-color)", dimmedSeriesLabelTextColor: "var(--graphy-dimmed-series-label-text-color)", dimmedSeriesLabelLineColor: "var(--graphy-dimmed-series-label-line-color)", trendNegativeColor: "var(--graphy-trend-negative-color)", trendPositiveColor: "var(--graphy-trend-positive-color)", tooltipBackground: "var(--graphy-tooltip-background)", tooltipBorderColor: "var(--graphy-tooltip-border-color)", tooltipHeadingTextColor: "var(--graphy-tooltip-heading-text-color)", tooltipLabelTextColor: "var(--graphy-tooltip-label-text-color)", tooltipValueTextColor: "var(--graphy-tooltip-value-text-color)", heatmapEmptyTileBackground: "var(--graphy-heatmap-empty-tile-background)", stackedBarHoverBorderColor: "var(--graphy-stacked-bar-hover-border-color)", defaultArrowAnnotationColor: "var(--graphy-default-arrow-annotation-color)", annotationFrameBorderColor: "var(--graphy-annotation-frame-border-color)", annotationMenuTriggerIconColor: "var(--graphy-annotation-menu-trigger-icon-color)", fontFamilyDefault: "var(--graphy-font-family-default)", fontFamilyHeading: "var(--graphy-font-family-heading)", fontWeightRegular: "var(--graphy-font-weight-regular)", fontWeightMedium: "var(--graphy-font-weight-medium)", fontWeightSemibold: "var(--graphy-font-weight-semibold)", fontWeightBold: "var(--graphy-font-weight-bold)", fontXxs: "var(--graphy-font-xxs)", fontXs: "var(--graphy-font-xs)", fontSm: "var(--graphy-font-sm)", fontMd: "var(--graphy-font-md)", fontLg: "var(--graphy-font-lg)", fontXl: "var(--graphy-font-xl)", fontEditorBody: "var(--graphy-font-editor-body)", fontHeadingSm: "var(--graphy-font-heading-sm)", fontHeadingMd: "var(--graphy-font-heading-md)", fontHeadingLg: "var(--graphy-font-heading-lg)", fontTickLabel: "var(--graphy-font-tick-label)", fontAxisLabel: "var(--graphy-font-axis-label)", fontDataLabel: "var(--graphy-font-data-label)", fontStackTotal: "var(--graphy-font-stack-total)", fontLegendLabel: "var(--graphy-font-legend-label)", fontSeriesLabel: "var(--graphy-font-series-label)", fontTooltipLabel: "var(--graphy-font-tooltip-label)", fontTooltipHeading: "var(--graphy-font-tooltip-heading)", fontTooltipFooter: "var(--graphy-font-tooltip-footer)", fontJumboTooltipLabel: "var(--graphy-font-jumbo-tooltip-label)", fontJumboTooltip: "var(--graphy-font-jumbo-tooltip)", fontMiniTooltipLabel: "var(--graphy-font-mini-tooltip-label)", fontMiniTooltipFooter: "var(--graphy-font-mini-tooltip-footer)", fontTooltipCaption: "var(--graphy-font-tooltip-caption)", fontTooltipCaptionSmall: "var(--graphy-font-tooltip-caption-small)", fontTrendTag: "var(--graphy-font-trend-tag)", fontTrendTagSmall: "var(--graphy-font-trend-tag-small)", fontGoalLineLabel: "var(--graphy-font-goal-line-label)", fontPieLabel: "var(--graphy-font-pie-label)", fontPieChartTotal: "var(--graphy-font-pie-chart-total)", fontDifferenceArrowSmall: "var(--graphy-font-difference-arrow-small)", fontDifferenceArrowMedium: "var(--graphy-font-difference-arrow-medium)", fontDifferenceArrowLarge: "var(--graphy-font-difference-arrow-large)", fontButton: "var(--graphy-font-button)", fontInput: "var(--graphy-font-input)", fontInputLabel: "var(--graphy-font-input-label)", fontSelectLabel: "var(--graphy-font-select-label)", fontSelectDescription: "var(--graphy-font-select-description)", fontColorSelectLabel: "var(--graphy-font-color-select-label)", fontMenuTitle: "var(--graphy-font-menu-title)", fontMenuGroupTitle: "var(--graphy-font-menu-group-title)", fontMenuItemLabel: "var(--graphy-font-menu-item-label)", fontMenuItemLabelSecondary: "var(--graphy-font-menu-item-label-secondary)", fontUITooltip: "var(--graphy-font-uitooltip)", fontUITooltipSecondary: "var(--graphy-font-uitooltip-secondary)", fontErrorBoundaryTitle: "var(--graphy-font-error-boundary-title)", fontErrorBoundaryMessage: "var(--graphy-font-error-boundary-message)", fontTableCell: "var(--graphy-font-table-cell)", fontTableHeaderCell: "var(--graphy-font-table-header-cell)", fontSourceLabel: "var(--graphy-font-source-label)", fontSourceLink: "var(--graphy-font-source-link)", fontTextEditorH1: "var(--graphy-font-text-editor-h1)", fontTextEditorH2: "var(--graphy-font-text-editor-h2)", fontTextEditorH3: "var(--graphy-font-text-editor-h3)", fontTextEditorH6: "var(--graphy-font-text-editor-h6)", fontTextEditorBody: "var(--graphy-font-text-editor-body)", fontTextEditorLink: "var(--graphy-font-text-editor-link)", fontHighlightModeTitle: "var(--graphy-font-highlight-mode-title)", fontHighlightModeSubtitle: "var(--graphy-font-highlight-mode-subtitle)" }, ar = "_1rkj4kp0", fr = "_1rkj4kp1";
819
- const yr = ({ theme: e, children: t, className: r, style: o }) => {
820
- const n = y(() => {
821
- if (!e) return o;
822
- const a = {};
823
- for (const [i, l] of Object.entries(e))
824
- l !== void 0 && (a[or[i]] = l);
825
- return { ...o, ...Bt(a) };
826
- }, [e, o]);
827
- return /* @__PURE__ */ s("div", { className: St(ar, r), style: n, children: t });
828
19
  };
829
20
  export {
830
- H as CanvasTextMeasurer,
831
- pr as GraphRenderer,
832
- yr as ThemeProvider,
833
- fr as darkTheme,
834
- Wt as useTextMeasurer,
835
- or as vars
21
+ c as GraphProvider
836
22
  };