Skip to content
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The component is the default export of `@opencor/plot`, and is also exported as
| `PlotData` | `{ traces, xAxisTitle?, yAxisTitle?, xAxisRange?, yAxisRange? }` | The data to plot (see [Data](#data)). |
| `PlotTrace` | `{ name, x, y, xValue, yValue, color, traceId?, legendRank?, runLabel? }` | A trace to plot (see [Data](#data)). |
| `PlotMargins` | `{ left: number; right: number }` | The left and right margins (in pixels) of a plot, i.e. the space taken by its Y axis and legend (see the [`margins`](#props) prop and the [`marginsUpdated`](#events) event). |
| `PlotHoverEvent` | `{ x: number \| null }` | The payload of the [`hovered`](#events) event: the X value that the mouse pointer hovers, or `null` if the hover has ended (see the [`hoverAt()`](#methods) method). |
| `PlotTheme` | `'system' \| 'light' \| 'dark'` | The value of the [`theme`](#props) prop. |
| `PlotCsvExportEvent` | `PlotCsvExportStartedEvent \| PlotCsvExportProgressEvent \| PlotCsvExportFinishedEvent` | The payload of the [`csvExport`](#events) event. Use its `type` to tell which one it is. |
| `PlotCsvExportStartedEvent` | `{ type: 'started' }` | An export to CSV has started. |
Expand Down Expand Up @@ -157,6 +158,7 @@ To draw traces without our level of detail, use `:levelOfDetail="false"`. Our pa
| Event | Payload | Description |
|---|---|---|
| `marginsUpdated` | [`PlotMargins`](#types) | The margins that the plot needs have changed. To line up several plots, pass the largest left and right margins of all of them to each plot's [`margins`](#props) prop. |
| `hovered` | [`PlotHoverEvent`](#types) | The X value that the mouse pointer hovers (i.e. the X value of the hovered point that is the closest to it) has changed, or the hover has ended (`null`). To link the hover of several plots, pass it to the [`hoverAt()`](#methods) method of the other plots. |
| `csvExport` | [`PlotCsvExportEvent`](#types) | An export to CSV has `'started'`, made `'progress'` (with a `percent`), or `'finished'` (with whether it was a `success`), so that its progress can be shown. |
| `imageExport` | [`PlotImageExportEvent`](#types) | The plot has been copied to the clipboard or exported to an image (or has failed to be), so that the user can be told about it. |
| `contextMenu` | [`PlotContextMenuEvent`](#types) | Only with [`customContextMenu`](#props): the context menu was requested at `clientX`/`clientY`, with the `items` that our context menu would have shown. If `usingKeyboard` is true, the custom menu should take the keyboard focus. |
Expand All @@ -168,6 +170,7 @@ Available through a template ref:
| Method | Description |
|---|---|
| `resetMargins()` | Emit [`marginsUpdated`](#events) again, e.g. after the shared margins have been reset. |
| `hoverAt(x)` | Show the guide line and hovered points at X value `x` (e.g., the one that another plot gave through its [`hovered`](#events) event), or stop showing them if `x` is `null`. Only the traces whose X values are sorted (i.e. not phase plots) get a hovered point, there is no hover tooltip, and the mouse pointer takes precedence. It doesn't emit [`hovered`](#events), so linked plots don't keep hovering each other. |
| `contextMenuHidden()` | Tell the plot that a custom context menu (see [`contextMenu`](#events)) has been hidden, so that it can get the keyboard focus back. |
| `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 Down
36 changes: 36 additions & 0 deletions demo/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:margins="sharedMargins ? margins : undefined"
@contextMenu="(event) => onContextMenu(event, index)"
@csvExport="onCsvExport"
@hovered="(event) => onHovered(event, index)"
@marginsUpdated="(newMargins) => onMarginsUpdated(newMargins, index)"
/>
</div>
Expand Down Expand Up @@ -116,6 +117,10 @@
<input v-model="sharedMargins" type="checkbox" />
Shared margins
</label>
<label class="demo-check">
<input v-model="linkedHover" type="checkbox" />
Link hover
</label>
<label class="demo-field">
<span>Theme</span>
<select v-model="theme">
Expand Down Expand Up @@ -166,6 +171,7 @@ import OpenCORPlot, {
type PlotContextMenuEvent,
type PlotCsvExportEvent,
type PlotData,
type PlotHoverEvent,
type PlotMargins,
type PlotMemoryUsage,
type PlotTheme
Expand Down Expand Up @@ -199,6 +205,7 @@ const showLegend = vue.ref<boolean>(true);
const customContextMenu = vue.ref<boolean>(false);
const layout = vue.ref<'grid' | 'stacked'>('grid'); // Whether our instances are in a grid or stacked (in one column).
const sharedMargins = vue.ref<boolean>(true); // Whether our instances share their margins (see onMarginsUpdated()).
const linkedHover = vue.ref<boolean>(true); // Whether our instances have their hover linked (see onHovered()).
const live = vue.ref<boolean>(false);
const nbOfPointsPerSecond = vue.ref<number>(1000);
const xRange = vue.ref<'fixed' | 'growing'>('fixed');
Expand Down Expand Up @@ -524,6 +531,35 @@ const onMarginsUpdated = (newMargins: PlotMargins, index: number): void => {
}
};

// Linked hover, i.e. hovering an instance shows the guide line and hovered points of our other instances at the same X
// value.
// Note: an instance doesn't emit the X value at which it is hovered through hoverAt() (see PlotWidget.vue), so our
// instances don't keep hovering each other.

const onHovered = (event: PlotHoverEvent, index: number): void => {
// Hover our other instances at the X value that the given instance hovers, if our hover is to be linked.

if (!linkedHover.value) {
return;
}

for (let plotIndex = 0; plotIndex < datasets.value.length; ++plotIndex) {
if (plotIndex !== index) {
plotRefs[plotIndex]?.hoverAt(event.x);
}
}
};

// Stop hovering our instances at an X value when our hover is not to be linked anymore.

vue.watch(linkedHover, (newLinkedHover: boolean) => {
if (!newLinkedHover) {
for (const plot of plotRefs) {
plot?.hoverAt(null);
}
}
});

// 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
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type {
PlotCsvExportProgressEvent,
PlotCsvExportStartedEvent,
PlotData,
PlotHoverEvent,
PlotImageExportEvent,
PlotMargins,
PlotMemoryUsage,
Expand Down
Loading