MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / main

Function main

examples/sampling/main.ts:163–240  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

161};
162
163async function main(): Promise<void> {
164 const container = document.getElementById('chart');
165 if (!(container instanceof HTMLElement)) {
166 throw new Error('Chart container not found');
167 }
168
169 const modeEl = document.getElementById('samplingMode');
170 const thresholdEl = document.getElementById('samplingThreshold');
171 const applyEl = document.getElementById('apply');
172
173 if (!(modeEl instanceof HTMLSelectElement)) throw new Error('Sampling mode control not found');
174 if (!(thresholdEl instanceof HTMLInputElement)) throw new Error('Sampling threshold control not found');
175 if (!(applyEl instanceof HTMLButtonElement)) throw new Error('Apply button not found');
176
177 // Defaults picked to make downsampling obvious when zoomed out.
178 modeEl.value = 'lttb';
179 thresholdEl.value = '2000';
180
181 const data = createZoomyLineData(100_000);
182 const xMax = data.length - 1;
183
184 let controls: SamplingControls = { mode: 'lttb', threshold: 2000 };
185 let userOptions: ChartGPUOptions = createOptions(data, controls, xMax);
186
187 const chart = await ChartGPU.create(container, userOptions);
188
189 const ro = attachCoalescedResizeObserver([container], [chart]);
190
191 // Initial sizing/render.
192 chart.resize();
193
194 const apply = (): void => {
195 controls = {
196 mode: normalizeSamplingMode(modeEl.value),
197 threshold: normalizeThreshold(thresholdEl.value),
198 };
199
200 userOptions = createOptions(data, controls, xMax);
201 chart.setOption(userOptions);
202 updateReadouts(data.length, xMax, controls, chart.getZoomRange());
203 };
204
205 applyEl.addEventListener('click', apply);
206 thresholdEl.addEventListener('keydown', (e) => {
207 if (e.key === 'Enter') apply();
208 });
209
210 // Keep readouts in sync with slider / inside-zoom updates.
211 // (No public zoom-change event yet; polling is cheap.)
212 let rafId: number | null = null;
213 let lastKey = '';
214 const tick = (): void => {
215 const z = chart.getZoomRange();
216 const key = z
217 ? `${z.start.toFixed(3)}:${z.end.toFixed(3)}:${controls.mode}:${controls.threshold}`
218 : `null:${controls.mode}:${controls.threshold}`;
219 if (key !== lastKey) {
220 lastKey = key;

Callers 1

main.tsFile · 0.70

Calls 9

createZoomyLineDataFunction · 0.85
updateReadoutsFunction · 0.85
createMethod · 0.80
createOptionsFunction · 0.70
applyFunction · 0.70
resizeMethod · 0.65
getZoomRangeMethod · 0.65
disposeMethod · 0.65

Tested by

no test coverage detected