Title: [BUG]: categoryorder 'median ascending' sorts values as strings · Issue #8166 · plotly/plotly.js · GitHub
Open Graph Title: [BUG]: categoryorder 'median ascending' sorts values as strings · Issue #8166 · plotly/plotly.js
X Title: [BUG]: categoryorder 'median ascending' sorts values as strings · Issue #8166 · plotly/plotly.js
Description: Description With categoryorder: 'median ascending', some categories get the wrong position on the axis. Lib.median in src/lib/stats.js sorts with data.slice().sort() and no comparator. JavaScript then compares the values as strings. So L...
Open Graph Description: Description With categoryorder: 'median ascending', some categories get the wrong position on the axis. Lib.median in src/lib/stats.js sorts with data.slice().sort() and no comparator. JavaScript t...
X Description: Description With categoryorder: 'median ascending', some categories get the wrong position on the axis. Lib.median in src/lib/stats.js sorts with data.slice().sort() and no comparator. Java...
Opengraph URL: https://github.com/plotly/plotly.js/issues/8166
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[BUG]: categoryorder 'median ascending' sorts values as strings","articleBody":"### Description\n\nWith `categoryorder: 'median ascending'`, some categories get the wrong position on the axis. `Lib.median` in `src/lib/stats.js` sorts with `data.slice().sort()` and no comparator. JavaScript then compares the values as strings. So `Lib.median([1, 10, 2])` returns 10, not 2, and `Lib.median([-1, -5, 2])` returns -5, not -1.\n\nThe `median()` tests in `lib_test.js` use only single-digit positive values. String order and numeric order agree for those values, so the tests pass.\n\n### Screenshots/Video\n\nNo screenshot. The steps below show the order on the axis.\n\n### Steps to reproduce\n\n```js\nPlotly.newPlot(gd, [{\n x: ['a', 'a', 'a', 'b', 'b', 'b'],\n y: [1, 10, 2, 3, 3, 3]\n}], {\n xaxis: {type: 'category', categoryorder: 'median ascending'}\n});\n```\n\n- The median of `a` is 2. The median of `b` is 3.\n- Expected axis order: `a`, `b`.\n- Actual axis order: `b`, `a`, because the median of `a` comes out as 10.\n\n### Notes\n\nA numeric comparator in `Lib.median` fixes it: `data.slice().sort((x, y) => x - y)`. The only caller of `Lib.median` is the median aggregation for `categoryorder` in `src/plots/plots.js`. Box and violin traces compute their quartiles separately. I can send a PR with this change, a test case in `lib_test.js` and a draftlog entry.\n","author":{"url":"https://github.com/G26karthik","@type":"Person","name":"G26karthik"},"datePublished":"2026-11-09T17:47:32Z","url":"https://github.com/plotly/plotly.js/issues/8166"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3a2e406f-5a6d-652f-5208-569d8674e9d7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D730:11EACE:26DD976:33E93AC:6B01AA6E |
| html-safe-nonce | a5f3e693e68c8432956b10fe1551749055407d077b282515062ac701811a502b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzMwOjExRUFDRToyNkREOTc2OjMzRTkzQUM6NkIwMUFBNkUiLCJ2aXNpdG9yX2lkIjoiNDA5NzU1NzM5ODE0MTY0MzM3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 45ee4971eb657389a354206900951c97db9e2a4bcba718a77fd24aa1a6240e66 |
| hovercard-subject-tag | issue:6291507549 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/plotly/plotly.js/8166/issue_layout |
| twitter:image | https://opengraph.githubassets.com/df3dcc3985843cdce096538afe15f92d965d95a0a22a93f1d1747ca0e7a5df0f/plotly/plotly.js/issues/8166 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/df3dcc3985843cdce096538afe15f92d965d95a0a22a93f1d1747ca0e7a5df0f/plotly/plotly.js/issues/8166 |
| og:image:alt | Description With categoryorder: 'median ascending', some categories get the wrong position on the axis. Lib.median in src/lib/stats.js sorts with data.slice().sort() and no comparator. JavaScript t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | G26karthik |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/plotly/plotly.js git https://github.com/plotly/plotly.js.git |
| octolytics-dimension-user_id | 5997976 |
| octolytics-dimension-user_login | plotly |
| octolytics-dimension-repository_id | 45646037 |
| octolytics-dimension-repository_nwo | plotly/plotly.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 45646037 |
| octolytics-dimension-repository_network_root_nwo | plotly/plotly.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width