GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Fix adjustFormat dropping d3-format specs that start with a sign flag by TemRevil · Pull Request #7900 · plotly/plotly.js Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for the PR! I'll take a look and follow up. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! I'd like to make some changes to avoid some unintended consequences of this update.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // 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]; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Let's remove these from the prefix group. Without removing these, "$f" will get changed to "$~f". This means that "1.50" would get changed to "$1.5", which isn't what we want.
| var prefix = (formatStr.match(/^[+\-( ]?[$#]?/) || [''])[0]; | |
| var prefix = (formatStr.match(/^[+\-( ]/) || [''])[0]; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| var rest = formatStr.slice(prefix.length); | ||
|
|
||
| // try adding tilde to trim trailing zeros | ||
| if (!/^[~,.0$]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| if (!/^[~,.0$]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest; | |
| if (!/^[~,.0$#]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest; |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // 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'}, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| // 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'}, | |
| // sign flag with an explicit precision must not be dropped | |
| { format: '+.2f', number: float, exp: '+12345.68'}, | |
| { format: '+.0f', number: float, exp: '+12346'}, | |
| { format: '-.4f', number: float, exp: '12345. | |
| // symbol-led specs ($, #) are left untrimmed | |
| { format: '$f', number: 1.5, exp: '$1.500000'}, | |
| { format: '#f', number: 1.5, exp: '1.500000'}, | |
| { format: '$s', number: 1500, exp: '$1.50000k'}, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -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)] | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| - 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)] | |
| - Fix `hovertemplate`/`texttemplate`/`tickformat`/`hoverformat` improperly handling d3-format specs that start with a sign flag such as `+.2f` [[#7900](https://github.com/plotly/plotly.js/pull/7900)] |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
i'm getting some mind melting currently, so i'll review it and send you back. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
camdecoster pointed out that folding $/# into the prefix group broke symbol-led specs: "$f" became "$~f", an invalid spec, and stripping the symbol before the trim check meant "$1.500000" would come out as "$1.5" once the tilde got added. Only sign flags (+, -, (, space) belong in the stripped prefix; symbol-led specs now fall straight through to the untrimmed return, matching the existing hex/octal/binary "#" cases. Added test coverage for $f/#f/$s, reworded the draftlog line to "improperly handling" since it's not strictly a silent drop anymore.
|
alright, back on this, sorry for the wait. applied all four: narrowed the prefix match to just the sign flags, added # to the rest-exclusion regex, reworded the draftlog line, and fixed up the test file. one thing on that last part, the suggested diff cut off mid-string ( ran those plus the rest of the suite against d3-format directly, all correct. thanks for digging into this, the $/# distinction wasn't something I'd thought through carefully enough the first time. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That must have been a bad copy/paste. I also deleted a "?" by mistake. 🤦
At any rate, this looks good. Thanks for the fix!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Appreciate you sticking with it through both rounds. Glad it's in now. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. "+.2f")
There was an error while loading. Please reload this page.