@astryxdesign/lab 0.1.4-canary.37c19d3 → 0.1.4-canary.39ffd21

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 (142) hide show
  1. package/dist/ChartV2/Chart.d.ts +32 -0
  2. package/dist/ChartV2/Chart.d.ts.map +1 -0
  3. package/dist/ChartV2/Chart.js +281 -0
  4. package/dist/ChartV2/ChartAxis.d.ts +36 -0
  5. package/dist/ChartV2/ChartAxis.d.ts.map +1 -0
  6. package/dist/ChartV2/ChartAxis.js +161 -0
  7. package/dist/ChartV2/ChartGrid.d.ts +20 -0
  8. package/dist/ChartV2/ChartGrid.d.ts.map +1 -0
  9. package/dist/ChartV2/ChartGrid.js +76 -0
  10. package/dist/ChartV2/ChartLegend.d.ts +14 -0
  11. package/dist/ChartV2/ChartLegend.d.ts.map +1 -0
  12. package/dist/ChartV2/ChartLegend.js +54 -0
  13. package/dist/ChartV2/ChartSwatch.d.ts +36 -0
  14. package/dist/ChartV2/ChartSwatch.d.ts.map +1 -0
  15. package/dist/ChartV2/ChartSwatch.js +82 -0
  16. package/dist/ChartV2/ChartTooltip.d.ts +46 -0
  17. package/dist/ChartV2/ChartTooltip.d.ts.map +1 -0
  18. package/dist/ChartV2/ChartTooltip.js +267 -0
  19. package/dist/ChartV2/ChartV2Context.d.ts +4 -0
  20. package/dist/ChartV2/ChartV2Context.d.ts.map +1 -0
  21. package/dist/ChartV2/ChartV2Context.js +12 -0
  22. package/dist/ChartV2/index.d.ts +13 -0
  23. package/dist/ChartV2/index.d.ts.map +1 -0
  24. package/dist/ChartV2/index.js +10 -0
  25. package/dist/ChartV2/layout.d.ts +25 -0
  26. package/dist/ChartV2/layout.d.ts.map +1 -0
  27. package/dist/ChartV2/layout.js +195 -0
  28. package/dist/ChartV2/legend.d.ts +18 -0
  29. package/dist/ChartV2/legend.d.ts.map +1 -0
  30. package/dist/ChartV2/legend.js +24 -0
  31. package/dist/ChartV2/marks/area.d.ts +19 -0
  32. package/dist/ChartV2/marks/area.d.ts.map +1 -0
  33. package/dist/ChartV2/marks/area.js +109 -0
  34. package/dist/ChartV2/marks/band.d.ts +9 -0
  35. package/dist/ChartV2/marks/band.d.ts.map +1 -0
  36. package/dist/ChartV2/marks/band.js +59 -0
  37. package/dist/ChartV2/marks/bar.d.ts +17 -0
  38. package/dist/ChartV2/marks/bar.d.ts.map +1 -0
  39. package/dist/ChartV2/marks/bar.js +120 -0
  40. package/dist/ChartV2/marks/candlestick.d.ts +15 -0
  41. package/dist/ChartV2/marks/candlestick.d.ts.map +1 -0
  42. package/dist/ChartV2/marks/candlestick.js +83 -0
  43. package/dist/ChartV2/marks/dot.d.ts +15 -0
  44. package/dist/ChartV2/marks/dot.d.ts.map +1 -0
  45. package/dist/ChartV2/marks/dot.js +65 -0
  46. package/dist/ChartV2/marks/dotGL.d.ts +16 -0
  47. package/dist/ChartV2/marks/dotGL.d.ts.map +1 -0
  48. package/dist/ChartV2/marks/dotGL.js +178 -0
  49. package/dist/ChartV2/marks/dotGLInteractive.d.ts +30 -0
  50. package/dist/ChartV2/marks/dotGLInteractive.d.ts.map +1 -0
  51. package/dist/ChartV2/marks/dotGLInteractive.js +464 -0
  52. package/dist/ChartV2/marks/errorBar.d.ts +27 -0
  53. package/dist/ChartV2/marks/errorBar.d.ts.map +1 -0
  54. package/dist/ChartV2/marks/errorBar.js +87 -0
  55. package/dist/ChartV2/marks/heatmapGL.d.ts +23 -0
  56. package/dist/ChartV2/marks/heatmapGL.d.ts.map +1 -0
  57. package/dist/ChartV2/marks/heatmapGL.js +242 -0
  58. package/dist/ChartV2/marks/index.d.ts +13 -0
  59. package/dist/ChartV2/marks/index.d.ts.map +1 -0
  60. package/dist/ChartV2/marks/index.js +14 -0
  61. package/dist/ChartV2/marks/line.d.ts +18 -0
  62. package/dist/ChartV2/marks/line.d.ts.map +1 -0
  63. package/dist/ChartV2/marks/line.js +76 -0
  64. package/dist/ChartV2/marks/referenceLine.d.ts +35 -0
  65. package/dist/ChartV2/marks/referenceLine.d.ts.map +1 -0
  66. package/dist/ChartV2/marks/referenceLine.js +186 -0
  67. package/dist/ChartV2/marks/streamGL.d.ts +36 -0
  68. package/dist/ChartV2/marks/streamGL.d.ts.map +1 -0
  69. package/dist/ChartV2/marks/streamGL.js +204 -0
  70. package/dist/ChartV2/tooltip.d.ts +38 -0
  71. package/dist/ChartV2/tooltip.d.ts.map +1 -0
  72. package/dist/ChartV2/tooltip.js +54 -0
  73. package/dist/ChartV2/types.d.ts +115 -0
  74. package/dist/ChartV2/types.d.ts.map +1 -0
  75. package/dist/ChartV2/types.js +35 -0
  76. package/dist/CodeEditor/CodeEditor.d.ts +1 -4
  77. package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
  78. package/dist/CodeEditor/CodeEditor.js +0 -3
  79. package/dist/Sankey/SankeyChart.d.ts.map +1 -1
  80. package/dist/Sankey/SankeyChart.js +0 -3
  81. package/dist/Schedule/ListView.d.ts.map +1 -1
  82. package/dist/Schedule/ListView.js +4 -7
  83. package/dist/Schedule/MonthlyView.js +2 -3
  84. package/dist/Schedule/Schedule.d.ts +1 -3
  85. package/dist/Schedule/Schedule.d.ts.map +1 -1
  86. package/dist/Schedule/Schedule.js +4 -9
  87. package/dist/Schedule/TimeGridView.js +2 -3
  88. package/dist/Schedule/context.d.ts +0 -2
  89. package/dist/Schedule/context.d.ts.map +1 -1
  90. package/dist/index.d.ts +1 -1
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +2 -5
  93. package/dist/lab.css +15 -6
  94. package/package.json +2 -2
  95. package/src/ChartV2/Chart.tsx +348 -0
  96. package/src/ChartV2/ChartAxis.tsx +209 -0
  97. package/src/ChartV2/ChartGrid.tsx +99 -0
  98. package/src/ChartV2/ChartLegend.tsx +69 -0
  99. package/src/ChartV2/ChartSwatch.doc.mjs +17 -0
  100. package/src/ChartV2/ChartSwatch.tsx +86 -0
  101. package/src/ChartV2/ChartTooltip.tsx +382 -0
  102. package/src/ChartV2/ChartV2.doc.mjs +16 -0
  103. package/src/ChartV2/ChartV2Context.ts +15 -0
  104. package/src/ChartV2/index.ts +62 -0
  105. package/src/ChartV2/layout.ts +223 -0
  106. package/src/ChartV2/legend.ts +32 -0
  107. package/src/ChartV2/marks/area.tsx +122 -0
  108. package/src/ChartV2/marks/band.tsx +70 -0
  109. package/src/ChartV2/marks/bar.tsx +159 -0
  110. package/src/ChartV2/marks/candlestick.tsx +106 -0
  111. package/src/ChartV2/marks/dot.tsx +64 -0
  112. package/src/ChartV2/marks/dotGL.tsx +202 -0
  113. package/src/ChartV2/marks/dotGLInteractive.tsx +546 -0
  114. package/src/ChartV2/marks/errorBar.tsx +89 -0
  115. package/src/ChartV2/marks/heatmapGL.tsx +299 -0
  116. package/src/ChartV2/marks/index.ts +14 -0
  117. package/src/ChartV2/marks/line.tsx +94 -0
  118. package/src/ChartV2/marks/referenceLine.tsx +224 -0
  119. package/src/ChartV2/marks/streamGL.tsx +251 -0
  120. package/src/ChartV2/tooltip.ts +70 -0
  121. package/src/ChartV2/types.ts +129 -0
  122. package/src/CodeEditor/CodeEditor.tsx +0 -5
  123. package/src/Sankey/SankeyChart.tsx +0 -3
  124. package/src/Schedule/ListView.tsx +2 -5
  125. package/src/Schedule/MonthlyView.tsx +2 -2
  126. package/src/Schedule/Schedule.test.tsx +0 -39
  127. package/src/Schedule/Schedule.tsx +0 -8
  128. package/src/Schedule/TimeGridView.tsx +2 -2
  129. package/src/Schedule/context.tsx +0 -2
  130. package/src/index.ts +46 -5
  131. package/dist/InfoTip/InfoTip.d.ts +0 -58
  132. package/dist/InfoTip/InfoTip.d.ts.map +0 -1
  133. package/dist/InfoTip/InfoTip.js +0 -91
  134. package/dist/InfoTip/index.d.ts +0 -6
  135. package/dist/InfoTip/index.d.ts.map +0 -1
  136. package/dist/InfoTip/index.js +0 -8
  137. package/src/CodeEditor/CodeEditor.test.tsx +0 -21
  138. package/src/InfoTip/InfoTip.doc.mjs +0 -97
  139. package/src/InfoTip/InfoTip.test.tsx +0 -169
  140. package/src/InfoTip/InfoTip.tsx +0 -155
  141. package/src/InfoTip/index.ts +0 -10
  142. package/src/Sankey/SankeyChart.test.tsx +0 -77
