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

Tick display precision should be configurable #336

Open
DavidGamba opened this issue Feb 9, 2017 · 4 comments
Open

Tick display precision should be configurable #336

DavidGamba opened this issue Feb 9, 2017 · 4 comments

Comments

@DavidGamba
Copy link

Commit 2651c0e added a displayPrecision variable in line 18 (2651c0e#diff-d7f174bedb1bfb5e7a82248d40e9b46fR18).
This variable is used to format float64 ticks. The default value of 4 causes a small-ish number like 20000 to be rendered as 2e+04.
The value should be configurable to allow the user to define if he ever wants scientific notation or not.

I can submit a PR that exposes DefaultDisplayPrecision as a global variable to plot, by changing the const to an exported var but you might have something else in mind. Please let me know how you would like to expose access to that precision without forcing the user to implement his own ticks logic just for the precision.
The approach from the wiki example on the comma separated ticks marks based on the default ticks doesn't work because at that point the tick string has already been generated using the displayPrecision.

@ctessum
Copy link
Contributor

ctessum commented Feb 9, 2017

I like this idea, although I'm not a huge fan of using a global variable, as a user may want different precision for different plots or axes.

Would it be better to change the Ticker interface to the following:

type Ticker interface {
    // Ticks returns Ticks in a specified range
    Ticks(min, max float64, format func(v float64, prec int) string) []Tick
}

and then add a field to Axis.Tick that allows for the specification of a custom format function? (If the custom format function was nil, then the default would be used.)

@DavidGamba
Copy link
Author

Sounds like a plan. I'll give it a shot during the weekend hopefully.

@kortschak
Copy link
Member

This also allows the possibility of exporting some of these helpers.

@DavidGamba
Copy link
Author

DavidGamba commented May 25, 2017

I created PR #362.
I expanded the Ticker interface but did not add the field to Axis because the places where the format was used had no knowledge of Axis so Axis couldn't be checked there. I might be missing something.

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

3 participants