René's URL Explorer Experiment


Title: [BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. "+.2f") · Issue #7897 · plotly/plotly.js · GitHub

Open Graph Title: [BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. "+.2f") · Issue #7897 · plotly/plotly.js

X Title: [BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. "+.2f") · Issue #7897 · plotly/plotly.js

Description: Description A d3-format specifier that starts with a sign flag — +, -, (, or a space — is silently dropped when used in hovertemplate, texttemplate, tickformat, or hoverformat, and the raw (unformatted) number is shown instead. For examp...

Open Graph Description: Description A d3-format specifier that starts with a sign flag — +, -, (, or a space — is silently dropped when used in hovertemplate, texttemplate, tickformat, or hoverformat, and the raw (unforma...

X Description: Description A d3-format specifier that starts with a sign flag — +, -, (, or a space — is silently dropped when used in hovertemplate, texttemplate, tickformat, or hoverformat, and the raw (unforma...

Opengraph URL: https://github.com/plotly/plotly.js/issues/7897

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. \"+.2f\")","articleBody":"### Description\n\nA d3-format specifier that starts with a **sign flag** — `+`, `-`, `(`, or a space — is silently dropped when used in `hovertemplate`, `texttemplate`, `tickformat`, or `hoverformat`, and the raw (unformatted) number is shown instead.\n\nFor example, `%{y:+.2f}` should render `+12.35`, but it renders the full-precision value `12.3456789`. The sibling spec `%{y:.2f}` (no sign flag) works correctly and renders `12.35`.\n\n`+.2f` is a valid d3-format specifier (grammar: `[[fill]align][sign][symbol][0][width][,][.precision][~][type]`), so it is expected to work.\n\n**Root cause** is in `Lib.adjustFormat` (`src/lib/index.js`). Its \"add a leading tilde to trim trailing zeros\" heuristic does not account for a leading sign flag:\n\n```js\n// src/lib/index.js\nlib.adjustFormat = function adjustFormat(formatStr) {\n    if (!formatStr || /^\\d[.]\\df/.test(formatStr) || /[.]\\d%/.test(formatStr)) return formatStr;\n    if (formatStr === '0.f') return '~f';\n    if (/^\\d%/.test(formatStr)) return '~%';\n    if (/^\\ds/.test(formatStr)) return '~s';\n\n    // try adding tilde to the start of format in order to trim\n    if (!/^[~,.0$]/.test(formatStr) && /[&fps]/.test(formatStr)) return '~' + formatStr;\n\n    return formatStr;\n};\n```\n\nFor `formatStr = \"+.2f\"`:\n- `/^[~,.0$]/.test(\"+.2f\")` is `false` (it starts with `+`, which is not in the set), so `!(...)` is `true`;\n- `/[&fps]/.test(\"+.2f\")` is `true` (contains `f`);\n- therefore `adjustFormat` returns **`\"~+.2f\"`**.\n\n`\"~+.2f\"` is an **invalid** d3-format spec (the `~` trim flag must appear immediately before the type, e.g. `+.2~f`; a leading `~` followed by a sign does not parse). `d3Format('~+.2f')` throws, and `Lib.numberFormat` catches it and falls back to `Lib.noFormat`, which returns `String(value)` — the unformatted number:\n\n```js\nlib.numberFormat = function (formatStr) {\n    var fn;\n    try {\n        fn = d3Format(lib.adjustFormat(formatStr));\n    } catch (e) {\n        lib.warnBadFormat(formatStr);   // logs: encountered bad format: \"+.2f\"\n        return lib.noFormat;            // -> String(value), unformatted\n    }\n    return fn;\n};\n```\n\nBy contrast, `\".2f\"` starts with `.`, which **is** in `[~,.0$]`, so `adjustFormat` leaves it untouched and it formats correctly.\n\nThis affects every code path that goes through `Lib.numberFormat`: `hovertemplate`, `texttemplate`, `tickformat`, and `hoverformat`.\n\n### Screenshots/Video\n\n_Hovering the bar in the repro below: field A (`:.2f`) shows `12.35`; field B (`:+.2f`) shows `12.3456789` instead of `+12.35`. The browser console also logs `encountered bad format: \"+.2f\"`._\n\n### Steps to reproduce\n\n```html\n\u003c!DOCTYPE html>\n\u003chtml>\n\u003chead>\n  \u003cmeta charset=\"utf-8\" />\n  \u003cscript src=\"https://cdn.plot.ly/plotly-3.7.0.js\">\u003c/script>\n\u003c/head>\n\u003cbody>\n  \u003cdiv id=\"chart\" style=\"width:700px;height:260px;\">\u003c/div>\n  \u003cscript>\n    var delta = 12.3456789;\n    Plotly.newPlot('chart', [{\n      type: 'bar', orientation: 'h',\n      y: ['example'], x: [delta],\n      customdata: [[delta, delta]],\n      hovertemplate:\n        'A (:.2f)  = %{customdata[0]:.2f}\u003cbr>' +\n        'B (:+.2f) = %{customdata[1]:+.2f}\u003cextra>\u003c/extra>'\n    }]);\n    // Expected hover:  A = 12.35    B = +12.35\n    // Actual   hover:  A = 12.35    B = 12.3456789\n  \u003c/script>\n\u003c/body>\n\u003c/html>\n```\n- Open the page in a browser ([JSFiddle](https://jsfiddle.net/j3urLn7o)).\n- Hover over the bar.\n- Note that field **B** (`%{...:+.2f}`) shows `12.3456789` instead of `+12.35`, while field **A** (`%{...:.2f}`) correctly shows `12.35`.\n- Open the developer console and note the warning: `encountered bad format: \"+.2f\"`.\n\nThe same failure occurs with any spec beginning with a sign flag and containing one of `f`/`p`/`s`/`&`, e.g. `-.2f`, `( .2f`, `+,.0f`, `+.1%`, `+.3s`. It also reproduces via `tickformat: '+.2f'` and `hoverformat: '+.2f'`.\n\n### Notes\n\n- Confirmed present on `master` (and released `v3.7.0`) — `Lib.adjustFormat` is unchanged as of commit `227bba91` and still contains the tilde-prepend heuristic above.\n- Suggested fix: in the tilde-prepend branch, do not prepend `~` when the spec begins with a sign flag. For example, exclude a leading `[+\\-( ]` (and any leading fill/align) from that branch, or only insert `~` immediately before the type character rather than at the start of the spec. A regression test covering `+.2f`, `-.2f`, `( .2f`, `+,.0f`, `+.3s`, `+.1%` would guard this.\n- Workaround for users: pre-format the value in the data (pass a pre-rendered string via `customdata`/`text`) or omit the leading `+` sign flag.\n","author":{"url":"https://github.com/omtee","@type":"Person","name":"omtee"},"datePublished":"2026-07-10T12:09:34Z","url":"https://github.com/plotly/plotly.js/issues/7897"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5bef781d-56f3-2231-e90d-f860099b6c8a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD20A:8FAC9:3C38CB:4E6192:6AFF8B06
html-safe-nonce308bc5277c012bf1c3ccd46d92fea50ed178c2f0e3b611a393e68978448bd20b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjBBOjhGQUM5OjNDMzhDQjo0RTYxOTI6NkFGRjhCMDYiLCJ2aXNpdG9yX2lkIjoiMzY4MjMwNzYyMDUyMzE4Mjg1NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8bf8bdf8e54c670a1b05983e29bb08f7f962515d06209e29fe02066e5fc17a4e
hovercard-subject-tagissue:4854849021
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.js/7897/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ec9b333c51e069c3aabebaf50009469d2b87a73dd1fb09c564a9c094159e7f5e/plotly/plotly.js/issues/7897
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ec9b333c51e069c3aabebaf50009469d2b87a73dd1fb09c564a9c094159e7f5e/plotly/plotly.js/issues/7897
og:image:altDescription A d3-format specifier that starts with a sign flag — +, -, (, or a space — is silently dropped when used in hovertemplate, texttemplate, tickformat, or hoverformat, and the raw (unforma...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameomtee
hostnamegithub.com
expected-hostnamegithub.com
None587ad99a3e443b2e1cb0d3df059ec49ab54389861f13310766dfdeb615fed90d
turbo-cache-controlno-preview
go-importgithub.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git
octolytics-dimension-user_id5997976
octolytics-dimension-user_loginplotly
octolytics-dimension-repository_id45646037
octolytics-dimension-repository_nwoplotly/plotly.js
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id45646037
octolytics-dimension-repository_network_root_nwoplotly/plotly.js
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5bb0fb68d64881d1344f5863d809515d496801e5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/plotly/plotly.js/issues/7897#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.js%2Fissues%2F7897
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fplotly%2Fplotly.js%2Fissues%2F7897
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=plotly%2Fplotly.js
Reloadhttps://github.com/plotly/plotly.js/issues/7897
Reloadhttps://github.com/plotly/plotly.js/issues/7897
Reloadhttps://github.com/plotly/plotly.js/issues/7897
plotlyhttps://github.com/plotly
plotly.jshttps://github.com/plotly/plotly.js
Codehttps://github.com/plotly/plotly.js
Issues726 (726)https://github.com/plotly/plotly.js/issues
Pull requests81 (81)https://github.com/plotly/plotly.js/pulls
Actionshttps://github.com/plotly/plotly.js/actions
Security and qualityhttps://github.com/plotly/plotly.js/security
Insightshttps://github.com/plotly/plotly.js/insights
https://github.com/plotly/plotly.js
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/7897
New issuehttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/7897
#7900https://github.com/plotly/plotly.js/pull/7900
[BUG]: hovertemplate/texttemplate/tickformat silently ignore a valid d3-format spec that begins with a sign flag (e.g. "+.2f")https://github.com/plotly/plotly.js/issues/7897#top
#7900https://github.com/plotly/plotly.js/pull/7900
P2considered for next cyclehttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P2%22
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
size: 1https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%201%22
https://github.com/omtee
omteehttps://github.com/omtee
on Jul 10, 2026https://github.com/plotly/plotly.js/issues/7897#issue-4854849021
JSFiddlehttps://jsfiddle.net/j3urLn7o
omteehttps://github.com/omtee
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
on Jul 10, 2026https://github.com/plotly/plotly.js/issues/7897#event-27812518421
https://github.com/camdecoster
camdecosterhttps://github.com/camdecoster
on Jul 22, 2026https://github.com/plotly/plotly.js/issues/7897#issuecomment-5048566832
robertclaushttps://github.com/robertclaus
P2considered for next cyclehttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P2%22
size: 1https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%201%22
on Jul 23, 2026https://github.com/plotly/plotly.js/issues/7897#event-28401229774
camdecosterhttps://github.com/camdecoster
completedhttps://github.com/plotly/plotly.js/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#7900https://github.com/plotly/plotly.js/pull/7900
on Jul 29, 2026https://github.com/plotly/plotly.js/issues/7897#event-28668585141
pullhttps://github.com/apps/pull
on Jul 29, 2026https://github.com/plotly/plotly.js/issues/7897#event-28677346032
Fix adjustFormat dropping d3-format specs that start with a sign flaghttps://github.com/Mu-L/plotly.js/commit/a6b2c2a4af659415dece74a2a3d49385a9ac88b1
https://docs.github.com/articles/closing-issues-via-commit-messages
a6b2c2ahttps://github.com/Mu-L/plotly.js/commit/a6b2c2a4af659415dece74a2a3d49385a9ac88b1
Sign up for freehttps://github.com/signup?return_to=https://github.com/plotly/plotly.js/issues/7897
Sign in to commenthttps://github.com/login?return_to=https://github.com/plotly/plotly.js/issues/7897
P2considered for next cyclehttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22P2%22
bugsomething brokenhttps://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22bug%22
size: 1https://github.com/plotly/plotly.js/issues?q=state%3Aopen%20label%3A%22size%3A%201%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.