Skip to content

Commit 2b627f7

Browse files
committed
legendgroup and other legend attrs
1 parent 5627ff8 commit 2b627f7

File tree

7 files changed

+90
-11
lines changed

7 files changed

+90
-11
lines changed

src/components/fields/AxesCreator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ UnconnectedAxisCreator.propTypes = {
9999
attr: PropTypes.string,
100100
label: PropTypes.string,
101101
options: PropTypes.array,
102-
canAddAxis: PropTypes.bool,
103102
container: PropTypes.object,
104103
fullContainer: PropTypes.object,
105104
updateContainer: PropTypes.func,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React, {Component} from 'react';
2+
import {connectToContainer} from 'lib';
3+
import Field from './Field';
4+
import Dropdown from './Dropdown';
5+
import PropTypes from 'prop-types';
6+
import Button from '../widgets/Button';
7+
import {PlusIcon} from 'plotly-icons';
8+
9+
class UnconnectedLegendgroupCreator extends Component {
10+
canAddGroup() {
11+
const currentGroup = this.props.fullContainer.legendgroup;
12+
const currentTraceIndex = this.props.fullContainer.index;
13+
14+
return (
15+
!currentGroup ||
16+
this.context.fullData.some(
17+
d => d.index !== currentTraceIndex && d.legendgroup === currentGroup
18+
)
19+
);
20+
}
21+
22+
addAndUpdateGroup() {
23+
const lastGroupNumber =
24+
Math.max.apply(Math, this.context.fullData.map(t => t.legendgroup)) || 0;
25+
26+
this.props.updatePlot(lastGroupNumber + 1);
27+
}
28+
29+
render() {
30+
const {localize: _} = this.context;
31+
32+
const options = [{label: _('None'), value: ''}];
33+
const allGroups = [...new Set(this.context.data.map(t => t.legendgroup))].filter(
34+
g => g !== undefined // eslint-disable-line no-undefined
35+
);
36+
allGroups.forEach(g => options.push({label: _('Group ') + g, value: g}));
37+
options.sort((a, b) => a.value - b.value);
38+
39+
const icon = <PlusIcon />;
40+
const addButton = this.canAddGroup() ? (
41+
<Button variant="no-text" icon={icon} onClick={() => this.addAndUpdateGroup()} />
42+
) : (
43+
<Button variant="no-text--disabled" icon={icon} onClick={() => {}} />
44+
);
45+
46+
return (
47+
<Dropdown
48+
label={_('Legend Group')}
49+
attr={this.props.attr}
50+
clearable={false}
51+
options={options}
52+
updatePlot={this.props.updatePlot}
53+
extraComponent={addButton}
54+
/>
55+
);
56+
}
57+
}
58+
59+
UnconnectedLegendgroupCreator.propTypes = {
60+
attr: PropTypes.string,
61+
fullContainer: PropTypes.object,
62+
...Field.propTypes,
63+
};
64+
65+
UnconnectedLegendgroupCreator.contextTypes = {
66+
localize: PropTypes.func,
67+
data: PropTypes.array,
68+
fullData: PropTypes.array,
69+
};
70+
71+
export default connectToContainer(UnconnectedLegendgroupCreator);

src/components/fields/SubplotCreator.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import React, {Component} from 'react';
12
import Dropdown from './Dropdown';
23
import Info from './Info';
34
import PropTypes from 'prop-types';
4-
import React, {Component} from 'react';
55
import {EDITOR_ACTIONS, SUBPLOT_TO_ATTR} from 'lib/constants';
66
import Button from '../widgets/Button';
77
import {PlusIcon} from 'plotly-icons';
88
import {connectToContainer, traceTypeToAxisType, getSubplotTitle} from 'lib';
99
import {PlotlySection} from 'components';
1010

1111
class UnconnectedSingleSubplotCreator extends Component {
12-
canAddAxis() {
12+
canAddSubplot() {
1313
const currentAxisId = this.props.fullContainer[this.props.attr];
1414
const currentTraceIndex = this.props.fullContainer.index;
1515
return this.context.fullData.some(
@@ -62,7 +62,7 @@ class UnconnectedSingleSubplotCreator extends Component {
6262

6363
render() {
6464
const icon = <PlusIcon />;
65-
const extraComponent = this.canAddAxis() ? (
65+
const extraComponent = this.canAddSubplot() ? (
6666
<Button variant="no-text" icon={icon} onClick={() => this.addAndUpdateSubplot()} />
6767
) : (
6868
<Button variant="no-text--disabled" icon={icon} onClick={() => {}} />
@@ -86,7 +86,6 @@ UnconnectedSingleSubplotCreator.propTypes = {
8686
layoutAttr: PropTypes.string,
8787
label: PropTypes.string,
8888
options: PropTypes.array,
89-
canAddAxis: PropTypes.bool,
9089
container: PropTypes.object,
9190
fullContainer: PropTypes.object,
9291
updateContainer: PropTypes.func,

src/components/fields/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import TraceSelector from './TraceSelector';
2121
import ErrorBars from './ErrorBars';
2222
import AxesCreator from './AxesCreator';
2323
import SubplotCreator from './SubplotCreator';
24+
import LegendgroupCreator from './LegendgroupCreator';
2425
import UpdateMenuButtons from './UpdateMenuButtons';
2526
import {FilterOperation, FilterValue} from './FilterOperation';
2627
import MarkerSize from './MarkerSize';
@@ -100,6 +101,7 @@ export {
100101
TraceSelector,
101102
AxesCreator,
102103
SubplotCreator,
104+
LegendgroupCreator,
103105
AxisOverlayDropdown,
104106
AxisSide,
105107
UpdateMenuButtons,

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
RangesliderVisible,
4040
AxesCreator,
4141
SubplotCreator,
42+
LegendgroupCreator,
4243
SymbolSelector,
4344
TextEditor,
4445
TraceOrientation,
@@ -146,6 +147,7 @@ export {
146147
SingleSidebarItem,
147148
AxesCreator,
148149
SubplotCreator,
150+
LegendgroupCreator,
149151
SymbolSelector,
150152
TextEditor,
151153
SubplotAccordion,

src/default_panels/StyleLegendPanel.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ const StyleLegendPanel = (props, {localize: _}) => (
6363
/>
6464
</PlotlySection>
6565
<PlotlySection name={_('Trace Order')}>
66-
<Radio
66+
<Dropdown
6767
attr="legend.traceorder"
6868
options={[
6969
{label: _('Normal'), value: 'normal'},
7070
{label: _('Reversed'), value: 'reversed'},
71+
{label: _('Grouped'), value: 'grouped'},
72+
{label: _('Reversed and Grouped'), value: 'reversed+grouped'},
7173
]}
7274
/>
75+
<Numeric label={_('Gap Between Groups')} attr="legend.tracegroupgap" units="px" />
7376
</PlotlySection>
7477
</PlotlyFold>
7578
</TraceRequiredPanel>

src/default_panels/StyleTracesPanel.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
ErrorBars,
3131
DataSelector,
3232
VisibilitySelect,
33+
LegendgroupCreator,
3334
} from '../components';
3435
import {
3536
BinningNumeric,
@@ -43,12 +44,14 @@ import {
4344
const StyleTracesPanel = (props, {localize: _}) => (
4445
<TraceAccordion canGroup>
4546
<TextEditor label={_('Name')} attr="name" richTextOnly />
46-
<ShowInLegend
47-
label={_('Show in Legend')}
48-
attr="showlegend"
49-
options={[{label: _('Show'), value: true}, {label: _('Hide'), value: false}]}
50-
/>
5147
<NumericFraction label={_('Trace Opacity')} attr="opacity" />
48+
<PlotlySection name={_('Show in Legend')}>
49+
<ShowInLegend
50+
attr="showlegend"
51+
options={[{label: _('Show'), value: true}, {label: _('Hide'), value: false}]}
52+
/>
53+
<LegendgroupCreator attr="legendgroup" />
54+
</PlotlySection>
5255
<PlotlySection name={_('Cones & Streamtubes')}>
5356
<Numeric label={_('Size')} attr="sizeref" />
5457
<Dropdown

0 commit comments

Comments
 (0)