@pharos-ds/charts 0.0.0-bootstrap.0 → 1.0.10

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 (139) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/LICENSE +24 -0
  3. package/README.md +118 -0
  4. package/dist/Chart.d.ts +62 -0
  5. package/dist/Chart.d.ts.map +1 -0
  6. package/dist/Chart.js +401 -0
  7. package/dist/ChartAxis.d.ts +37 -0
  8. package/dist/ChartAxis.d.ts.map +1 -0
  9. package/dist/ChartAxis.js +233 -0
  10. package/dist/ChartContext.d.ts +4 -0
  11. package/dist/ChartContext.d.ts.map +1 -0
  12. package/dist/ChartContext.js +15 -0
  13. package/dist/ChartGrid.d.ts +26 -0
  14. package/dist/ChartGrid.d.ts.map +1 -0
  15. package/dist/ChartGrid.js +118 -0
  16. package/dist/ChartLegend.d.ts +14 -0
  17. package/dist/ChartLegend.d.ts.map +1 -0
  18. package/dist/ChartLegend.js +62 -0
  19. package/dist/ChartSwatch.d.ts +36 -0
  20. package/dist/ChartSwatch.d.ts.map +1 -0
  21. package/dist/ChartSwatch.js +85 -0
  22. package/dist/ChartTooltip.d.ts +46 -0
  23. package/dist/ChartTooltip.d.ts.map +1 -0
  24. package/dist/ChartTooltip.js +330 -0
  25. package/dist/charts.css +33 -0
  26. package/dist/dataTable.d.ts +56 -0
  27. package/dist/dataTable.d.ts.map +1 -0
  28. package/dist/dataTable.js +88 -0
  29. package/dist/formatters.d.ts +37 -0
  30. package/dist/formatters.d.ts.map +1 -0
  31. package/dist/formatters.js +156 -0
  32. package/dist/getChartColors.d.ts +67 -0
  33. package/dist/getChartColors.d.ts.map +1 -0
  34. package/dist/getChartColors.js +191 -0
  35. package/dist/index.d.ts +17 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +19 -0
  38. package/dist/layout.d.ts +40 -0
  39. package/dist/layout.d.ts.map +1 -0
  40. package/dist/layout.js +322 -0
  41. package/dist/legend.d.ts +17 -0
  42. package/dist/legend.d.ts.map +1 -0
  43. package/dist/legend.js +40 -0
  44. package/dist/markColor.d.ts +20 -0
  45. package/dist/markColor.d.ts.map +1 -0
  46. package/dist/markColor.js +56 -0
  47. package/dist/marks/area.d.ts +19 -0
  48. package/dist/marks/area.d.ts.map +1 -0
  49. package/dist/marks/area.js +121 -0
  50. package/dist/marks/band.d.ts +9 -0
  51. package/dist/marks/band.d.ts.map +1 -0
  52. package/dist/marks/band.js +64 -0
  53. package/dist/marks/bar.d.ts +21 -0
  54. package/dist/marks/bar.d.ts.map +1 -0
  55. package/dist/marks/bar.js +161 -0
  56. package/dist/marks/candlestick.d.ts +16 -0
  57. package/dist/marks/candlestick.d.ts.map +1 -0
  58. package/dist/marks/candlestick.js +110 -0
  59. package/dist/marks/dot.d.ts +19 -0
  60. package/dist/marks/dot.d.ts.map +1 -0
  61. package/dist/marks/dot.js +98 -0
  62. package/dist/marks/dotGL.d.ts +16 -0
  63. package/dist/marks/dotGL.d.ts.map +1 -0
  64. package/dist/marks/dotGL.js +231 -0
  65. package/dist/marks/dotGLInteractive.d.ts +35 -0
  66. package/dist/marks/dotGLInteractive.d.ts.map +1 -0
  67. package/dist/marks/dotGLInteractive.js +584 -0
  68. package/dist/marks/errorBar.d.ts +29 -0
  69. package/dist/marks/errorBar.d.ts.map +1 -0
  70. package/dist/marks/errorBar.js +95 -0
  71. package/dist/marks/heatmapGL.d.ts +27 -0
  72. package/dist/marks/heatmapGL.d.ts.map +1 -0
  73. package/dist/marks/heatmapGL.js +335 -0
  74. package/dist/marks/index.d.ts +13 -0
  75. package/dist/marks/index.d.ts.map +1 -0
  76. package/dist/marks/index.js +14 -0
  77. package/dist/marks/line.d.ts +18 -0
  78. package/dist/marks/line.d.ts.map +1 -0
  79. package/dist/marks/line.js +83 -0
  80. package/dist/marks/referenceLine.d.ts +37 -0
  81. package/dist/marks/referenceLine.d.ts.map +1 -0
  82. package/dist/marks/referenceLine.js +204 -0
  83. package/dist/marks/streamGL.d.ts +41 -0
  84. package/dist/marks/streamGL.d.ts.map +1 -0
  85. package/dist/marks/streamGL.js +317 -0
  86. package/dist/tooltip.d.ts +38 -0
  87. package/dist/tooltip.d.ts.map +1 -0
  88. package/dist/tooltip.js +57 -0
  89. package/dist/types.d.ts +193 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +70 -0
  92. package/dist/useChartColors.d.ts +16 -0
  93. package/dist/useChartColors.d.ts.map +1 -0
  94. package/dist/useChartColors.js +37 -0
  95. package/dist/utils.d.ts +15 -0
  96. package/dist/utils.d.ts.map +1 -0
  97. package/dist/utils.js +31 -0
  98. package/dist/webgl.d.ts +77 -0
  99. package/dist/webgl.d.ts.map +1 -0
  100. package/dist/webgl.js +235 -0
  101. package/package.json +72 -4
  102. package/src/Chart.doc.mjs +174 -0
  103. package/src/Chart.test.tsx +273 -0
  104. package/src/Chart.tsx +535 -0
  105. package/src/ChartAxis.tsx +289 -0
  106. package/src/ChartContext.ts +18 -0
  107. package/src/ChartGrid.tsx +136 -0
  108. package/src/ChartLegend.tsx +77 -0
  109. package/src/ChartSwatch.doc.mjs +17 -0
  110. package/src/ChartSwatch.tsx +89 -0
  111. package/src/ChartTooltip.tsx +452 -0
  112. package/src/charts.css.d.ts +3 -0
  113. package/src/dataTable.test.ts +86 -0
  114. package/src/dataTable.ts +124 -0
  115. package/src/formatters.ts +167 -0
  116. package/src/getChartColors.test.ts +114 -0
  117. package/src/getChartColors.ts +282 -0
  118. package/src/index.ts +88 -0
  119. package/src/layout.ts +372 -0
  120. package/src/legend.ts +44 -0
  121. package/src/markColor.ts +70 -0
  122. package/src/marks/area.tsx +142 -0
  123. package/src/marks/band.tsx +86 -0
  124. package/src/marks/bar.tsx +210 -0
  125. package/src/marks/candlestick.tsx +128 -0
  126. package/src/marks/dot.tsx +119 -0
  127. package/src/marks/dotGL.tsx +274 -0
  128. package/src/marks/dotGLInteractive.tsx +660 -0
  129. package/src/marks/errorBar.tsx +119 -0
  130. package/src/marks/heatmapGL.tsx +392 -0
  131. package/src/marks/index.ts +17 -0
  132. package/src/marks/line.tsx +118 -0
  133. package/src/marks/referenceLine.tsx +252 -0
  134. package/src/marks/streamGL.tsx +381 -0
  135. package/src/tooltip.ts +73 -0
  136. package/src/types.ts +212 -0
  137. package/src/useChartColors.ts +41 -0
  138. package/src/utils.ts +38 -0
  139. package/src/webgl.ts +262 -0
