texttemplate #3816
Copy link
Copy link
Closed
Description
This idea keeps coming up as we discuss various questions... Here's an issue for it!
We should have a texttemplate attribute wherever we accept text or textinfo, with similar semantics as hovertemplate.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featuresomething newsomething new
Activity
antoinerg commentedon Jul 12, 2019
Ok so here are the affected traces/components:
etpinard commentedon Jul 12, 2019
More like:
A lot of traces have
textas simply an alias forhovertext, so they don't needtextinfo.I don't think
textinfois necessary for components like annotations as they don't have any data arrays (e.g.%{y}) associated with them.etpinard commentedon Jul 12, 2019
... and we can probably do 👌 w/o adding
texttemplatefor all thescatter*traces in the first iteration.So that leaves 6 trace types:
pie,sunburst,funnelarea,bar,waterfallandfunnel.antoinerg commentedon Jul 15, 2019
In the context of
hovertemplate, should the variabletextbe given the value of the compiledtexttemplatewhen it's available or should it only point to the value intext?etpinard commentedon Jul 15, 2019
Thanks for pointing this out!
I think pointing to the value in
textwill be sufficient. That is,should show
%{label} %{value}(i.e. the raw un-templated string), as it would be easy enough to set:We had a similar discussion in #3865
etpinard commentedon Jul 15, 2019
More precisely in #3865 (comment)
antoinerg commentedon Jul 16, 2019
Initial implementation for those 6 traces on this branch: https://github.com/plotly/plotly.js/compare/texttemplate
Note that I'll remove
texttemplate_tests.jsand insert the tests into each trace's test file.etpinard commentedon Jul 16, 2019
That's a very 💪 first attempt @antoinerg !
I like the way you put some of the logic in
Drawing.textPointStyle. So DRY!A few comments:
trace._metais handled inDrawing.textPointStyle, we could potentially cut a few lines like this blockplotly.js/src/traces/pie/plot.js
Lines 208 to 210 in 1cf8a85
see #3865 for more potentially redundant
trace._metablocks.We'll have to rename
Lib.hovertemplateStringto e.g.Lib.traceTemplateStringorLib.templateStringWithDataor maybe we could combine itLib.templateString?We should make sure traces that have
textinfoandtexttemplatedo not coercetextinfowhentexttemplateis non-empty, similar toplotly.js/src/plots/plots.js
Line 1294 in 218a919
You wrote "
TODO: calcTextinfo should build a texttemplate pass it to calcTexttemplate()". That's interesting, I was thinking about doing the same in our_module.hoverPointsmethods to DRY things up. But we should be careful here. creating a template string than parsing it must be slower than simply creating a string from(text|hover)infoflags. How much slower, I don't know. It would be interesting to benchmark this e.g. try plotting a trace with 1e4 with atexttemplateand check how much slower that is compared to with just atextarray.The jasmine tests you wrote look good, but I would prefer seeing
texttemplatein action in one or multiple mocks.antoinerg commentedon Jul 17, 2019
I think it should have
template,stringandformatin its name. Its main difference withLib.templateStringis that it supports number formatting (as well as default formats). So, what aboutLib.templateFormatString?cc @etpinard
etpinard commentedon Jul 17, 2019
Lib.templateFormatStringsounds 10/10 to meantoinerg commentedon Jul 19, 2019
Done in branch texttemplate
To do:
colorvariable inpieandfunnelareatexttemplate_test.jsinto each trace's test filetextinfowhentexttemplate(without tests for now)