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

Refactor & export pan and zoom functions #464

Merged
merged 5 commits into from
Apr 25, 2021
Merged

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Apr 25, 2021

  • Simplify the doPan and doZoom interface.
  • export doPan, doZoom and resetZoom functions.
  • add pan and zoom functions to chart instance.
  • Add sample

@kurkle kurkle requested a review from etimberg April 25, 2021 18:09
Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor point. The only other part I had comments about was removing some of the checks around the enabled option, but I'm guessing that is because they were redundant

src/core.js Outdated Show resolved Hide resolved
@kurkle kurkle linked an issue Apr 25, 2021 that may be closed by this pull request
etimberg
etimberg previously approved these changes Apr 25, 2021
@kurkle kurkle merged commit 15b227c into chartjs:master Apr 25, 2021
@etimberg etimberg mentioned this pull request Apr 25, 2021
@etimberg etimberg linked an issue Apr 25, 2021 that may be closed by this pull request
@KoalaBear84
Copy link

Thanks! Will try it out ASAP 👍

@kurkle kurkle deleted the export branch April 26, 2021 14:55
@KoalaBear84
Copy link

Thanks @kurkle. Looks like it is only for 'relative' zoom/panning. I think it is not possible to do something like "zoom to last 24 hours" or so. My 'workaround' works, but everytime I call it, it shifts/moves a little. Also, it really becomes a (range) limit instead of a 'suggestion'.

See #444

@kurkle
Copy link
Member Author

kurkle commented Apr 26, 2021

@KoalaBear84 I think you can use the scale options directly for "zoom to somewhere" kind of functionality.

yourchart.options.scales.x.min = new Date('2021-04-19');
yourchart.options.scales.x.max = new Date('2021-04-20');
yourchart.update();

@KoalaBear84
Copy link

Hmm, didn't knew about that. It does work, as in that it also zooms to this period.

But it also 'locks' the graph, so you cannot zoom out, and the "Reset zoom" button I use doesn't show anymore, probably because it isn't a real zoom command anymore. Hmm, I guess I know now I see my check, it is based on the values we change on the sample you supplied.

Somehow there looks to be a change to the onZoomComplete function.

In 1.0.0-beta.1 I have to use this (with curly brackets):

    onZoomComplete: function ({ chart }) {
        showHideZoomButton(chart);
    }

function showHideZoomButton(chart) {
	document.querySelector('.resetZoomButton').style.display = (chart.scales.x.options.min != 0 || chart.scales.x.options.max != 0 || chart.scales.y.options.min != 0 || chart.scales.y.options.max != 0) ? 'block' : 'none';
}

In 1.0.0-beta.2 I have to use this (without curly brackets):

    onZoomComplete: function (chart) {
        showHideZoomButton(chart);
    }

Is there any logic to this, or am I doing something wrong?

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