-
-
Notifications
You must be signed in to change notification settings - Fork 112
subplots panel initial #610
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
76c22fd
subplots panel initial
dmt0 b1e0e4b
prototype rectangle positioner
nicolaskruchten 6259573
grid-snap
nicolaskruchten 0a5ea61
rectangle positioner for cartesian
dmt0 00ebb3a
fix for Axes to Use section appearing randomly
dmt0 0e2e760
axis creation for combinations of different cartesian traces
dmt0 74f4593
widgets for multiple subplots for non-cartesian traces
dmt0 9399c48
cartesian axes - not swapping and garbage collection
dmt0 3aabee2
garbage-collect axes/subplot on trace deletion
dmt0 0944218
move overlaying, etc to subplots panel
dmt0 e17d153
improve RectanglePositioner
dmt0 758e07b
minor refactor
dmt0 480f766
fix styling bugs
nicolaskruchten 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import PlotlyFold from './PlotlyFold'; | ||
import TraceRequiredPanel from './TraceRequiredPanel'; | ||
import PropTypes from 'prop-types'; | ||
import React, {Component} from 'react'; | ||
import { | ||
connectTraceToPlot, | ||
connectCartesianSubplotToLayout, | ||
connectNonCartesianSubplotToLayout, | ||
} from 'lib'; | ||
import {TRACE_TO_AXIS, SUBPLOT_TO_ATTR} from 'lib/constants'; | ||
|
||
const TraceFold = connectTraceToPlot(PlotlyFold); | ||
const NonCartesianSubplotFold = connectNonCartesianSubplotToLayout(PlotlyFold); | ||
const CartesianSubplotFold = connectCartesianSubplotToLayout(PlotlyFold); | ||
|
||
class SubplotAccordion extends Component { | ||
render() { | ||
const {data = [], layout = {}} = this.context; | ||
const {children, messageIfEmptyFold} = this.props; | ||
const subplotFolds = []; | ||
|
||
const allCartesianAxisCombinations = data.reduce((acc, curVal, inx) => { | ||
if (TRACE_TO_AXIS.cartesian.some(c => c === curVal.type)) { | ||
const xaxis = 'xaxis' + (curVal.xaxis ? curVal.xaxis.substring(1) : ''); | ||
const yaxis = 'yaxis' + (curVal.yaxis ? curVal.yaxis.substring(1) : ''); | ||
|
||
const existingComboIndex = acc.findIndex( | ||
t => t.xaxis === xaxis && t.yaxis === yaxis | ||
); | ||
if (existingComboIndex === -1) { | ||
acc.push({ | ||
xaxis: xaxis, | ||
yaxis: yaxis, | ||
xaxisName: curVal.xaxis || 'x1', | ||
yaxisName: curVal.yaxis || 'y1', | ||
index: [inx], | ||
}); | ||
} else { | ||
acc[existingComboIndex].index.push(inx); | ||
} | ||
} | ||
return acc; | ||
}, []); | ||
|
||
allCartesianAxisCombinations.forEach( | ||
d => | ||
(subplotFolds[d.index[0]] = ( | ||
<CartesianSubplotFold | ||
key={d.index[0]} | ||
traceIndexes={d.index} | ||
canDelete={false} | ||
messageIfEmpty={messageIfEmptyFold} | ||
xaxis={d.xaxis} | ||
yaxis={d.yaxis} | ||
name={`${d.xaxisName} ${d.yaxisName}`} | ||
> | ||
{children} | ||
</CartesianSubplotFold> | ||
)) | ||
); | ||
|
||
// For each key in layout, find all traces that belong to this subplot. | ||
// E.g. if layout attr is 'ternary', find all traces that are of type | ||
// that has subplot ternary, if layout attr is 'ternary2', find traces | ||
// of right type that have attr 'subplot': 'ternary' in their data. | ||
|
||
/** | ||
Example: | ||
{ | ||
"data": [ | ||
{ | ||
"type": "scatterternary", | ||
"mode": "markers", | ||
}, | ||
{ | ||
"type": "scatterternary", | ||
"mode": "markers", | ||
"subplot": "ternary2" | ||
} | ||
], | ||
"layout": { | ||
"ternary": {}, | ||
"ternary2": {}, | ||
}, | ||
} | ||
*/ | ||
|
||
Object.keys(layout).forEach(layoutKey => { | ||
const traceIndexes = []; | ||
if ( | ||
['geo', 'mapbox', 'polar', 'gl3d', 'ternary'].some(subplotType => { | ||
const trIndex = | ||
SUBPLOT_TO_ATTR[subplotType].layout === layoutKey | ||
? data.findIndex(trace => | ||
TRACE_TO_AXIS[subplotType].some(tt => tt === trace.type) | ||
) | ||
: data.findIndex( | ||
trace => | ||
trace[SUBPLOT_TO_ATTR[subplotType].data] === layoutKey | ||
); | ||
if (trIndex !== -1) { | ||
traceIndexes.push(trIndex); | ||
} | ||
return layoutKey.startsWith(SUBPLOT_TO_ATTR[subplotType].layout); | ||
}) | ||
) { | ||
subplotFolds[traceIndexes[0]] = ( | ||
<NonCartesianSubplotFold | ||
key={layoutKey} | ||
traceIndexes={traceIndexes} | ||
canDelete={false} | ||
messageIfEmpty={messageIfEmptyFold} | ||
subplot={layoutKey} | ||
name={layoutKey} | ||
> | ||
{children} | ||
</NonCartesianSubplotFold> | ||
); | ||
} | ||
}); | ||
|
||
data.forEach((d, i) => { | ||
if ((d.type === 'pie' && d.values) || d.type === 'table') { | ||
subplotFolds[i] = ( | ||
<TraceFold | ||
key={i} | ||
traceIndexes={[i]} | ||
canDelete={false} | ||
messageIfEmpty={messageIfEmptyFold} | ||
name={`${d.type} ${i}`} | ||
> | ||
{children} | ||
</TraceFold> | ||
); | ||
} | ||
}); | ||
|
||
return <TraceRequiredPanel>{subplotFolds}</TraceRequiredPanel>; | ||
} | ||
} | ||
|
||
SubplotAccordion.contextTypes = { | ||
fullData: PropTypes.array, | ||
data: PropTypes.array, | ||
layout: PropTypes.object, | ||
localize: PropTypes.func, | ||
}; | ||
|
||
SubplotAccordion.propTypes = { | ||
children: PropTypes.node, | ||
messageIfEmptyFold: PropTypes.string, | ||
}; | ||
|
||
export default SubplotAccordion; |
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
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.
are we actually using it?
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.
it's a peer dep of the draggy thing.