Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions src/EditorControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class EditorControls extends Component {
constructor(props, context) {
super(props, context);

this.localize = key =>
localizeString(this.props.dictionaries || {}, this.props.locale, key);

// we only need to compute this once.
if (this.props.plotly) {
this.plotSchema = this.props.plotly.PlotSchema.get();
Expand All @@ -38,8 +41,7 @@ class EditorControls extends Component {
dataSourceValueRenderer: this.props.dataSourceValueRenderer,
dataSourceOptionRenderer: this.props.dataSourceOptionRenderer,
dictionaries: this.props.dictionaries || {},
localize: key =>
localizeString(this.props.dictionaries || {}, this.props.locale, key),
localize: this.localize,
frames: gd._transitionData ? gd._transitionData._frames : [],
fullData: gd._fullData,
fullLayout: gd._fullLayout,
Expand Down Expand Up @@ -281,7 +283,9 @@ class EditorControls extends Component {
break;

default:
throw new Error('must specify an action type to handleEditorUpdate');
throw new Error(
this.localize('must specify an action type to handleEditorUpdate')
);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/components/containers/ModalProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ class ModalProvider extends React.Component {
}
}

openModal(component, props) {
openModal(component, componentProps) {
const {localize: _} = this.context;
if (!component) {
throw Error('You need to provide a component for the modal to open!');
throw Error(_('You need to provide a component for the modal to open!'));
}
const {open} = this.state;

if (!open) {
this.setState({
component: component,
componentProps: props,
componentProps: componentProps,
open: true,
});
}
Expand Down Expand Up @@ -85,6 +86,9 @@ class ModalProvider extends React.Component {
ModalProvider.propTypes = {
children: PropTypes.node,
};
ModalProvider.contextTypes = {
localize: PropTypes.func,
};
ModalProvider.childContextTypes = {
openModal: PropTypes.func,
closeModal: PropTypes.func,
Expand Down
4 changes: 3 additions & 1 deletion src/components/containers/TraceAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {Component} from 'react';
import {EDITOR_ACTIONS} from 'lib/constants';
import {connectTraceToPlot, plotlyTraceToCustomTrace} from 'lib';
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
import {traceTypes} from 'lib/traceTypes';

const TraceFold = connectTraceToPlot(PlotlyFold);

Expand Down Expand Up @@ -38,6 +39,7 @@ class TraceAccordion extends Component {
return null;
}

const {localize: _} = this.context;
const dataArrayPositionsByTraceType = {};
const fullDataArrayPositionsByTraceType = {};

Expand All @@ -62,7 +64,7 @@ class TraceAccordion extends Component {
<TraceFold
key={index}
traceIndexes={dataArrayPositionsByTraceType[type]}
name={type}
name={traceTypes(_).find(t => t.value === type).label}
fullDataArrayPosition={fullDataArrayPositionsByTraceType[type]}
>
{this.props.children}
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/AxesCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class UnconnectedAxesCreator extends Component {
<AxisCreator
key={index}
attr={type}
label={type.charAt(0).toUpperCase() + ' Axis'}
label={type.charAt(0).toUpperCase() + _(' Axis')}
options={getOptions(type)}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/fields/AxesSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import React, {Component} from 'react';
class AxesSelector extends Component {
constructor(props, context) {
super(props, context);
const {localize: _} = context;

if (!context.axesTargetHandler) {
throw new Error(
'AxesSelector must be nested within a connectAxesToPlot component'
_('AxesSelector must be nested within a connectAxesToPlot component')
);
}
}
Expand Down
112 changes: 60 additions & 52 deletions src/components/fields/FilterOperation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,38 @@ import DropdownWidget from '../widgets/Dropdown';
import TextInput from '../widgets/TextInput';
import {connectToContainer} from 'lib';

const operators = [
{
label: 'Inequality',
value: 'inequality',
},
{
label: 'Include Range',
value: 'inrange',
},
{
label: 'Exclude Range',
value: 'exrange',
},
{
label: 'Include Values',
value: 'inset',
},
{
label: 'Exclude Values',
value: 'exset',
},
];

const operations = {
const operations = _ => ({
inequality: [
{value: '!=', label: 'Target ≠ Reference'},
{value: '<', label: 'Target < Reference'},
{value: '<=', label: 'Target ≤ Reference'},
{value: '=', label: 'Target = Reference'},
{value: '>', label: 'Target > Reference'},
{value: '>=', label: 'Target ≥ Reference'},
{value: '!=', label: _('Target ≠ Reference')},
{value: '<', label: _('Target < Reference')},
{value: '<=', label: _('Target ≤ Reference')},
{value: '=', label: _('Target = Reference')},
{value: '>', label: _('Target > Reference')},
{value: '>=', label: _('Target ≥ Reference')},
],
inrange: [
{value: '[]', label: 'Lower ≤ Target ≤ Upper'},
{value: '()', label: 'Lower < Target < Upper'},
{value: '[)', label: 'Lower ≤ Target < Upper'},
{value: '(]', label: 'Lower < Target ≤ Upper'},
{value: '[]', label: _('Lower ≤ Target ≤ Upper')},
{value: '()', label: _('Lower < Target < Upper')},
{value: '[)', label: _('Lower ≤ Target < Upper')},
{value: '(]', label: _('Lower < Target ≤ Upper')},
],
exrange: [
{value: ')(', label: 'Lower ≤ Target ≤ Upper'},
{value: '][', label: 'Lower < Target < Upper'},
{value: ')[', label: 'Lower ≤ Target < Upper'},
{value: '](', label: 'Lower < Target ≤ Upper'},
{value: ')(', label: _('Lower ≤ Target ≤ Upper')},
{value: '][', label: _('Lower < Target < Upper')},
{value: ')[', label: _('Lower ≤ Target < Upper')},
{value: '](', label: _('Lower < Target ≤ Upper')},
],
inset: [{value: '{}', label: 'Include'}],
exset: [{value: '}{', label: 'Exclude'}],
};
inset: [{value: '{}', label: _('Include')}],
exset: [{value: '}{', label: _('Exclude')}],
});

const findOperation = operator => {
const findOperation = (operator, _) => {
let op = 'inequality';
for (const key in operations) {
const ops = operations(_);
for (const key in ops) {
if (
operations.hasOwnProperty(key) &&
operations[key].map(o => o.value).indexOf(operator) !== -1
ops.hasOwnProperty(key) &&
ops[key].map(o => o.value).indexOf(operator) !== -1
) {
op = key;
break;
Expand All @@ -70,17 +48,19 @@ const findOperation = operator => {
class UnconnectedFilterOperation extends Component {
constructor(props, context) {
super(props, context);
const {localize: _} = context;

this.state = {
operation: findOperation(this.props.fullValue),
operator: operations.inequality[0].value,
operation: findOperation(this.props.fullValue, _),
operator: operations(_).inequality[0].value,
};

this.setOperation = this.setOperation.bind(this);
}

setOperation(value) {
const operator = operations[value][0].value;
const {localize: _} = this.context;
const operator = operations(_)[value][0].value;
this.setState({operation: value, operator: operator});
this.props.updatePlot(operator);
}
Expand All @@ -94,6 +74,30 @@ class UnconnectedFilterOperation extends Component {
backgroundDark,
attr,
} = this.props;
const {localize: _} = this.context;

const operators = [
{
label: _('Inequality'),
value: 'inequality',
},
{
label: _('Include Range'),
value: 'inrange',
},
{
label: _('Exclude Range'),
value: 'exrange',
},
{
label: _('Include Values'),
value: 'inset',
},
{
label: _('Exclude Values'),
value: 'exset',
},
];

const opValue =
fullValue && fullValue.length > 0 ? fullValue : this.state.operator;
Expand All @@ -103,7 +107,7 @@ class UnconnectedFilterOperation extends Component {
<DropdownWidget
backgroundDark={backgroundDark}
options={operators}
value={findOperation(opValue)}
value={findOperation(opValue, _)}
onChange={this.setOperation}
clearable={false}
optionRenderer={optionRenderer}
Expand All @@ -113,7 +117,7 @@ class UnconnectedFilterOperation extends Component {
this.state.operation === 'exset' ? null : (
<DropdownWidget
backgroundDark={backgroundDark}
options={operations[this.state.operation]}
options={operations(_)[this.state.operation]}
value={opValue}
onChange={updatePlot}
clearable={false}
Expand All @@ -132,6 +136,9 @@ UnconnectedFilterOperation.propTypes = {
updatePlot: PropTypes.func,
...Field.propTypes,
};
UnconnectedFilterOperation.contextTypes = {
localize: PropTypes.func,
};

class UnconnectedFilterValue extends Component {
constructor(props, context) {
Expand All @@ -144,7 +151,8 @@ class UnconnectedFilterValue extends Component {
}

setValue(v) {
const op = findOperation(this.context.container.operation);
const {localize: _, container} = this.context;
const op = findOperation(container.operation, _);
this.setState({value: v});
let val;
val = op === 'inrange' || op === 'exrange' ? [v, this.state.valueMax] : v;
Expand All @@ -167,7 +175,7 @@ class UnconnectedFilterValue extends Component {
container && container.operation ? container.operation : '=';

const {fullValue, attr, defaultValue} = this.props;
const op = findOperation(operation);
const op = findOperation(operation, _);

let label1 = _('Reference');
if (op === 'inrange' || op === 'exrange') {
Expand Down
1 change: 1 addition & 0 deletions src/components/fields/MarkerColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class UnconnectedMarkerColor extends Component {
this.context.updateContainer({
['marker.colorsrc']: null,
['marker.colorscale']: null,
['marker.showscale']: null,
});
this.setState({colorscale: null});
} else {
Expand Down
Loading