Skip to content

Symbol selector #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 6 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
26 changes: 10 additions & 16 deletions src/DefaultEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
PanelMenuWrapper,
Radio,
Section,
SubPanel,
MenuPanel,
SymbolSelector,
TraceAccordion,
TraceSelector,
} from './components';
Expand Down Expand Up @@ -142,24 +143,17 @@ class DefaultEditor extends Component {
</Section>

<Section name={_('Points')}>
<Numeric
label={_('Marker Opacity')}
step={0.1}
attr="marker.opacity"
/>

<ColorPicker label={_('Marker Color')} attr="marker.color" />

<ColorPicker label={_('Color')} attr="marker.color" />
<Numeric label={_('Opacity')} step={0.1} attr="marker.opacity" />
<Numeric label={_('Size')} attr="marker.size" />

<Numeric label={_('Line width')} attr="marker.line.width" />
<SymbolSelector label={_('Symbol')} attr="marker.symbol" />
<Numeric label={_('Border Width')} attr="marker.line.width" />
<ColorPicker label={_('Border Color')} attr="marker.line.color" />
</Section>

<Section name={_('Lines')}>
<Numeric label={_('Width')} step={1.0} attr="line.width" />

<ColorPicker label={_('Line color')} attr="line.color" />

<ColorPicker label={_('Line Color')} attr="line.color" />
<Radio
label={_('Connect Gaps')}
attr="connectgaps"
Expand Down Expand Up @@ -278,7 +272,7 @@ class DefaultEditor extends Component {
/>
</Section>
<Section name={_('Positioning')}>
<SubPanel>
<MenuPanel>
<Section name={_('Anchor Point')}>
<Info>
{_(
Expand All @@ -303,7 +297,7 @@ class DefaultEditor extends Component {
]}
/>
</Section>
</SubPanel>
</MenuPanel>
<Numeric
label={_('X Position')}
step={0.01}
Expand Down
65 changes: 65 additions & 0 deletions src/components/containers/MenuPanel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import ModalBox from './ModalBox';

export default class MenuPanel extends Component {
constructor() {
super();
this.state = {isOpen: false};

this.togglePanel = this.togglePanel.bind(this);
}

menupanelClasses() {
if (this.props.iconClass) {
return {
iconClass: `menupanel__icon ${this.props.iconClass}`,
spanClass: 'menupanel__icon-span',
};
} else if (this.props.question) {
return {
iconClass: 'menupanel__icon plotlyjs_editor__icon-question-circle',
spanClass: `menupanel__icon-span menupanel__icon-span--question`,
};
}
return {
iconClass: 'menupanel__icon plotlyjs_editor__icon-cog',
spanClass: 'menupanel__icon-span menupanel__icon-span--cog',
};
}

togglePanel() {
this.setState({isOpen: !this.state.isOpen});
}

render() {
const isOpen = this.props.show || this.state.isOpen;
const containerClass = classnames('menupanel', {
'menupanel--ownline': this.props.ownline,
});

const {iconClass, spanClass} = this.menupanelClasses();

return (
<div className={containerClass}>
<span className={spanClass}>
<span>{this.props.label}</span>
<i className={iconClass} onClick={this.togglePanel} />
</span>
{isOpen ? (
<ModalBox onClose={this.togglePanel}>{this.props.children}</ModalBox>
) : null}
</div>
);
}
}

MenuPanel.propTypes = {
children: PropTypes.node,
iconClass: PropTypes.string,
show: PropTypes.bool,
ownline: PropTypes.bool,
question: PropTypes.bool,
label: PropTypes.string,
};
24 changes: 24 additions & 0 deletions src/components/containers/ModalBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';

export default class ModalBox extends Component {
render() {
let style;
if (this.props.backgroundColor) {
style = {backgroundColor: this.props.backgroundColor};
}

return (
<div className="modalbox" style={style}>
<div className="modalbox__cover" onClick={this.props.onClose} />
<div>{this.props.children}</div>
</div>
);
}
}

ModalBox.propTypes = {
backgroundColor: PropTypes.string,
children: PropTypes.node,
onClose: PropTypes.func,
};
20 changes: 10 additions & 10 deletions src/components/containers/Section.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import SubPanel from './SubPanel';
import MenuPanel from './MenuPanel';
import React, {Component, cloneElement} from 'react';
import PropTypes from 'prop-types';
import unpackPlotProps from '../../lib/unpackPlotProps';
Expand All @@ -12,7 +12,7 @@ class Section extends Component {
super(props, context);

this.children = null;
this.subPanel = null;
this.menuPanel = null;

this.processAndSetChildren(context);
}
Expand All @@ -28,19 +28,19 @@ class Section extends Component {
}

const attrChildren = [];
let subPanel = null;
let menuPanel = null;

for (let i = 0; i < children.length; i++) {
const child = children[i];
if (!child) {
continue;
}
if (child.type === SubPanel) {
// Process the first subPanel. Ignore the rest.
if (subPanel) {
if (child.type === MenuPanel) {
// Process the first menuPanel. Ignore the rest.
if (menuPanel) {
continue;
}
subPanel = child;
menuPanel = child;
continue;
}

Expand All @@ -54,19 +54,19 @@ class Section extends Component {
}

this.children = attrChildren.length ? attrChildren : null;
this.subPanel = subPanel;
this.menuPanel = menuPanel;
}

render() {
const hasVisibleChildren =
(this.children && this.children.some(childIsVisible)) ||
Boolean(this.subPanel);
Boolean(this.menuPanel);

return hasVisibleChildren ? (
<div className="section">
<div className="section__heading">
{this.props.name}
{this.subPanel}
{this.menuPanel}
</div>
{this.children}
</div>
Expand Down
67 changes: 0 additions & 67 deletions src/components/containers/SubPanel.js

This file was deleted.

12 changes: 6 additions & 6 deletions src/components/containers/__tests__/Section-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Section from '../Section';
import SubPanel from '../SubPanel';
import MenuPanel from '../MenuPanel';
import {Flaglist, Info, Numeric} from '../../fields';
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
import {connectTraceToPlot} from '../../../lib';
Expand Down Expand Up @@ -91,20 +91,20 @@ describe('Section', () => {
expect(wrapper.find(Numeric).exists()).toBe(false);
});

it('will render first subPanel even with no visible attrs', () => {
it('will render first menuPanel even with no visible attrs', () => {
const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<Section name="test-section">
<SubPanel show>
<MenuPanel show>
<Info>INFO</Info>
</SubPanel>
<SubPanel show>
</MenuPanel>
<MenuPanel show>
<Info>MISINFORMATION</Info>
</SubPanel>
</MenuPanel>
</Section>
</TestEditor>
).find('[name="test-section"]');
Expand Down
4 changes: 2 additions & 2 deletions src/components/containers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SubPanel from './SubPanel';
import MenuPanel from './MenuPanel';
import Fold from './Fold';
import Panel from './Panel';
import Section from './Section';
import TraceAccordion from './TraceAccordion';

export {SubPanel, Fold, Panel, Section, TraceAccordion};
export {MenuPanel, Fold, Panel, Section, TraceAccordion};
4 changes: 3 additions & 1 deletion src/components/fields/DataSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class DataSelector extends Component {

updatePlot(value) {
const attr = this.dataSrcExists ? this.srcAttr : this.props.attr;
this.props.updateContainer && this.props.updateContainer({[attr]: value});
if (this.props.updateContainer) {
this.props.updateContainer({[attr]: value});
}
}

render() {
Expand Down
6 changes: 3 additions & 3 deletions src/components/fields/Field.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React, {Component} from 'react';
import SubPanel from '../containers/SubPanel';
import MenuPanel from '../containers/MenuPanel';
import classnames from 'classnames';
import {bem, localize} from '../../lib';
import {multiValueText} from '../../lib/constants';
Expand Down Expand Up @@ -48,11 +48,11 @@ class Field extends Component {
<div className={fieldClass}>
{children}
{multiValued ? (
<SubPanel label={_(multiValueText.title)} ownline question>
<MenuPanel label={_(multiValueText.title)} ownline question>
<div className="info__title">{_(multiValueText.title)}</div>
<div className="info__text">{_(multiValueText.text)}</div>
<div className="info__sub-text">{_(multiValueText.subText)}</div>
</SubPanel>
</MenuPanel>
) : null}
</div>
{postfix ? (
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/Numeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Numeric.propTypes = {
fullValue: PropTypes.func,
min: PropTypes.number,
max: PropTypes.number,
showArrows: PropTypes.number,
showArrows: PropTypes.bool,
step: PropTypes.number,
updatePlot: PropTypes.func,
...Field.propTypes,
Expand Down
Loading