Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e980e44
Linting/formatting
camdecoster Sep 29, 2025
212f892
Return empty string for undefined value in templateFormatString
camdecoster Sep 29, 2025
75b157f
Refactoring
camdecoster Oct 2, 2025
5f3670f
Add fallback value for template strings
camdecoster Oct 3, 2025
336e9ae
Add fallback to calls to hovertemplateString
camdecoster Oct 3, 2025
02a4cad
Add fallback to calls to texttemplateString
camdecoster Oct 3, 2025
77bc2b9
Add fallback to calls to texttemplateStringForShapes
camdecoster Oct 7, 2025
85b67e9
Update defaults calculations
camdecoster Oct 6, 2025
680c793
Add helper function for template fallback attributes
camdecoster Oct 6, 2025
52c29cc
Add fallback value to attributes files
camdecoster Oct 7, 2025
f623b22
Update esbuild strip meta plugin to handle more joined arrays
camdecoster Oct 8, 2025
074f8a0
Return array from ternary
camdecoster Oct 8, 2025
6f3daa8
Update tests per default fallback value
camdecoster Oct 8, 2025
6719bd3
Update schema
camdecoster Oct 8, 2025
84fc044
Update test baselines
camdecoster Oct 8, 2025
e719f74
Rename object keys
camdecoster Oct 8, 2025
fb7a40c
Add/update tests to check fallback value
camdecoster Oct 9, 2025
faaae28
Add draftlog
camdecoster Oct 9, 2025
5c032c6
Fix typos
camdecoster Oct 21, 2025
a0ce641
Update fallback `editType` to match template
camdecoster Oct 21, 2025
14ab31c
Handle undefined values and missing values differently
camdecoster Oct 23, 2025
4f79efe
Update default fallback value and template attribute descriptions
camdecoster Oct 23, 2025
257475c
Add tests for missing and undefined values
camdecoster Oct 23, 2025
a148edd
Update schema
camdecoster Oct 23, 2025
c40fe9f
Merge remote-tracking branch 'origin/master' into cam/7564/return-emp…
camdecoster Oct 23, 2025
6a66148
Revert "Update test baselines"
camdecoster Oct 23, 2025
5215f13
Always use fallback for missing values, except when fallback is false
camdecoster Oct 24, 2025
30f87f3
Update schema
camdecoster Oct 24, 2025
b61d70d
Update mocks to show fallback values
camdecoster Oct 24, 2025
d900ca3
Update tests per final behavior
camdecoster Oct 24, 2025
a061787
Update baseline images
camdecoster Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add helper function for template fallback attributes
  • Loading branch information
camdecoster committed Oct 9, 2025
commit 680c7930ce7cdeee2fef8375ebcc0489a8de9baa
84 changes: 40 additions & 44 deletions src/plots/template_attributes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
const { DATE_FORMAT_LINK, FORMAT_LINK } = require('../constants/docs');

function templateFormatStringDescription(opts = {}) {
const { supportOther } = opts;
function templateFormatStringDescription({ supportOther } = {}) {
const supportOtherText =
' as well as %{xother}, {%_xother}, {%_xother_}, {%xother_}. When showing info for several points, *xother* will be added to those with different x positions from the first point. An underscore before or after *(x|y)other* will add a space on that side, only when this field is shown.';

Expand Down Expand Up @@ -34,53 +33,43 @@ function describeVariables({ description, keys = [] }) {
return descPart;
}

exports.hovertemplateAttrs = (opts = {}, extra = {}) => {
const hovertemplate = {
valType: 'string',
dflt: '',
editType: opts.editType || 'none',
description: [
'Template string used for rendering the information that appear on hover box.',
'Note that this will override `hoverinfo`.',
templateFormatStringDescription({ supportOther: true }),
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data.',
'Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
describeVariables(extra),
'Anything contained in tag `<extra>` is displayed in the secondary box, for example `<extra>%{fullData.name}</extra>`.',
'To hide the secondary box completely, use an empty tag `<extra></extra>`.'
].join(' ')
};

if (opts.arrayOk !== false) hovertemplate.arrayOk = true;

return hovertemplate;
};

exports.texttemplateAttrs = (opts = {}, extra = {}) => {
const texttemplate = {
valType: 'string',
dflt: '',
editType: opts.editType || 'calc',
description: [
'Template string used for rendering the information text that appear on points.',
'Note that this will override `textinfo`.',
templateFormatStringDescription(),
'Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
describeVariables(extra)
].join(' ')
};

if (opts.arrayOk !== false) texttemplate.arrayOk = true;
exports.hovertemplateAttrs = ({ editType = 'none', arrayOk } = {}, extra = {}) => ({
valType: 'string',
dflt: '',
editType,
description: [
'Template string used for rendering the information that appear on hover box.',
'Note that this will override `hoverinfo`.',
templateFormatStringDescription({ supportOther: true }),
'The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data.',
'Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
describeVariables(extra),
'Anything contained in tag `<extra>` is displayed in the secondary box, for example `<extra>%{fullData.name}</extra>`.',
'To hide the secondary box completely, use an empty tag `<extra></extra>`.'
].join(' '),
...(arrayOk !== false ? { arrayOk: true } : {})
});

return texttemplate;
};
exports.texttemplateAttrs = ({ editType = 'calc', arrayOk } = {}, extra = {}) => ({
valType: 'string',
dflt: '',
editType,
description: [
'Template string used for rendering the information text that appears on points.',
'Note that this will override `textinfo`.',
templateFormatStringDescription(),
'Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available.',
describeVariables(extra)
].join(' '),
...(arrayOk !== false ? { arrayOk: true } : {})
});

exports.shapeTexttemplateAttrs = (opts = {}, extra = {}) => ({
exports.shapeTexttemplateAttrs = ({ editType = 'arraydraw', newshape }, extra = {}) => ({
valType: 'string',
dflt: '',
editType: opts.editType || 'arraydraw',
editType,
description: [
`Template string used for rendering the ${opts.newshape ? 'new ' : ''}shape's label.`,
`Template string used for rendering the ${newshape ? 'new ' : ''}shape's label.`,
'Note that this will override `text`.',
'Variables are inserted using %{variable},',
'for example "x0: %{x0}".',
Expand All @@ -97,3 +86,10 @@ exports.shapeTexttemplateAttrs = (opts = {}, extra = {}) => ({
describeVariables(extra)
].join(' ')
});

exports.templatefallbackAttrs = ({ editType = 'none' } = {}) => ({
Copy link
Contributor

@emilykl emilykl Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to set the correct editType here, I think it should be calc (or possibly plot?)

Reference for meaning of different editType values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing the changes again, I think it should be 'none' for hovertemplatefallback, 'calc' for texttemplatefallback, and 'arraydraw' for the shape text template fallback. I'll go through and double check all of them.

valType: 'string',
dflt: '',
editType,
description: "Fallback value that's displayed when a variable referenced in a template can't be found."
});