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

minRange for Category #796

Open
mBreyerBG opened this issue Nov 8, 2023 · 3 comments
Open

minRange for Category #796

mBreyerBG opened this issue Nov 8, 2023 · 3 comments

Comments

@mBreyerBG
Copy link

I have a barChart with categories. i am using drag to zoom. How can i define a minimum amount of categories, just like e.g: limits.x.minRange would work? Is this possible?!
Right now i can zoom, so that only one category is visible and fills the whole chart. i want like minimum of 4 categories to be visible

@jgrayson-apl
Copy link

+1

@alimertcakar
Copy link

alimertcakar commented Apr 24, 2024

+1

There is supposed to be a prop for this but nothing worked. You can try this as a workaround:

           const minDesiredElems = 10;
           onZoomStart: ({ event, chart }) => {
            const isZoomIn = event.deltaY < 0;
            const hasLessThanDesired = chart.scales.xAxes.ticks?.length <= minDesiredElems;
            // reset it back in case of a big step
            if (chart.scales.xAxes.ticks?.length <= minDesiredElems-1 && isZoomIn) {
              chart.zoom(chart, { x: minDesiredElems });
            }
            // skip zoom event
            if (isZoomIn && hasLessThanDesired) return false;
          }

(This isn't really well tested code, but somewhat works)

@fecipo
Copy link

fecipo commented May 13, 2024

+1

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

No branches or pull requests

4 participants