GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@TemRevil

@TemRevil TemRevil commented Jul 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #7897

A d3-format specifier that begins with a sign flag (+, -, (, or a space) was silently ignored in hovertemplate, texttemplate, tickformat, and hoverformat, showing the raw unformatted number instead. For example %{y:+.2f} rendered 12.3456789 rather than +12.35.

Cause: Lib.adjustFormat prepends a trim tilde to the start of the whole string, so +.2f became ~+.2f — an invalid spec (the ~ flag must sit just before the type). d3.format threw, Lib.numberFormat caught it and fell back to Lib.noFormat.

Fix: skip past an optional leading sign flag and symbol ($, #) before the trim heuristic, then reattach that prefix, so the tilde is only inserted in a valid position. Formats without such a prefix are unchanged.

Verified against d3-format v1 directly: +.2f → +12345.68, +.0f → +12346, -.4f → 12345.6789, while .2f, s, 0.3s, +13, -13, ($15, #0X, .2% produce identical output to before. Added matching cases in test/jasmine/tests/lib_number_format_test.js.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
TemRevil added 4 commits July 10, 2026 16:04
@TemRevil
Fix adjustFormat dropping d3-format specs that start with a sign flag
a6b2c2a
A d3-format specifier beginning with a sign flag (+, -, (, space) was
silently ignored: adjustFormat prepended a trim tilde to the whole
string, producing an invalid spec like ~+.2f. d3.format then threw,
numberFormat fell back to noFormat, and the raw unformatted number was
shown (e.g. %{y:+.2f} rendered 12.3456789 instead of +12.35).

Skip past an optional leading sign flag and symbol ($, #) before the
trim heuristic and reattach it, so the tilde is only added in a valid
position. Formats without such a prefix are unaffected.

Fixes plotly#7897
@TemRevil
Add draftlog for #
053662f
@TemRevil
Remove malformed draftlog
6ae433c
@TemRevil
Add draftlog for plotly#7900
95dc3ad
@camdecoster camdecoster self-assigned this Jul 15, 2026
@camdecoster

camdecoster commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR! I'll take a look and follow up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

camdecoster
camdecoster requested changes Jul 27, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

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.

Thanks for the fix! I'd like to make some changes to avoid some unintended consequences of this update.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/lib/index.js Outdated
// 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];

@camdecoster camdecoster Jul 27, 2026

Copy link
Copy Markdown
Contributor

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.

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.

Suggested change
var prefix = (formatStr.match(/^[+\-( ]?[$#]?/) || [''])[0];
var prefix = (formatStr.match(/^[+\-( ]/) || [''])[0];

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/lib/index.js Outdated
var rest = formatStr.slice(prefix.length);

// try adding tilde to trim trailing zeros
if (!/^[~,.0$]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest;

@camdecoster camdecoster Jul 27, 2026

Copy link
Copy Markdown
Contributor

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.

Suggested change
if (!/^[~,.0$]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest;
if (!/^[~,.0$#]/.test(rest) && /[&fps]/.test(rest)) return prefix + '~' + rest;

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/jasmine/tests/lib_number_format_test.js
Comment on lines +56 to +60
// 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'},

@camdecoster camdecoster Jul 27, 2026

Copy link
Copy Markdown
Contributor

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.

Suggested change
// 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread draftlogs/7900_fix.md Outdated
@@ -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)]

@camdecoster camdecoster Jul 27, 2026

Copy link
Copy Markdown
Contributor

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.

Suggested change
- 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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TemRevil

TemRevil commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

i'm getting some mind melting currently, so i'll review it and send you back.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TemRevil
Keep symbol-led specs out of the trimmed-prefix path
a6c9816
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.
@TemRevil

TemRevil commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

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 (exp: '12345. with nothing after), so instead of pasting it as-is I kept -.4f's original expected value and added the $f/#f/$s cases as their own lines.

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

camdecoster added 2 commits July 29, 2026 08:21
@camdecoster
Add deleted '?' back
3272f8e
@camdecoster
Update draftlog
3320c44
camdecoster
camdecoster approved these changes Jul 29, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

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.

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
camdecoster merged commit 49a42a9 into plotly:master Jul 29, 2026
84 of 85 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@TemRevil

TemRevil commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Appreciate you sticking with it through both rounds. Glad it's in now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@emilykl emilykl mentioned this pull request Aug 31, 2026
Y-axis tickformat='+' causes unexpected scientific notation for zero tick plotly/plotly.py#5152
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@camdecoster camdecoster

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

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")

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@TemRevil @camdecoster
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.