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

Highstock chart does not show "Reset Zoom" button when zoom type is set to "x" #10320

Closed
LaniMoo opened this issue Mar 14, 2019 · 7 comments
Closed

Comments

@LaniMoo
Copy link

LaniMoo commented Mar 14, 2019

  1. Create Highstock chart
  2. Disable range selector
  3. Set zoomType to 'x'
  4. Zoom in to chart using mouse drag

Expected behaviour

Reset Zoom button appears.

Actual behaviour

Reset Zoom button does not appear.

Live demo with steps to reproduce

https://jsfiddle.net/lanimelrok/1gvp9s45/
If you switch the zoomType to 'xy' and repeat the above steps, the Reset Zoom button appears.

Product version

Highstock 7.0.3

@sebastianbochan
Copy link
Contributor

sebastianbochan commented Mar 15, 2019

Hi @LaniMoo,
Thank you for reporting. This is the default functionality of Highstock, because the navigator allows you to zooming out.

Related topic #979

Workaround
You can overwrite that behaviour by catching selection event and render button by API. Then catch setExtremes event to check "zoomOut" state. If there is, hide the button.

Example:

@LaniMoo
Copy link
Author

LaniMoo commented Mar 18, 2019

Thank you for the workaround, @sebastianbochan. I'd prefer to use the built-in showResetZoom() method since that's what I use elsewhere in my code instead of recreating the button completely. But is there a reason why the showResetZoom() method does not work for this scenario?

Edit: Never mind I figured it out. To those who are trying to accomplish the same thing, one way to do it is to remove the event listener that prevents the Reset Zoom button from showing. Example: http://jsfiddle.net/lanimelrok/1kbd9vhx/

Please let me know if there's a better workaround for this. Thank you!

@alexkharech
Copy link

working solution for xAxis only

.reset-zoom-btn {
    position: absolute;
    right: 50px;
    top: 5px;
}
 xAxis: {
    type: "datetime",
    ordinal: false,
    events: {
      afterSetExtremes() {
        let btn = document.querySelector(".reset-zoom-btn");
        if (btn) btn.remove();

        const showBtn =
          this.chart.navigator.range !== undefined &&
          this.chart.navigator.size - this.chart.navigator.range > 0.1;
        if (showBtn) {
          btn = document.createElement("button");
          btn.innerHTML = "Сбросить масштаб";
          btn.className =
            "btn btn-default reset-zoom-btn btn-outline-secondary btn-sm";
          btn.onclick = () => {
            this.chart.zoomOut();
            if (btn) btn.remove();
          };
          this.chart.renderTo.appendChild(btn);
        }
      }
    }
  }

@zyura
Copy link

zyura commented Mar 25, 2021

In Highstock 9 it is enough to remove 'beforeShowResetZoom' event from Chart class:

Highcharts.removeEvent(Highcharts.Chart, 'beforeShowResetZoom');

Example: http://jsfiddle.net/gmdnzah4/

I would really like to have possibility to choose the behavior with options rather than using hacks and workarounds to bring back the default functionality. Navigator is really inconvenient to use to restore the default zoom.

@KacperMadej
Copy link

If you want to see a new feature added to Highcharta then please open a feature request. Commenting on a closed issue is less impactful.

@zyura
Copy link

zyura commented Mar 31, 2021

If you want to see a new feature added to Highcharta then please open a feature request. Commenting on a closed issue is less impactful.

I'm commenting here only because of the fact that this page is in the top search results. I see a lot of people using ugly workarounds so I decided to share a better solution here (so it can be found).

This feature has been rejected many times by the Highcharts developers (see comments above) so I see no point in creating another feature request.

Although, as a paid customer, I'm deeply disappointed by the fact that sane requests get rejected.

@KacperMadej
Copy link

@zyura
I don't discourage you from commenting on a closed issue (it's reasonable just as you have justified) - only trying to encourage proper feature request reporting to address your last text section (starting with "I would really like to have ...").

We are aiming in implementing the most popular feature requests. Less popular features are not rejected - the tickets should remain open until they will gain more popularity. I guess it doesn't do much if I only write about the general approach or strategy, so please point me to the rejected sane requests that we could check, address and possibly reopen.

This issue was opened when we were tracking feature requests outside of GitHub issues, so it was rightfully closed as not a bug.

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

No branches or pull requests

5 participants