Demo
Renderers, large data and data colors
Documented in Rendering and colors.
Renderers, large data and data colors
Up to 500,000 points drawn as SVG or on a canvas with min/max or LTTB decimation, a server-rendered SVG figure with an accessible data table, the derived palette or a brand palette, and per-point data colors.
100,000 samples; decimation keeps the extremes of every pixel column.
| x | Signal |
|---|---|
| 0 | 0 |
| 1 | 3.24 |
| 2 | 6.45 |
| 3 | 9.62 |
| 4 | 12.73 |
| 5 | 15.74 |
| 6 | 18.65 |
| 7 | 8.43 |
| 8 | 11.08 |
| 9 | 13.58 |
| 10 | 15.92 |
| 11 | 18.1 |
| 12 | 20.12 |
| 13 | 8.97 |
| 14 | 10.67 |
| 15 | 12.23 |
| 16 | 13.64 |
| 17 | 14.93 |
| 18 | 16.12 |
| 19 | 17.21 |
| 20 | 5.24 |
| 21 | 6.23 |
| 22 | 7.19 |
| 23 | 8.15 |
| 24 | 9.13 |
| 25 | 10.17 |
| 26 | -1.74 |
| 27 | -0.55 |
| 28 | 0.74 |
| 29 | 2.16 |
| 30 | 3.72 |
| 31 | 5.42 |
| 32 | 7.28 |
| 33 | -3.7 |
| 34 | -1.52 |
| 35 | 0.83 |
| 36 | 3.33 |
| 37 | 5.98 |
| 38 | 8.76 |
| 39 | -1.33 |
| 40 | 1.69 |
| 41 | 4.79 |
| 42 | 7.96 |
| 43 | 11.18 |
| 44 | 14.41 |
| 45 | 17.65 |
| 46 | 7.87 |
| 47 | 11.04 |
| 48 | 14.14 |
| 49 | 17.15 |
| 50 | 20.05 |
| 51 | 22.83 |
| 52 | 12.48 |
| 53 | 14.97 |
| 54 | 17.31 |
| 55 | 19.49 |
| 56 | 21.5 |
| 57 | 23.36 |
| 58 | 25.05 |
| 59 | 13.6 |
| 60 | 15.01 |
| 61 | 16.3 |
| 62 | 17.49 |
| 63 | 18.58 |
| 64 | 19.61 |
| 65 | 7.59 |
| 66 | 8.55 |
| 67 | 9.51 |
| 68 | 10.5 |
| 69 | 11.53 |
| 70 | 12.62 |
| 71 | 13.81 |
| 72 | 2.11 |
| 73 | 3.53 |
| 74 | 5.08 |
| 75 | 6.79 |
| 76 | 8.65 |
| 77 | 10.67 |
| 78 | -0.14 |
| 79 | 2.2 |
| 80 | 4.7 |
| 81 | 7.35 |
| 82 | 10.14 |
| 83 | 13.05 |
| 84 | 16.07 |
| 85 | 6.17 |
| 86 | 9.34 |
| 87 | 12.56 |
| 88 | 15.8 |
| 89 | 19.03 |
| 90 | 22.25 |
| 91 | 12.41 |
| 92 | 15.51 |
| 93 | 18.52 |
| 94 | 21.42 |
| 95 | 24.2 |
| 96 | 26.84 |
| 97 | 29.33 |
| 98 | 18.66 |
| 99 | 20.84 |
| 100 | 22.85 |
| 101 | 24.69 |
| 102 | 26.39 |
| 103 | 27.93 |
| 104 | 16.34 |
| 105 | 17.63 |
| 106 | 18.8 |
| 107 | 19.9 |
| 108 | 20.92 |
| 109 | 21.9 |
| 110 | 22.86 |
| 111 | 10.82 |
| 112 | 11.8 |
| 113 | 12.83 |
| 114 | 13.93 |
| 115 | 15.12 |
| 116 | 16.42 |
| 117 | 4.83 |
| 118 | 6.39 |
| 119 | 8.1 |
| 120 | 9.96 |
| 121 | 11.98 |
| 122 | 14.17 |
| 123 | 16.52 |
| 124 | 6.02 |
| 125 | 8.67 |
| 126 | 11.46 |
| 127 | 14.37 |
| 128 | 17.39 |
| 129 | 20.49 |
| 130 | 10.66 |
| 131 | 13.87 |
| 132 | 17.11 |
| 133 | 20.34 |
| 134 | 23.55 |
| 135 | 26.72 |
| 136 | 29.81 |
| 137 | 19.82 |
| 138 | 22.71 |
| 139 | 25.49 |
| 140 | 28.12 |
| 141 | 30.61 |
| 142 | 32.94 |
| 143 | 22.11 |
| 144 | 24.11 |
| 145 | 25.95 |
| 146 | 27.64 |
| 147 | 29.18 |
| 148 | 30.59 |
| 149 | 31.87 |
| 150 | 20.04 |
| 151 | 21.13 |
| 152 | 22.15 |
| 153 | 23.13 |
| 154 | 24.09 |
| 155 | 25.04 |
| 156 | 13.03 |
| 157 | 14.05 |
| 158 | 15.15 |
| 159 | 16.34 |
| 160 | 17.63 |
| 161 | 19.05 |
| 162 | 20.61 |
| 163 | 9.32 |
| 164 | 11.18 |
| 165 | 13.2 |
| 166 | 15.39 |
| 167 | 17.74 |
| 168 | 20.24 |
| 169 | 9.89 |
| 170 | 12.68 |
| 171 | 15.59 |
| 172 | 18.6 |
| 173 | 21.71 |
| 174 | 24.87 |
| 175 | 28.09 |
| 176 | 18.32 |
| 177 | 21.55 |
| 178 | 24.76 |
| 179 | 27.92 |
| 180 | 31.01 |
| 181 | 34.01 |
| 182 | 23.9 |
| 183 | 26.67 |
| 184 | 29.3 |
| 185 | 31.78 |
| 186 | 34.1 |
| 187 | 36.27 |
| 188 | 38.27 |
| 189 | 27.1 |
| 190 | 28.79 |
| 191 | 30.32 |
| 192 | 31.72 |
| 193 | 33 |
| 194 | 34.17 |
| 195 | 22.25 |
| 196 | 23.27 |
| 197 | 24.24 |
| 198 | 25.2 |
| 199 | 26.15 |
| 200 | 27.13 |
| 201 | 28.16 |
| 202 | 16.25 |
| 203 | 17.44 |
| 204 | 18.73 |
| 205 | 20.15 |
| 206 | 21.71 |
| 207 | 23.41 |
| 208 | 12.27 |
| 209 | 14.3 |
| 210 | 16.48 |
| 211 | 18.83 |
| 212 | 21.33 |
| 213 | 23.99 |
| 214 | 26.77 |
| 215 | 16.68 |
| 216 | 19.69 |
| 217 | 22.79 |
| 218 | 25.96 |
| 219 | 29.17 |
| 220 | 32.4 |
| 221 | 22.63 |
| 222 | 25.83 |
| 223 | 28.98 |
| 224 | 32.07 |
| 225 | 35.06 |
| 226 | 37.95 |
| 227 | 40.71 |
| 228 | 30.34 |
| 229 | 32.81 |
| 230 | 35.13 |
| 231 | 37.29 |
| 232 | 39.28 |
| 233 | 41.11 |
| 234 | 29.79 |
| 235 | 31.32 |
| 236 | 32.71 |
| 237 | 33.98 |
| 238 | 35.14 |
| 239 | 36.22 |
| 240 | 37.24 |
| 241 | 25.21 |
| 242 | 26.15 |
| 243 | 27.11 |
| 244 | 28.08 |
| 245 | 29.11 |
| 246 | 30.2 |
| 247 | 18.38 |
| 248 | 19.68 |
| 249 | 21.09 |
| 250 | 22.65 |
| 251 | 24.35 |
| 252 | 26.21 |
| 253 | 28.23 |
| 254 | 17.42 |
| 255 | 19.77 |
| 256 | 22.27 |
| 257 | 24.92 |
| 258 | 27.7 |
| 259 | 30.61 |
| 260 | 20.62 |
| 261 | 23.72 |
| 262 | 26.88 |
| 263 | 30.09 |
| 264 | 33.31 |
| 265 | 36.54 |
| 266 | 39.73 |
| 267 | 29.88 |
| 268 | 32.96 |
| 269 | 35.95 |
| 270 | 38.83 |
| 271 | 41.59 |
| 272 | 44.21 |
| 273 | 33.67 |
| 274 | 35.98 |
| 275 | 38.13 |
| 276 | 40.12 |
| 277 | 41.94 |
| 278 | 43.61 |
| 279 | 45.13 |
| 280 | 33.52 |
| 281 | 34.78 |
| 282 | 35.94 |
| 283 | 37.02 |
| 284 | 38.03 |
| 285 | 38.99 |
| 286 | 26.93 |
| 287 | 27.88 |
| 288 | 28.85 |
| 289 | 29.87 |
| 290 | 30.96 |
| 291 | 32.15 |
| 292 | 33.44 |
| 293 | 21.85 |
| 294 | 23.4 |
| 295 | 25.1 |
| 296 | 26.96 |
| 297 | 28.99 |
| 298 | 31.17 |
| 299 | 20.51 |
| 300 | 23.01 |
| 301 | 25.66 |
| 302 | 28.44 |
| 303 | 31.35 |
| 304 | 34.35 |
| 305 | 37.45 |
| 306 | 27.61 |
| 307 | 30.81 |
| 308 | 34.03 |
| 309 | 37.25 |
| 310 | 40.44 |
| 311 | 43.59 |
| 312 | 33.66 |
| 313 | 36.64 |
| 314 | 39.52 |
| 315 | 42.26 |
| 316 | 44.87 |
| 317 | 47.33 |
| 318 | 49.64 |
| 319 | 38.78 |
| 320 | 40.76 |
| 321 | 42.57 |
| 322 | 44.23 |
| 323 | 45.75 |
| 324 | 47.13 |
| 325 | 35.38 |
| 326 | 36.54 |
| 327 | 37.6 |
| 328 | 38.61 |
| 329 | 39.57 |
| 330 | 40.5 |
| 331 | 41.45 |
| 332 | 29.41 |
| 333 | 30.43 |
| 334 | 31.52 |
| 335 | 32.69 |
| 336 | 33.98 |
| 337 | 35.39 |
| 338 | 23.94 |
| 339 | 25.64 |
| 340 | 27.5 |
| 341 | 29.52 |
| 342 | 31.7 |
| 343 | 34.04 |
| 344 | 36.54 |
| 345 | 26.18 |
| 346 | 28.96 |
| 347 | 31.86 |
| 348 | 34.87 |
| 349 | 37.96 |
| 350 | 41.11 |
| 351 | 31.31 |
| 352 | 34.53 |
| 353 | 37.74 |
| 354 | 40.93 |
| 355 | 44.06 |
| 356 | 47.13 |
| 357 | 50.1 |
| 358 | 39.97 |
| 359 | 42.71 |
| 360 | 45.31 |
| 361 | 47.77 |
| 362 | 50.06 |
| 363 | 52.19 |
| 364 | 41.16 |
| 365 | 42.97 |
| 366 | 44.62 |
| 367 | 46.13 |
| 368 | 47.5 |
| 369 | 48.75 |
| 370 | 49.9 |
| 371 | 37.96 |
| 372 | 38.95 |
| 373 | 39.9 |
| 374 | 40.84 |
| 375 | 41.77 |
| 376 | 42.74 |
| 377 | 30.75 |
| 378 | 31.83 |
| 379 | 33 |
| 380 | 34.29 |
| 381 | 35.7 |
| 382 | 37.24 |
| 383 | 38.94 |
| 384 | 27.79 |
| 385 | 29.81 |
| 386 | 31.99 |
| 387 | 34.33 |
| 388 | 36.82 |
| 389 | 39.46 |
| 390 | 29.24 |
| 391 | 32.13 |
| 392 | 35.13 |
| 393 | 38.22 |
| 394 | 41.37 |
| 395 | 44.56 |
| 396 | 47.77 |
| 397 | 37.98 |
| 398 | 41.16 |
| 399 | 44.29 |
| 400 | 47.35 |
| 401 | 50.31 |
| 402 | 53.17 |
| 403 | 42.9 |
| 404 | 45.5 |
| 405 | 47.94 |
| 406 | 50.23 |
| 407 | 52.35 |
| 408 | 54.31 |
| 409 | 56.11 |
| 410 | 44.75 |
| 411 | 46.25 |
| 412 | 47.61 |
| 413 | 48.86 |
| 414 | 49.99 |
| 415 | 51.05 |
| 416 | 39.03 |
| 417 | 39.98 |
| 418 | 40.91 |
| 419 | 41.84 |
| 420 | 42.79 |
| 421 | 43.8 |
| 422 | 44.88 |
| 423 | 33.05 |
| 424 | 34.33 |
| 425 | 35.73 |
| 426 | 37.27 |
| 427 | 38.97 |
| 428 | 40.82 |
| 429 | 29.83 |
| 430 | 32 |
| 431 | 34.34 |
| 432 | 36.83 |
| 433 | 39.47 |
| 434 | 42.24 |
| 435 | 45.13 |
| 436 | 35.13 |
| 437 | 38.21 |
| 438 | 41.35 |
| 439 | 44.53 |
| 440 | 47.74 |
| 441 | 50.94 |
| 442 | 41.11 |
| 443 | 44.23 |
| 444 | 47.29 |
| 445 | 50.25 |
| 446 | 53.09 |
| 447 | 55.82 |
| 448 | 58.4 |
| 449 | 47.84 |
| 450 | 50.11 |
| 451 | 52.23 |
| 452 | 54.18 |
| 453 | 55.97 |
| 454 | 57.6 |
| 455 | 46.09 |
| 456 | 47.44 |
| 457 | 48.68 |
| 458 | 49.81 |
| 459 | 50.85 |
| 460 | 51.83 |
| 461 | 52.77 |
| 462 | 40.69 |
| 463 | 41.61 |
| 464 | 42.56 |
| 465 | 43.56 |
| 466 | 44.64 |
| 467 | 45.8 |
| 468 | 34.07 |
| 469 | 35.47 |
| 470 | 37.01 |
| 471 | 38.7 |
| 472 | 40.55 |
| 473 | 42.56 |
| 474 | 44.73 |
| 475 | 34.06 |
| 476 | 36.55 |
| 477 | 39.18 |
| 478 | 41.94 |
| 479 | 44.83 |
| 480 | 47.82 |
| 481 | 37.9 |
| 482 | 41.03 |
| 483 | 44.21 |
| 484 | 47.41 |
| 485 | 50.6 |
| 486 | 53.77 |
| 487 | 56.88 |
| 488 | 46.93 |
| 489 | 49.88 |
| 490 | 52.72 |
| 491 | 55.43 |
| 492 | 58 |
| 493 | 60.43 |
| 494 | 49.69 |
| 495 | 51.8 |
| 496 | 53.74 |
| 497 | 55.52 |
| 498 | 57.14 |
| 499 | 58.62 |
| 99500 more rows not shown | |
Column chart: Sales against target, 2 series, x from North to Central. Actual: 5 points, minimum 40, maximum 74, trending up. Target: 5 points, minimum 55, maximum 55, flat.
| x | Actual | Target |
|---|---|---|
| North | 40 | 55 |
| South | 57 | 55 |
| East | 74 | 55 |
| West | 56 | 55 |
| Central | 73 | 55 |
Demo.tsx
'use client';
import { useMemo, useState } from 'react';
import { Chart } from '@salmonui/charts/chart';
import { Checkbox } from '@salmonui/inputs/checkbox';
import { Select } from '@salmonui/dropdowns/select';
type Renderer = 'svg' | 'canvas' | 'auto';
type Decimation = 'auto' | 'lttb' | 'minMax' | 'off';
const brand = ['#1d4ed8', '#b45309', '#047857', '#7c3aed'];
// Nested records read through dotted field paths.
const regions = ['North', 'South', 'East', 'West', 'Central'].map((name, i) => ({ name, sales: { actual: 40 + ((i * 17) % 35), target: 55 } }));
export default function ChartRenderingDemo() {
const [count, setCount] = useState(100_000);
const [renderer, setRenderer] = useState<Renderer>('auto');
const [decimation, setDecimation] = useState<Decimation>('auto');
const [showTable, setShowTable] = useState(false);
const [brandColors, setBrandColors] = useState(false);
// Computed once per count, outside the chart render.
const signal = useMemo(() => Array.from({ length: count }, (_, i) => ({ i, v: Math.sin(i / 500) * 50 + Math.sin(i / 7) * 8 + ((i * 7919) % 13) })), [count]);
return (
<div className="demo-stack">
<div className="demo-toolbar">
<label>
Points
<Select aria-label="Points" data={[{ value: 1000, label: '1,000' }, { value: 100000, label: '100,000' }, { value: 500000, label: '500,000' }]} value={count} onValueChange={(value) => value != null && setCount(Number(value))} />
</label>
<label>
Renderer
<Select aria-label="Renderer" data={['svg', 'canvas', 'auto']} value={renderer} onValueChange={(value) => value != null && setRenderer(value as Renderer)} />
</label>
<label>
Decimation
<Select aria-label="Decimation" data={[{ value: 'auto', label: 'auto' }, { value: 'lttb', label: 'lttb' }, { value: 'minMax', label: 'minMax' }, { value: 'off', label: 'false' }]} value={decimation} onValueChange={(value) => value != null && setDecimation(value as Decimation)} />
</label>
</div>
<Chart
title="Vibration signal"
description={`${count.toLocaleString('en-US')} samples; decimation keeps the extremes of every pixel column.`}
data={signal}
height={260}
legend={false}
renderer={renderer}
decimation={decimation === 'off' ? false : decimation}
series={[{ type: 'line', name: 'Signal', xField: 'i', yField: 'v' }]}
/>
<div className="demo-toolbar">
<Checkbox checked={showTable} onCheckedChange={(checked) => setShowTable(checked)}>
Show the data table
</Checkbox>
<Checkbox checked={brandColors} onCheckedChange={(checked) => setBrandColors(checked)}>
Brand palette (data colors)
</Checkbox>
</div>
<Chart
title="Sales against target"
data={regions}
height={260}
showDataTable={showTable}
palette={brandColors ? brand : undefined}
series={[
{
type: 'column',
name: 'Actual',
xField: 'name',
yField: 'sales.actual',
// Called once per drawn point: below-target columns get a data color.
getPointStyle: (p) => (p.y < 50 ? { color: '#dc2626' } : undefined),
},
{ type: 'line', name: 'Target', xField: 'name', yField: 'sales.target', lineStyle: 'dashed' },
]}
/>
</div>
);
}
The signal chart takes up to 500,000 points. renderer moves only the
line to a canvas ('auto' switches above 20,000 drawn points) while the
axes stay SVG; decimation reduces the points per pixel column before
they reach the renderer, and the tooltip still reads the full data.
Both charts are SVG figures rendered on the server (view the page source)
and relaid out once after hydration. Each is a <figure> named by its
title with a visually hidden data table; "Show the data table" sets
showDataTable. The sales chart reads dotted paths ('sales.actual'),
colors its series from the derived --salmon-chart-* palette or from a
palette of brand data colors, and getPointStyle paints the
below-target columns red. In development each chart checks its data
colors against the plot surface and warns below 3:1.