@@ -0,0 +1,27 @@
1
+ import type { SeriesDef } from '../types';
2
+ export interface HeatmapGLOptions {
3
+ xKey: string;
4
+ yKey: string;
5
+ valueKey: string;
6
+ colorRange: string[];
7
+ domain?: [number, number];
8
+ cellGap?: number;
9
+ }
10
+ /**
11
+ * WebGL heatmap. Renders a 2D grid of colored cells using triangles.
12
+ *
13
+ * The rows are categorical: declaring `layout.yBandKey` makes the chart build a
14
+ * shared y band scale over `yKey`, so a left `<ChartAxis>` renders the row
15
+ * labels aligned to each cell (instead of a meaningless linear value axis).
16
+ * Columns use the chart's x band scale.
17
+ *
18
+ * @example
19
+ * ```
20
+ * series={[heatmapGL({
21
+ * xKey: 'hour', yKey: 'day', valueKey: 'count',
22
+ * colorRange: ['#f0f9ff', '#1e40af'],
23
+ * })]}
24
+ * ```
25
+ */
26
+ export declare function heatmapGL(options: HeatmapGLOptions): SeriesDef;
27
+ //# sourceMappingURL=heatmapGL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heatmapGL.d.ts","sourceRoot":"","sources":["../../src/marks/heatmapGL.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAC,SAAS,EAAgB,MAAM,UAAU,CAAC;AAavD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAgSD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAuD9D"}
@@ -0,0 +1,335 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file marks/heatmapGL.tsx
5
+ * @output WebGL heatmap — 2D grid of colored cells on canvas
6
+ *
7
+ * Cell geometry is memoized; GL context, program, and the position/color
8
+ * buffers are created once and reused across redraws, then released (context
9
+ * eagerly lost) on unmount. Handles context loss/restore and empty/NaN data.
10
+ */
11
+
12
+ import { useRef, useEffect, useMemo, useState } from 'react';
13
+ import { hexToGL, getWebGLContext, setupGLState, sizeCanvas, mountCanvasOverSVG, createProgram, registerContextLossHandlers, loseContext } from "../webgl.js";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ const VERT = `
16
+ attribute vec2 a_position;
17
+ attribute vec3 a_color;
18
+ uniform vec2 u_resolution;
19
+ varying vec3 v_color;
20
+ void main() {
21
+ vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
22
+ gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
23
+ v_color = a_color;
24
+ }
25
+ `;
26
+ const FRAG = `
27
+ precision mediump float;
28
+ varying vec3 v_color;
29
+ void main() {
30
+ gl_FragColor = vec4(v_color, 1.0);
31
+ }
32
+ `;
33
+ function sampleRamp(ramp, t) {
34
+ if (ramp.length === 0) {
35
+ return [0, 0, 0];
36
+ }
37
+ const c = Math.max(0, Math.min(1, Number.isFinite(t) ? t : 0));
38
+ if (ramp.length === 1) {
39
+ return ramp[0];
40
+ }
41
+ const s = c * (ramp.length - 1);
42
+ const lo = Math.floor(s);
43
+ const hi = Math.min(lo + 1, ramp.length - 1);
44
+ const f = s - lo;
45
+ return [ramp[lo][0] + f * (ramp[hi][0] - ramp[lo][0]), ramp[lo][1] + f * (ramp[hi][1] - ramp[lo][1]), ramp[lo][2] + f * (ramp[hi][2] - ramp[lo][2])];
46
+ }
47
+ /**
48
+ * Inline component — manages the heatmap WebGL canvas. Rows use the chart's
49
+ * shared y band scale so cells stay aligned with the left axis' category labels.
50
+ */
51
+ function HeatmapGLCanvas({
52
+ data,
53
+ xKey,
54
+ yKey,
55
+ valueKey,
56
+ xScale,
57
+ yBandScale,
58
+ colorRange,
59
+ domain: domainProp,
60
+ cellGap,
61
+ width,
62
+ height
63
+ }) {
64
+ const canvasRef = useRef(null);
65
+ const glRef = useRef(null);
66
+ const programRef = useRef(null);
67
+ const posBufferRef = useRef(null);
68
+ const colBufferRef = useRef(null);
69
+ const locsRef = useRef(null);
70
+ const markerRef = useRef(null);
71
+ // Bumped on context restore to force the draw effect to rebuild + repaint.
72
+ const [contextEpoch, setContextEpoch] = useState(0);
73
+ const ramp = useMemo(() => colorRange.map(hexToGL), [colorRange]);
74
+ const domain = useMemo(() => {
75
+ if (domainProp) {
76
+ return domainProp;
77
+ }
78
+ let min = Infinity,
79
+ max = -Infinity;
80
+ for (const d of data) {
81
+ const v = d[valueKey];
82
+ if (typeof v === 'number' && Number.isFinite(v)) {
83
+ if (v < min) {
84
+ min = v;
85
+ }
86
+ if (v > max) {
87
+ max = v;
88
+ }
89
+ }
90
+ }
91
+ // No finite values → neutral [0, 1] so t/ramp math never yields NaN.
92
+ if (!Number.isFinite(min) || !Number.isFinite(max)) {
93
+ return [0, 1];
94
+ }
95
+ return [min, max];
96
+ }, [data, valueKey, domainProp]);
97
+
98
+ // Build interleaved triangle geometry (2 triangles/cell) + per-vertex colors.
99
+ // Memoized so redraws (resize, context restore) don't re-walk the dataset.
100
+ const geometry = useMemo(() => {
101
+ const positions = [];
102
+ const colors = [];
103
+ const [dMin, dMax] = domain;
104
+ const range = dMax - dMin || 1;
105
+ const gap = cellGap;
106
+ const xBW = xScale.bandwidth();
107
+ const yBW = yBandScale.bandwidth();
108
+ // Heatmap cells fill their full slot (step), not just the band width. The
109
+ // shared x-scale carries bar-style padding (~0.2), so sizing cells to the
110
+ // bandwidth leaves gaps between columns while the local y-scale stays tight —
111
+ // an asymmetric, sparse grid. Sizing to the step and centering on the band
112
+ // keeps cells contiguous (a real heatmap); cellGap alone controls spacing.
113
+ const xStep = typeof xScale.step === 'function' ? xScale.step() : xBW;
114
+ const yStep = yBandScale.step();
115
+ for (const d of data) {
116
+ const xVal = xScale(String(d[xKey]));
117
+ const yVal = yBandScale(String(d[yKey]));
118
+ if (xVal == null || yVal == null) {
119
+ continue;
120
+ }
121
+ const raw = d[valueKey];
122
+ const v = typeof raw === 'number' && Number.isFinite(raw) ? raw : 0;
123
+ const t = (v - dMin) / range;
124
+ const [r, g, b] = sampleRamp(ramp, t);
125
+ const xc = xVal + xBW / 2;
126
+ const yc = yVal + yBW / 2;
127
+ const x0 = xc - xStep / 2 + gap / 2;
128
+ const x1 = xc + xStep / 2 - gap / 2;
129
+ const y0 = yc - yStep / 2 + gap / 2;
130
+ const y1 = yc + yStep / 2 - gap / 2;
131
+ positions.push(x0, y0, x1, y0, x0, y1, x1, y0, x1, y1, x0, y1);
132
+ for (let i = 0; i < 6; i++) {
133
+ colors.push(r, g, b);
134
+ }
135
+ }
136
+ return {
137
+ positions: new Float32Array(positions),
138
+ colors: new Float32Array(colors),
139
+ vertexCount: positions.length / 2
140
+ };
141
+ }, [data, xKey, yKey, valueKey, xScale, yBandScale, domain, ramp, cellGap]);
142
+
143
+ // Mount the canvas outside the SVG and wire context-loss recovery.
144
+ useEffect(() => {
145
+ const marker = markerRef.current;
146
+ if (!marker) {
147
+ return;
148
+ }
149
+ if (!canvasRef.current) {
150
+ canvasRef.current = document.createElement('canvas');
151
+ }
152
+ const canvas = canvasRef.current;
153
+ const detach = mountCanvasOverSVG(marker, canvas, width, height);
154
+ const unregister = registerContextLossHandlers(canvas, () => {
155
+ glRef.current = null;
156
+ programRef.current = null;
157
+ posBufferRef.current = null;
158
+ colBufferRef.current = null;
159
+ locsRef.current = null;
160
+ }, () => setContextEpoch(e => e + 1));
161
+ return () => {
162
+ unregister();
163
+ detach?.();
164
+ };
165
+ }, [width, height]);
166
+
167
+ // Draw. Context, program, and both buffers are created once and reused.
168
+ useEffect(() => {
169
+ const canvas = canvasRef.current;
170
+ if (!canvas || width <= 0 || height <= 0) {
171
+ return;
172
+ }
173
+ sizeCanvas(canvas, width, height);
174
+ if (!glRef.current) {
175
+ glRef.current = getWebGLContext(canvas);
176
+ }
177
+ const gl = glRef.current;
178
+ if (!gl || gl.isContextLost()) {
179
+ return;
180
+ }
181
+ if (!programRef.current) {
182
+ programRef.current = createProgram(gl, VERT, FRAG);
183
+ locsRef.current = null;
184
+ }
185
+ const program = programRef.current;
186
+ if (!program) {
187
+ return;
188
+ }
189
+ if (!posBufferRef.current) {
190
+ posBufferRef.current = gl.createBuffer();
191
+ }
192
+ if (!colBufferRef.current) {
193
+ colBufferRef.current = gl.createBuffer();
194
+ }
195
+ const posBuffer = posBufferRef.current;
196
+ const colBuffer = colBufferRef.current;
197
+ if (!posBuffer || !colBuffer) {
198
+ return;
199
+ }
200
+ if (!locsRef.current) {
201
+ locsRef.current = {
202
+ aPosition: gl.getAttribLocation(program, 'a_position'),
203
+ aColor: gl.getAttribLocation(program, 'a_color'),
204
+ uResolution: gl.getUniformLocation(program, 'u_resolution')
205
+ };
206
+ }
207
+ const locs = locsRef.current;
208
+ gl.viewport(0, 0, canvas.width, canvas.height);
209
+ setupGLState(gl);
210
+ gl.useProgram(program);
211
+ gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer);
212
+ gl.bufferData(gl.ARRAY_BUFFER, geometry.positions, gl.STATIC_DRAW);
213
+ gl.enableVertexAttribArray(locs.aPosition);
214
+ gl.vertexAttribPointer(locs.aPosition, 2, gl.FLOAT, false, 0, 0);
215
+ gl.bindBuffer(gl.ARRAY_BUFFER, colBuffer);
216
+ gl.bufferData(gl.ARRAY_BUFFER, geometry.colors, gl.STATIC_DRAW);
217
+ gl.enableVertexAttribArray(locs.aColor);
218
+ gl.vertexAttribPointer(locs.aColor, 3, gl.FLOAT, false, 0, 0);
219
+ gl.uniform2f(locs.uResolution, width, height);
220
+ gl.drawArrays(gl.TRIANGLES, 0, geometry.vertexCount);
221
+ }, [geometry, width, height, contextEpoch]);
222
+
223
+ // Release all GL resources on unmount.
224
+ useEffect(() => {
225
+ return () => {
226
+ const gl = glRef.current;
227
+ if (gl) {
228
+ if (posBufferRef.current) {
229
+ gl.deleteBuffer(posBufferRef.current);
230
+ }
231
+ if (colBufferRef.current) {
232
+ gl.deleteBuffer(colBufferRef.current);
233
+ }
234
+ if (programRef.current) {
235
+ gl.deleteProgram(programRef.current);
236
+ }
237
+ loseContext(gl);
238
+ }
239
+ glRef.current = null;
240
+ programRef.current = null;
241
+ posBufferRef.current = null;
242
+ colBufferRef.current = null;
243
+ locsRef.current = null;
244
+ };
245
+ }, []);
246
+ if (width <= 0 || height <= 0) {
247
+ return null;
248
+ }
249
+ return /*#__PURE__*/_jsx("g", {
250
+ ref: markerRef
251
+ });
252
+ }
253
+
254
+ /**
255
+ * WebGL heatmap. Renders a 2D grid of colored cells using triangles.
256
+ *
257
+ * The rows are categorical: declaring `layout.yBandKey` makes the chart build a
258
+ * shared y band scale over `yKey`, so a left `<ChartAxis>` renders the row
259
+ * labels aligned to each cell (instead of a meaningless linear value axis).
260
+ * Columns use the chart's x band scale.
261
+ *
262
+ * @example
263
+ * ```
264
+ * series={[heatmapGL({
265
+ * xKey: 'hour', yKey: 'day', valueKey: 'count',
266
+ * colorRange: ['#f0f9ff', '#1e40af'],
267
+ * })]}
268
+ * ```
269
+ */
270
+ export function heatmapGL(options) {
271
+ const {
272
+ xKey,
273
+ yKey,
274
+ valueKey,
275
+ colorRange
276
+ } = options;
277
+ const cellGap = options.cellGap ?? 1;
278
+ return {
279
+ type: 'heatmapGL',
280
+ key: `heatmap-${valueKey}`,
281
+ // The value drives cell COLOR, not a linear y-domain — no data keys keeps the
282
+ // heatmap out of the shared linear y-scale / left axis / value tooltip.
283
+ // `yBandKey` makes the chart build a categorical y band scale over the rows
284
+ // so the left axis shows the row labels aligned to each cell.
285
+ dataKeys: [],
286
+ layout: {
287
+ yBandKey: yKey
288
+ },
289
+ resolve(ctx) {
290
+ // The canvas handles its own cell layout; resolve only exposes row/column
291
+ // centers (for hover) using the shared band scales.
292
+ const {
293
+ data,
294
+ xScale,
295
+ yBandScale
296
+ } = ctx;
297
+ const points = [];
298
+ if (!('bandwidth' in xScale) || !yBandScale) {
299
+ return points;
300
+ }
301
+ const xs = xScale;
302
+ for (let i = 0; i < data.length; i++) {
303
+ const d = data[i];
304
+ const px = (xs(String(d[xKey])) ?? 0) + xs.bandwidth() / 2;
305
+ const py = (yBandScale(String(d[yKey])) ?? 0) + yBandScale.bandwidth() / 2;
306
+ points.push({
307
+ px,
308
+ py,
309
+ py0: py,
310
+ dataIndex: i
311
+ });
312
+ }
313
+ return points;
314
+ },
315
+ render(_resolved, ctx) {
316
+ // Needs a categorical x (columns) and the shared y band scale (rows).
317
+ if (!('bandwidth' in ctx.xScale) || !ctx.yBandScale) {
318
+ return null;
319
+ }
320
+ return /*#__PURE__*/_jsx(HeatmapGLCanvas, {
321
+ data: ctx.data,
322
+ xKey: xKey,
323
+ yKey: yKey,
324
+ valueKey: valueKey,
325
+ xScale: ctx.xScale,
326
+ yBandScale: ctx.yBandScale,
327
+ colorRange: colorRange,
328
+ domain: options.domain,
329
+ cellGap: cellGap,
330
+ width: ctx.width,
331
+ height: ctx.height
332
+ });
333
+ }
334
+ };
335
+ }
@@ -0,0 +1,13 @@
1
+ export { bar, type BarOptions } from './bar';
2
+ export { line, type LineOptions } from './line';
3
+ export { dot, type DotOptions } from './dot';
4
+ export { area, type AreaOptions } from './area';
5
+ export { band, type BandOptions } from './band';
6
+ export { candlestick, type CandlestickOptions } from './candlestick';
7
+ export { errorBar, type ErrorBarOptions } from './errorBar';
8
+ export { referenceLine, type ReferenceLineOptions } from './referenceLine';
9
+ export { dotGL, type DotGLOptions } from './dotGL';
10
+ export { dotGLInteractive, type DotGLInteractiveOptions, } from './dotGLInteractive';
11
+ export { heatmapGL, type HeatmapGLOptions } from './heatmapGL';
12
+ export { streamGL, type StreamGLOptions, type StreamGLHandle } from './streamGL';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/marks/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,GAAG,EAAE,KAAK,UAAU,EAAC,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAC,IAAI,EAAE,KAAK,WAAW,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,GAAG,EAAE,KAAK,UAAU,EAAC,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAC,IAAI,EAAE,KAAK,WAAW,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,IAAI,EAAE,KAAK,WAAW,EAAC,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAE,KAAK,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAE,KAAK,eAAe,EAAC,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAC,aAAa,EAAE,KAAK,oBAAoB,EAAC,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAC,KAAK,EAAE,KAAK,YAAY,EAAC,MAAM,SAAS,CAAC;AACjD,OAAO,EACL,gBAAgB,EAChB,KAAK,uBAAuB,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAC,SAAS,EAAE,KAAK,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAC,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAC,MAAM,YAAY,CAAC"}
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ export { bar } from "./bar.js";
4
+ export { line } from "./line.js";
5
+ export { dot } from "./dot.js";
6
+ export { area } from "./area.js";
7
+ export { band } from "./band.js";
8
+ export { candlestick } from "./candlestick.js";
9
+ export { errorBar } from "./errorBar.js";
10
+ export { referenceLine } from "./referenceLine.js";
11
+ export { dotGL } from "./dotGL.js";
12
+ export { dotGLInteractive } from "./dotGLInteractive.js";
13
+ export { heatmapGL } from "./heatmapGL.js";
14
+ export { streamGL } from "./streamGL.js";
@@ -0,0 +1,18 @@
1
+ import type { SeriesDef } from '../types';
2
+ declare const CURVES: {
3
+ readonly linear: import("d3-shape").CurveFactory;
4
+ readonly monotone: import("d3-shape").CurveFactory;
5
+ readonly natural: import("d3-shape").CurveFactory;
6
+ readonly step: import("d3-shape").CurveFactory;
7
+ };
8
+ export type CurveType = keyof typeof CURVES;
9
+ export interface LineOptions {
10
+ color?: string;
11
+ curve?: CurveType;
12
+ strokeWidth?: number;
13
+ dots?: boolean;
14
+ label?: string;
15
+ }
16
+ export declare function line(dataKey: string, options?: LineOptions): SeriesDef;
17
+ export {};
18
+ //# sourceMappingURL=line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line.d.ts","sourceRoot":"","sources":["../../src/marks/line.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAC,SAAS,EAAgB,MAAM,UAAU,CAAC;AAIvD,QAAA,MAAM,MAAM;;;;;CAKF,CAAC;AACX,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,MAAM,CAAC;AAE5C,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAOD,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,SAAS,CA0E1E"}
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file marks/line.tsx
5
+ * @output Line series — self-contained resolve + render
6
+ *
7
+ * Missing / non-finite values become gaps (via d3's `.defined()`) instead of a
8
+ * misleading drop to the baseline, and per-point dots are only drawn where the
9
+ * point is finite.
10
+ */
11
+
12
+ import { line as d3Line, curveLinear, curveMonotoneX, curveNatural, curveStep } from 'd3-shape';
13
+ import { seriesFill } from "../markColor.js";
14
+ import { xPixel } from "../utils.js";
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
+ const CURVES = {
17
+ linear: curveLinear,
18
+ monotone: curveMonotoneX,
19
+ natural: curveNatural,
20
+ step: curveStep
21
+ };
22
+ /** A point is drawable only when both of its plotted coordinates are finite. */
23
+ function isFinitePoint(p) {
24
+ return Number.isFinite(p.px) && Number.isFinite(p.py);
25
+ }
26
+ export function line(dataKey, options = {}) {
27
+ const color = options.color;
28
+ const curve = options.curve ?? 'monotone';
29
+ const strokeWidth = typeof options.strokeWidth === 'number' && Number.isFinite(options.strokeWidth) ? Math.max(0, options.strokeWidth) : 2;
30
+ const dots = options.dots ?? false;
31
+ const seriesDef = {
32
+ type: 'line',
33
+ key: dataKey,
34
+ dataKeys: [dataKey],
35
+ color,
36
+ label: options.label ?? dataKey,
37
+ layout: {},
38
+ resolve(ctx) {
39
+ const {
40
+ data,
41
+ xKey,
42
+ xScale,
43
+ yScale
44
+ } = ctx;
45
+ const points = [];
46
+ for (let i = 0; i < data.length; i++) {
47
+ const d = data[i];
48
+ const raw = d[dataKey];
49
+ const v = typeof raw === 'number' && Number.isFinite(raw) ? raw : NaN;
50
+ points.push({
51
+ px: xPixel(d, xKey, xScale),
52
+ py: yScale(v),
53
+ py0: yScale(0),
54
+ dataIndex: i
55
+ });
56
+ }
57
+ return points;
58
+ },
59
+ render(resolved) {
60
+ if (resolved.length === 0) {
61
+ return null;
62
+ }
63
+ const curveFactory = CURVES[curve] ?? curveMonotoneX;
64
+ const pathGen = d3Line().defined(isFinitePoint).x(d => d.px).y(d => d.py).curve(curveFactory);
65
+ const pathD = pathGen(resolved) ?? '';
66
+ const strokeColor = seriesFill(seriesDef, color);
67
+ return /*#__PURE__*/_jsxs("g", {
68
+ children: [/*#__PURE__*/_jsx("path", {
69
+ d: pathD,
70
+ fill: "none",
71
+ stroke: strokeColor,
72
+ strokeWidth: strokeWidth
73
+ }), dots && resolved.filter(isFinitePoint).map(p => /*#__PURE__*/_jsx("circle", {
74
+ cx: p.px,
75
+ cy: p.py,
76
+ r: 3,
77
+ fill: strokeColor
78
+ }, p.dataIndex))]
79
+ });
80
+ }
81
+ };
82
+ return seriesDef;
83
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @file marks/referenceLine.tsx
3
+ * @output Horizontal or vertical reference line/band annotation. Labels are
4
+ * clamped to stay fully inside the plot (which is clipped) for both
5
+ * orientations, and non-finite y/x values render nothing.
6
+ */
7
+ import type { SeriesDef } from '../types';
8
+ export interface ReferenceLineOptions {
9
+ /** Horizontal reference at this y value */
10
+ y?: number;
11
+ /** Second y value — draws a shaded band between y and y2 */
12
+ y2?: number;
13
+ /** Vertical reference at this x value */
14
+ x?: number;
15
+ /** Line/band color */
16
+ color?: string;
17
+ /** Stroke width (for lines) */
18
+ strokeWidth?: number;
19
+ /** Dash pattern */
20
+ strokeDasharray?: string;
21
+ /** Text label */
22
+ label?: string;
23
+ /** Label position */
24
+ labelPosition?: 'start' | 'end';
25
+ /** Band fill opacity (when y2 is set) */
26
+ bandOpacity?: number;
27
+ }
28
+ /**
29
+ * Reference line or band annotation. Not a data series — renders at fixed values.
30
+ *
31
+ * @example
32
+ * ```
33
+ * series={[line('revenue'), referenceLine({y: 100, label: 'Target'})]}
34
+ * ```
35
+ */
36
+ export declare function referenceLine(options: ReferenceLineOptions): SeriesDef;
37
+ //# sourceMappingURL=referenceLine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referenceLine.d.ts","sourceRoot":"","sources":["../../src/marks/referenceLine.tsx"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAGxC,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,4DAA4D;IAC5D,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,sBAAsB;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,aAAa,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAChC,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AA8DD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAsJtE"}