Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setSeries hook: Allow distinguishing between toggling a series vs. just hovering #988

Closed
juliusv opened this issue Aug 16, 2024 · 2 comments
Labels
question Further information is requested

Comments

@juliusv
Copy link

juliusv commented Aug 16, 2024

I want to mislead my users with stacked graphs, so I adopted the stacking code from https://leeoniya.github.io/uPlot/demos/stack.js (used by https://leeoniya.github.io/uPlot/demos/stacked-series.html).

It uses the setSeries hook to restack things when a series has been shown or hidden:

// restack on toggle
	opts.hooks = {
		setSeries: [
			(u, i) => {
				let stacked = stack(data, i => !u.series[i].show);
				u.delBand(null);
				stacked.bands.forEach(b => u.addBand(b));
				u.setData(stacked.data);
			}
		],
	};

However, the setSeries hook also fires when just hovering and focusing a series, so by just hovering over a graph with many series, a lot of extra computations are taking place and things get slow.

Is there a nice way to distinguish between toggling a series vs. just hover-focusing, or would this require code changes to uPlot?

I guess I could do it right now by manually remembering & comparing the show states of all series between hook firings, but it would be nice to be able to just tell them apart.

@leeoniya
Copy link
Owner

leeoniya commented Mar 8, 2025

@juliusv setSeries fires with the opts, so you should be able to discern why it was called?

https://github.com/leeoniya/uPlot/blob/5b0335c1a33be2dc3049f012e344864c7f2b4d46/src/uPlot.js#L2458C22-L2458C49

@leeoniya
Copy link
Owner

leeoniya commented Mar 9, 2025

when it's a series toggle you'll have opts.show != null, when it's a focus change you'll have opts.focus != null

e.g.

if (opts.focus != null) {

@leeoniya leeoniya closed this as completed Mar 9, 2025
@leeoniya leeoniya added the question Further information is requested label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants