Skip to content

Tickformat "p" fix #3868

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

Closed
wants to merge 3 commits into from
Closed

Tickformat "p" fix #3868

wants to merge 3 commits into from

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented May 15, 2019

etpinard added 2 commits May 15, 2019 14:38
... as v1.1.0 is only compatible with karma-jasmine@2x
... so that it can benefit from the same rounding precision algo
    as 'regular' number formatting calls
@etpinard etpinard added bug something broken status: reviewable labels May 15, 2019
@archmoj
Copy link
Contributor

archmoj commented May 16, 2019

@etpinard Thanks for the fix.
Unfortunately there is another issue with small ranges. See codepen where the Y-axis range is printed as 0 to 100% whereas it should be 0 to 0.01%.
Could we possibly address that in this PR?

@etpinard
Copy link
Contributor Author

Y-axis range is printed as 0 to 100% whereas it should be 0 to 0.01%.

Oh boy. Thanks for noticing that!

@archmoj
Copy link
Contributor

archmoj commented May 16, 2019

Y-axis range is printed as 0 to 100% whereas it should be 0 to 0.01%.

Oh boy. Thanks for noticing that!

For the funnelarea I would add the following function to the Lib. Thought it may be of interest.

lib.formatPercent = function(ratio, n) {
    n = n || 0;
    var str = (Math.round(100 * ratio * Math.pow(10, n)) * Math.pow(0.1, n)).toFixed(n) + '%';
    for(var i = 0; i < n; i++) {
        if(str.indexOf('.') !== -1) {
            str = str.replace('0%', '%');
            str = str.replace('.%', '%');
        }
    }
    return str;
};

@etpinard
Copy link
Contributor Author

@archmoj how do you compute the n passed to your formatPercent function?

@archmoj
Copy link
Contributor

archmoj commented May 16, 2019

@archmoj how do you compute the n passed to your formatPercent function?
That's the desired precision which in the case of financial traces is 0 or 1.
But one may pass that after calculating what precision needed or simply by using a higher default e.g. 6.

@etpinard
Copy link
Contributor Author

I'm having second thoughts about my attempt at fixing this bug.

Closing for now.

@etpinard etpinard closed this May 21, 2019
@etpinard etpinard deleted the tickformat-p-fixes branch May 21, 2019 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tickmark precision with percentage formatting
3 participants