-
-
Notifications
You must be signed in to change notification settings - Fork 112
Subplots2 #357
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
Subplots2 #357
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
707e90d
Min adjustment
VeraZab 816d282
Export getAllAxes and adjust for subplots
VeraZab 5dd25e8
Stop using child.type
VeraZab aee11ac
Create AxisCreator + Positionning controls
VeraZab fde5575
Correct axis selector axis names and display
VeraZab 3eddce8
Only allow creation of new axes for cartesian types for now
VeraZab d7f425a
Make y2 creation prettier
VeraZab 6ca5176
Correct annotation axesref
VeraZab dd3e2ef
Remove noShame function
VeraZab 0b543d7
Standardize axis titles
VeraZab c264f2a
Add Overlay Dropdown
VeraZab 9ac1b03
Rebasing and test fix
VeraZab cbfdb0d
Adjust axis Side
VeraZab e12b272
Make .subplot && .axisGroup private keys
VeraZab c5bd06e
Tests fix
VeraZab 716f490
:see_no_evil:
VeraZab 662c9fd
Rebase error
VeraZab fa6d53e
Refactor && add restrictions
VeraZab ca05f19
Style adjustments
VeraZab c02573b
Add axis overlaying adjustments like for yaxis
VeraZab d81e812
Make relationship between overlaying and domain clearer
VeraZab 6943cce
Overlaying adjustment
VeraZab f8c86ed
Linting
VeraZab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
import Dropdown from './Dropdown'; | ||
import Info from './Info'; | ||
import PropTypes from 'prop-types'; | ||
import React, {Component, Fragment} from 'react'; | ||
import {EDITOR_ACTIONS} from 'lib/constants'; | ||
import Button from '../widgets/Button'; | ||
import {PlusIcon} from 'plotly-icons'; | ||
import { | ||
connectToContainer, | ||
localize, | ||
traceTypeToAxisType, | ||
getAxisTitle, | ||
axisIdToAxisName, | ||
} from 'lib'; | ||
|
||
class UnconnectedNewAxisCreator extends Component { | ||
canAddAxis() { | ||
const currentAxisId = this.props.fullContainer[this.props.attr]; | ||
const currentTraceIndex = this.props.fullContainer.index; | ||
return this.context.fullData.some( | ||
d => d.index !== currentTraceIndex && d[this.props.attr] === currentAxisId | ||
); | ||
} | ||
|
||
updateAxis() { | ||
const {attr, updateContainer} = this.props; | ||
const {onUpdate, fullLayout} = this.context; | ||
|
||
updateContainer({ | ||
[attr]: attr.charAt(0) + (fullLayout._subplots[attr].length + 1), | ||
}); | ||
|
||
if (attr === 'yaxis') { | ||
onUpdate({ | ||
type: EDITOR_ACTIONS.UPDATE_LAYOUT, | ||
payload: { | ||
update: { | ||
[`${attr + (fullLayout._subplots[attr].length + 1)}.side`]: 'right', | ||
[`${attr + | ||
(fullLayout._subplots[attr].length + 1)}.overlaying`]: 'y', | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
if (attr === 'xaxis') { | ||
onUpdate({ | ||
type: EDITOR_ACTIONS.UPDATE_LAYOUT, | ||
payload: { | ||
update: { | ||
[`${attr + (fullLayout._subplots[attr].length + 1)}.side`]: 'top', | ||
[`${attr + | ||
(fullLayout._subplots[attr].length + 1)}.overlaying`]: 'x', | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
recalcAxes(update) { | ||
const currentAxisId = this.props.fullContainer[this.props.attr]; | ||
|
||
// When we select another axis, make sure no unused axes are left: | ||
// does any other trace have this axisID? If so, nothing needs to change | ||
if ( | ||
this.context.fullData.some( | ||
t => | ||
t[this.props.attr] === currentAxisId && | ||
t.index !== this.props.fullContainer.index | ||
) | ||
) { | ||
this.props.updateContainer({[this.props.attr]: update}); | ||
return; | ||
} | ||
|
||
// if not, send action to readjust axis references in trace data and layout | ||
const tracesToAdjust = this.context.fullData.filter( | ||
trace => | ||
Number(trace[this.props.attr].slice(1)) > Number(currentAxisId.slice(1)) | ||
); | ||
|
||
this.context.onUpdate({ | ||
type: EDITOR_ACTIONS.UPDATE_AXIS_REFERENCES, | ||
payload: {tracesToAdjust, attrToAdjust: this.props.attr}, | ||
}); | ||
|
||
this.props.updateContainer({[this.props.attr]: update}); | ||
} | ||
|
||
render() { | ||
const icon = <PlusIcon />; | ||
const extraComponent = this.canAddAxis() ? ( | ||
<Button variant="no-text" icon={icon} onClick={() => this.updateAxis()} /> | ||
) : ( | ||
<Button variant="no-text--disabled" icon={icon} onClick={() => {}} /> | ||
); | ||
|
||
return ( | ||
<Dropdown | ||
label={this.props.label} | ||
attr={this.props.attr} | ||
clearable={false} | ||
options={this.props.options} | ||
updatePlot={u => this.recalcAxes(u)} | ||
extraComponent={extraComponent} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
UnconnectedNewAxisCreator.propTypes = { | ||
attr: PropTypes.string, | ||
label: PropTypes.string, | ||
options: PropTypes.array, | ||
canAddAxis: PropTypes.bool, | ||
localize: PropTypes.func, | ||
container: PropTypes.object, | ||
fullContainer: PropTypes.object, | ||
updateContainer: PropTypes.func, | ||
}; | ||
|
||
UnconnectedNewAxisCreator.contextTypes = { | ||
fullLayout: PropTypes.object, | ||
data: PropTypes.array, | ||
fullData: PropTypes.array, | ||
onUpdate: PropTypes.func, | ||
}; | ||
|
||
const ConnectedNewAxisCreator = connectToContainer(UnconnectedNewAxisCreator); | ||
|
||
class AxisCreator extends Component { | ||
render() { | ||
const isFirstTraceOfType = | ||
this.context.data.filter(d => d.type === this.props.container.type) | ||
.length === 1; | ||
|
||
if (isFirstTraceOfType) { | ||
return null; | ||
} | ||
|
||
const {localize: _} = this.props; | ||
const {fullLayout} = this.context; | ||
const axisType = traceTypeToAxisType(this.props.container.type); | ||
const controls = []; | ||
|
||
function getOptions(axisType) { | ||
return fullLayout._subplots[axisType].map(axisId => ({ | ||
label: getAxisTitle(fullLayout[axisIdToAxisName(axisId)]), | ||
value: axisId, | ||
})); | ||
} | ||
|
||
// for the moment only cartesian subplots are supported | ||
if (axisType === 'cartesian') { | ||
['xaxis', 'yaxis'].forEach((type, index) => { | ||
controls.push( | ||
<ConnectedNewAxisCreator | ||
key={index} | ||
attr={type} | ||
label={type.charAt(0).toUpperCase() + ' Axis'} | ||
options={getOptions(type)} | ||
localize={_} | ||
/> | ||
); | ||
}); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
{controls} | ||
<Info> | ||
{_('You can style and position your axes in the Style > Axes Panel')} | ||
</Info> | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
||
AxisCreator.propTypes = { | ||
localize: PropTypes.func, | ||
container: PropTypes.object, | ||
fullContainer: PropTypes.object, | ||
}; | ||
|
||
AxisCreator.plotly_editor_traits = { | ||
is_axis_creator: true, | ||
}; | ||
|
||
AxisCreator.contextTypes = { | ||
data: PropTypes.array, | ||
fullData: PropTypes.array, | ||
fullLayout: PropTypes.object, | ||
}; | ||
|
||
export default localize(connectToContainer(AxisCreator)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
images don't have
.text
do they? Perhaps make a name from.source
? Not sure what to do about shapes... index and type perhaps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe so this change is @VeraZab cleaning up my copy-paste work from a previous PR... When I created the Images panel I'd based it off of the Notes panel but not renamed
ann
toimg
(and ditto Shapes). So any issues with this code should probably go in a separate issue that I can handle ;)