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: 5 additions & 5 deletions src/components/fields/DataSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Field from './Field';
import nestedProperty from 'plotly.js/src/lib/nested_property';
import {connectToContainer} from 'lib';

function attributeIsData(meta = {}) {
export function attributeIsData(meta = {}) {
return meta.valType === 'data_array' || meta.arrayOk;
}

class DataSelector extends Component {
export class UnconnectedDataSelector extends Component {
constructor(props, context) {
super(props, context);

Expand Down Expand Up @@ -91,14 +91,14 @@ class DataSelector extends Component {
}
}

DataSelector.propTypes = {
UnconnectedDataSelector.propTypes = {
fullValue: PropTypes.any,
updatePlot: PropTypes.func,
container: PropTypes.object,
...Field.propTypes,
};

DataSelector.contextTypes = {
UnconnectedDataSelector.contextTypes = {
dataSources: PropTypes.object,
dataSourceOptions: PropTypes.array,
dataSourceValueRenderer: PropTypes.func,
Expand All @@ -111,4 +111,4 @@ function modifyPlotProps(props, context, plotProps) {
}
}

export default connectToContainer(DataSelector, {modifyPlotProps});
export default connectToContainer(UnconnectedDataSelector, {modifyPlotProps});
171 changes: 171 additions & 0 deletions src/components/fields/ErrorBars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import PropTypes from 'prop-types';
import React, {Component, Fragment} from 'react';
import {DataSelector, Radio, Numeric} from '../index';
import RadioBlocks from '../widgets/RadioBlocks';
import Field from './Field';
import {connectToContainer} from 'lib';

class ErrorBars extends Component {
constructor(props, context) {
super(props, context);
this.updatePlot = this.updatePlot.bind(this);
}

updatePlot(value) {
if (value === 'symmetric') {
this.props.updatePlot({
...this.props.fullValue,
visible: true,
symmetric: true,
});
}

if (value === 'asymmetric') {
this.props.updatePlot({
...this.props.fullValue,
visible: true,
symmetric: false,
});
}

if (value === 'hidden') {
this.props.updatePlot({
...this.props.fullValue,
visible: false,
});
}
}

getMode() {
let mode;

if (!this.props.fullValue.visible) {
mode = 'hidden';
}

if (
this.props.fullValue.visible &&
(this.props.fullValue.symmetric ||
typeof this.props.fullValue.symmetric === 'undefined')
) {
// when this.props.fullValue.type === 'sqrt',
// then this.props.fullValue.symmetric is undefined, but 'sqrt' is only
// applicable when we want symmetric error bars
// https://github.com/plotly/plotly.js/issues/2359
mode = 'symmetric';
}

if (
this.props.fullValue.visible &&
this.props.fullValue.symmetric === false
) {
// it has to be explicitly set to false, because we don't want it to catch
// cases when it's undefined
mode = 'asymmetric';
}

return mode;
}

renderModeSelector() {
const {localize: _} = this.props;

return (
<Field>
<RadioBlocks
alignment="center"
onOptionChange={this.updatePlot}
activeOption={this.getMode()}
options={[
{label: _('Symmetric'), value: 'symmetric'},
{label: _('Asymmetric'), value: 'asymmetric'},
{label: _('Hidden'), value: 'hidden'},
]}
/>
</Field>
);
}

renderErrorBarControls() {
const {localize: _} = this.props;
const mode = this.getMode();
const showCustomDataControl = this.props.fullValue.type === 'data';

if (mode === 'symmetric') {
return (
<Fragment>
<Radio
label={_('Error Type')}
attr={`${this.props.attr}.type`}
options={[
{label: _('%'), value: 'percent'},
{label: _('Constant'), value: 'constant'},
{label: _('√'), value: 'sqrt'},
{label: _('Data'), value: 'data'},
]}
/>
<Numeric label={_('Value')} attr={`${this.props.attr}.value`} />
{showCustomDataControl ? (
<DataSelector
label={_(`Custom Data`)}
attr={`${this.props.attr}.array`}
/>
) : null}
</Fragment>
);
}

if (mode === 'asymmetric') {
return (
<Fragment>
<Radio
label={_('Error Type')}
attr={`${this.props.attr}.type`}
options={[
{label: _('%'), value: 'percent'},
{label: _('Constant'), value: 'constant'},
{label: _('Data'), value: 'data'},
]}
/>
<Numeric label={_('Value')} attr={`${this.props.attr}.value`} />
<Numeric
label={_('Value (-)')}
attr={`${this.props.attr}.valueminus`}
/>
{showCustomDataControl ? (
<Fragment>
<DataSelector
label={_(`Error (+)`)}
attr={`${this.props.attr}.array`}
/>
<DataSelector
label={_(`Error (-)`)}
attr={`${this.props.attr}.arrayminus`}
/>
</Fragment>
) : null}
</Fragment>
);
}

return null;
}

render() {
return (
<Fragment>
{this.renderModeSelector()}
{this.renderErrorBarControls()}
</Fragment>
);
}
}

ErrorBars.propTypes = {
attr: PropTypes.string,
localize: PropTypes.func,
fullValue: PropTypes.object,
updatePlot: PropTypes.func,
};

export default connectToContainer(ErrorBars);
4 changes: 2 additions & 2 deletions src/components/fields/derived.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import isNumeric from 'fast-isnumeric';
import {UnconnectedNumeric} from './Numeric';
import {UnconnectedDropdown} from './Dropdown';
import {UnconnectedRadio} from './Radio';
import {UnconnectedFlaglist} from './Flaglist';
import {UnconnectedNumeric} from './Numeric';
import {UnconnectedRadio} from './Radio';
import {
connectLayoutToPlot,
connectToContainer,
Expand Down
2 changes: 2 additions & 0 deletions src/components/fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DataSelector from './DataSelector';
import Numeric from './Numeric';
import SymbolSelector from './SymbolSelector';
import TraceSelector from './TraceSelector';
import ErrorBars from './ErrorBars';
import {
AnnotationArrowRef,
AnnotationRef,
Expand Down Expand Up @@ -40,6 +41,7 @@ export {
ContourNumeric,
DataSelector,
Dropdown,
ErrorBars,
FillDropdown,
Flaglist,
FontSelector,
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ContourNumeric,
DataSelector,
Dropdown,
ErrorBars,
FillDropdown,
Flaglist,
FontSelector,
Expand Down Expand Up @@ -63,6 +64,7 @@ export {
ContourNumeric,
DataSelector,
Dropdown,
ErrorBars,
FillDropdown,
Flaglist,
Fold,
Expand Down
13 changes: 13 additions & 0 deletions src/default_panels/GraphCreatePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {
DataSelector,
Dropdown,
ErrorBars,
GeoProjections,
GeoScope,
Radio,
Expand Down Expand Up @@ -62,6 +63,18 @@ const GraphCreatePanel = ({localize: _}) => {
<DataSelector label={_('C')} attr="c" />
</Section>

<Section name={_('Error Bars X')}>
<ErrorBars localize={_} attr="error_x" />
</Section>

<Section name={_('Error Bars Y')}>
<ErrorBars localize={_} attr="error_y" />
</Section>

<Section name={_('Error Bars Z')}>
<ErrorBars localize={_} attr="error_z" />
</Section>

<Section name={_('Options')}>
<DataSelector label={_('Intensity')} attr="intensity" />
<DataSelector label={_('Facecolor')} attr="facecolor" />
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ColorPicker,
ColorscalePicker,
ContourNumeric,
ErrorBars,
DataSelector,
Dropdown,
Flaglist,
Expand Down Expand Up @@ -75,6 +76,7 @@ export {
ColorPicker,
ColorscalePicker,
ContourNumeric,
ErrorBars,
DataSelector,
Dropdown,
EDITOR_ACTIONS,
Expand Down