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

When sync is enabled, hiding/showing dataset is also sync'ed? #23

Open
MehdiSaffar opened this issue Sep 20, 2019 · 3 comments · May be fixed by #33
Open

When sync is enabled, hiding/showing dataset is also sync'ed? #23

MehdiSaffar opened this issue Sep 20, 2019 · 3 comments · May be fixed by #33

Comments

@MehdiSaffar
Copy link

Situation

I have multiple charts in my page that show different datasets.

I want to use chartjs-plugin-crosshair to be able to show vertical lines on hover.

I also want to sync the vertical lines so that I can the vertical on the same date.

Bug

Both of the above work, except I noticed a weird bug where enabling sync: {enabled: true} means hiding/showing a dataset of one chart hides/shows a dataset of another (even though they have different keys)

When I make sync: {enabled: false}, the weird bug stops, but then I lose the feature of syncing the vertical lines.

I looked through the code of the plugin but I don't see anything that changes the hidden property of datasets.

Plugin config

The plugin config is simple:

    crosshair: {
      ...
      sync: {
        enabled: true, // enable trace line syncing with other charts
        group, // chart group
        suppressTooltips: false, // suppress tooltips when showing a synced tracer
      },
      zoom: {
        enabled: false,
      },
    },

image

For confidentiality reasons I had to hide some info with red boxes. When I toggle a label on the first chart (top left) some of the labels of the others ones also get toggled. I never touch any of the labels of the remaining charts.

What gives?

@AbelHeinsbroek
Copy link
Owner

Hi Mehdi,

It seems that all mouse interactions, including ones outside the chart area, are synced across charts. This can be fixed by adding a check for event position somewhere here:

if (!e.stop && syncEnabled) {

Due to a broken wrist I'm not able to do it myself easily soon I'm afraid.

@andreialecu
Copy link

@AbelHeinsbroek is there any reason to propagate any clicks to other charts? I'm not sure what goal syncing the clicks would accomplish.

Would filtering out the click event in that if seem like a valid fix? I could submit a PR with that.

@andreialecu
Copy link

Opened a PR, I tested the tweak in my project and it fixed this particular issue. I couldn't see any side effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants