diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index ef4290d..f0aeb94 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -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 diff --git a/README.md b/README.md index db3ee82..2429825 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ `@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). @@ -10,21 +10,22 @@ Key characteristics: - 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 @@ -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. | @@ -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. @@ -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.). | @@ -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. | @@ -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. diff --git a/demo/App.vue b/demo/App.vue index cef9fbd..b033f7d 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -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. diff --git a/demo/data.ts b/demo/data.ts index 6291695..2cb6704 100644 --- a/demo/data.ts +++ b/demo/data.ts @@ -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. diff --git a/package.json b/package.json index 16d03c7..c0aac56 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/common/levelOfDetailUtils.ts b/src/common/levelOfDetailUtils.ts index aef64dc..053da7b 100644 --- a/src/common/levelOfDetailUtils.ts +++ b/src/common/levelOfDetailUtils.ts @@ -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 diff --git a/src/common/pathLevelOfDetailUtils.ts b/src/common/pathLevelOfDetailUtils.ts index 99a619b..cab5597 100644 --- a/src/common/pathLevelOfDetailUtils.ts +++ b/src/common/pathLevelOfDetailUtils.ts @@ -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). @@ -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) { diff --git a/src/common/syncUtils.test.ts b/src/common/syncUtils.test.ts index cfe9171..07a2f1f 100644 --- a/src/common/syncUtils.test.ts +++ b/src/common/syncUtils.test.ts @@ -434,6 +434,62 @@ describe('AxisSyncer', () => { expect(plot2.hovers).toEqual([{ x: 5, yFraction: 0.25 }, undefined]); }); + it('gives where another plot of its group is hovered to a plot that joins it', () => { + const group = Symbol('group'); + const plot1 = testSyncer(group); + + plot1.syncer.setHover({ x: 5, yFraction: 0.25 }); + + const plot2 = testSyncer(group); + + expect(plot2.syncer.groupHover()).toEqual({ x: 5, yFraction: 0.25 }); + + // The plot that is hovered is not hovered by another plot of its group. + + expect(plot1.syncer.groupHover()).toBeUndefined(); + + // Nobody is hovered once the plot that was hovered stops being hovered. + + plot1.syncer.setHover(undefined); + + expect(plot2.syncer.groupHover()).toBeUndefined(); + + // A plot that is not in a group is not hovered by another plot. + + plot1.syncer.setHover({ x: 5, yFraction: 0.25 }); + plot2.syncer.setGroup(undefined, LINEAR); + + expect(plot2.syncer.groupHover()).toBeUndefined(); + }); + + it('gives a copy of where another plot of its group is hovered', () => { + const group = Symbol('group'); + const plot1 = testSyncer(group); + const plot2 = testSyncer(group); + const hover: SyncHover = { x: 5, yFraction: 0.25 }; + + plot1.syncer.setHover(hover); + + hover.x = 100; + + const groupHover = plot2.syncer.groupHover() as SyncHover; + + groupHover.x = 200; + + expect(plot2.syncer.groupHover()).toEqual({ x: 5, yFraction: 0.25 }); + }); + + it('forgets where a plot is hovered when it leaves its group', () => { + const group = Symbol('group'); + const plot1 = testSyncer(group); + const plot2 = testSyncer(group); + + plot1.syncer.setHover({ x: 5, yFraction: 0.25 }); + plot1.syncer.setGroup(undefined, LINEAR); + + expect(plot2.syncer.groupHover()).toBeUndefined(); + }); + it('copes with a plot that does not want to know where the other plots are hovered', () => { const group = Symbol('group'); const plot1 = testSyncer(group); diff --git a/src/common/syncUtils.ts b/src/common/syncUtils.ts index 6e7e8cc..83678f9 100644 --- a/src/common/syncUtils.ts +++ b/src/common/syncUtils.ts @@ -68,10 +68,11 @@ interface Group { state: SyncAxisState; naturalRange: Range | undefined; hoveredMember: AxisSyncer | undefined; + hover: SyncHover | undefined; } // Our groups for each axis, i.e. the syncers (i.e. plots) that are in each of them, the state of their axis, their -// natural range, and which of them is hovered, if any. +// natural range, and which of them is hovered and where, if any. // Note #1: the groups of our X axes are separate from those of our Y axes, so that the same group can be used for both // without the X axis of a plot being synchronised with the Y axis of another. // Note #2: a group gets removed once it is empty, so that we don't keep track of groups that are not used anymore. @@ -150,7 +151,8 @@ export class AxisSyncer { members: new Set([this]), state: copiedState(state), naturalRange: undefined, - hoveredMember: undefined + hoveredMember: undefined, + hover: undefined }); return undefined; @@ -161,6 +163,19 @@ export class AxisSyncer { return copiedState(group.state); } + 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 + // tooltip there too when it joins a group while another plot of that group is hovered. + + const group = this.group(); + + if (!group?.hover || group.hoveredMember === this) { + return undefined; + } + + return { x: group.hover.x, yFraction: group.hover.yFraction }; + } + setHover(hover: SyncHover | undefined): void { // Our plot is hovered at the given place (or is not hovered anymore, if undefined), so tell the other plots in our // group, if any, so that they can show their hover guide and tooltip there too (or hide them). @@ -175,6 +190,7 @@ export class AxisSyncer { } group.hoveredMember = hover ? this : undefined; + group.hover = hover && { x: hover.x, yFraction: hover.yFraction }; for (const member of this.otherMembers(group)) { member.handlers.onHover?.(hover && { x: hover.x, yFraction: hover.yFraction }); diff --git a/src/common/traceValues.ts b/src/common/traceValues.ts index 31a680f..8619843 100644 --- a/src/common/traceValues.ts +++ b/src/common/traceValues.ts @@ -116,7 +116,7 @@ export const valuesStatistics = (values: Float64Array, previous?: ValuesStatisti // values too. // Note #2: we create a new buffer whenever some values are not a continuation of the previous ones, so that we never // present new values as a continuation of old ones. Also, a new buffer has room for twice as many values as we -// have (but no more than what is left of the buffer of our values, e.g. live data, which buffer has room for +// have (but no more than what is left of the buffer of our values, e.g., live data, which buffer has room for // all the data of a simulation run), and it doubles in size when it needs to grow. Growing our buffer means // that our logarithm is not a continuation of the previous one anymore (so that whatever uses it has to // process all of it again, see Note #1), but this only happens a few times (e.g., during a simulation run) and diff --git a/src/widgets/IconWidget.vue b/src/widgets/IconWidget.vue index 0a44f8d..2c71f9c 100644 --- a/src/widgets/IconWidget.vue +++ b/src/widgets/IconWidget.vue @@ -10,7 +10,7 @@ import { ICONS, type IconName } from '../common/icons'; // An icon (see icons.ts), which takes the colour of its text (i.e. currentcolor) and whose size is that of its text, // unless it is set by its parent (e.g., using a class). // Note #1: our size is also set using attributes (rather than only using CSS), so that we always have an intrinsic size -// (some browsers would otherwise give us no size in some cases, e.g. in a flex container). +// (some browsers would otherwise give us no size in some cases, e.g., in a flex container). // Note #2: our view box leaves out the 3-unit margin that PrimeIcons' SVG files have on each side (i.e. we only use the // 18x18 box in which their icons are drawn), so that we look like PrimeIcons' font, which glyphs fill their // whole em box (i.e. a 14px icon is as big as a 14px PrimeIcons glyph). diff --git a/src/widgets/PlotWidget.vue b/src/widgets/PlotWidget.vue index 394a988..f804b48 100644 --- a/src/widgets/PlotWidget.vue +++ b/src/widgets/PlotWidget.vue @@ -417,11 +417,12 @@ const props = withDefaults( * 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, 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 the same relative height as the mouse pointer), if any is - * close enough to it. A symbol is unique, so that unrelated parts of a page can't end up in the same group by using - * the same string. + * 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), 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 the same relative height as the mouse pointer), if any is close enough + * to it. A symbol is unique, so that unrelated parts of a page can't end up in the same group by using the same + * string. */ xAxisSync?: PlotGroup; /** @@ -3311,14 +3312,6 @@ const joinAxisSyncGroup = (axisKey: AxisKey, group: PlotGroup | undefined): void log: logAxes.value[axisKey] }); - // Forget where another plot of our previous X axis synchronisation group was hovered, if anywhere. - - if (axisKey === 'x' && groupHover) { - groupHover = undefined; - - updateHover(); - } - if (groupState) { if (groupState.log !== logAxes.value[axisKey]) { setLogAxis(axisKey, groupState.log, groupState.zoomRange); @@ -3327,6 +3320,28 @@ const joinAxisSyncGroup = (axisKey: AxisKey, group: PlotGroup | undefined): void } } + // Tell the other plots of our new X axis synchronisation group where we are hovered, if anywhere, or show where + // another plot of our new group is hovered, if anywhere, or forget where another plot of our previous group was + // hovered, if anywhere. + // Note #1: we must tell the other plots of our new group where we are hovered since our hover hasn't changed, i.e. we + // wouldn't otherwise tell them (see the watcher of our hover below). + // Note #2: we do this once we have adopted the state of our new group, so that our hover guide and tooltip are shown + // using its range and scale. + + if (axisKey === 'x') { + if (hover.value?.local) { + axisSyncers.x.setHover({ x: hover.value.xValue, yFraction: hover.value.yFraction }); + } + + const newGroupHover = axisSyncers.x.groupHover(); + + if (newGroupHover || groupHover) { + groupHover = newGroupHover; + + updateHover(); + } + } + // Our natural range may have changed (e.g., it is now the union of the natural ranges of the plots in our new group, // or our own natural range if we are not in a group anymore). @@ -5992,7 +6007,7 @@ const linearPath = ( // often, so that we still find out whether it has become smooth (e.g., once zoomed in, see TraceSmoothness in // simplifiedPathUtils.ts). // Note #9: the level of our path level of detail that we need (see Note #7) costs O(number of points) to build the -// first time (see Note #5 and Note #9 of pathLevelOfDetailUtils.ts), e.g. about 0.1 s for a trace of +// first time (see Note #5 and Note #9 of pathLevelOfDetailUtils.ts), e.g., about 0.1 s for a trace of // 10,000,000 points, i.e. about 1 s for ten such traces, which would freeze our plot (e.g., the first time // that we pan it, or when zooming in needs a finer level). So, we build it in the background, bit by bit (see // buildPathLevels()), and keep using our (column) level of detail until it is built. We stop building it if @@ -6606,8 +6621,11 @@ const setPlotSize = (u: uPlot, width: number, height: number): void => { // at the X value at which another plot of our group is hovered, if any (and we are not hovered ourselves), so // that the values of all of our plots can be read at once. We then do as if the mouse pointer was at that X // value and at the same relative height as the mouse pointer (or finger) in the hovered plot, i.e. our tooltip -// is next to our guide line at that height. So, for a trace which X values are not sorted (see Note #1), we -// use its point that is closest to that position, if any is close enough to it. +// is next to our guide line at that height. So, like when we are hovered ourselves, our guide line is at the X +// value of our point that is the closest to that X value (which may not be that X value if our X values are +// not the same as those of the hovered plot), so that it goes through our highlighted points and our tooltip +// shows the X value of its values. Also, for a trace which X values are not sorted (see Note #1), we use its +// point that is closest to that position, if any is close enough to it. interface HoverPoint { seriesIndex: number;