@astryxdesign/lab 0.1.4-canary.39ffd21 → 0.1.4-canary.3d64ef2

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 (143) hide show
  1. package/README.md +2 -0
  2. package/dist/CodeEditor/CodeEditor.d.ts +4 -1
  3. package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
  4. package/dist/CodeEditor/CodeEditor.js +3 -0
  5. package/dist/InfoTip/InfoTip.d.ts +58 -0
  6. package/dist/InfoTip/InfoTip.d.ts.map +1 -0
  7. package/dist/InfoTip/InfoTip.js +91 -0
  8. package/dist/InfoTip/index.d.ts +6 -0
  9. package/dist/InfoTip/index.d.ts.map +1 -0
  10. package/dist/InfoTip/index.js +8 -0
  11. package/dist/Sankey/SankeyChart.d.ts.map +1 -1
  12. package/dist/Sankey/SankeyChart.js +3 -0
  13. package/dist/Schedule/ListView.d.ts.map +1 -1
  14. package/dist/Schedule/ListView.js +7 -4
  15. package/dist/Schedule/MonthlyView.js +3 -2
  16. package/dist/Schedule/Schedule.d.ts +3 -1
  17. package/dist/Schedule/Schedule.d.ts.map +1 -1
  18. package/dist/Schedule/Schedule.js +9 -4
  19. package/dist/Schedule/TimeGridView.js +3 -2
  20. package/dist/Schedule/context.d.ts +2 -0
  21. package/dist/Schedule/context.d.ts.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +5 -2
  25. package/dist/lab.css +6 -15
  26. package/package.json +2 -2
  27. package/src/CodeEditor/CodeEditor.test.tsx +21 -0
  28. package/src/CodeEditor/CodeEditor.tsx +5 -0
  29. package/src/InfoTip/InfoTip.doc.mjs +97 -0
  30. package/src/InfoTip/InfoTip.test.tsx +169 -0
  31. package/src/InfoTip/InfoTip.tsx +155 -0
  32. package/src/InfoTip/index.ts +10 -0
  33. package/src/Sankey/SankeyChart.test.tsx +77 -0
  34. package/src/Sankey/SankeyChart.tsx +3 -0
  35. package/src/Schedule/ListView.tsx +5 -2
  36. package/src/Schedule/MonthlyView.tsx +2 -2
  37. package/src/Schedule/Schedule.test.tsx +39 -0
  38. package/src/Schedule/Schedule.tsx +8 -0
  39. package/src/Schedule/TimeGridView.tsx +2 -2
  40. package/src/Schedule/context.tsx +2 -0
  41. package/src/index.ts +5 -46
  42. package/dist/ChartV2/Chart.d.ts +0 -32
  43. package/dist/ChartV2/Chart.d.ts.map +0 -1
  44. package/dist/ChartV2/Chart.js +0 -281
  45. package/dist/ChartV2/ChartAxis.d.ts +0 -36
  46. package/dist/ChartV2/ChartAxis.d.ts.map +0 -1
  47. package/dist/ChartV2/ChartAxis.js +0 -161
  48. package/dist/ChartV2/ChartGrid.d.ts +0 -20
  49. package/dist/ChartV2/ChartGrid.d.ts.map +0 -1
  50. package/dist/ChartV2/ChartGrid.js +0 -76
  51. package/dist/ChartV2/ChartLegend.d.ts +0 -14
  52. package/dist/ChartV2/ChartLegend.d.ts.map +0 -1
  53. package/dist/ChartV2/ChartLegend.js +0 -54
  54. package/dist/ChartV2/ChartSwatch.d.ts +0 -36
  55. package/dist/ChartV2/ChartSwatch.d.ts.map +0 -1
  56. package/dist/ChartV2/ChartSwatch.js +0 -82
  57. package/dist/ChartV2/ChartTooltip.d.ts +0 -46
  58. package/dist/ChartV2/ChartTooltip.d.ts.map +0 -1
  59. package/dist/ChartV2/ChartTooltip.js +0 -267
  60. package/dist/ChartV2/ChartV2Context.d.ts +0 -4
  61. package/dist/ChartV2/ChartV2Context.d.ts.map +0 -1
  62. package/dist/ChartV2/ChartV2Context.js +0 -12
  63. package/dist/ChartV2/index.d.ts +0 -13
  64. package/dist/ChartV2/index.d.ts.map +0 -1
  65. package/dist/ChartV2/index.js +0 -10
  66. package/dist/ChartV2/layout.d.ts +0 -25
  67. package/dist/ChartV2/layout.d.ts.map +0 -1
  68. package/dist/ChartV2/layout.js +0 -195
  69. package/dist/ChartV2/legend.d.ts +0 -18
  70. package/dist/ChartV2/legend.d.ts.map +0 -1
  71. package/dist/ChartV2/legend.js +0 -24
  72. package/dist/ChartV2/marks/area.d.ts +0 -19
  73. package/dist/ChartV2/marks/area.d.ts.map +0 -1
  74. package/dist/ChartV2/marks/area.js +0 -109
  75. package/dist/ChartV2/marks/band.d.ts +0 -9
  76. package/dist/ChartV2/marks/band.d.ts.map +0 -1
  77. package/dist/ChartV2/marks/band.js +0 -59
  78. package/dist/ChartV2/marks/bar.d.ts +0 -17
  79. package/dist/ChartV2/marks/bar.d.ts.map +0 -1
  80. package/dist/ChartV2/marks/bar.js +0 -120
  81. package/dist/ChartV2/marks/candlestick.d.ts +0 -15
  82. package/dist/ChartV2/marks/candlestick.d.ts.map +0 -1
  83. package/dist/ChartV2/marks/candlestick.js +0 -83
  84. package/dist/ChartV2/marks/dot.d.ts +0 -15
  85. package/dist/ChartV2/marks/dot.d.ts.map +0 -1
  86. package/dist/ChartV2/marks/dot.js +0 -65
  87. package/dist/ChartV2/marks/dotGL.d.ts +0 -16
  88. package/dist/ChartV2/marks/dotGL.d.ts.map +0 -1
  89. package/dist/ChartV2/marks/dotGL.js +0 -178
  90. package/dist/ChartV2/marks/dotGLInteractive.d.ts +0 -30
  91. package/dist/ChartV2/marks/dotGLInteractive.d.ts.map +0 -1
  92. package/dist/ChartV2/marks/dotGLInteractive.js +0 -464
  93. package/dist/ChartV2/marks/errorBar.d.ts +0 -27
  94. package/dist/ChartV2/marks/errorBar.d.ts.map +0 -1
  95. package/dist/ChartV2/marks/errorBar.js +0 -87
  96. package/dist/ChartV2/marks/heatmapGL.d.ts +0 -23
  97. package/dist/ChartV2/marks/heatmapGL.d.ts.map +0 -1
  98. package/dist/ChartV2/marks/heatmapGL.js +0 -242
  99. package/dist/ChartV2/marks/index.d.ts +0 -13
  100. package/dist/ChartV2/marks/index.d.ts.map +0 -1
  101. package/dist/ChartV2/marks/index.js +0 -14
  102. package/dist/ChartV2/marks/line.d.ts +0 -18
  103. package/dist/ChartV2/marks/line.d.ts.map +0 -1
  104. package/dist/ChartV2/marks/line.js +0 -76
  105. package/dist/ChartV2/marks/referenceLine.d.ts +0 -35
  106. package/dist/ChartV2/marks/referenceLine.d.ts.map +0 -1
  107. package/dist/ChartV2/marks/referenceLine.js +0 -186
  108. package/dist/ChartV2/marks/streamGL.d.ts +0 -36
  109. package/dist/ChartV2/marks/streamGL.d.ts.map +0 -1
  110. package/dist/ChartV2/marks/streamGL.js +0 -204
  111. package/dist/ChartV2/tooltip.d.ts +0 -38
  112. package/dist/ChartV2/tooltip.d.ts.map +0 -1
  113. package/dist/ChartV2/tooltip.js +0 -54
  114. package/dist/ChartV2/types.d.ts +0 -115
  115. package/dist/ChartV2/types.d.ts.map +0 -1
  116. package/dist/ChartV2/types.js +0 -35
  117. package/src/ChartV2/Chart.tsx +0 -348
  118. package/src/ChartV2/ChartAxis.tsx +0 -209
  119. package/src/ChartV2/ChartGrid.tsx +0 -99
  120. package/src/ChartV2/ChartLegend.tsx +0 -69
  121. package/src/ChartV2/ChartSwatch.doc.mjs +0 -17
  122. package/src/ChartV2/ChartSwatch.tsx +0 -86
  123. package/src/ChartV2/ChartTooltip.tsx +0 -382
  124. package/src/ChartV2/ChartV2.doc.mjs +0 -16
  125. package/src/ChartV2/ChartV2Context.ts +0 -15
  126. package/src/ChartV2/index.ts +0 -62
  127. package/src/ChartV2/layout.ts +0 -223
  128. package/src/ChartV2/legend.ts +0 -32
  129. package/src/ChartV2/marks/area.tsx +0 -122
  130. package/src/ChartV2/marks/band.tsx +0 -70
  131. package/src/ChartV2/marks/bar.tsx +0 -159
  132. package/src/ChartV2/marks/candlestick.tsx +0 -106
  133. package/src/ChartV2/marks/dot.tsx +0 -64
  134. package/src/ChartV2/marks/dotGL.tsx +0 -202
  135. package/src/ChartV2/marks/dotGLInteractive.tsx +0 -546
  136. package/src/ChartV2/marks/errorBar.tsx +0 -89
  137. package/src/ChartV2/marks/heatmapGL.tsx +0 -299
  138. package/src/ChartV2/marks/index.ts +0 -14
  139. package/src/ChartV2/marks/line.tsx +0 -94
  140. package/src/ChartV2/marks/referenceLine.tsx +0 -224
  141. package/src/ChartV2/marks/streamGL.tsx +0 -251
  142. package/src/ChartV2/tooltip.ts +0 -70
  143. package/src/ChartV2/types.ts +0 -129
