Skip to content

Commit

Permalink
Merge pull request #846 from plotly/fix-meta-titles
Browse files Browse the repository at this point in the history
Fix meta titles
  • Loading branch information
VeraZab authored Feb 17, 2019
2 parents 8d0c41f + 8b63f28 commit fce716e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/components/containers/AnnotationAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -19,12 +18,11 @@ class AnnotationAccordion extends Component {
const content =
annotations.length &&
annotations.map((ann, i) => {
const textPostTemplate = templateString(ann.text, {meta});
return (
<AnnotationFold
key={i}
annotationIndex={i}
name={textPostTemplate === '' ? ann.text : textPostTemplate}
name={getParsedTemplateString(ann.text, meta)}
canDelete={canAdd}
>
{children}
Expand Down
11 changes: 9 additions & 2 deletions src/components/containers/RangeSelectorAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) => (
<RangeSelectorFold key={i} rangeselectorIndex={i} name={btn.label} canDelete={true}>
<RangeSelectorFold
key={i}
rangeselectorIndex={i}
name={getParsedTemplateString(btn.label, meta)}
canDelete={true}
>
{children}
</RangeSelectorFold>
));
Expand Down Expand Up @@ -57,6 +63,7 @@ class RangeSelectorAccordion extends Component {
RangeSelectorAccordion.contextTypes = {
fullContainer: PropTypes.object,
localize: PropTypes.func,
layout: PropTypes.object,
};

RangeSelectorAccordion.propTypes = {
Expand Down
13 changes: 11 additions & 2 deletions src/components/fields/AxesCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}));
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/TextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/connectTraceToPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -194,6 +195,7 @@ export default function connectTraceToPlot(WrappedComponent) {
data: PropTypes.array,
plotly: PropTypes.object,
onUpdate: PropTypes.func,
layout: PropTypes.object,
};

TraceConnectedComponent.childContextTypes = {
Expand Down
52 changes: 32 additions & 20 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
};

0 comments on commit fce716e

Please sign in to comment.