@@ -0,0 +1,202 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file marks/dotGL.tsx
5
+ * @output WebGL scatter — canvas overlay, single draw call
6
+ */
7
+
8
+ import {useRef, useEffect, useCallback} from 'react';
9
+ import type {SeriesDef, ResolvedPoint} from '../types';
10
+ import type {ScaleBand} from 'd3-scale';
11
+ import {useChartV2} from '../ChartV2Context';
12
+ import {
13
+ hexToGL,
14
+ getWebGLContext,
15
+ setupGLState,
16
+ sizeCanvas,
17
+ mountCanvasOverSVG,
18
+ createProgram,
19
+ POINT_SIZE_COMPENSATION,
20
+ } from '../../Chart/webgl';
21
+
22
+ export interface DotGLOptions {
23
+ color: string;
24
+ size?: number;
25
+ opacity?: number;
26
+ }
27
+
28
+ const VERT = `
29
+ attribute vec2 a_position;
30
+ uniform vec2 u_resolution;
31
+ uniform float u_size;
32
+ void main() {
33
+ vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
34
+ gl_Position = vec4(clip.x, -clip.y, 0.0, 1.0);
35
+ gl_PointSize = u_size * ${POINT_SIZE_COMPENSATION.toFixed(6)};
36
+ }
37
+ `;
38
+
39
+ const FRAG = `
40
+ precision mediump float;
41
+ uniform vec3 u_color;
42
+ uniform float u_opacity;
43
+ void main() {
44
+ vec2 coord = gl_PointCoord - vec2(0.5);
45
+ float dist = length(coord);
46
+ if (dist > 0.5) discard;
47
+ float edge = 1.0 - smoothstep(0.48, 0.5, dist);
48
+ float a = u_opacity * edge;
49
+ gl_FragColor = vec4(u_color * a, a);
50
+ }
51
+ `;
52
+
53
+ /**
54
+ * Inline component returned by render() — manages the WebGL canvas lifecycle.
55
+ * Needs access to svgRef from ChartV2Context to mount the canvas outside SVG.
56
+ */
57
+ function DotGLCanvas({
58
+ resolved,
59
+ color,
60
+ size,
61
+ opacity,
62
+ width,
63
+ height,
64
+ }: {
65
+ resolved: ResolvedPoint[];
66
+ color: string;
67
+ size: number;
68
+ opacity: number;
69
+ width: number;
70
+ height: number;
71
+ }) {
72
+ const {svgRef: _svgRef} = useChartV2();
73
+ const canvasRef = useRef<HTMLCanvasElement | null>(null);
74
+ const glRef = useRef<WebGLRenderingContext | null>(null);
75
+ const programRef = useRef<WebGLProgram | null>(null);
76
+ const markerRef = useRef<SVGGElement>(null);
77
+
78
+ const getPositions = useCallback((): Float32Array => {
79
+ const positions: number[] = [];
80
+ for (const p of resolved) {
81
+ positions.push(p.px, p.py);
82
+ }
83
+ return new Float32Array(positions);
84
+ }, [resolved]);
85
+
86
+ // Mount canvas outside SVG
87
+ useEffect(() => {
88
+ const marker = markerRef.current;
89
+ if (!marker) {
90
+ return;
91
+ }
92
+ if (!canvasRef.current) {
93
+ canvasRef.current = document.createElement('canvas');
94
+ }
95
+ return mountCanvasOverSVG(marker, canvasRef.current, width, height);
96
+ }, [width, height]);
97
+
98
+ // Draw
99
+ useEffect(() => {
100
+ const canvas = canvasRef.current;
101
+ if (!canvas || width <= 0 || height <= 0) {
102
+ return;
103
+ }
104
+
105
+ const dpr = sizeCanvas(canvas, width, height);
106
+
107
+ if (!glRef.current) {
108
+ glRef.current = getWebGLContext(canvas);
109
+ }
110
+ const gl = glRef.current;
111
+ if (!gl) {
112
+ return;
113
+ }
114
+
115
+ if (!programRef.current) {
116
+ programRef.current = createProgram(gl, VERT, FRAG);
117
+ }
118
+ const program = programRef.current;
119
+ if (!program) {
120
+ return;
121
+ }
122
+
123
+ gl.viewport(0, 0, canvas.width, canvas.height);
124
+ setupGLState(gl);
125
+ gl.useProgram(program);
126
+
127
+ const positions = getPositions();
128
+ const posBuffer = gl.createBuffer();
129
+ gl.bindBuffer(gl.ARRAY_BUFFER, posBuffer);
130
+ gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);
131
+ const aPos = gl.getAttribLocation(program, 'a_position');
132
+ gl.enableVertexAttribArray(aPos);
133
+ gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
134
+
135
+ const [r, g, b] = hexToGL(color);
136
+ gl.uniform2f(gl.getUniformLocation(program, 'u_resolution'), width, height);
137
+ gl.uniform3f(gl.getUniformLocation(program, 'u_color'), r, g, b);
138
+ gl.uniform1f(gl.getUniformLocation(program, 'u_size'), size * dpr);
139
+ gl.uniform1f(gl.getUniformLocation(program, 'u_opacity'), opacity);
140
+
141
+ gl.drawArrays(gl.POINTS, 0, positions.length / 2);
142
+ gl.deleteBuffer(posBuffer);
143
+ }, [width, height, color, size, opacity, getPositions]);
144
+
145
+ if (width <= 0 || height <= 0) {
146
+ return null;
147
+ }
148
+ return <g ref={markerRef} />;
149
+ }
150
+
151
+ /**
152
+ * WebGL scatter plot. Canvas mounted outside SVG for sharp Retina rendering.
153
+ *
154
+ * @example
155
+ * ```
156
+ * series={[dotGL('value', {color: '#4f46e5'})]}
157
+ * ```
158
+ */
159
+ export function dotGL(dataKey: string, options: DotGLOptions): SeriesDef {
160
+ const {color} = options;
161
+ const size = options.size ?? 6;
162
+ const opacity = options.opacity ?? 0.8;
163
+
164
+ return {
165
+ type: 'dotGL',
166
+ key: dataKey,
167
+ dataKeys: [dataKey],
168
+ layout: {},
169
+
170
+ resolve(ctx) {
171
+ const {data, xKey, xScale, yScale} = ctx;
172
+ const points: ResolvedPoint[] = [];
173
+ for (let i = 0; i < data.length; i++) {
174
+ const d = data[i];
175
+ let px: number;
176
+ if ('bandwidth' in xScale) {
177
+ px =
178
+ ((xScale as ScaleBand<string>)(String(d[xKey])) ?? 0) +
179
+ (xScale as ScaleBand<string>).bandwidth() / 2;
180
+ } else {
181
+ px = xScale(d[xKey] as number);
182
+ }
183
+ const v = typeof d[dataKey] === 'number' ? (d[dataKey] as number) : 0;
184
+ points.push({px, py: yScale(v), py0: yScale(0), dataIndex: i});
185
+ }
186
+ return points;
187
+ },
188
+
189
+ render(resolved, ctx) {
190
+ return (
191
+ <DotGLCanvas
192
+ resolved={resolved}
193
+ color={color}
194
+ size={size}
195
+ opacity={opacity}
196
+ width={ctx.width}
197
+ height={ctx.height}
198
+ />
199
+ );
200
+ },
201
+ };
202
+ }