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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"fast-isnumeric": "^1.1.1",
"immutability-helper": "^2.6.4",
"plotly-icons": "latest",
"plotly.js": "1.39.4",
"plotly.js": "1.40.0",
"prop-types": "^15.5.10",
"raf": "^3.4.0",
"react-color": "^2.13.8",
Expand Down
7 changes: 2 additions & 5 deletions src/DefaultEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
StyleColorbarsPanel,
StyleUpdateMenusPanel,
} from './default_panels';
import {traceHasColorbar} from './default_panels/StyleColorbarsPanel';
import Logo from './components/widgets/Logo';
import {TRANSFORMABLE_TRACES} from './lib/constants';

Expand Down Expand Up @@ -62,11 +63,7 @@ class DefaultEditor extends Component {
}

hasColorbars() {
return this.context.fullData.some(
d =>
(d.marker && d.marker.showscale !== undefined) || // eslint-disable-line no-undefined
d.showscale !== undefined // eslint-disable-line no-undefined
);
return this.context.fullData.some(d => traceHasColorbar({}, d));
}

render() {
Expand Down
6 changes: 1 addition & 5 deletions src/components/containers/SubplotAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CartesianSubplotFold = connectCartesianSubplotToLayout(PlotlyFold);
class SubplotAccordion extends Component {
render() {
const {data = [], layout = {}, localize: _} = this.context;
const {children, messageIfEmptyFold} = this.props;
const {children} = this.props;
const subplotFolds = [];

const allCartesianAxisCombinations = data.reduce((acc, curVal, inx) => {
Expand Down Expand Up @@ -54,7 +54,6 @@ class SubplotAccordion extends Component {
key={d.index[0]}
traceIndexes={d.index}
canDelete={false}
messageIfEmpty={messageIfEmptyFold}
xaxis={d.xaxis}
yaxis={d.yaxis}
name={`${d.xaxisName} | ${d.yaxisName}`}
Expand Down Expand Up @@ -116,7 +115,6 @@ class SubplotAccordion extends Component {
key={layoutKey}
traceIndexes={traceIndexes}
canDelete={false}
messageIfEmpty={messageIfEmptyFold}
subplot={layoutKey}
name={subplotName}
>
Expand All @@ -140,7 +138,6 @@ class SubplotAccordion extends Component {
key={i}
traceIndexes={[i]}
canDelete={false}
messageIfEmpty={messageIfEmptyFold}
name={
d.type === 'pie'
? `${_('Pie')} ${pieCounter > 1 ? pieCounter : ''}`
Expand All @@ -166,7 +163,6 @@ SubplotAccordion.contextTypes = {

SubplotAccordion.propTypes = {
children: PropTypes.node,
messageIfEmptyFold: PropTypes.string,
};

export default SubplotAccordion;
93 changes: 39 additions & 54 deletions src/components/containers/TraceAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ class TraceAccordion extends Component {
setLocals(props, context) {
// we don't want to include analysis transforms when we're in the create panel
const base = props.canGroup ? context.fullData : context.data;
const traceFilterCondition =
this.props.traceFilterCondition || (() => true);

this.filteredTracesFullDataPositions = [];
this.filteredTracesIndexes = [];
this.filteredTraces = base.filter((t, i) => {
if (props.excludeFits) {
return !(t.transforms && t.transforms.every(tr => tr.type === 'fit'));
if (traceFilterCondition(t, context.fullData[i])) {
this.filteredTracesIndexes.push(i);
return true;
}
this.filteredTracesFullDataPositions.push(i);
return true;
return false;
});
}

renderGroupedTraceFolds() {
if (!this.filteredTraces.length || this.filteredTraces.length < 2) {
if (!this.filteredTraces.length || this.filteredTraces.length <= 1) {
return null;
}

Expand All @@ -55,61 +57,45 @@ class TraceAccordion extends Component {

dataArrayPositionsByTraceType[traceType].push(trace.index);
fullDataArrayPositionsByTraceType[traceType].push(
this.filteredTracesFullDataPositions[index]
this.filteredTracesIndexes[index]
);
});

return Object.keys(fullDataArrayPositionsByTraceType).map((type, index) => {
return (
<TraceFold
key={index}
traceIndexes={dataArrayPositionsByTraceType[type]}
name={traceTypes(_).find(t => t.value === type).label}
fullDataArrayPosition={fullDataArrayPositionsByTraceType[type]}
>
{this.props.children}
</TraceFold>
);
});
return Object.keys(fullDataArrayPositionsByTraceType).map((type, index) => (
<TraceFold
key={index}
traceIndexes={dataArrayPositionsByTraceType[type]}
name={traceTypes(_).find(t => t.value === type).label}
fullDataArrayPosition={fullDataArrayPositionsByTraceType[type]}
>
{this.props.children}
</TraceFold>
));
}

renderUngroupedTraceFolds() {
if (!this.filteredTraces.length) {
return null;
}

return this.filteredTraces.map((d, i) => {
return (
<TraceFold
key={i}
traceIndexes={[d.index]}
canDelete={this.props.canAdd}
messageIfEmpty={this.props.messageIfEmptyFold}
fullDataArrayPosition={[this.filteredTracesFullDataPositions[i]]}
>
{this.props.children}
</TraceFold>
);
});
return this.filteredTraces.map((d, i) => (
<TraceFold
key={i}
traceIndexes={[d.index]}
canDelete={this.props.canAdd}
fullDataArrayPosition={[this.filteredTracesIndexes[i]]}
>
{this.props.children}
</TraceFold>
));
}

renderTraceFolds() {
if (!this.filteredTraces.length) {
return null;
}

return this.filteredTraces.map((d, i) => {
return (
<TraceFold
key={i}
traceIndexes={[i]}
canDelete={this.props.canAdd}
messageIfEmpty={this.props.messageIfEmptyFold}
>
{this.props.children}
</TraceFold>
);
});
return this.filteredTraces.map((d, i) => (
<TraceFold
key={i}
traceIndexes={[this.filteredTracesIndexes[i]]}
canDelete={this.props.canAdd}
>
{this.props.children}
</TraceFold>
));
}

render() {
Expand Down Expand Up @@ -178,8 +164,7 @@ TraceAccordion.propTypes = {
canAdd: PropTypes.bool,
canGroup: PropTypes.bool,
children: PropTypes.node,
excludeFits: PropTypes.bool,
messageIfEmptyFold: PropTypes.string,
traceFilterCondition: PropTypes.func,
};

export default TraceAccordion;
14 changes: 1 addition & 13 deletions src/components/containers/TransformAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import PlotlyPanel from './PlotlyPanel';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import {connectTransformToTrace} from 'lib';
import FoldEmpty from './FoldEmpty';
import {PlotScatterIcon} from 'plotly-icons';
import {TRANSFORMABLE_TRACES} from 'lib/constants';

const TransformFold = connectTransformToTrace(PlotlyFold);

class TransformAccordion extends Component {
render() {
const {
fullContainer,
fullContainer: {transforms = []},
localize: _,
container,
Expand All @@ -27,15 +23,6 @@ class TransformAccordion extends Component {
{label: _('Sort'), type: 'sort'},
];

if (!TRANSFORMABLE_TRACES.includes(fullContainer.type)) {
return (
<FoldEmpty
icon={PlotScatterIcon}
messagePrimary={_('No transforms available for this trace type')}
/>
);
}

const transformBy =
container.transforms &&
container.transforms.map(tr => {
Expand Down Expand Up @@ -97,6 +84,7 @@ class TransformAccordion extends Component {

const payload = {type};
if (type === 'filter') {
payload.target = [];
payload.targetsrc = null;
} else {
payload.groupssrc = null;
Expand Down
7 changes: 6 additions & 1 deletion src/default_panels/GraphCreatePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {

const GraphCreatePanel = (props, {localize: _}) => {
return (
<TraceAccordion canAdd excludeFits>
<TraceAccordion
canAdd
traceFilterCondition={t =>
!(t.transforms && t.transforms.every(tr => tr.type === 'fit'))
}
>
<TraceSelector label={_('Type')} attr="type" show />

<LocationSelector attr="type" />
Expand Down
5 changes: 4 additions & 1 deletion src/default_panels/GraphTransformsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FilterValue,
} from '../components';
import {connectAggregationToTransform} from '../lib';
import {TRANSFORMABLE_TRACES} from 'lib/constants';

const AggregationSection = connectAggregationToTransform(PlotlySection);

Expand Down Expand Up @@ -68,7 +69,9 @@ Aggregations.contextTypes = {

const GraphTransformsPanel = (props, {localize: _}) => {
return (
<TraceAccordion>
<TraceAccordion
traceFilterCondition={t => TRANSFORMABLE_TRACES.includes(t.type)}
>
<TransformAccordion>
<Radio
attr="enabled"
Expand Down
8 changes: 5 additions & 3 deletions src/default_panels/StyleColorbarsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
VisibilitySelect,
} from '../components';

export const traceHasColorbar = (trace, fullTrace) =>
(fullTrace.marker && fullTrace.marker.showscale !== undefined) || // eslint-disable-line no-undefined
fullTrace.showscale !== undefined; // eslint-disable-line no-undefined

const StyleColorBarsPanel = (props, {localize: _}) => {
return (
<TraceAccordion
messageIfEmptyFold={_('Need a color scale for a colorbar!')}
>
<TraceAccordion traceFilterCondition={traceHasColorbar}>
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, this is much better on the api

{['', 'marker.'].map(prefix => {
return (
<VisibilitySelect
Expand Down
8 changes: 5 additions & 3 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ export const TRANSFORMS_LIST = ['filter', 'groupby', 'aggregate', 'sort'];

export const TRANSFORMABLE_TRACES = [
'scatter',
'bar',
'scattergl',
'histogram',
'histogram2d',
'box',
'violin',
'bar',
'ohlc',
Copy link
Contributor

Choose a reason for hiding this comment

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

so here we've just added ohlc and candlestick, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that's all that can be done safely, box and violin are already there

'candlestick',
'histogram',
'histogram2d',
];

export const COLORS = {
Expand Down