@@ -1,64 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file marks/dot.tsx
5
- * @output Dot/scatter series — self-contained resolve + render
6
- */
7
-
8
- import type {SeriesDef, ResolvedPoint} from '../types';
9
- import type {ScaleBand} from 'd3-scale';
10
-
11
- export type ColorAccessor = string | ((datum: Record<string, unknown>, index: number) => string);
12
-
13
- export interface DotOptions {
14
- color?: ColorAccessor;
15
- radius?: number;
16
- opacity?: number;
17
- dodge?: boolean;
18
- label?: string;
19
- }
20
-
21
- export function dot(dataKey: string, options: DotOptions = {}): SeriesDef {
22
- const color = options.color ?? 'var(--color-chart-1)';
23
- const radius = options.radius ?? 4;
24
- const opacity = options.opacity ?? 0.8;
25
-
26
- return {
27
- type: 'dot',
28
- key: dataKey,
29
- dataKeys: [dataKey],
30
- color: typeof color === 'string' ? color : undefined,
31
- label: options.label ?? dataKey,
32
- layout: {},
33
-
34
- resolve(ctx) {
35
- const {data, xKey, xScale, yScale} = ctx;
36
- const points: ResolvedPoint[] = [];
37
- for (let i = 0; i < data.length; i++) {
38
- const d = data[i];
39
- let px: number;
40
- if ('bandwidth' in xScale) {
41
- px = ((xScale as ScaleBand<string>)(String(d[xKey])) ?? 0) + (xScale as ScaleBand<string>).bandwidth() / 2;
42
- } else {
43
- px = xScale(d[xKey] as number);
44
- }
45
- const v = typeof d[dataKey] === 'number' ? (d[dataKey] as number) : 0;
46
- points.push({px, py: yScale(v), py0: yScale(0), dataIndex: i});
47
- }
48
- // TODO: dodge layout runs here — has access to radius + all points
49
- return points;
50
- },
51
-
52
- render(resolved, ctx) {
53
- const {data} = ctx;
54
- return (
55
- <g>
56
- {resolved.map((p, i) => {
57
- const fill = typeof color === 'function' ? color(data[p.dataIndex], p.dataIndex) : color;
58
- return <circle key={i} cx={p.px} cy={p.py} r={radius} fill={fill} opacity={opacity} />;
59
- })}
60
- </g>
61
- );
62
- },
63
- };
64
- }
@@ -1,202 +0,0 @@
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
- }