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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Simple component that takes in props and renders.
* `<TraceAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to traces via `connectTraceToPlot()`.
* `<LayoutPanel />`: `<Panel />` whose children are connected to the `layout` figure key
* `<TraceRequiredPanel />`: `<LayoutPanel />` renders `<PanelEmpty />` if no trace data is set
* `<AxisRequiredPanel />`: `<Panel />` renders `<PanelEmpty />` if no axis in `_fullLayout._subplots`
* `<AnnotationAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to annotations via `connectAnnotationToLayout()`. For use in a `<LayoutPanel />`.
* `<ShapeAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to shapes via `connectShapeToLayout()`. For use in a `<LayoutPanel />`.
* `<ImageAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to images via `connectImageToLayout()`. For use in a `<LayoutPanel />`.
Expand Down
51 changes: 51 additions & 0 deletions src/components/containers/AxisRequiredPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import PanelEmpty from './PanelEmpty';
import Panel from './Panel';

class AxisRequiredPanel extends Component {
constructor(props) {
super(props);
this.state = {
hasAxis: true,
};
}

checkAxisExistence() {
const hasSubplot =
Object.keys(this.context.fullContainer._subplots).filter(
type =>
!['cartesian', 'mapbox'].includes(type) &&
this.context.fullContainer._subplots[type].length > 0
).length > 0;
if (!hasSubplot) {
this.setState({hasAxis: false});
}
}

componentWillReceiveProps() {
this.checkAxisExistence();
}

componentDidMount() {
this.checkAxisExistence();
}

render() {
if (this.state.hasAxis) {
return <Panel>{this.props.children}</Panel>;
}
return <PanelEmpty heading={this.props.emptyPanelHeader} />;
}
}

AxisRequiredPanel.propTypes = {
children: PropTypes.node,
emptyPanelHeader: PropTypes.string,
};

AxisRequiredPanel.contextTypes = {
fullContainer: PropTypes.object,
};

export default AxisRequiredPanel;
14 changes: 5 additions & 9 deletions src/components/containers/PanelEmpty.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import {ChartLineIcon} from 'plotly-icons';
import {bem, localize} from 'lib';
import {bem} from 'lib';

class PanelEmpty extends Component {
render() {
const {
children,
localize: _,
heading = _("Looks like there aren't any traces defined yet."),
message = _("Go to the 'Create' tab to define traces."),
icon: Icon,
} = this.props;
const {children, icon: Icon} = this.props;
const heading = this.props.heading || '';
const message = this.props.message || '';

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

export default localize(PanelEmpty);
export default PanelEmpty;
15 changes: 10 additions & 5 deletions src/components/containers/TraceRequiredPanel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import PanelEmpty from './PanelEmpty';
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import {LayoutPanel} from './derived';
import {localize} from 'lib';

class TraceRequiredPanel extends Component {
constructor(props) {
Expand Down Expand Up @@ -36,14 +37,17 @@ class TraceRequiredPanel extends Component {
}

render() {
const {children, ...rest} = this.props;
const {localize: _, children, ...rest} = this.props;
const {hasTraces} = this.state;

if (this.props.visible) {
return hasTraces ? (
<LayoutPanel {...rest}>{children}</LayoutPanel>
) : (
<PanelEmpty />
<PanelEmpty
heading={_("Looks like there aren't any traces defined yet.")}
message={_("Go to the 'Create' tab to define traces.")}
/>
);
}
return null;
Expand All @@ -52,6 +56,7 @@ class TraceRequiredPanel extends Component {

TraceRequiredPanel.propTypes = {
children: PropTypes.node,
localize: PropTypes.func,
visible: PropTypes.bool,
};

Expand All @@ -63,4 +68,4 @@ TraceRequiredPanel.contextTypes = {
fullData: PropTypes.array,
};

export default TraceRequiredPanel;
export default localize(TraceRequiredPanel);
2 changes: 2 additions & 0 deletions src/components/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AnnotationAccordion from './AnnotationAccordion';
import ShapeAccordion from './ShapeAccordion';
import ImageAccordion from './ImageAccordion';
import AxesFold from './AxesFold';
import AxisRequiredPanel from './AxisRequiredPanel';
import Fold from './Fold';
import MenuPanel from './MenuPanel';
import Panel from './Panel';
Expand All @@ -14,6 +15,7 @@ import SingleSidebarItem from './SingleSidebarItem';

export {
AnnotationAccordion,
AxisRequiredPanel,
ShapeAccordion,
ImageAccordion,
MenuPanel,
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
ShapeAccordion,
ImageAccordion,
AxesFold,
AxisRequiredPanel,
Fold,
LayoutPanel,
MenuPanel,
Expand Down Expand Up @@ -63,6 +64,7 @@ export {
AxesFold,
AxesRange,
AxesSelector,
AxisRequiredPanel,
Button,
CanvasSize,
ColorPicker,
Expand Down
Loading