@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.
- package/dist/ChartV2/Chart.d.ts +32 -0
- package/dist/ChartV2/Chart.d.ts.map +1 -0
- package/dist/ChartV2/Chart.js +281 -0
- package/dist/ChartV2/ChartAxis.d.ts +36 -0
- package/dist/ChartV2/ChartAxis.d.ts.map +1 -0
- package/dist/ChartV2/ChartAxis.js +161 -0
- package/dist/ChartV2/ChartGrid.d.ts +20 -0
- package/dist/ChartV2/ChartGrid.d.ts.map +1 -0
- package/dist/ChartV2/ChartGrid.js +76 -0
- package/dist/ChartV2/ChartLegend.d.ts +14 -0
- package/dist/ChartV2/ChartLegend.d.ts.map +1 -0
- package/dist/ChartV2/ChartLegend.js +54 -0
- package/dist/ChartV2/ChartSwatch.d.ts +36 -0
- package/dist/ChartV2/ChartSwatch.d.ts.map +1 -0
- package/dist/ChartV2/ChartSwatch.js +82 -0
- package/dist/ChartV2/ChartTooltip.d.ts +46 -0
- package/dist/ChartV2/ChartTooltip.d.ts.map +1 -0
- package/dist/ChartV2/ChartTooltip.js +267 -0
- package/dist/ChartV2/ChartV2Context.d.ts +4 -0
- package/dist/ChartV2/ChartV2Context.d.ts.map +1 -0
- package/dist/ChartV2/ChartV2Context.js +12 -0
- package/dist/ChartV2/index.d.ts +13 -0
- package/dist/ChartV2/index.d.ts.map +1 -0
- package/dist/ChartV2/index.js +10 -0
- package/dist/ChartV2/layout.d.ts +25 -0
- package/dist/ChartV2/layout.d.ts.map +1 -0
- package/dist/ChartV2/layout.js +195 -0
- package/dist/ChartV2/legend.d.ts +18 -0
- package/dist/ChartV2/legend.d.ts.map +1 -0
- package/dist/ChartV2/legend.js +24 -0
- package/dist/ChartV2/marks/area.d.ts +19 -0
- package/dist/ChartV2/marks/area.d.ts.map +1 -0
- package/dist/ChartV2/marks/area.js +109 -0
- package/dist/ChartV2/marks/band.d.ts +9 -0
- package/dist/ChartV2/marks/band.d.ts.map +1 -0
- package/dist/ChartV2/marks/band.js +59 -0
- package/dist/ChartV2/marks/bar.d.ts +17 -0
- package/dist/ChartV2/marks/bar.d.ts.map +1 -0
- package/dist/ChartV2/marks/bar.js +120 -0
- package/dist/ChartV2/marks/candlestick.d.ts +15 -0
- package/dist/ChartV2/marks/candlestick.d.ts.map +1 -0
- package/dist/ChartV2/marks/candlestick.js +83 -0
- package/dist/ChartV2/marks/dot.d.ts +15 -0
- package/dist/ChartV2/marks/dot.d.ts.map +1 -0
- package/dist/ChartV2/marks/dot.js +65 -0
- package/dist/ChartV2/marks/dotGL.d.ts +16 -0
- package/dist/ChartV2/marks/dotGL.d.ts.map +1 -0
- package/dist/ChartV2/marks/dotGL.js +178 -0
- package/dist/ChartV2/marks/dotGLInteractive.d.ts +30 -0
- package/dist/ChartV2/marks/dotGLInteractive.d.ts.map +1 -0
- package/dist/ChartV2/marks/dotGLInteractive.js +464 -0
- package/dist/ChartV2/marks/errorBar.d.ts +27 -0
- package/dist/ChartV2/marks/errorBar.d.ts.map +1 -0
- package/dist/ChartV2/marks/errorBar.js +87 -0
- package/dist/ChartV2/marks/heatmapGL.d.ts +23 -0
- package/dist/ChartV2/marks/heatmapGL.d.ts.map +1 -0
- package/dist/ChartV2/marks/heatmapGL.js +242 -0
- package/dist/ChartV2/marks/index.d.ts +13 -0
- package/dist/ChartV2/marks/index.d.ts.map +1 -0
- package/dist/ChartV2/marks/index.js +14 -0
- package/dist/ChartV2/marks/line.d.ts +18 -0
- package/dist/ChartV2/marks/line.d.ts.map +1 -0
- package/dist/ChartV2/marks/line.js +76 -0
- package/dist/ChartV2/marks/referenceLine.d.ts +35 -0
- package/dist/ChartV2/marks/referenceLine.d.ts.map +1 -0
- package/dist/ChartV2/marks/referenceLine.js +186 -0
- package/dist/ChartV2/marks/streamGL.d.ts +36 -0
- package/dist/ChartV2/marks/streamGL.d.ts.map +1 -0
- package/dist/ChartV2/marks/streamGL.js +204 -0
- package/dist/ChartV2/tooltip.d.ts +38 -0
- package/dist/ChartV2/tooltip.d.ts.map +1 -0
- package/dist/ChartV2/tooltip.js +54 -0
- package/dist/ChartV2/types.d.ts +115 -0
- package/dist/ChartV2/types.d.ts.map +1 -0
- package/dist/ChartV2/types.js +35 -0
- package/dist/CodeEditor/CodeEditor.d.ts +1 -4
- package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
- package/dist/CodeEditor/CodeEditor.js +0 -3
- package/dist/Sankey/SankeyChart.d.ts.map +1 -1
- package/dist/Sankey/SankeyChart.js +0 -3
- package/dist/Schedule/ListView.d.ts.map +1 -1
- package/dist/Schedule/ListView.js +4 -7
- package/dist/Schedule/MonthlyView.js +2 -3
- package/dist/Schedule/Schedule.d.ts +1 -3
- package/dist/Schedule/Schedule.d.ts.map +1 -1
- package/dist/Schedule/Schedule.js +4 -9
- package/dist/Schedule/TimeGridView.js +2 -3
- package/dist/Schedule/context.d.ts +0 -2
- package/dist/Schedule/context.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- package/dist/lab.css +15 -6
- package/package.json +2 -2
- package/src/ChartV2/Chart.tsx +348 -0
- package/src/ChartV2/ChartAxis.tsx +209 -0
- package/src/ChartV2/ChartGrid.tsx +99 -0
- package/src/ChartV2/ChartLegend.tsx +69 -0
- package/src/ChartV2/ChartSwatch.doc.mjs +17 -0
- package/src/ChartV2/ChartSwatch.tsx +86 -0
- package/src/ChartV2/ChartTooltip.tsx +382 -0
- package/src/ChartV2/ChartV2.doc.mjs +16 -0
- package/src/ChartV2/ChartV2Context.ts +15 -0
- package/src/ChartV2/index.ts +62 -0
- package/src/ChartV2/layout.ts +223 -0
- package/src/ChartV2/legend.ts +32 -0
- package/src/ChartV2/marks/area.tsx +122 -0
- package/src/ChartV2/marks/band.tsx +70 -0
- package/src/ChartV2/marks/bar.tsx +159 -0
- package/src/ChartV2/marks/candlestick.tsx +106 -0
- package/src/ChartV2/marks/dot.tsx +64 -0
- package/src/ChartV2/marks/dotGL.tsx +202 -0
- package/src/ChartV2/marks/dotGLInteractive.tsx +546 -0
- package/src/ChartV2/marks/errorBar.tsx +89 -0
- package/src/ChartV2/marks/heatmapGL.tsx +299 -0
- package/src/ChartV2/marks/index.ts +14 -0
- package/src/ChartV2/marks/line.tsx +94 -0
- package/src/ChartV2/marks/referenceLine.tsx +224 -0
- package/src/ChartV2/marks/streamGL.tsx +251 -0
- package/src/ChartV2/tooltip.ts +70 -0
- package/src/ChartV2/types.ts +129 -0
- package/src/CodeEditor/CodeEditor.tsx +0 -5
- package/src/Sankey/SankeyChart.tsx +0 -3
- package/src/Schedule/ListView.tsx +2 -5
- package/src/Schedule/MonthlyView.tsx +2 -2
- package/src/Schedule/Schedule.test.tsx +0 -39
- package/src/Schedule/Schedule.tsx +0 -8
- package/src/Schedule/TimeGridView.tsx +2 -2
- package/src/Schedule/context.tsx +0 -2
- package/src/index.ts +46 -5
- package/dist/InfoTip/InfoTip.d.ts +0 -58
- package/dist/InfoTip/InfoTip.d.ts.map +0 -1
- package/dist/InfoTip/InfoTip.js +0 -91
- package/dist/InfoTip/index.d.ts +0 -6
- package/dist/InfoTip/index.d.ts.map +0 -1
- package/dist/InfoTip/index.js +0 -8
- package/src/CodeEditor/CodeEditor.test.tsx +0 -21
- package/src/InfoTip/InfoTip.doc.mjs +0 -97
- package/src/InfoTip/InfoTip.test.tsx +0 -169
- package/src/InfoTip/InfoTip.tsx +0 -155
- package/src/InfoTip/index.ts +0 -10
- 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
|
+
}
|