◐ Shell
clean mode source ↗

feat: Add template string fallback attributes by camdecoster · Pull Request #7577 · plotly/plotly.js

@camdecoster A couple high-level comments before I dig into the gritty details:

  • I'm starting to feel that - might be a better default fallback value than empty string, because it indicates that it's a placeholder for something, which looks less awkward when you're using the templated value as part of a sentence. To take an example from the Jasmine tests, '- of -' looks less awkward than ' of '.

  • We've discussed that there are two separate scenarios where a value may end up as undefined: (1) is where the attribute named in the template simply doesn't exist, and (2) is where the attribute exists, but some individual data values happen to be undefined. I do think these two cases should be handled differently. The first is an error on the chart developer's part, and they should be alerted to it so they can fix it; the second is a normal quirk of the data and should be handled seamlessly. Open to discussing further but at the moment my suggestion is:

    • If the attribute named in the hovertemplate does not exist (e.g. dev has provided hovertemplate 'value: %{foo:.2f}' but trace.foo is not an existing attribute): Maintain existing behavior -- raw template string is rendered in hover tooltip
    • If attribute named in hovertemplate does exist, but the individual data value happens to be undefined (e.g. dev has provided hovertemplate 'value: %{foo:.2f}' and trace.foo is [1, undefined, 2]: Template string is replaced with hovertemplatefallback, AND no warning is emitted. So basically the behavior implemented in this PR, but without the warning. My feeling is that the dev has not done anything wrong and doesn't need to change anything, so a warning is just log noise at that point.