This pen https://codepen.io/nicolaskruchten/pen/YzzXwdL shows some differences between texttemplate and hovertemplate, specifically that %{y} in texttemplate doesn't seem to pick up the formatting from the yaxis ticklabels the way hovertemplate does.
Looking at https://github.com/plotly/plotly.js/pull/4071, I found:
that discussed similar things, but nothing on axis attributes having an effect on the default texttemplate output - @antoinerg do you remember discussing this?
I'd call this bug, axis tickformat, tickprefix and ticksuffix should be considered in texttemplate. Internally, this means using Axes.tickText everywhere.
Mmm... that is unfortunate indeed. The code path a value takes before reaching texttemplate and hovertemplate is a bit different hence the difference. We should aim to close the gap.
I'd call this bug, axis
tickformat,tickprefixandticksuffixshould be considered intexttemplate. Internally, this means usingAxes.tickTexteverywhere.
I agree that the default labels should contain those 3 tick properties.
Is there any case for not declaring absolutely that they should always be equal, not just with those three properties but all properties?
Is there any case for not declaring absolutely that they should always be equal, not just with those three properties but all properties?
If I remember correctly, by defaults hover labels may/should have more precision than displayed text.
I seem to recall discussing this, yes.
All in all this is a wicked feature already :)
@antoinerg I think I found a fix for this issue - ok if I assign myself this one?
@antoinerg I think I found a fix for this issue - ok if I assign myself this one?
Sure go ahead :) Thanks for taking this on
I probably won't have the time to make a PR to fix this bug for all traces that support texttemplate before my vacation, so here's some info I gathered about this problem.
There are currently four different texttemplate "pathways" used currently:
Lib.texttemplateString inside bar/plot.jsLib.texttemplateString from their formatSliceLabel routineDrawing.textPointStyle via Scatter.styleTextLib.texttemplateString in their "convert" stepFixing this bug here for bar, funnel and waterfall traces is relatively easy: we simply need to copy the labelLabel and valueLabel formatted values
to xLabel and yLabel depending on the orientation.
pie, funnelarea, sunburst and treemap appear unaffected by this bug. Their texttemplate formatting appears equivalent to their hovertemplate formatting.
All the scatter* traces appear affected, example: https://codepen.io/etpinard/pen/pooWyMg
To fix the scatter case, we'll need to pass xLabel and yLabel to Lib.texttemplateString as formatted by Axes.tickText similarly to how we fill in xLabel and yLabel during hover.
(note that Axes.hoverLabelText calls Axes.tickText internally)
To fix the scatterternary case, we'll need to pass aLabel, bLabel and cLabel
For the scattergeo, lonLabel and latLabel
... and so on.
In brief, the logic here in Drawing.textPointStyle
is not sufficient.
Now, if we agree that the default texttemplate formatting should be the same as the default hovertemplate formatting everywhere (i.e. with the same number precision), we should probably start thinking about ways to reuse the same coordinate-to-label formatting functions for both hover and texttemplate formatting.
I'm thinking either adding a new trace module method (e.g. _module._formatCoords) or add format functions to the trace's corresponding fullData[i] objects e.g. during supplyDefaults
// in scatterternary/defaults.js
trace._aFormatFn = function(cdi) { return Axes.tickText(ternary.aaxis, cdi.a, 'hover').text; };
With a bit more work, perhaps we could even generalise _module.eventData so that it also formats the coordinates.
Oh well, having all the per-trace coordinate formatting logic in one place should be a big win.
OK to bump to 1.52
OK to bump to 1.52
Sure, but this can be done in a 1.51.x patch release also.
Here's my WIP branch:
https://github.com/plotly/plotly.js/compare/texttemplate-formatting-fixes
Anyone should feel free to pull it down and add commits to it during the next two weeks.
Most helpful comment
Mmm... that is unfortunate indeed. The code path a value takes before reaching
texttemplateandhovertemplateis a bit different hence the difference. We should aim to close the gap.I agree that the default labels should contain those 3
tickproperties.