Shapes are misplaced when using numbers as categoryarray values
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.3k
- Forks
- 2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 28
Description
If X axis type is category, and categoryarray contains (string type) numbers, then shapes are horizontally misplaced, as x0 and x1 values in the shape are not considered as items, but as indices of the categoryarray.
Eg.
This one works perfectly:
<div id="tester"></div>
<script>
var layout = {
"xaxis": {
"type": "category",
"categoryarray": [
"red", "green", "blue", "purple", "cyan", "yellow", "magenta"
],
},
"shapes": [
{
"type": "rect",
"xref": "x",
"yref": "y",
"x0": "purple",
"x1": "yellow",
"y0": 10,
"y1": 20,
"fillcolor": "rgba(45,180,135,0.3)",
}
]
};
var data = [
{
"x": [ "red", "blue", "cyan", "magenta" ],
"y": [ 10, 20, 30, 40],
},
];
TESTER = document.getElementById('tester');
Plotly.newPlot( TESTER, data, layout );
</script>

But if I replace the color names to numbers:
// in "categoryarray":
"10", "20", "30", "40", "50", "60", "70"
...
// in "shapes" this won't work:
"x0": "40",
"x1": "60",
...
// in data:
"x": [ "10", "30", "50", "70" ],

It will work only if I replace the category values to their indices in the shapes:
"x0": 3,
"x1": 5,

Note: if this is not intended to be a bug, but an undocumented feature, please document it, so I can rely on it later. 😃
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the inline JavaScript reproduction in the issue and compare the category-axis and shape behavior for color labels versus numeric string labels. Reproduce the misplaced shapes, then verify that shape coordinates using numeric category values align with the corresponding categories rather than only their indices.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100