Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Contents:
- [Events](#events)
- [Methods](#methods)
- [Interaction](#interaction)
- [Context menu items](#context-menu-items)
- [Theming](#theming)
- [Development](#development)
- [Benchmarking](#benchmarking)
Expand Down Expand Up @@ -88,7 +89,7 @@ The component is the default export of `@opencor/plot`, and is also exported as
| `PlotImageExportEvent` | `{ action: 'copy' \| 'export'; format: 'jpeg' \| 'png' \| 'svg' \| 'webp'; success: boolean }` | The payload of the [`imageExport`](#events) event: whether the plot was copied to the clipboard (always as PNG) or exported to an image file, in which format, and whether it worked. |
| `PlotContextMenuEvent` | `{ clientX: number; clientY: number; usingKeyboard: boolean; items: ContextMenuItem[] }` | The payload of the [`contextMenu`](#events) event: where the context menu was requested (in client coordinates), whether it was requested using the keyboard (in which case the custom menu should take the keyboard focus), and the items that our context menu would have shown. These items reflect the plot as it was when the context menu was requested and don't get updated if the data changes while the custom context menu is shown, but their commands always act on the plot as it is when they are chosen. |
| `ContextMenuItem` | `ContextMenuAction \| ContextMenuSeparator \| ContextMenuHeader` | An item of a context menu. |
| `ContextMenuAction` | `{ label: string; icon?: IconName; checked?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), the `command` to call when it is chosen, and its submenu `items`, if any. |
| `ContextMenuAction` | `{ id?: string; label: string; icon?: IconName; checked?: boolean; command?: () => void; items?: ContextMenuItem[] }` | An action: its `id` (so that it can be found, see [Context menu items](#context-menu-items)), its `label`, its `icon`, whether it is checked (only for a checkable action, e.g., to make an axis logarithmic), the `command` to call when it is chosen, and its submenu `items`, if any. |
| `ContextMenuSeparator` | `{ separator: true }` | A separator. |
| `ContextMenuHeader` | `{ header: string }` | A header that can't be chosen, e.g., the full name of a trace when the context menu is requested from its legend item. It can contain a little HTML (see [Data](#data)). |
| `IconName` | `'angle-right' \| 'arrows-h' \| 'arrows-v' \| 'chart-line' \| 'check' \| 'copy' \| 'download' \| 'eye' \| 'image' \| 'pencil' \| 'refresh' \| 'search-minus' \| 'search-plus'` | The name of an icon (from [PrimeIcons](https://primevue.org/icons/)). |
Expand Down Expand Up @@ -227,6 +228,7 @@ To keep track of the ranges of the axes of a plot (e.g., to restore them later),
| `yAxisSync` | [`PlotGroup`](#types) | | The group of plots whose Y axis is to be synchronised with this plot's, i.e. which share the range and the scale of their Y axis, so that zooming, panning, or resetting the zoom of one of them does the same to the others, as does making its Y axis logarithmic (or not). Their Y axes always show the same range, which, until one of them gets zoomed or panned, fits the data of all of them. |
| `appendTo` | `HTMLElement \| string` | `body` | Where to append our overlays (context menu, hover tooltip, etc.). |
| `customContextMenu` | `boolean` | `false` | Whether to emit a [`contextMenu`](#events) event rather than show our own context menu. To have no context menu at all, set it and don't handle the `contextMenu` event. |
| `contextMenuItems` | `(items: ContextMenuItem[]) => ContextMenuItem[]` | | A function that customises the items of the context menu, i.e. that is given the plot's items (a new array each time) and returns the items to show, e.g., to add an item that lets the user choose whether the X axis of the plot is synchronised with that of other plots (by setting the [`xAxisSync`](#props) prop accordingly). It gets called whenever the items are built (e.g., when the context menu is requested), so the items that it adds can reflect the current state of the app (e.g., whether an item is checked). Its items are also the `items` of the [`contextMenu`](#events) event. The plot's actions have an `id` (see [`ContextMenuAction`](#types)), so that they can be found whatever their label (see [Context menu items](#context-menu-items)).
| `levelOfDetail` | `boolean` | `true` | Whether to only go through the points that are needed for a trace to look the same when drawing it (see [Large and live data](#large-and-live-data)). Hovering a trace whose X values are sorted always does. Only meant to be disabled to see how much it helps. |
| `live` | `boolean` | `false` | Whether the data is live (e.g., while a simulation is running), in which case the last point of each visible trace is marked. |

Expand Down Expand Up @@ -267,10 +269,51 @@ Hovering shows the value of each visible trace at the X value under the mouse po

With synchronised axes (see [Several plots](#several-plots)), zooming, panning, resetting the zoom, editing the range of an axis, and making an axis logarithmic (or not) apply to all the plots of the group of that axis, be it done with the mouse, by touch, with the keyboard, or from the context menu.

The context menu can zoom in and out, reset the zoom, edit the range of an axis, make an axis logarithmic, copy the plot to the clipboard, export it as JPEG, PNG, SVG, or WebP, and export its data to CSV. When requested from a legend item, it can also show only that trace (or all the traces again), or show or hide it if it is the only trace.
The context menu can zoom in and out, reset the zoom, edit the range of an axis, make an axis logarithmic, copy the plot to the clipboard, export it as JPEG, PNG, SVG, or WebP, and export its data to CSV, and an app can customise it (see [`contextMenuItems`](#props)). When requested from a legend item, it can also show only that trace (or all the traces again), or show or hide it if it is the only trace.

Copied and exported images always use the light colours (white background, dark text), whatever the current theme, since they are typically used in light documents.

### Context menu items

The items of the context menu can be customised using the [`contextMenuItems`](#props) prop, e.g., to add an item that lets the user choose whether the X axes of some plots are synchronised, right before the items that make an axis logarithmic (and separated from them):

```ts
const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => {
const index = items.findIndex((item) => 'id' in item && item.id === 'logarithmicXAxis');

items.splice(
index,
0,
{
icon: 'arrows-h',
label: 'Linked X Axes',
checked: linkedXAxes.value,
command: () => {
linkedXAxes.value = !linkedXAxes.value;
}
},
{
separator: true
}
);

return items;
};
```

The plot's actions have an `id`, so that they can be found whatever their label:

| ID | Action |
|---|---|
| `traceVisibility` | Show only a trace (or all the traces again), or show or hide it if it is the only trace (only when the context menu is requested from a legend item, after a header with the name of its trace). |
| `zoomIn`, `zoomOut` | Zoom in and out. |
| `resetZoom` | Reset the zoom. |
| `editAxisRange` | Edit the range of an axis, with `xAxisMinimum`, `xAxisMaximum`, `yAxisMinimum`, and `yAxisMaximum` in its submenu. |
| `logarithmicXAxis`, `logarithmicYAxis` | Make an axis logarithmic (or not). |
| `copyToClipboard` | Copy the plot to the clipboard. |
| `exportPlot` | Export the plot, with `exportPlotAsJpeg`, `exportPlotAsPng`, `exportPlotAsSvg`, and `exportPlotAsWebp` in its submenu. |
| `exportDataToCsv` | Export the data to CSV. |

### Theming

Set any of these CSS variables on an ancestor of the component. Each has a light and a dark default, based on [PrimeVue](https://primevue.org/)'s Aura theme. They don't affect copied and exported images, which always use the light defaults:
Expand Down
34 changes: 34 additions & 0 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:live="liveRunning"
:showLegend="showLegend"
:customContextMenu="customContextMenu"
:contextMenuItems="contextMenuItems"
:xAxisAlign="alignedXAxes ? ALIGN_GROUP : undefined"
:xAxisSync="linkedXAxes ? SYNC_GROUP : undefined"
:yAxisAlign="alignedYAxes ? ALIGN_GROUP : undefined"
Expand Down Expand Up @@ -528,6 +529,39 @@ const ALIGN_GROUP = Symbol('demo');

const SYNC_GROUP = Symbol('demo');

// Customise the context menu of our instances, so that the user can choose whether their X and/or Y axes are
// synchronised from there too, right before the items that make their axes logarithmic (and separated from them).

const contextMenuItems = (items: ContextMenuItem[]): ContextMenuItem[] => {
const index = items.findIndex((item: ContextMenuItem) => 'id' in item && item.id === 'logarithmicXAxis');

items.splice(
index,
0,
{
icon: 'arrows-h',
label: 'Linked X Axes',
checked: linkedXAxes.value,
command: () => {
linkedXAxes.value = !linkedXAxes.value;
}
},
{
icon: 'arrows-v',
label: 'Linked Y Axes',
checked: linkedYAxes.value,
command: () => {
linkedYAxes.value = !linkedYAxes.value;
}
},
{
separator: true
}
);

return items;
};

// Our frame rate, and the number of points that our instances actually draw compared to their number of points (i.e.
// without level of detail), which we update twice a second (rather than reactively, which would be costly with many
// instances).
Expand Down
2 changes: 1 addition & 1 deletion 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.1",
"version": "0.20261202.2",
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/common/syncUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class AxisSyncer {
}

groupHover(): SyncHover | undefined {
// Return where another plot of our group is hovered, if any, e.g. so that our plot can show its hover guide and
// Return where another plot of our group is hovered, if any, e.g., so that our plot can show its hover guide and
// tooltip there too when it joins a group while another plot of that group is hovered.

const group = this.group();
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/ContextMenuWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ import IconWidget from './IconWidget.vue';
/** An action of a context menu. */

export interface ContextMenuAction {
/**
* The ID of the action, if any, so that it can be found (e.g., `'logarithmicXAxis'` for one of the actions of a plot,
* see the `contextMenuItems` prop of `OpenCORPlot`).
*/
id?: string;
/** The label of the action. */
label: string;
/** The icon of the action, if any. */
Expand Down
Loading