-
Notifications
You must be signed in to change notification settings - Fork 223
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
Add in formatters. #533
Add in formatters. #533
Conversation
Plottable.Util.Formatters now includes functions that generate formatters: - identity() : String-ifies the input. - general() : Shows at most [precision] decimal places (using round-half-up). - fixed() : Shows exactly [precision] decimal places (IEEE 754 rounding). - currency() : Displays fixed() values with a currency symbol (defaults to $) - percentage() : Dipplayes fixed() values as percentages.
export interface IFormatter { | ||
(d: any): String; | ||
} | ||
export module Formatters { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt be plural. maybe should just be Format
not Formatter
?
Also fix breaking test due to character-encoding problems.
percentage not working as expected http://jsfiddle.net/cmorford/LMXct/ |
percentage(3) breaks yaxis ditto for fixed() at higher numbers |
I know that something Slate wanted was for values to only show up once if there were duplicates. So if you use fixed(0), you should only see one 0, one 1, one 2, etc... Is this the branch to fix that in? |
re: |
Formatters now also have an option to show only values that are unchanged by formatting. For example: var f = new Plottable.Util.Formatter.Fixed(3); f.format(1); // "1.000" f.format(1.234); // "1.234" f.format(1.2345); // "" This value can be set with .showOnlyUnchangedValues() and is true by default. In addition, added in Formatter.Custom to allow the Javascript consumers of Plottable to create new Formatters without writing TypeScript code.
Not a big fan of this behavior on the y-axis |
Looks good! |
That's a cutoff problem, yeah. Try increasing the width. |
Conflicts: quicktests/gridlines-quicktest.html
GIL |
if (typeof d === "number") { | ||
if (Math.abs(d) < 1) { | ||
return String(Math.round(1000 * d) / 1000); // round to 3 decimal places | ||
} | ||
return numberFormatter(d); | ||
} | ||
return d; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to factor this base format function into a defaultFormatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered having it in the general formatter, but I'm thinking formatters should take Number
s going forward, instead of any
s. However, that doesn't mesh well with the inevitable need for formatters for DateAxis..
minor change then GIL |
Also added tests for the Identity formatter.
I do think it's odd that only Identity and General are defined for OrdinalScale+(X/Y)Axis, I'd prefer all or nothing. How soon are those getting deprecated? |
@danmane Can you explain what you mean in more detail? |
Plottable.Util.Formatters now includes functions that generate formatters: