From 2456896b7a3afc775c1f454432cd8d677b63733a Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 2 Dec 2026 12:58:32 +1300 Subject: [PATCH 01/35] Plot: replaced `xAxisTitle`, `yAxisTitle`, `xAxisRange`, and `yAxisRange` with `xAxis` and `yAxis` (`PlotAxis`). --- README.md | 25 ++++++++++++------- demo/App.vue | 2 +- demo/data.ts | 2 +- index.ts | 1 + src/widgets/PlotWidget.vue | 49 +++++++++++++++++++++----------------- 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 289bc64..9e86377 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,8 @@ import '@opencor/plot/style.css'; const x = Float64Array.from({ length: 1000 }, (_, i) => i / 100); const data: PlotData = { - xAxisTitle: 'Time (s)', - yAxisTitle: 'Voltage (mV)', + xAxis: { title: 'Time (s)' }, + yAxis: { title: 'Voltage (mV)' }, traces: [ { name: 'V', @@ -76,7 +76,8 @@ The component is the default export of `@opencor/plot`, and is also exported as | Type | Definition | Description | |---|---|---| -| `PlotData` | `{ traces, xAxisTitle?, yAxisTitle?, xAxisRange?, yAxisRange? }` | The data to plot (see [Data](#data)). | +| `PlotData` | `{ traces, xAxis?, yAxis? }` | The data to plot (see [Data](#data)). | +| `PlotAxis` | `{ title?, range? }` | An axis of the plot (see [Data](#data)). | | `PlotTrace` | `{ name, x, y, xValue, yValue, color, traceId?, legendRank?, runLabel? }` | A trace to plot (see [Data](#data)). | | `PlotTheme` | `'system' \| 'light' \| 'dark'` | The value of the [`theme`](#props) prop. | | `PlotGroup` | `string \| symbol` | A group of plots, i.e. the value of the [`xAxisAlign`](#props), [`xAxisSync`](#props), [`yAxisAlign`](#props), and [`yAxisSync`](#props) props. A symbol is unique, so that unrelated parts of a page can't end up in the same group by using the same string. | @@ -103,8 +104,14 @@ The component is the default export of `@opencor/plot`, and is also exported as | Property | Type | Description | |---|---|---| | `traces` | [`PlotTrace`](#types)`[]` | The traces to plot. | -| `xAxisTitle`, `yAxisTitle` | `string` | The axis titles. | -| `xAxisRange`, `yAxisRange` | `[number, number]` | The range of an axis when the zoom is reset. By default, it fits the data. | +| `xAxis`, `yAxis` | [`PlotAxis`](#types) | The axes. | + +[`PlotAxis`](#types): + +| Property | Type | Description | +|---|---|---| +| `title` | `string` | The title of the axis. | +| `range` | `[number, number]` | The range of the axis when the zoom is reset. By default, it fits the data. | [`PlotTrace`](#types): @@ -178,8 +185,8 @@ const linked = ref(true); const t = Float64Array.from({ length: 1000 }, (_, i) => i / 100); const voltageData: PlotData = { - xAxisTitle: 'Time (s)', - yAxisTitle: 'Voltage (mV)', + xAxis: { title: 'Time (s)' }, + yAxis: { title: 'Voltage (mV)' }, traces: [ { name: 'V', @@ -193,8 +200,8 @@ const voltageData: PlotData = { }; const currentData: PlotData = { - xAxisTitle: 'Time (s)', - yAxisTitle: 'Current (µA/cm²)', + xAxis: { title: 'Time (s)' }, + yAxis: { title: 'Current (µA/cm²)' }, traces: [ { name: 'I', diff --git a/demo/App.vue b/demo/App.vue index 1d78563..eba4a4b 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -388,7 +388,7 @@ const liveDatasets = (nbOfPoints: number, xAxisRanges: ([number, number] | undef return { ...data, - xAxisRange: xAxisRanges[instance], + xAxis: { ...data.xAxis, range: xAxisRanges[instance] }, traces: data.traces.map((trace) => { let x = xViews.get(trace.x); diff --git a/demo/data.ts b/demo/data.ts index 2cb6704..b905a6c 100644 --- a/demo/data.ts +++ b/demo/data.ts @@ -178,5 +178,5 @@ export const plotData = (kind: DataKind, nbOfTraces: number, nbOfPoints: number, const [xAxisTitle, yAxisTitle] = AXIS_TITLES[kind]; - return { xAxisTitle, yAxisTitle, traces }; + return { xAxis: { title: xAxisTitle }, yAxis: { title: yAxisTitle }, traces }; }; diff --git a/index.ts b/index.ts index 3dc35c7..b86a3c6 100644 --- a/index.ts +++ b/index.ts @@ -10,6 +10,7 @@ export type { ContextMenuSeparator } from './src/widgets/ContextMenuWidget.vue'; export type { + PlotAxis, PlotTheme, PlotContextMenuEvent, PlotCsvExportEvent, diff --git a/src/widgets/PlotWidget.vue b/src/widgets/PlotWidget.vue index b30fb3d..444b0ab 100644 --- a/src/widgets/PlotWidget.vue +++ b/src/widgets/PlotWidget.vue @@ -74,16 +74,16 @@ @keydown="onRangeEditorKeyDown" @blur="closeRangeEditor(true)" >{{ rangeEditor.text }} -
-
- + {{ hover.x }}
@@ -253,20 +253,25 @@ export interface PlotTrace { runLabel?: string; } +/** An axis of the plot. */ + +export interface PlotAxis { + /** The title of the axis. It can contain a little HTML (see `PlotTrace.name`). */ + title?: string; + /** The range of the axis when the zoom is reset. By default, it fits the data. */ + range?: [number, number]; +} + /** * The data to plot. It is not watched, so to update it, give the plot a new `PlotData` object (see * {@link https://github.com/opencor/plot#large-and-live-data | Large and live data}). */ export interface PlotData { - /** The title of the X axis. It can contain a little HTML (see `PlotTrace.name`). */ - xAxisTitle?: string; - /** The title of the Y axis. It can contain a little HTML (see `PlotTrace.name`). */ - yAxisTitle?: string; - /** The range of the X axis when the zoom is reset. By default, it fits the data. */ - xAxisRange?: [number, number]; - /** The range of the Y axis when the zoom is reset. By default, it fits the data. */ - yAxisRange?: [number, number]; + /** The X axis. */ + xAxis?: PlotAxis; + /** The Y axis. */ + yAxis?: PlotAxis; /** The traces to plot. */ traces: PlotTrace[]; } @@ -2684,7 +2689,7 @@ const ownNaturalRange = (u: uPlot, axisKey: AxisKey): Range | undefined => { // If a range was given for the axis and it can be plotted (i.e. it is finite and, for a logarithmic axis, positive, // see plotValue()), then we use it. - const givenRange = axisKey === 'x' ? props.data.xAxisRange : props.data.yAxisRange; + const givenRange = (axisKey === 'x' ? props.data.xAxis : props.data.yAxis)?.range; const range: Range | undefined = givenRange && [plotValue(axisKey, givenRange[0]), plotValue(axisKey, givenRange[1])]; if (range && Number.isFinite(range[0]) && Number.isFinite(range[1])) { @@ -4995,8 +5000,8 @@ const plainText = (html: string | undefined): string => { const plotLabel = vue.computed(() => { // Our plot, as described to assistive technologies, i.e. based on the titles of our axes, if any. - const xAxisTitle = plainText(props.data.xAxisTitle); - const yAxisTitle = plainText(props.data.yAxisTitle); + const xAxisTitle = plainText(props.data.xAxis?.title); + const yAxisTitle = plainText(props.data.yAxis?.title); if (xAxisTitle && yAxisTitle) { return `Plot of ${yAxisTitle} against ${xAxisTitle}`; @@ -5529,7 +5534,7 @@ let naturalYAxisSize = 0; const yAxisTitleSize = (): number => { // Return the size of our Y axis title, if any. - return props.data.yAxisTitle ? Y_AXIS_TITLE_SIZE : 0; + return props.data.yAxis?.title ? Y_AXIS_TITLE_SIZE : 0; }; const yAxisSize = (): number => { @@ -5589,7 +5594,7 @@ const rightMargin = (): number => { const naturalBottomMargin = (): number => { // Return the size of our X axis, including its title, if any (see the X axis in createPlot()). - return props.data.xAxisTitle ? X_AXIS_SIZE_WITH_TITLE + X_AXIS_TITLE_SIZE : X_AXIS_SIZE_WITHOUT_TITLE; + return props.data.xAxis?.title ? X_AXIS_SIZE_WITH_TITLE + X_AXIS_TITLE_SIZE : X_AXIS_SIZE_WITHOUT_TITLE; }; const topPadding = (): number => { @@ -7323,8 +7328,8 @@ const createPlot = (width: number, height: number): void => { ...axis, scale: 'x', side: 2, - size: props.data.xAxisTitle ? X_AXIS_SIZE_WITH_TITLE : X_AXIS_SIZE_WITHOUT_TITLE, - label: props.data.xAxisTitle ? '' : undefined, + size: props.data.xAxis?.title ? X_AXIS_SIZE_WITH_TITLE : X_AXIS_SIZE_WITHOUT_TITLE, + label: props.data.xAxis?.title ? '' : undefined, labelSize: X_AXIS_TITLE_SIZE, splits: axisSplits('x'), values: axisValues('x') @@ -7334,7 +7339,7 @@ const createPlot = (width: number, height: number): void => { scale: 'y', side: 3, size: yAxisSize, - label: props.data.yAxisTitle ? '' : undefined, + label: props.data.yAxis?.title ? '' : undefined, labelSize: Y_AXIS_TITLE_SIZE, labelGap: Y_AXIS_TITLE_GAP, splits: axisSplits('y'), @@ -7451,7 +7456,7 @@ const updatePlot = (): void => { // Reset our zoom and forget our last autoranges (see naturalRange()) if we are plotting something else. - const titles = `${props.data.xAxisTitle ?? ''}::${props.data.yAxisTitle ?? ''}`; + const titles = `${props.data.xAxis?.title ?? ''}::${props.data.yAxis?.title ?? ''}`; if (titles !== zoomTitles) { // Note: we keep the zoom range of an axis that is synchronised with other plots, since it is theirs too (see From e88475556a270d40e2293a2e9e85684401287419 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Wed, 2 Dec 2026 23:32:29 +1300 Subject: [PATCH 02/35] Plot: allowed only one end of an axis range to be set (e.g., `[0, null]`), with the other end fitting the data. --- README.md | 2 +- demo/App.vue | 30 +++++++- src/common/rangeUtils.test.ts | 121 +++++++++++++++++++++++++++++- src/common/rangeUtils.ts | 83 +++++++++++++++++++++ src/widgets/PlotWidget.vue | 135 +++++++++++++++++++--------------- 5 files changed, 307 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 9e86377..4d2c67e 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ The component is the default export of `@opencor/plot`, and is also exported as | Property | Type | Description | |---|---|---| | `title` | `string` | The title of the axis. | -| `range` | `[number, number]` | The range of the axis when the zoom is reset. By default, it fits the data. | +| `range` | `[number \| null, number \| null]` | The range of the axis when the zoom is reset. By default, it fits the data. An end that is `null` (or that can't be plotted, e.g., a non-positive end along a logarithmic axis) fits the data, while the other end is kept (e.g., `[0, null]` for an axis that starts at 0). If there is no data to fit or it is all beyond the end that is kept, then the axis extends from that end by 1 or 1ppm of it, whichever is bigger. | [`PlotTrace`](#types): diff --git a/demo/App.vue b/demo/App.vue index eba4a4b..1206703 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -1,7 +1,7 @@ @@ -20,15 +20,14 @@ diff --git a/src/widgets/PlotWidget.vue b/src/widgets/PlotWidget.vue index ce1434d..e3d7e89 100644 --- a/src/widgets/PlotWidget.vue +++ b/src/widgets/PlotWidget.vue @@ -147,10 +147,8 @@ @focus="onLegendFocus($event, legendItem.index)" @blur="highlightTrace(null)" > - @@ -164,7 +162,7 @@ {{ hover.x }}
- + {{ row.value }}
@@ -259,11 +257,9 @@ export interface PlotTrace { */ y: Float64Array; /** - * The colour of the trace, as a CSS colour (e.g., `'#1f77b4'`), which is that of its line and markers, unless its - * line style says otherwise (see `line`). + * The optional style of the line of the trace, which also gives the colour of its markers (a solid line, 2 pixels + * thick, of one of our default colours, by default). */ - color: string; - /** The optional style of the line of the trace (a solid line of the colour of the trace, 2 pixels thick, by default). */ line?: PlotLineStyle; /** The optional rank of the trace in the legend (lower ranks first, 1000 by default). */ legendRank?: number; @@ -286,8 +282,10 @@ export interface PlotLineStyle { /** The type of the line (`'solid'` by default). */ type?: PlotLineType; /** - * The colour of the line, as a CSS colour, which can be transparent (e.g., `'#1f77b480'` or - * `'rgba(31, 119, 180, 0.5)'`). By default, it is the colour of the trace. + * The colour of the line, and of the markers of its trace, as a CSS colour, which can be transparent (e.g., + * `'#1f77b4'`, `'#1f77b480'`, or `'rgba(31, 119, 180, 0.5)'`). By default, it is one of Tableau 10's colours, based + * on the position of its trace in `PlotData.traces` (i.e. `'#4e79a7'` for the first trace, `'#f28e2b'` for the second + * one, etc., and `'#4e79a7'` again for the eleventh one). */ color?: string; /** The thickness of the line, in pixels (2 by default). */ @@ -1199,14 +1197,11 @@ vue.watch( // Note #1: our legend lists our traces by increasing legend rank (and then in the order in which they are given), while // our traces are drawn in the order in which they are given. // Note #2: the swatch of a legend item (see PlotSwatchWidget.vue), which our hover tooltip also uses, shows the line of -// its trace, if any, and its markers, if any (in the colour of the line of its trace and in the colour of its -// trace, respectively). +// its trace, if any, and its markers, if any. interface LegendItem { index: number; color: string; - lineColor: string; - markerColor: string; line: lineStyleUtils.LegendLine | undefined; name: string; visible: boolean; @@ -1224,9 +1219,7 @@ const legendItems = vue.computed(() => { return { index, - color: traceColor(index), - lineColor: lineStyle.color, - markerColor: trace.color, + color: lineStyle.color, line: lineStyleUtils.legendLine(lineStyle.type, lineStyle.thickness), name: trace.name, visible: visibilities[index] ?? true, @@ -2260,13 +2253,13 @@ const svgLegend = (origin: DOMRect, scale: number, colors: ExportColors): string const dashAttributes = line.dash.length ? ` stroke-dasharray="${line.dash.map(svgNumber).join(' ')}"` : ''; res.push( - `` + `` ); } if (legendItem.markers) { res.push( - `` + `` ); } } @@ -2411,20 +2404,20 @@ const svgDocument = (scale: number = 1): SvgDocument => { for (let seriesIndex = 1; seriesIndex < u.series.length; ++seriesIndex) { const [xValues, yValues] = seriesData(u, seriesIndex) ?? []; - const color = props.data.traces[seriesIndex - 1]?.color; + const lineStyle = traceLineStyles.value[seriesIndex - 1]; - if (!u.series[seriesIndex]?.show || !xValues || !yValues || !color) { + if (!u.series[seriesIndex]?.show || !xValues || !yValues || !lineStyle) { continue; } - const lineStyle = seriesLineStyle(seriesIndex); + const color = lineStyle.color; if (lineStyle.type !== 'none') { const traceLineWidth = lineStyle.thickness * scale; const dash = lineStyleUtils.dashPattern(lineStyle.type, lineStyle.thickness, scale); const tracePath = createChunkedPath(svgPath, MAX_PATH_POINTS, dash.length > 0); const dashAttributes = dash.length ? ` stroke-dasharray="${dash.map(svgNumber).join(' ')}"` : ''; - const traceAttributes = `${svgPaint('stroke', lineStyle.color)} stroke-width="${svgNumber(traceLineWidth)}"${dashAttributes} stroke-linejoin="round" fill="none" clip-path="url(#${traceClipPath(traceLineWidth)})"`; + const traceAttributes = `${svgPaint('stroke', color)} stroke-width="${svgNumber(traceLineWidth)}"${dashAttributes} stroke-linejoin="round" fill="none" clip-path="url(#${traceClipPath(traceLineWidth)})"`; const simplifiedPath = new SimplifiedPath(tracePath, 0); linearPath( @@ -2800,13 +2793,13 @@ const seriesData = (u: uPlot, seriesIndex: number): [Float64Array, Float64Array] return (u.data as unknown as [null, ...[Float64Array, Float64Array][]])[seriesIndex] ?? undefined; }; -// The style of the line of our traces (see PlotLineStyle), and the colour of our traces, i.e. that of their line, if -// they have one, or their own colour otherwise (e.g., for their hover points, live points, and hover tooltip rows). +// The style of the line of our traces (see PlotLineStyle), whose colour is also that of their markers, hover points, +// live points, legend swatch, and hover tooltip swatch. const NO_LINE_STYLE: lineStyleUtils.ResolvedLineStyle = { type: 'none', color: 'transparent', thickness: 0 }; const traceLineStyles = vue.computed(() => - props.data.traces.map((trace: PlotTrace) => lineStyleUtils.resolvedLineStyle(trace.line, trace.color)) + props.data.traces.map((trace: PlotTrace, index: number) => lineStyleUtils.resolvedLineStyle(trace.line, index)) ); const seriesLineStyle = (seriesIndex: number): lineStyleUtils.ResolvedLineStyle => { @@ -2824,19 +2817,11 @@ const seriesLineWidth = (seriesIndex: number): number => { }; const seriesColor = (seriesIndex: number): string => { - // Return the colour of the line of the given series. + // Return the colour of the given series, i.e. that of the line of its trace. return seriesLineStyle(seriesIndex).color; }; -const traceColor = (index: number): string => { - // Return the colour of the given trace, i.e. that of its line, if it has one, or its own colour otherwise. - - const lineStyle = traceLineStyles.value[index]; - - return lineStyle && lineStyle.type !== 'none' ? lineStyle.color : (props.data.traces[index]?.color ?? 'transparent'); -}; - const hasMarkers = (xValues?: Float64Array, yValues?: Float64Array): boolean => { // Like Plotly, a trace with fewer than 20 points also has markers. @@ -6945,7 +6930,7 @@ const updateLivePoints = (u: uPlot | undefined): void => { // Make sure that our trace is visible and that it has some data. const [xValues, yValues] = seriesData(u, seriesIndex) ?? []; - const color = props.data.traces[seriesIndex - 1] ? traceColor(seriesIndex - 1) : undefined; + const color = traceLineStyles.value[seriesIndex - 1]?.color; if (!u.series[seriesIndex]?.show || !xValues || !yValues || !color) { continue; From 7ab5c5ff17ba1560cc70aa71664dba402bd3f157 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 3 Dec 2026 18:59:18 +1300 Subject: [PATCH 10/35] Plot: added a `marker` property to `PlotTrace` to set the type, size, fill, outline colour, and thickness of the markers of a trace, which then has markers whatever its number of points (unless their type is none). --- README.md | 39 +- demo/App.vue | 95 ++++- index.ts | 2 + src/common/lineStyleUtils.ts | 3 +- src/common/markerStyleUtils.test.ts | 473 ++++++++++++++++++++++++ src/common/markerStyleUtils.ts | 437 ++++++++++++++++++++++ src/widgets/PlotSwatchWidget.vue | 37 +- src/widgets/PlotWidget.vue | 551 ++++++++++++++++++++++------ 8 files changed, 1494 insertions(+), 143 deletions(-) create mode 100644 src/common/markerStyleUtils.test.ts create mode 100644 src/common/markerStyleUtils.ts diff --git a/README.md b/README.md index e466a85..4a05f1b 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,11 @@ The component is the default export of `@opencor/plot`, and is also exported as |---|---|---| | `PlotData` | `{ traces, xAxis?, yAxis? }` | The data to plot (see [Data](#data)). | | `PlotAxis` | `{ title?, range?, grid?, log? }` | An axis of the plot (see [Data](#data)). | -| `PlotTrace` | `{ name, x, y, xValue, yValue, line?, traceId?, legendRank?, runLabel? }` | A trace to plot (see [Data](#data)). | +| `PlotTrace` | `{ name, x, y, xValue, yValue, line?, marker?, traceId?, legendRank?, runLabel? }` | A trace to plot (see [Data](#data)). | | `PlotLineStyle` | `{ type?, color?, thickness? }` | The style of the line of a trace (see [Data](#data)). | | `PlotLineType` | `'none' \| 'solid' \| 'dash' \| 'dot' \| 'dashDot' \| 'dashDotDot'` | The type of the line of a trace (see [Data](#data)). | +| `PlotMarkerStyle` | `{ type?, size?, fill?, lineColor?, lineThickness? }` | The style of the markers of a trace (see [Data](#data)). | +| `PlotMarkerType` | `'none' \| 'square' \| 'circle' \| 'diamond' \| 'xCross' \| 'plus' \| 'star' \| 'triangleUp' \| 'triangleDown' \| 'triangleLeft' \| 'triangleRight' \| 'hDash' \| 'vDash'` | The type of the markers of a trace (see [Data](#data)). | | `PlotTheme` | `'system' \| 'light' \| 'dark'` | The value of the [`theme`](#props) prop. | | `PlotGroup` | `string \| symbol` | A group of plots, i.e. the value of the [`xAxisAlign`](#props), [`xAxisSync`](#props), [`yAxisAlign`](#props), and [`yAxisSync`](#props) props. A symbol is unique, so that unrelated parts of a page can't end up in the same group by using the same string. | | `PlotAxesSettings` | `{ x: PlotAxisSettings; y: PlotAxisSettings }` | The payload of the [`axesUpdated`](#events) event, i.e. the current settings of the axes, which the user can change using the context menu, so that the data can say the same (see [`PlotAxis`](#types)). | @@ -125,7 +127,8 @@ The component is the default export of `@opencor/plot`, and is also exported as | `name` | `string` | The name of the trace, as shown in the legend, the hover tooltip, and the CSV export. | | `x`, `y` | `Float64Array` | The X and Y values of the trace. | | `xValue`, `yValue` | `string` | What the X and Y values are (e.g., the name of a model variable), used in the CSV export. | -| `line` | [`PlotLineStyle`](#types) | The optional style of the line of the trace, which also gives the colour of its markers (see below). | +| `line` | [`PlotLineStyle`](#types) | The optional style of the line of the trace, which also gives the default colour of its markers (see below). | +| `marker` | [`PlotMarkerStyle`](#types) | The optional style of the markers of the trace (see below). Without it, the trace has circle markers if it has fewer than 20 points, and no markers otherwise. | | `traceId` | `string` | An optional identifier that keeps the visibility of the trace when the data is updated. Otherwise, the trace is identified by its `name`, `xValue`, `yValue`, and `runLabel` (and, among traces that have the same ones, by their order), or by its position if it doesn't have a `name`, `xValue`, and `yValue`. | | `legendRank` | `number` | The optional rank of the trace in the legend (lower ranks first, 1000 by default). | | `runLabel` | `string` | An optional label that tells apart the X column of the trace from those of other runs in the CSV export. | @@ -135,7 +138,7 @@ The component is the default export of `@opencor/plot`, and is also exported as | Property | Type | Description | |---|---|---| | `type` | [`PlotLineType`](#types) | The type of the line: no line at all (`'none'`), a solid line (`'solid'`, the default), or a dashed line, with dashes (`'dash'`), dots (`'dot'`), dashes and dots (`'dashDot'`), or dashes and pairs of dots (`'dashDotDot'`). The dashes, dots, and gaps of a dashed line are 4, 1, and 2 times its thickness (or 8, 2, and 4 pixels if it is less than 2 pixels thick, so that it still looks dashed). | -| `color` | `string` | The colour of the line, and of the markers of its trace, as a CSS colour, which can be transparent (e.g., `'#1f77b4'`, `'#1f77b480'`, or `'rgba(31, 119, 180, 0.5)'`). By default, it is one of [Tableau 10](https://www.tableau.com/blog/colors-upgrade-tableau-10-56782)'s colours, based on the position of its trace in `traces`, i.e. `'#4e79a7'` (blue), `'#f28e2b'` (orange), `'#e15759'` (red), `'#76b7b2'` (teal), `'#59a14f'` (green), `'#edc948'` (yellow), `'#b07aa1'` (purple), `'#ff9da7'` (pink), `'#9c755f'` (brown), `'#bab0ac'` (grey), and then `'#4e79a7'` again, etc. | +| `color` | `string` | The colour of the line (and, by default, of the markers of its trace), as a CSS colour, which can be transparent (e.g., `'#1f77b4'`, `'#1f77b480'`, or `'rgba(31, 119, 180, 0.5)'`). By default, it is one of [Tableau 10](https://www.tableau.com/blog/colors-upgrade-tableau-10-56782)'s colours, based on the position of its trace in `traces`, i.e. `'#4e79a7'` (blue), `'#f28e2b'` (orange), `'#e15759'` (red), `'#76b7b2'` (teal), `'#59a14f'` (green), `'#edc948'` (yellow), `'#b07aa1'` (purple), `'#ff9da7'` (pink), `'#9c755f'` (brown), `'#bab0ac'` (grey), and then `'#4e79a7'` again, etc. | | `thickness` | `number` | The thickness of the line, in pixels (2 by default). | For example, a dashed red line that is 3 pixels thick and half transparent: @@ -153,12 +156,40 @@ const trace: PlotTrace = { The style of a line is used wherever its trace is drawn: the plot, its legend and hover tooltip (whose swatches show a dashed line with a dash pattern of its own, which fits in them, so that it can be told apart from others), its hover points, its live point, and its copied and exported images (including SVG, where a transparent colour uses an opacity attribute, since SVG 1.1 has no transparent colours). +[`PlotMarkerStyle`](#types): + +| Property | Type | Description | +|---|---|---| +| `type` | [`PlotMarkerType`](#types) | The type of the markers: no markers at all (`'none'`), a square (`'square'`), a circle (`'circle'`, the default), a diamond (`'diamond'`), an X cross (`'xCross'`), a plus (`'plus'`), a star (`'star'`, i.e. a plus and an X cross), a triangle that points up (`'triangleUp'`), down (`'triangleDown'`), left (`'triangleLeft'`), or right (`'triangleRight'`), or a horizontal (`'hDash'`) or vertical (`'vDash'`) dash. | +| `size` | `number` | The size of the markers, in pixels (6 by default), i.e. the width and height of the square in which the shape of a marker fits, outline excluded (like Plotly). | +| `fill` | `string` | The colour inside the markers, as a CSS colour, which can be transparent (e.g., `'transparent'` for hollow markers). By default, it is the colour of the line of the trace. An X cross, a plus, a star, and a dash have no inside, so they have no fill. | +| `lineColor` | `string` | The colour of the outline of the markers (or of the lines of an X cross, a plus, a star, or a dash), as a CSS colour, which can be transparent. By default, it is the colour of the line of the trace. | +| `lineThickness` | `number` | The thickness of the outline of the markers (or of the lines of an X cross, a plus, a star, or a dash), in pixels (1 by default, or 0 if the outline has the same colour as the fill, as it does by default, since it would then only make the markers look bigger). An outline is centred on the edge of the shape of a marker, so it makes it look bigger by its thickness (e.g., 7 pixels for a 6-pixel marker with a 1-pixel outline). It can be 0 for markers that only have a fill. | + +For example, hollow red diamonds that are 10 pixels big, without a line: + +```ts +const trace: PlotTrace = { + name: 'Measurements', + xValue: 'time', + x, + yValue: 'V', + y, + line: { type: 'none' }, + marker: { type: 'diamond', size: 10, fill: 'transparent', lineColor: '#d62728', lineThickness: 2 } +}; +``` + +Giving a marker style, even an empty one (i.e. `marker: {}`), means that the trace has markers whatever its number of points, and `type: 'none'` means that it has no markers at all. A marker which fill and outline have the same colour (as they do by default) and which has an outline is drawn as one filled shape, including its outline, so that it looks the same, even if that colour is transparent (rather than its outline showing over its fill). Markers are drawn one by one, so a marker covers those drawn before it, and transparent markers get darker where they overlap. A trace with many points gets at most one marker per pixel (since more markers would look the same, but would be slower to draw). The axes get padded so that the markers of the points at the end of an axis are fully shown (by an amount that depends on their size). + +Like the line of a trace, its markers are used wherever its trace is drawn: the plot, its legend and hover tooltip (whose swatches show its line, if any, and its marker, if any, up to 10 pixels big), its hover points (which are its marker, a third bigger, and at least 8 pixels big), and its copied and exported images (including SVG). A trace that has neither a line nor markers is not drawn at all, and it is not listed in the legend or the hover tooltip (but it is still exported to CSV). + A dashed line is dashed along the path that is actually drawn, which goes through up to four points per pixel column (see [Large and live data](#large-and-live-data)). So, a dense trace (e.g., noisy data) looks solid, like a solid line would, since its pixel columns are drawn as vertical segments. Its dash pattern also starts again where the trace comes back into the plotting area (e.g., when zoomed in) or carries on after a gap. Notes: - Titles and trace names can contain a little HTML (`b`, `br`, `code`, `em`, `i`, `strong`, `sub`, and `sup`). Anything else is removed. - A trace can be a function of X (e.g., against time) or not (e.g., a phase plot). A point with a non-finite X or Y value (e.g., `NaN`) is a gap in its trace. -- A trace with fewer than 20 points is also drawn with markers. +- A trace with fewer than 20 points also has circle markers, unless it has a [`marker`](#data) style. ### Large and live data diff --git a/demo/App.vue b/demo/App.vue index 58f3c9d..61963e6 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -157,6 +157,34 @@ +
+

Markers

+ + + + +

Plot