Skip to content

Commit 7f15f42

Browse files
authored
Merge pull request #331 from plotly/axes-for-all
Axes for all
2 parents e2e2f39 + 36dae8f commit 7f15f42

File tree

9 files changed

+406
-317
lines changed

9 files changed

+406
-317
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Simple component that takes in props and renders.
148148
* `<TraceAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to traces via `connectTraceToPlot()`.
149149
* `<LayoutPanel />`: `<Panel />` whose children are connected to the `layout` figure key
150150
* `<TraceRequiredPanel />`: `<LayoutPanel />` renders `<PanelEmpty />` if no trace data is set
151+
* `<AxisRequiredPanel />`: `<Panel />` renders `<PanelEmpty />` if no axis in `_fullLayout._subplots`
151152
* `<AnnotationAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to annotations via `connectAnnotationToLayout()`. For use in a `<LayoutPanel />`.
152153
* `<ShapeAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to shapes via `connectShapeToLayout()`. For use in a `<LayoutPanel />`.
153154
* `<ImageAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to images via `connectImageToLayout()`. For use in a `<LayoutPanel />`.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React, {Component} from 'react';
2+
import PropTypes from 'prop-types';
3+
import PanelEmpty from './PanelEmpty';
4+
import Panel from './Panel';
5+
6+
class AxisRequiredPanel extends Component {
7+
constructor(props) {
8+
super(props);
9+
this.state = {
10+
hasAxis: true,
11+
};
12+
}
13+
14+
checkAxisExistence() {
15+
const hasSubplot =
16+
Object.keys(this.context.fullContainer._subplots).filter(
17+
type =>
18+
!['cartesian', 'mapbox'].includes(type) &&
19+
this.context.fullContainer._subplots[type].length > 0
20+
).length > 0;
21+
if (!hasSubplot) {
22+
this.setState({hasAxis: false});
23+
}
24+
}
25+
26+
componentWillReceiveProps() {
27+
this.checkAxisExistence();
28+
}
29+
30+
componentDidMount() {
31+
this.checkAxisExistence();
32+
}
33+
34+
render() {
35+
if (this.state.hasAxis) {
36+
return <Panel>{this.props.children}</Panel>;
37+
}
38+
return <PanelEmpty heading={this.props.emptyPanelHeader} />;
39+
}
40+
}
41+
42+
AxisRequiredPanel.propTypes = {
43+
children: PropTypes.node,
44+
emptyPanelHeader: PropTypes.string,
45+
};
46+
47+
AxisRequiredPanel.contextTypes = {
48+
fullContainer: PropTypes.object,
49+
};
50+
51+
export default AxisRequiredPanel;

src/components/containers/PanelEmpty.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import PropTypes from 'prop-types';
22
import React, {Component} from 'react';
33
import {ChartLineIcon} from 'plotly-icons';
4-
import {bem, localize} from 'lib';
4+
import {bem} from 'lib';
55

66
class PanelEmpty extends Component {
77
render() {
8-
const {
9-
children,
10-
localize: _,
11-
heading = _("Looks like there aren't any traces defined yet."),
12-
message = _("Go to the 'Create' tab to define traces."),
13-
icon: Icon,
14-
} = this.props;
8+
const {children, icon: Icon} = this.props;
9+
const heading = this.props.heading || '';
10+
const message = this.props.message || '';
1511

1612
return (
1713
<div className={bem('panel', 'empty')}>
@@ -38,4 +34,4 @@ PanelEmpty.propTypes = {
3834
icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
3935
};
4036

41-
export default localize(PanelEmpty);
37+
export default PanelEmpty;

src/components/containers/TraceRequiredPanel.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, {Component} from 'react';
2-
import PropTypes from 'prop-types';
31
import PanelEmpty from './PanelEmpty';
2+
import PropTypes from 'prop-types';
3+
import React, {Component} from 'react';
44
import {LayoutPanel} from './derived';
5+
import {localize} from 'lib';
56

67
class TraceRequiredPanel extends Component {
78
constructor(props) {
@@ -36,14 +37,17 @@ class TraceRequiredPanel extends Component {
3637
}
3738

3839
render() {
39-
const {children, ...rest} = this.props;
40+
const {localize: _, children, ...rest} = this.props;
4041
const {hasTraces} = this.state;
4142

4243
if (this.props.visible) {
4344
return hasTraces ? (
4445
<LayoutPanel {...rest}>{children}</LayoutPanel>
4546
) : (
46-
<PanelEmpty />
47+
<PanelEmpty
48+
heading={_("Looks like there aren't any traces defined yet.")}
49+
message={_("Go to the 'Create' tab to define traces.")}
50+
/>
4751
);
4852
}
4953
return null;
@@ -52,6 +56,7 @@ class TraceRequiredPanel extends Component {
5256

5357
TraceRequiredPanel.propTypes = {
5458
children: PropTypes.node,
59+
localize: PropTypes.func,
5560
visible: PropTypes.bool,
5661
};
5762

@@ -63,4 +68,4 @@ TraceRequiredPanel.contextTypes = {
6368
fullData: PropTypes.array,
6469
};
6570

66-
export default TraceRequiredPanel;
71+
export default localize(TraceRequiredPanel);

src/components/containers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import AnnotationAccordion from './AnnotationAccordion';
22
import ShapeAccordion from './ShapeAccordion';
33
import ImageAccordion from './ImageAccordion';
44
import AxesFold from './AxesFold';
5+
import AxisRequiredPanel from './AxisRequiredPanel';
56
import Fold from './Fold';
67
import MenuPanel from './MenuPanel';
78
import Panel from './Panel';
@@ -14,6 +15,7 @@ import SingleSidebarItem from './SingleSidebarItem';
1415

1516
export {
1617
AnnotationAccordion,
18+
AxisRequiredPanel,
1719
ShapeAccordion,
1820
ImageAccordion,
1921
MenuPanel,

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
ShapeAccordion,
3737
ImageAccordion,
3838
AxesFold,
39+
AxisRequiredPanel,
3940
Fold,
4041
LayoutPanel,
4142
MenuPanel,
@@ -63,6 +64,7 @@ export {
6364
AxesFold,
6465
AxesRange,
6566
AxesSelector,
67+
AxisRequiredPanel,
6668
Button,
6769
CanvasSize,
6870
ColorPicker,

0 commit comments

Comments
 (0)