Skip to content

Canvas size #87

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 4 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions src/PlotlyEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class PlotlyEditor extends Component {
noShame({plotly: this.props.plotly});

// we only need to compute this once.
this.plotSchema = this.props.plotly.PlotSchema.get();
if (this.props.plotly) {
this.plotSchema = this.props.plotly.PlotSchema.get();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, I see how this is nice for testing, but real users will always want plotly and will be confused about what's happening if they forget it. Perhaps a warning if it's not there?

Copy link
Member Author

Choose a reason for hiding this comment

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

#89

}

getChildContext() {
Expand Down Expand Up @@ -51,7 +53,7 @@ class PlotlyEditor extends Component {

PlotlyEditor.propTypes = {
onUpdate: PropTypes.func,
plotly: PropTypes.object.isRequired,
plotly: PropTypes.object,
graphDiv: PropTypes.object,
locale: PropTypes.string,
dataSources: PropTypes.object,
Expand All @@ -72,8 +74,8 @@ PlotlyEditor.childContextTypes = {
layout: PropTypes.object,
locale: PropTypes.string,
onUpdate: PropTypes.func,
plotSchema: PropTypes.object.isRequired,
plotly: PropTypes.object.isRequired,
plotSchema: PropTypes.object,
plotly: PropTypes.object,
};

export default PlotlyEditor;
4 changes: 2 additions & 2 deletions src/components/containers/__tests__/Layout-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {Fold, Panel, Section} from '..';
import NumericInput from '../../widgets/NumericInputStatefulWrapper';
import React from 'react';
import {EDITOR_ACTIONS} from '../../../constants';
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
import {TestEditor, fixtures} from '../../../lib/test-utils';
import {connectLayoutToPlot} from '../../../lib';
import {mount} from 'enzyme';

const Layouts = [Panel, Fold, Section].map(connectLayoutToPlot);
const Editor = props => (
<TestEditor {...{plotly, onUpdate: jest.fn(), ...props}} />
<TestEditor {...{onUpdate: jest.fn(), ...props}} />
);

Layouts.forEach(Layout => {
Expand Down
26 changes: 5 additions & 21 deletions src/components/containers/__tests__/Section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Section from '../Section';
import MenuPanel from '../MenuPanel';
import {Flaglist, Info, Numeric} from '../../fields';
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
import {TestEditor, fixtures} from '../../../lib/test-utils';
import {connectTraceToPlot} from '../../../lib';
import {mount} from 'enzyme';

Expand All @@ -12,11 +12,7 @@ describe('Section', () => {
it('is visible if it contains any visible children', () => {
// mode is visible with scatter. Hole is not visible. Section should show.
const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter({deref: true})}>
<TraceSection traceIndex={0} name="test-section">
<Flaglist
attr="mode"
Expand Down Expand Up @@ -50,11 +46,7 @@ describe('Section', () => {

it('is visible if it contains any non attr children', () => {
const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter({deref: true})}>
<Section name="test-section">
<Info>INFO</Info>
</Section>
Expand All @@ -69,11 +61,7 @@ describe('Section', () => {
it('is not visible if it contains no visible children', () => {
// pull and hole are not scatter attrs. Section should not show.
const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter({deref: true})}>
<TraceSection traceIndex={0} name="test-section">
<Numeric attr="pull" min={0} max={1} step={0.1} traceIndex={0} />
<Numeric attr="hole" min={0} max={1} step={0.1} traceIndex={0} />
Expand All @@ -93,11 +81,7 @@ describe('Section', () => {

it('will render first menuPanel even with no visible attrs', () => {
const wrapper = mount(
<TestEditor
plotly={plotly}
onUpdate={jest.fn()}
{...fixtures.scatter({deref: true})}
>
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter({deref: true})}>
<Section name="test-section">
<MenuPanel show>
<Info>INFO</Info>
Expand Down
28 changes: 17 additions & 11 deletions src/lib/connectAxesToLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ function deepCopyPublic(value) {
/*
* Test that we can connectLayoutToPlot(connectAxesToLayout(Panel))
*/
function setMultiValuedContainer(intoObj, fromObj, key, searchArrays) {
function setMultiValuedContainer(intoObj, fromObj, key, config = {}) {
var intoVal = intoObj[key],
fromVal = fromObj[key];

var searchArrays = config.searchArrays;

// don't merge private attrs
if (
(typeof key === 'string' && key.charAt(0) === '_') ||
Expand Down Expand Up @@ -126,18 +128,22 @@ export default function connectAxesToLayout(WrappedComponent) {
setLocals(nextProps, nextState, nextContext) {
const {plotly, graphDiv, container, fullContainer} = nextContext;
const {axesTarget} = nextState;
this.axes = plotly.Axes.list(graphDiv);
if (plotly) {
this.axes = plotly.Axes.list(graphDiv);
} else {
this.axes = [];
}
this.axesOptions = computeAxesOptions(fullContainer, this.axes);

if (axesTarget === 'allaxes') {
const multiValuedContainer = deepCopyPublic(this.axes[0]);
this.axes
.slice(1)
.forEach(ax =>
Object.keys(ax).forEach(key =>
setMultiValuedContainer(multiValuedContainer, ax, key)
)
);
this.axes.slice(1).forEach(ax =>
Object.keys(ax).forEach(key =>
setMultiValuedContainer(multiValuedContainer, ax, key, {
searchArrays: true,
})
)
);
this.fullContainer = multiValuedContainer;
this.defaultContainer = this.axes[0];
// what should this be set to? Probably doesn't matter.
Expand Down Expand Up @@ -214,8 +220,8 @@ export default function connectAxesToLayout(WrappedComponent) {
container: PropTypes.object.isRequired,
fullContainer: PropTypes.object.isRequired,
graphDiv: PropTypes.object.isRequired,
plotly: PropTypes.object.isRequired,
updateContainer: PropTypes.func.isRequired,
plotly: PropTypes.object,
updateContainer: PropTypes.func,
};

AxesConnectedComponent.childContextTypes = {
Expand Down
13 changes: 9 additions & 4 deletions src/lib/connectLayoutToPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ export default function connectLayoutToPlot(WrappedComponent) {

getChildContext() {
const {layout, fullLayout, plotly} = this.context;
return {
getValObject: attr =>

let getValObject;
if (plotly) {
getValObject = attr =>
plotly.PlotSchema.getLayoutValObject(
fullLayout,
nestedProperty({}, attr).parts
),
);
}
return {
getValObject,
updateContainer: this.updateContainer,
container: layout,
fullContainer: fullLayout,
Expand Down Expand Up @@ -48,7 +53,7 @@ export default function connectLayoutToPlot(WrappedComponent) {
LayoutConnectedComponent.contextTypes = {
layout: PropTypes.object,
fullLayout: PropTypes.object,
plotly: PropTypes.object.isRequired,
plotly: PropTypes.object,
onUpdate: PropTypes.func,
};

Expand Down
14 changes: 10 additions & 4 deletions src/lib/connectTraceToPlot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ export default function connectTraceToPlot(WrappedComponent) {
const trace = data[traceIndex] || {};
const fullTraceIndex = findFullTraceIndex(fullData, traceIndex);
const fullTrace = fullData[fullTraceIndex] || {};
return {
getValObject: attr =>

let getValObject;
if (plotly) {
getValObject = attr =>
plotly.PlotSchema.getTraceValObject(
fullTrace,
nestedProperty({}, attr).parts
),
);
}

return {
getValObject,
updateContainer: this.updateTrace,
deleteContainer: this.deleteTrace,
container: trace,
Expand Down Expand Up @@ -70,7 +76,7 @@ export default function connectTraceToPlot(WrappedComponent) {
TraceConnectedComponent.contextTypes = {
fullData: PropTypes.array,
data: PropTypes.array,
plotly: PropTypes.object.isRequired,
plotly: PropTypes.object,
onUpdate: PropTypes.func,
};

Expand Down
17 changes: 11 additions & 6 deletions src/lib/unpackPlotProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export default function unpackPlotProps(props, context, ComponentClass) {
}

// Property descriptions and meta:
const attrMeta = context.getValObject(props.attr) || {};
let attrMeta;
if (getValObject) {
attrMeta = context.getValObject(props.attr) || {};
}

// Update data functions:
const updatePlot = v => updateContainer && updateContainer({[props.attr]: v});
Expand All @@ -61,11 +64,13 @@ export default function unpackPlotProps(props, context, ComponentClass) {
multiValued,
};

if (isNumeric(attrMeta.max)) {
plotProps.max = attrMeta.max;
}
if (isNumeric(attrMeta.min)) {
plotProps.min = attrMeta.min;
if (attrMeta) {
if (isNumeric(attrMeta.max)) {
plotProps.max = attrMeta.max;
}
if (isNumeric(attrMeta.min)) {
plotProps.min = attrMeta.min;
}
}

// Give Component Classes the space to modify plotProps:
Expand Down