Open perdodi opened 3 years ago
This seems to be due to the behaviour of the package fast-isnumeric
, which is used in https://github.com/plotly/plotly.js/blob/2f17e117648e56ff3eebb5f55e57db522f4d9200/src/plots/cartesian/set_convert.js#L182
Indeed, in a nodejs
console:
> var isNumeric = require('fast-isnumeric');
> isNumeric(40)
true
> isNumeric("40")
true
This makes it so that getCategoryIndex
is not called even when the value is a string that looks like a number (e.g., "40").
@alexcjohnson is this behaviour desired?
also related: https://github.com/plotly/plotly.js/issues/5741
See also autotypenumbers: 'strict'
https://github.com/plotly/plotly.js/pull/5240
(which is now the default for graphs made with plotly.py)
Ok I see. Setting autotypenumbers: "strict"
in layout
or layout.xaxis
(relevant to this use case) doesn't fix the bug, but to be fair the docs just mention "trace data" and not the coordinates of shapes (or images or annotations for that matter). But the expected behaviour is most likely to follow what the axis' autotypesnumbers
setting says to do for shapes as well.
Yep, that sounds right - if an axis is in strict mode, that should apply to shapes, annotations, and images as well as traces. So that part of this issue can be considered a bug.
If X axis
type
iscategory
, andcategoryarray
contains (string type) numbers, then shapes are horizontally misplaced, asx0
andx1
values in theshape
are not considered as items, but as indices of thecategoryarray
.Eg.
This one works perfectly:
But if I replace the color names to numbers:
It will work only if I replace the category values to their indices in the
shapes
:Note: if this is not intended to be a bug, but an undocumented feature, please document it, so I can rely on it later. 😃