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
2 changes: 1 addition & 1 deletion .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
# comes from (see https://github.com/actions/deploy-pages#usage).
# Note #2: GitHub Pages must have been enabled for our repository, with GitHub Actions as its source (see
# https://github.com/opencor/plot/settings/pages), since our GITHUB_TOKEN can't enable it (only a token
# with admin rights can, e.g. using actions/configure-pages with its enablement input).
# with admin rights can, e.g., using actions/configure-pages with its enablement input).
permissions:
pages: write
id-token: write
Expand Down
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

`@opencor/plot` is a [Vue 3](https://vuejs.org/) component for plotting data. It is used by [OpenCOR](https://opencor.ws/), but it can be used by any Vue 3 application.

Try it out in our [demo app](https://opencor.github.io/plot/), e.g. with millions of points, live data, or several plots whose axes are aligned and synchronised.
Try it out in our [demo app](https://opencor.github.io/plot/), e.g., with millions of points, live data, or several plots whose axes are aligned and synchronised.

Key characteristics:
- Built as a [Vue 3](https://vuejs.org/) component using the [Composition API](https://vuejs.org/guide/extras/composition-api-faq).
- Uses [uPlot](https://github.com/leeoniya/uPlot) under the hood, and draws traces using Canvas 2D.
- It does not rely on any UI framework (e.g., [PrimeVue](https://primevue.org/)) or CSS framework (e.g., [Tailwind CSS](https://tailwindcss.com/)).

Contents:
- [Installation](#installation)
- [Usage](#usage)
- [Types](#types)
- [Data](#data)
- [Large and live data](#large-and-live-data)
- [Several plots](#several-plots)
- [Props](#props)
- [Events](#events)
- [Methods](#methods)
- [Interaction](#interaction)
- [Theming](#theming)
- [Development](#development)
- [Benchmarking](#benchmarking)
- [Releasing](#releasing)
- [License](#license)
- [OpenCOR Plot](#opencor-plot)
- [Installation](#installation)
- [Usage](#usage)
- [Types](#types)
- [Data](#data)
- [Large and live data](#large-and-live-data)
- [Several plots](#several-plots)
- [Props](#props)
- [Events](#events)
- [Methods](#methods)
- [Interaction](#interaction)
- [Theming](#theming)
- [Development](#development)
- [Benchmarking](#benchmarking)
- [Releasing](#releasing)
- [License](#license)

## Installation

Expand Down Expand Up @@ -87,9 +88,9 @@ 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` | `{ 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. |
| `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)). |
| `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/)). |
| `PlotPointCounts` | `{ nbOfPoints: number; nbOfDrawnPoints: number }` | The value returned by the [`pointCounts()`](#methods) method. |
| `PlotMemoryUsage` | `{ levelOfDetail: number; logValues: number }` | The value returned by the [`memoryUsage()`](#methods) method. |
Expand Down Expand Up @@ -141,13 +142,13 @@ data.value = {
};
```

Also set the [`live`](#props) prop while the data is live, so that the last point of each visible trace gets marked, making its latest value easy to spot (even where a trace overlaps itself, e.g. in a phase plot).
Also set the [`live`](#props) prop while the data is live, so that the last point of each visible trace gets marked, making its latest value easy to spot (even where a trace overlaps itself, e.g., in a phase plot).

### Several plots

Plots can be shown together (e.g., stacked or side by side) and made to work as one, using a [`PlotGroup`](#types), i.e. a string or a symbol, which all the plots of a group share:
- **Aligned axes:** the plots of an [`xAxisAlign`](#props) group get the same left and right margins, so that their plotting areas line up when they are stacked, while those of a [`yAxisAlign`](#props) group get the same top and bottom margins, so that their plotting areas line up when they are side by side.
- **Synchronised axes:** the plots of an [`xAxisSync`](#props) (or [`yAxisSync`](#props)) group share the range and the scale (i.e. linear or logarithmic) of their X (or Y) axis. Zooming, panning, or resetting the zoom of one of them, or making its axis logarithmic (or not), does the same to the others, be it done by the user or using [`setRanges()`](#methods). Until one of them gets zoomed or panned, their axes fit the data of all of them. With a synchronised X axis, hovering one of them also shows the hover guide and tooltip of the others, at the same X value.
- **Synchronised axes:** the plots of an [`xAxisSync`](#props) (or [`yAxisSync`](#props)) group share the range and the scale (i.e. linear or logarithmic) of their X (or Y) axis. Zooming, panning, or resetting the zoom of one of them, or making its axis logarithmic (or not), does the same to the others, be it done by the user or using [`setRanges()`](#methods). Until one of them gets zoomed or panned, their axes fit the data of all of them. With a synchronised X axis, hovering one of them also shows the hover guide and tooltip of the others, at the same X value (or, for a plot that has no point there, at its closest point, as when it is hovered itself).

Aligning and synchronising are independent of each other: plots can be aligned without being synchronised (e.g., when they show different X values), and synchronised without being aligned (e.g., when they are not shown next to each other). A plot can also be in different groups for its X and Y axes, and the groups of X axes are separate from those of Y axes, so the same group can be used for both.

Expand Down Expand Up @@ -221,7 +222,7 @@ To keep track of the ranges of the axes of a plot (e.g., to restore them later),
| `showLegend` | `boolean` | `true` | Whether to show the legend. The legend takes at most 40% of the width of the plot (with long trace names truncated, and shown in full when hovered or in the context menu of their legend item), and is hidden if the plot is too narrow for it to be useful. |
| `theme` | [`PlotTheme`](#types) | `'system'` | Whether to use light or dark mode, or whatever the system uses. |
| `xAxisAlign` | [`PlotGroup`](#types) | | The group of plots whose X axes are to line up with this plot's, i.e. whose plotting areas are to have the same left and right edges (e.g., when they are stacked). |
| `xAxisSync` | [`PlotGroup`](#types) | | The group of plots whose X axis is to be synchronised with this plot's, i.e. which share the range and the scale of their X axis, so that zooming, panning, or resetting the zoom of one of them does the same to the others, as does making its X axis logarithmic (or not). Their X axes always show the same range, which, until one of them gets zoomed or panned, fits the data of all of them. Hovering one of them also shows the hover guide and tooltip of the others at the same X value (next to their guide line, at the same relative height as the mouse pointer or finger), so that the values of all of them can be read at once. For a trace whose X values are not sorted (e.g., a phase plot), the others show the point that is closest to where the mouse pointer would be, i.e. at their guide line and at that relative height, if any is close enough to it. |
| `xAxisSync` | [`PlotGroup`](#types) | | The group of plots whose X axis is to be synchronised with this plot's, i.e. which share the range and the scale of their X axis, so that zooming, panning, or resetting the zoom of one of them does the same to the others, as does making its X axis logarithmic (or not). Their X axes always show the same range, which, until one of them gets zoomed or panned, fits the data of all of them. Hovering one of them also shows the hover guide and tooltip of the others at the same X value (next to their guide line, at the same relative height as the mouse pointer or finger), so that the values of all of them can be read at once. Like the hovered plot, a plot that has no point at that X value shows its closest point instead, so that its guide line goes through its highlighted points and its tooltip shows the X value of its values. For a trace whose X values are not sorted (e.g., a phase plot), the others show the point that is closest to where the mouse pointer would be, i.e. at their guide line and at that relative height, if any is close enough to it. |
| `yAxisAlign` | [`PlotGroup`](#types) | | The group of plots whose Y axes are to line up with this plot's, i.e. whose plotting areas are to have the same top and bottom edges (e.g., when they are side by side). |
| `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.). |
Expand All @@ -246,7 +247,7 @@ Available through a template ref:

| Method | Description |
|---|---|
| `contextMenuHidden()` | Tell the plot that a custom context menu (see [`contextMenu`](#events)) has been hidden, so that it can get the keyboard focus back (unless something else, e.g. an editor opened by the chosen item, has it). |
| `contextMenuHidden()` | Tell the plot that a custom context menu (see [`contextMenu`](#events)) has been hidden, so that it can get the keyboard focus back (unless something else, e.g., an editor opened by the chosen item, has it). |
| `setRanges(ranges, options?)` | Zoom the axes into the given ranges and/or reset their zoom (see [`PlotRangesToSet`](#types)), as if the user had done it (so, a synchronised axis gets updated in all the plots of its group), animating the change if `options.animate` is set (`false` by default). A range that can't be plotted (e.g., with a non-positive end along a logarithmic axis, or with two ends that are the same) is ignored. |
| `pointCounts()` | The number of points of the visible traces (`nbOfPoints`), and how many of them were last drawn (`nbOfDrawnPoints`), as a [`PlotPointCounts`](#types). Meant for testing and benchmarking. |
| `memoryUsage()` | The memory (in bytes) used by the component itself, not counting the data, as a [`PlotMemoryUsage`](#types): by its levels of detail (`levelOfDetail`) and by the logarithm of its values along logarithmic axes (`logValues`). Meant for testing and benchmarking. |
Expand All @@ -258,7 +259,7 @@ Like with [Plotly](https://plotly.com/javascript/):
- **Middle of an axis:** drag to pan along that axis, use the mouse wheel to zoom along it, and double-click to reset its zoom.
- **Ends of an axis and bottom corners:** drag to move an end of the axis, or click an end of the axis to type its value.
- **Legend:** click a trace to show or hide it, double-click it to only show that trace (or all the traces again), and hover it to highlight its trace. Its context menu (right-click, or Shift+F10 once it has the focus) can also show only that trace (or all the traces again), or show or hide it if it is the only trace.
- **Touch** (or a pen): on the plotting area, swipe to scroll the page, use two fingers to zoom and pan, touch and hold, then drag to zoom (in browsers that don't turn a pen into touch events, e.g. Chrome on Windows, a pen doesn't scroll the page, but drags to zoom straight away, as a mouse does), and tap, then drag straight away to move the hover tooltip (which is shown above the finger). On the axes, drag with one finger as with a mouse. Tap and double-tap as you would click and double-click. Touch and hold, then release, to open the context menu (as with a right-click), including from a legend item. If a touchscreen is available, the axes can be dragged a bit further away from the plotting area, the ends of the axes are longer, and the legend items and context menu items are taller.
- **Touch** (or a pen): on the plotting area, swipe to scroll the page, use two fingers to zoom and pan, touch and hold, then drag to zoom (in browsers that don't turn a pen into touch events, e.g., Chrome on Windows, a pen doesn't scroll the page, but drags to zoom straight away, as a mouse does), and tap, then drag straight away to move the hover tooltip (which is shown above the finger). On the axes, drag with one finger as with a mouse. Tap and double-tap as you would click and double-click. Touch and hold, then release, to open the context menu (as with a right-click), including from a legend item. If a touchscreen is available, the axes can be dragged a bit further away from the plotting area, the ends of the axes are longer, and the legend items and context menu items are taller.
- **Keyboard** (once the plot has the focus): `+` and `−` to zoom in and out, `0` to reset the zoom, the arrow keys to pan, and Shift+F10 (or the context menu key) to open the context menu (e.g., to type the value of an end of an axis). Each legend item can also get the focus: Enter or Space shows or hides its trace, and Shift+F10 opens its context menu.
- **Escape**, or pressing another mouse button, cancels a drag.

Expand Down
2 changes: 1 addition & 1 deletion demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const instanceTheme = (index: number): PlotTheme => {

// Our data, i.e. the data of each of our instances.
// Note #1: we limit the total number of points that we plot since each point takes 16 bytes (8 bytes for its X value,
// which our traces share if possible, and 8 bytes for its Y value), e.g. 100,000,000 points take at least 800
// which our traces share if possible, and 8 bytes for its Y value), e.g., 100,000,000 points take at least 800
// MB. So, the options that would exceed that limit are disabled.
// Note #2: we let our status get painted before generating our data since it may take a while.

Expand Down
4 changes: 2 additions & 2 deletions demo/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const X_MAX = 10; // Last X value of our sorted data (whose first X value is 0),
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_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.

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.0",
"version": "0.20261202.1",
"exports": {
".": {
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/common/levelOfDetailUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ export const neighbouringPoints = (
): [before: number, after: number] => {
// Return the index of the last finite point, of the given points (whose finite points must have sorted X values, see
// Note #7 above), that has an X value less than the given X value (or -1 if there is none), and the index of the
// first finite point that has an X value not less than it (or the given number of points if there is none), e.g. so
// first finite point that has an X value not less than it (or the given number of points if there is none), e.g., so
// that we can determine the point that gets hovered.
// Note #1: our level of detail must be up to date (see update()).
// Note #2: lowerBound() returns the point after the last finite point that has an X value less than the given X value
Expand Down
6 changes: 3 additions & 3 deletions src/common/pathLevelOfDetailUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
// point (which may have changed), unless they are the very same values (i.e. the same arrays), which we assume
// haven't changed (e.g., when a plot gets redrawn without its data having changed).
// Note #9: taking the points of a trace into account (see update()) and updating a level (see updatedLevel()) both cost
// O(number of points), e.g. about 0.1 s for a trace of 10,000,000 points, which is too long to be done while
// drawing a plot. So, they can also be done bit by bit (see buildLevel()), e.g. in the background. Our ranges
// O(number of points), e.g., about 0.1 s for a trace of 10,000,000 points, which is too long to be done while
// drawing a plot. So, they can also be done bit by bit (see buildLevel()), e.g., in the background. Our ranges
// then cover the points that we have taken into account so far, but we only get our sizes (and therefore our
// levels) once we have taken all of our points into account, and a level that has processed some of our points
// resumes from its snapshot, like when our trace gets new points (see Note #5).
Expand Down Expand Up @@ -186,7 +186,7 @@ const reset = (lod: PathLevelOfDetail): void => {
export const invalidate = (lod: PathLevelOfDetail, from: number): void => {
// Invalidate the given level of detail from the given point onwards (i.e. those points may have changed), resetting
// it if all of its points may have changed (so that we get new sizes and that our levels don't keep any of our
// previous points, e.g. if we now have no points), or if it doesn't have sizes yet (so that our ranges and origin,
// previous points, e.g., if we now have no points), or if it doesn't have sizes yet (so that our ranges and origin,
// which we get our sizes from, don't come from points that may have changed, see Note #9 above).

if (from <= 0 || lod.xSize === 0) {
Expand Down
Loading