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

Custom formatter function for tickFormat #99

Open
jampekka opened this issue Sep 3, 2014 · 3 comments
Open

Custom formatter function for tickFormat #99

jampekka opened this issue Sep 3, 2014 · 3 comments

Comments

@jampekka
Copy link

jampekka commented Sep 3, 2014

By examining the axis._getFormat method it seems that axis.tickFormat must be a string that will get passed to d3.format. Is there a reason why this couldn't also be any function that takes the value and returns a string? This would make the formatting even more flexible.

This can be accomplished by monkeypatching that seems to work without problems in my simple usage. Eg:

function my_custom_format(value) {
    // Any transformation to string here
    return "prefix" + parseInt(value*100) + "postfix";  
}
var ax = chart.addMeasureAxis('x', 'value');
ax._getFormat = function() { return my_custom_format; }; 

However, such ugliness would be unnecessary if axis._getFormat would check if the axis.tickFormat is a function and returning it if so.

If preferred, I can make a pull request of such a feature, but the line or two is probably faster added by an existing commiter if this proposal is accepted.

@johnkiernander
Copy link
Member

I like it, good idea. It should be quite a simple addition, I'll work it into the next release.

@ses4j
Copy link
Contributor

ses4j commented Nov 3, 2014

+1.

@raghavi92
Copy link

Is there an update for this?

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

4 participants