Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2456896
Plot: replaced `xAxisTitle`, `yAxisTitle`, `xAxisRange`, and `yAxisRa…
agarny Dec 1, 2026
e884755
Plot: allowed only one end of an axis range to be set (e.g., `[0, nul…
agarny Dec 2, 2026
827af09
Plot: added a `log` property to `PlotAxis` to make an axis logarithmi…
agarny Dec 2, 2026
01cdcf3
Plot: added a `grid` property to `PlotAxis` to hide the grid lines al…
agarny Dec 2, 2026
23ee703
Plot: reorganised the context menu by axis, with an `xAxis` and a `yA…
agarny Dec 2, 2026
6b6fe9a
Plot: added a context menu item to show or hide the legend, and an `u…
agarny Dec 2, 2026
74bab3f
Demo: made the context menu of an instance only show or hide its own …
agarny Dec 3, 2026
51248cd
Plot: added a `line` property to `PlotTrace` to set the type (none, s…
agarny Dec 3, 2026
7bd1b1d
Plot: removed the `color` property of `PlotTrace`, so that the colour…
agarny Dec 3, 2026
7ab5c5f
Plot: added a `marker` property to `PlotTrace` to set the type, size,…
agarny Dec 3, 2026
deddf28
Demo: reworked the settings panel, with collapsible sections (remembe…
agarny Dec 3, 2026
ae9fb78
Demo: removed the "Large offsets" kind of data (and its benchmark sce…
agarny Dec 3, 2026
7105af5
Plot: an empty plot, or one whose traces have neither a line nor mark…
agarny Dec 3, 2026
d728ce0
Plot: the number of drawn points no longer includes stale marker coun…
agarny Dec 3, 2026
bb3ae7b
Plot: the legend's context menu and double-click now ignore traces th…
agarny Dec 3, 2026
13f6d2f
Plot: in Firefox, traces with many markers no longer need one extra d…
agarny Dec 3, 2026
f6ecdcd
Plot: an unknown line or marker colour now falls back to the default …
agarny Dec 3, 2026
6c4249c
Plot: made resetting the zoom drop any pending wheel zoom, so that it…
agarny Dec 3, 2026
7f983f8
Demo: made it possible to stop the benchmark, leaving the plots as th…
agarny Dec 3, 2026
8c4b80d
Plot: resetting the zoom, including from a synchronised plot, now dro…
agarny Dec 3, 2026
81c231b
Plot: a currentColor line or marker colour now falls back to the defa…
agarny Dec 3, 2026
8bd7a52
Plot: colour checks now fall back to a canvas element when an offscre…
agarny Dec 3, 2026
8186c25
Plot: colour checks are now cached, so that they don't run again on e…
agarny Dec 3, 2026
c13b560
Plot: updated the comments about isolating a trace to only mention di…
agarny Dec 3, 2026
f0aa6df
Plot: making an axis logarithmic (or not) now drops any pending wheel…
agarny Dec 3, 2026
6b60c5b
Plot: a reset of one axis no longer loses the wheel zoom that is pend…
agarny Dec 3, 2026
22df714
Plot: joining a synchronisation group with no zoom no longer drops a …
agarny Dec 3, 2026
e7b1a54
Demo: stopping the benchmark in any way during its live interaction n…
agarny Dec 3, 2026
d727081
Demo: the benchmark now forgets what it was waiting for once it is do…
agarny Dec 3, 2026
b9eb4cd
New version.
agarny Dec 3, 2026
78f5346
Updated our dependencies.
agarny Dec 3, 2026
481ff7b
Plot: tested that we forget the colours that we have checked once we …
agarny Dec 3, 2026
04fbd66
Plot: traces that have neither a line nor markers are exported to CSV…
agarny Dec 3, 2026
e754d7b
Plot: the autorange padding for markers now also depends on the thick…
agarny Dec 3, 2026
1e42948
Plot: a trace whose line is fully transparent now uses the colour of …
agarny Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 102 additions & 33 deletions README.md

Large diffs are not rendered by default.

80 changes: 40 additions & 40 deletions bun.lock

Large diffs are not rendered by default.

803 changes: 704 additions & 99 deletions demo/App.vue

Large diffs are not rendered by default.

30 changes: 10 additions & 20 deletions demo/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,23 @@ import type { PlotData, PlotTrace } from '../index';
// - unsorted: Lissajous curves, i.e. X values that are not sorted (so neither the culling of invisible points nor the
// column level of detail can be used, but the path level of detail can);
// - unsortedNoisy: Lissajous curves with some noise, i.e. the worst case for drawing many unsorted points (since the
// path level of detail can hardly simplify them);
// - largeOffsets: sine waves with timestamp-like X values and large Y values, i.e. values that must still be drawn
// precisely once zoomed in a lot (which they wouldn't be using 32-bit floats).
// path level of detail can hardly simplify them).

export type DataKind = 'smooth' | 'noisy' | 'steps' | 'gaps' | 'unsorted' | 'unsortedNoisy' | 'largeOffsets';
export type DataKind = 'smooth' | 'noisy' | 'steps' | 'gaps' | 'unsorted' | 'unsortedNoisy';

export const DATA_KINDS: Record<DataKind, string> = {
smooth: 'Smooth',
noisy: 'Noisy',
steps: 'Steps',
gaps: 'Gaps',
unsorted: 'Unsorted X',
unsortedNoisy: 'Unsorted X (noisy)',
largeOffsets: 'Large offsets'
unsortedNoisy: 'Unsorted X (noisy)'
};

const X_MAX = 10; // Last X value of our sorted data (whose first X value is 0), whatever our number of points.
const NB_OF_PERIODS = 5; // Number of periods of our curves, whatever our number of points.
const GAP_PERIOD = 0.1; // Fraction of our points between the start of two consecutive gaps.
const GAP_LENGTH = 0.01; // Fraction of our points that each gap spans.
const LARGE_X_OFFSET = 1e9; // First X value of our large-offset data, e.g., a number of seconds since 1970.
const LARGE_X_STEP = 1e-3; // Step between two X values of our large-offset data, e.g., one millisecond.
const LARGE_Y_OFFSET = 1e6; // Value around which the Y values of our large-offset data oscillate.
const NB_OF_SCALES = 4; // Number of scales of the Y values of our instances, i.e. 1, 10, 100, and 1,000.

const random = (seed: number): (() => number) => {
Expand Down Expand Up @@ -71,15 +65,14 @@ const traceColor = (index: number): string => {
return TABLEAU_10[index] ?? `hsl(${Math.round((index * 137.508) % 360)} 60% 50%)`;
};

const xValues = (kind: DataKind, nbOfPoints: number): Float64Array => {
const xValues = (nbOfPoints: number): Float64Array => {
// Return the X values of our (sorted) data.

const res = new Float64Array(nbOfPoints);
const step = kind === 'largeOffsets' ? LARGE_X_STEP : X_MAX / Math.max(1, nbOfPoints - 1);
const offset = kind === 'largeOffsets' ? LARGE_X_OFFSET : 0;
const step = X_MAX / Math.max(1, nbOfPoints - 1);

for (let i = 0; i < nbOfPoints; ++i) {
res[i] = offset + i * step;
res[i] = i * step;
}

return res;
Expand All @@ -100,8 +93,6 @@ const yValues = (kind: DataKind, nbOfPoints: number, phase: number, seed: number
res[i] = scale * (value + 0.3 * (nextRandom() - 0.5));
} else if (kind === 'steps') {
res[i] = (scale * Math.round(3 * value)) / 3;
} else if (kind === 'largeOffsets') {
res[i] = LARGE_Y_OFFSET + scale * value;
} else {
res[i] = scale * value;
}
Expand Down Expand Up @@ -151,8 +142,7 @@ const AXIS_TITLES: Record<DataKind, [x: string, y: string]> = {
steps: ['Time (<i>s</i>)', 'Level'],
gaps: ['Time (<i>s</i>)', 'Signal'],
unsorted: ['sin(3<i>t</i>)', 'sin(4<i>t</i>)'],
unsortedNoisy: ['sin(3<i>t</i>)', 'sin(4<i>t</i>)'],
largeOffsets: ['Time since 1970 (<i>s</i>)', 'Signal']
unsortedNoisy: ['sin(3<i>t</i>)', 'sin(4<i>t</i>)']
};

export const plotData = (kind: DataKind, nbOfTraces: number, nbOfPoints: number, instance: number): PlotData => {
Expand All @@ -162,7 +152,7 @@ export const plotData = (kind: DataKind, nbOfTraces: number, nbOfPoints: number,
// have different natural margins (see ALIGN_GROUP in App.vue).
// Note: our traces share their X values, if possible, to save memory.

const x = kind === 'unsorted' || kind === 'unsortedNoisy' ? undefined : xValues(kind, nbOfPoints);
const x = kind === 'unsorted' || kind === 'unsortedNoisy' ? undefined : xValues(nbOfPoints);
const scale = 10 ** (instance % NB_OF_SCALES);
const traces: PlotTrace[] = [];

Expand All @@ -173,10 +163,10 @@ export const plotData = (kind: DataKind, nbOfTraces: number, nbOfPoints: number,
: lissajousValues(kind, nbOfPoints, phase, 1000 * instance + i, scale);
const name = `Trace #${i + 1}`;

traces.push({ name, xValue: 'x', x: traceX, yValue: name, y: traceY, color: traceColor(i) });
traces.push({ name, xValue: 'x', x: traceX, yValue: name, y: traceY, line: { color: traceColor(i) } });
}

const [xAxisTitle, yAxisTitle] = AXIS_TITLES[kind];

return { xAxisTitle, yAxisTitle, traces };
return { xAxis: { title: xAxisTitle }, yAxis: { title: yAxisTitle }, traces };
};
7 changes: 7 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export type {
ContextMenuSeparator
} from './src/widgets/ContextMenuWidget.vue';
export type {
PlotAxesSettings,
PlotAxis,
PlotAxisSettings,
PlotTheme,
PlotContextMenuEvent,
PlotCsvExportEvent,
Expand All @@ -18,6 +21,10 @@ export type {
PlotCsvExportStartedEvent,
PlotData,
PlotImageExportEvent,
PlotLineStyle,
PlotLineType,
PlotMarkerStyle,
PlotMarkerType,
PlotMemoryUsage,
PlotPointCounts,
PlotRanges,
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"type": "module",
"types": "dist/index.d.ts",
"version": "0.20261202.2",
"version": "0.20261204.0",
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -62,18 +62,18 @@
"vue": "^3.5.2"
},
"devDependencies": {
"@biomejs/biome": "^2.6.9",
"@biomejs/biome": "^2.6.10",
"@happy-dom/global-registrator": "^21.0.4",
"@types/bun": "^1.4.5",
"@vitejs/plugin-vue": "^6.0.11",
"@vitejs/plugin-vue": "^6.1.1",
"@vue/tsconfig": "^0.9.1",
"puppeteer-core": "^25.19.0",
"stylelint": "^18.1.0",
"puppeteer-core": "^26.0.0",
"stylelint": "^18.2.0",
"stylelint-config-standard": "^41.1.0",
"typescript": "^7.0.2",
"typescript-6": "npm:typescript@^6.0.3",
"vite": "^8.4.0",
"vue": "^3.5.46",
"vite": "^8.4.1",
"vue": "^3.5.47",
"vue-tsc": "^3.3.14"
}
}
1 change: 0 additions & 1 deletion scripts/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const SCENARIOS: Scenario[] = [
{ id: 'noisy-3x1m', kind: 'noisy', traces: 3, points: 1_000_000, instances: 1 },
{ id: 'steps-3x1m', kind: 'steps', traces: 3, points: 1_000_000, instances: 1 },
{ id: 'gaps-3x1m', kind: 'gaps', traces: 3, points: 1_000_000, instances: 1 },
{ id: 'large-offsets-3x1m', kind: 'largeOffsets', traces: 3, points: 1_000_000, instances: 1 },
{ id: 'noisy-3x10m', kind: 'noisy', traces: 3, points: 10_000_000, instances: 1 },
{ id: 'noisy-30x1m', kind: 'noisy', traces: 30, points: 1_000_000, instances: 1 },
{ id: 'noisy-100x1k', kind: 'noisy', traces: 100, points: 1_000, instances: 1 },
Expand Down
155 changes: 155 additions & 0 deletions src/common/chunkedPathUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,53 @@ const chunkedCommands = (commands: Command[], maxNbOfPoints?: number): Command[]
return path.paths.map((recorded) => recorded.commands);
};

const chunkedDashedCommands = (commands: Command[], maxNbOfPoints: number): [Command[][], number[]] => {
// Return the commands of each of the paths into which the given commands get split, keeping track of their dash
// offset, and their dash offsets.

const path = createChunkedPath(recordedPath, maxNbOfPoints, true);

addCommands(path, commands);

return [path.paths.map((recorded) => recorded.commands), path.dashOffsets];
};

const segmentDashPositions = (paths: Command[][], dashOffsets: number[]): Map<string, number> => {
// Return where each segment of the given paths starts in its dash pattern, i.e. how far along its polyline it starts,
// plus the dash offset of its path, knowing that the dash pattern of each polyline of a path starts again from the
// dash offset of that path, like with a canvas or SVG. A segment is identified by the X values of its points.

const res = new Map<string, number>();

paths.forEach((path: Command[], index: number) => {
let position = 0;
let previous: Command | undefined;

for (const command of path) {
const [type, x, y] = command;

if (type === 'M' || !previous) {
position = dashOffsets[index] ?? 0;
} else {
const key = `${previous[1]},${x}`;
const expected = res.get(key);

if (expected === undefined) {
res.set(key, position);
} else {
expect(position).toBeCloseTo(expected, 9);
}

position += Math.hypot(x - previous[1], y - previous[2]);
}

previous = command;
}
});

return res;
};

const polyline = (from: number, to: number): Command[] => {
// Return a polyline from the given point to the given point, where point i is (i, 10 * i).

Expand Down Expand Up @@ -194,6 +241,114 @@ describe('createChunkedPath()', () => {
expect(nbOfPoints(MAX_PATH_POINTS)).toEqual([MAX_PATH_POINTS, 3]);
});

it('keeps track of the dash offset of each path, if requested', () => {
const commands: Command[] = [
['M', 0, 0],
['L', 3, 4],
['L', 6, 8],
['L', 9, 12],
['L', 12, 16]
];

expect(chunkedDashedCommands(commands, 3)).toEqual([
[
[
['M', 0, 0],
['L', 3, 4],
['L', 6, 8]
],
[
['M', 3, 4],
['L', 6, 8],
['L', 9, 12]
],
[
['M', 6, 8],
['L', 9, 12],
['L', 12, 16]
]
],
[0, 5, 10]
]);
expect(chunkedDashedCommands(commands, 5)).toEqual([[commands], [0]]);
});

it('has no dash offsets, unless requested', () => {
const path = createChunkedPath(recordedPath, 3);

addCommands(path, polyline(0, 7));

expect(path.paths.length).toBe(6);
expect(path.dashOffsets).toEqual([0, 0, 0, 0, 0, 0]);
});

it('starts a polyline in a new path if the current path has a dash offset', () => {
const commands: Command[] = [
['M', 0, 0],
['L', 3, 4],
['L', 6, 8],
['L', 9, 12],
['M', 20, 0],
['L', 23, 4]
];

expect(chunkedDashedCommands(commands, 4)).toEqual([
[
[
['M', 0, 0],
['L', 3, 4],
['L', 6, 8],
['L', 9, 12]
],
[
['M', 20, 0],
['L', 23, 4]
]
],
[0, 0]
]);
expect(chunkedDashedCommands(commands, 3)).toEqual([
[
[
['M', 0, 0],
['L', 3, 4],
['L', 6, 8]
],
[
['M', 3, 4],
['L', 6, 8],
['L', 9, 12]
],
[
['M', 20, 0],
['L', 23, 4]
]
],
[0, 5, 0]
]);
});

it('draws random dashed polylines as if they were one path', () => {
const random = randomGenerator(7);

for (let k = 0; k < 500; ++k) {
const commands = randomCommands(random, 1 + Math.floor(200 * random()));
const maxNbOfPoints = 3 + Math.floor(20 * random());
const [paths, dashOffsets] = chunkedDashedCommands(commands, maxNbOfPoints);

for (const path of paths) {
expect(path.length).toBeLessThanOrEqual(maxNbOfPoints);
}

// Our paths have the same commands, once the points that they carry on from are removed, and each segment starts
// at the same place in its dash pattern as it would in one path.

expect(paths.length).toBe(dashOffsets.length);
expect(unchunkedCommands(paths)).toEqual(commands);
expect(segmentDashPositions(paths, dashOffsets)).toEqual(segmentDashPositions([commands], [0]));
}
});

it('draws random polylines as if they were one path', () => {
const random = randomGenerator(42);

Expand Down
Loading