diff --git a/src/components/containers/AnnotationAccordion.js b/src/components/containers/AnnotationAccordion.js index 18dd9692e..6b8a69303 100644 --- a/src/components/containers/AnnotationAccordion.js +++ b/src/components/containers/AnnotationAccordion.js @@ -3,8 +3,7 @@ import {LayoutPanel} from './derived'; import {PanelMessage} from './PanelEmpty'; import PropTypes from 'prop-types'; import React, {Component} from 'react'; -import {connectAnnotationToLayout} from 'lib'; -import {templateString} from 'plotly.js/src/lib'; +import {connectAnnotationToLayout, getParsedTemplateString} from 'lib'; const AnnotationFold = connectAnnotationToLayout(PlotlyFold); @@ -19,12 +18,11 @@ class AnnotationAccordion extends Component { const content = annotations.length && annotations.map((ann, i) => { - const textPostTemplate = templateString(ann.text, {meta}); return ( {children} diff --git a/src/components/containers/RangeSelectorAccordion.js b/src/components/containers/RangeSelectorAccordion.js index 940799ec1..539910db2 100644 --- a/src/components/containers/RangeSelectorAccordion.js +++ b/src/components/containers/RangeSelectorAccordion.js @@ -2,7 +2,7 @@ import PlotlyFold from './PlotlyFold'; import PlotlyPanel from './PlotlyPanel'; import PropTypes from 'prop-types'; import React, {Component} from 'react'; -import {connectRangeSelectorToAxis} from 'lib'; +import {connectRangeSelectorToAxis, getParsedTemplateString} from 'lib'; const RangeSelectorFold = connectRangeSelectorToAxis(PlotlyFold); @@ -23,13 +23,19 @@ class RangeSelectorAccordion extends Component { rangeselector: {buttons = []}, }, localize: _, + layout: meta, } = this.context; const {children} = this.props; const content = buttons.length && buttons.map((btn, i) => ( - + {children} )); @@ -57,6 +63,7 @@ class RangeSelectorAccordion extends Component { RangeSelectorAccordion.contextTypes = { fullContainer: PropTypes.object, localize: PropTypes.func, + layout: PropTypes.object, }; RangeSelectorAccordion.propTypes = { diff --git a/src/components/fields/AxesCreator.js b/src/components/fields/AxesCreator.js index 13e19d816..ff1a8553b 100644 --- a/src/components/fields/AxesCreator.js +++ b/src/components/fields/AxesCreator.js @@ -5,7 +5,13 @@ import React, {Component} from 'react'; import {EDITOR_ACTIONS} from 'lib/constants'; import Button from '../widgets/Button'; import {PlusIcon} from 'plotly-icons'; -import {connectToContainer, traceTypeToAxisType, getAxisTitle, axisIdToAxisName} from 'lib'; +import { + connectToContainer, + traceTypeToAxisType, + getAxisTitle, + axisIdToAxisName, + getParsedTemplateString, +} from 'lib'; import {PlotlySection} from 'components'; class UnconnectedAxisCreator extends Component { @@ -128,7 +134,10 @@ class UnconnectedAxesCreator extends Component { function getOptions(axisType) { return fullLayout._subplots[axisType].map(axisId => ({ - label: getAxisTitle(fullLayout[axisIdToAxisName(axisId)]), + label: getParsedTemplateString( + getAxisTitle(fullLayout[axisIdToAxisName(axisId)]), + fullLayout.meta + ), value: axisId, })); } diff --git a/src/components/fields/TextEditor.js b/src/components/fields/TextEditor.js index cd8b6689b..c5a0a76f7 100644 --- a/src/components/fields/TextEditor.js +++ b/src/components/fields/TextEditor.js @@ -32,7 +32,7 @@ export class UnconnectedTextEditor extends Component { if (index) { const adjustedIndex = parseInt(index[3], 10) - 1; if (!isNaN(adjustedIndex)) { - return `%{meta[${adjustedIndex}]}`; + return `%{meta[${adjustedIndex < 0 ? 0 : adjustedIndex}]}`; } } return match; diff --git a/src/lib/connectTraceToPlot.js b/src/lib/connectTraceToPlot.js index af621122c..d3420f40e 100644 --- a/src/lib/connectTraceToPlot.js +++ b/src/lib/connectTraceToPlot.js @@ -7,6 +7,7 @@ import { renderTraceIcon, traceTypeToAxisType, getFullTrace, + getParsedTemplateString, } from '../lib'; import {deepCopyPublic, setMultiValuedContainer} from './multiValues'; import {EDITOR_ACTIONS, SUBPLOT_TO_ATTR} from 'lib/constants'; @@ -27,7 +28,7 @@ export default function connectTraceToPlot(WrappedComponent) { setLocals(props, context) { const {traceIndexes} = props; - const {data, fullData, plotly} = context; + const {data, fullData, plotly, layout: meta} = context; const trace = data[traceIndexes[0]]; const fullTrace = getFullTrace(props, context); @@ -68,7 +69,7 @@ export default function connectTraceToPlot(WrappedComponent) { if (trace && fullTrace) { this.icon = renderTraceIcon(plotlyTraceToCustomTrace(trace)); - this.name = fullTrace.name; + this.name = getParsedTemplateString(fullTrace.name, meta); } } @@ -194,6 +195,7 @@ export default function connectTraceToPlot(WrappedComponent) { data: PropTypes.array, plotly: PropTypes.object, onUpdate: PropTypes.func, + layout: PropTypes.object, }; TraceConnectedComponent.childContextTypes = { diff --git a/src/lib/index.js b/src/lib/index.js index 5a071d4dd..2102ea5e3 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -30,6 +30,7 @@ import * as PlotlyIcons from 'plotly-icons'; import striptags from './striptags'; import {capitalize, lowerCase, upperCase, removeNonWord, camelCase, pascalCase} from './strings'; import {getColorscale} from 'react-colorscales'; +import {templateString} from 'plotly.js/src/lib'; const TOO_LIGHT_FACTOR = 0.8; @@ -202,51 +203,62 @@ function getFullTrace(props, context) { return fullTrace; } +function getParsedTemplateString(originalString, meta) { + let text = originalString; + + if (originalString && meta && meta.length) { + text = templateString(originalString, {meta}); + } + + return text === '' && originalString ? originalString : text; +} + export { adjustColorscale, axisIdToAxisName, bem, - capitalize, - lowerCase, - upperCase, - removeNonWord, camelCase, - pascalCase, + capitalize, clamp, + computeTraceOptionsFromSchema, + connectAggregationToTransform, + connectAnnotationToLayout, + connectAxesToLayout, connectCartesianSubplotToLayout, + connectImageToLayout, + connectLayoutToPlot, connectNonCartesianSubplotToLayout, - connectAnnotationToLayout, + connectRangeSelectorToAxis, connectShapeToLayout, connectSliderToLayout, - connectUpdateMenuToLayout, - connectImageToLayout, - connectAxesToLayout, - connectLayoutToPlot, connectToContainer, - connectRangeSelectorToAxis, - connectTransformToTrace, - connectAggregationToTransform, connectTraceToPlot, + connectTransformToTrace, + connectUpdateMenuToLayout, containerConnectedContextTypes, - computeTraceOptionsFromSchema, - traceTypeToPlotlyInitFigure, dereference, getAllAxes, getAxisTitle, - getSubplotTitle, getDisplayName, + getFullTrace, + getSubplotTitle, isPlainObject, localize, localizeString, + lowerCase, maybeAdjustSrc, maybeTransposeData, + getParsedTemplateString, + pascalCase, plotlyTraceToCustomTrace, + removeNonWord, renderTraceIcon, - unpackPlotProps, - walkObject, - tooLight, striptags, + tooLight, traceTypeToAxisType, + traceTypeToPlotlyInitFigure, transpose, - getFullTrace, + unpackPlotProps, + upperCase, + walkObject, };