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

BUG on calculating the min sample size #134

Open
MehGokalp opened this issue Nov 13, 2022 · 0 comments
Open

BUG on calculating the min sample size #134

MehGokalp opened this issue Nov 13, 2022 · 0 comments

Comments

@MehGokalp
Copy link

Hi there,
I am using chartjs v3.6.0 and moment (with moment adapter) i faced an issue while i am trying to use this plugin. Here is the problem;

Screen Shot 2022-11-14 at 00 26 27

After some investigations i found the problem;

function computeMinSampleSize(scale, pixels) {
        let min = scale._length;
        let prev, curr, i, ilen;

        for (i = 1, ilen = pixels.length; i < ilen; ++i) {
            min = Math.min(min, Math.abs(pixels[i] - pixels[i - 1]));
        }

        for (i = 0, ilen = scale.ticks.length; i < ilen; ++i) {
            curr = scale.getPixelForTick(i);
            min = i > 0 ? Math.min(min, Math.abs(curr - prev)) : min; // here min value is becaming NaN because of curr and prev can be NaN
            prev = curr;
        }

        return min;
    }

My solution was (for very quick fix);

function computeMinSampleSize(scale, pixels) {
        let min = scale._length;
        let prev, curr, i, ilen;

        for (i = 1, ilen = pixels.length; i < ilen; ++i) {
            min = Math.min(min, Math.abs(pixels[i] - pixels[i - 1]));
        }

        for (i = 0, ilen = scale.ticks.length; i < ilen; ++i) {
            curr = scale.getPixelForTick(i);
            min = i > 0 && !isNaN(curr) && !isNaN(prev) ? Math.min(min, Math.abs(curr - prev)) : min; // add check for NaN values
            prev = curr;
        }

        return min;
    }

and the result is;

Screen Shot 2022-11-14 at 01 02 05

but as i see scale.getPixelForTick() always returns NaN and it can be because of wrong date parsing but anyway it should not cause wrong output.

This is all i found in couple of hours please add, share your thoughts and i hope it helps everyone who faced this issue!
Thank you.

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

1 participant