-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix adjustFormat dropping d3-format specs that start with a sign flag #7900
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fix `hovertemplate`/`texttemplate`/`tickformat`/`hoverformat` silently ignoring d3-format specs that start with a sign flag such as `+.2f` [[#7900](https://github.com/plotly/plotly.js/pull/7900)] | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,8 +19,15 @@ lib.adjustFormat = function adjustFormat(formatStr) { | |||||
| if (/^\d%/.test(formatStr)) return '~%'; | ||||||
| if (/^\ds/.test(formatStr)) return '~s'; | ||||||
|
|
||||||
| // try adding tilde to the start of format in order to trim | ||||||
| if (!/^[~,.0$]/.test(formatStr) && /[&fps]/.test(formatStr)) return '~' + formatStr; | ||||||
| // A d3-format spec may begin with a sign flag (+, -, (, space) and/or a | ||||||
| // symbol ($, #). Look past that prefix before deciding whether to trim, and | ||||||
| // reattach it: prepending the tilde to the whole string (e.g. "~+.2f") is an | ||||||
| // invalid spec that d3Format rejects, so "+.2f" used to be silently dropped. | ||||||
| var prefix = (formatStr.match(/^[+\-( ]?[$#]?/) || [''])[0]; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove these from the prefix group. Without removing these,
Suggested change
|
||||||
| var rest = formatStr.slice(prefix.length); | ||||||
|
|
||||||
| // try adding tilde to trim trailing zeros | ||||||
| if (!/^[~,.0$]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| return formatStr; | ||||||
| }; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,12 @@ describe('number format', function() { | |||||||||||||||||||||||||||||
| { format: '0f', number: float, exp: '12345.678901'}, | ||||||||||||||||||||||||||||||
| { format: '1f', number: float, exp: '12345.678901'}, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // sign flag with an explicit precision must not be dropped (was silently | ||||||||||||||||||||||||||||||
| // ignored because adjustFormat produced the invalid spec "~+.2f") | ||||||||||||||||||||||||||||||
| { format: '+.2f', number: float, exp: '+12345.68'}, | ||||||||||||||||||||||||||||||
| { format: '+.0f', number: float, exp: '+12346'}, | ||||||||||||||||||||||||||||||
| { format: '-.4f', number: float, exp: '12345.6789'}, | ||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+60
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // space-filled and default sign | ||||||||||||||||||||||||||||||
| { format: '-13', number: float, exp: '-12345.678901'}, | ||||||||||||||||||||||||||||||
| { format: '-14', number: float, exp: ' -12345.678901'}, | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.