-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[take 2] Implement scatter cliponaxis: false
#1861
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
Changes from 1 commit
c28b26a
8f72d1f
1909034
4b5c4bb
d46cae7
7228d5d
fe1f889
89ee533
e4d7889
091473b
9becb7c
62ab845
0496144
7b62b73
02b9fbc
1c85de6
e44aa4d
e84701f
e234827
6f494c6
bbb31f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- keep track of which subplots have 1 or more `cliponaxis: false` traces + if so, don't clip the subplot layer + instead, clip all trace module layers except for 'scatterlayer' + when `cliponaxis: false`, clip all lines and errorbar groups - use ax.isWithinRange and Drawing.hideOutsideRangePoint to hide markers and text node that are out of range.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,14 @@ | |
var d3 = require('d3'); | ||
var isNumeric = require('fast-isnumeric'); | ||
|
||
var Drawing = require('../drawing'); | ||
var subTypes = require('../../traces/scatter/subtypes'); | ||
|
||
module.exports = function plot(traces, plotinfo, transitionOpts) { | ||
var isNew; | ||
|
||
var xa = plotinfo.xaxis, | ||
ya = plotinfo.yaxis; | ||
var xa = plotinfo.xaxis; | ||
var ya = plotinfo.yaxis; | ||
|
||
var hasAnimation = transitionOpts && transitionOpts.duration > 0; | ||
|
||
|
@@ -60,6 +61,11 @@ module.exports = function plot(traces, plotinfo, transitionOpts) { | |
.style('opacity', 1); | ||
} | ||
|
||
errorbars.call( | ||
Drawing.setClipUrl, | ||
plotinfo._hasClipOnAxisFalse ? plotinfo.clipId : null | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps it would simplify things if when we calculate Also a debatable style point, I've started avoiding |
||
|
||
errorbars.each(function(d) { | ||
var errorbar = d3.select(this); | ||
var coords = errorCoords(d, xa, ya); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,24 +294,8 @@ function makeSubplotData(gd) { | |
} | ||
|
||
function makeSubplotLayer(plotinfo) { | ||
var plotgroup = plotinfo.plotgroup, | ||
id = plotinfo.id; | ||
|
||
// Layers to keep plot types in the right order. | ||
// from back to front: | ||
// 1. heatmaps, 2D histos and contour maps | ||
// 2. bars / 1D histos | ||
// 3. errorbars for bars and scatter | ||
// 4. scatter | ||
// 5. box plots | ||
function joinPlotLayers(parent) { | ||
joinLayer(parent, 'g', 'imagelayer'); | ||
joinLayer(parent, 'g', 'maplayer'); | ||
joinLayer(parent, 'g', 'barlayer'); | ||
joinLayer(parent, 'g', 'carpetlayer'); | ||
joinLayer(parent, 'g', 'boxlayer'); | ||
joinLayer(parent, 'g', 'scatterlayer'); | ||
} | ||
var plotgroup = plotinfo.plotgroup; | ||
var id = plotinfo.id; | ||
|
||
if(!plotinfo.mainplot) { | ||
var backLayer = joinLayer(plotgroup, 'g', 'layer-subplot'); | ||
|
@@ -354,7 +338,10 @@ function makeSubplotLayer(plotinfo) { | |
} | ||
|
||
// common attributes for all subplots, overlays or not | ||
plotinfo.plot.call(joinPlotLayers); | ||
|
||
10000 | for(var i = 0; i < constants.layers.length; i++) { | |
joinLayer(plotinfo.plot, 'g', constants.layers[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
} | ||
|
||
plotinfo.xlines | ||
.style('fill', 'none') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, transitionOpts, makeOnCo | |
// the z-order of fill layers is correct. | ||
linkTraces(gd, plotinfo, cdscatter); | ||
|
||
createFills(gd, scatterlayer); | ||
createFills(gd, scatterlayer, plotinfo); | ||
|
||
// Sort the traces, once created, so that the ordering is preserved even when traces | ||
// are shown and hidden. This is needed since we're not just wiping everything out | ||
|
@@ -100,7 +100,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, transitionOpts, makeOnCo | |
scatterlayer.selectAll('path:not([d])').remove(); | ||
}; | ||
|
||
function createFills(gd, scatterlayer) { | ||
function createFills(gd, scatterlayer, plotinfo) { | ||
var trace; | ||
|
||
scatterlayer.selectAll('g.trace').each(function(d) { | ||
|
@@ -138,6 +138,10 @@ function createFills(gd, scatterlayer) { | |
tr.selectAll('.js-fill.js-tozero').remove(); | ||
trace._ownFill = null; | ||
} | ||
|
||
if(plotinfo._hasClipOnAxisFalse) { | ||
tr.selectAll('.js-fill').call(Drawing.setClipUrl, plotinfo.clipId); | ||
} | ||
}); | ||
} | ||
|
||
<
8000
/a>
|
@@ -324,6 +328,10 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition | |
.call(Drawing.lineGroupStyle) | ||
.each(makeUpdate(true)); | ||
|
||
if(plotinfo._hasClipOnAxisFalse) { | ||
Drawing.setClipUrl(lineJoin, plotinfo.clipId); | ||
} | ||
|
||
if(segments.length) { | ||
if(ownFillEl3) { | ||
if(pt0 && pt1) { | ||
|
@@ -400,7 +408,8 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition | |
var trace = d[0].trace, | ||
s = d3.select(this), | ||
showMarkers = subTypes.hasMarkers(trace), | ||
showText = subTypes.hasText(trace); | ||
showText = subTypes.hasText(trace), | ||
hasClipOnAxisFalse = trace.cliponaxis === false; | ||
|
||
var keyFunc = getKeyFunc(trace), | ||
markerFilter = hideFilter, | ||
|
@@ -426,7 +435,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition | |
if(hasTransition) { | ||
enter | ||
.call(Drawing.pointStyle, trace, gd) | ||
.call(Drawing.translatePoints, xa, ya, trace) | ||
.call(Drawing.translatePoints, xa, ya) | ||
.style('opacity', 0) | ||
.transition() | ||
.style('opacity', 1); | ||
|
@@ -445,6 +454,10 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition | |
if(hasNode) { | ||
Drawing.singlePointStyle(d, sel, trace, markerScale, lineScale, gd); | ||
|
||
if(hasClipOnAxisFalse) { | ||
Drawing.hideOutsideRangePoint(d, sel, xa, ya); | ||
} | ||
|
||
if(trace.customdata) { | ||
el.classed('plotly-customdata', d.data !== null && d.data !== undefined); | ||
} | ||
|
@@ -475,7 +488,14 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition | |
var g = d3.select(this); | ||
var sel = transition(g.select('text')); | ||
hasNode = Drawing.translatePoint(d, sel, xa, ya); | ||
if(!hasNode) g.remove(); | ||
|
||
if(hasNode) { | ||
if(hasClipOnAxisFalse) { | ||
Drawing.hideOutsideRangePoint(d, g, xa, ya); | ||
} | ||
} else { | ||
g.remove(); | ||
} | ||
}); | ||
|
||
join.selectAll('text') | ||
|
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.
possibly better to use
display: 'none'
instead?visibility: 'hidden'
still includes the element in the rendering pipeline (so children could be made visible for example, as we've seen!), which is probably slower and also means it still contributes to the bounding box (potential confusion for illustrator? I suppose we could also add something to our static plot pipeline to removevisibility: 'hidden'
anddisplay: 'none'
elements completely...)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.
Would be nice to benchmark these things, but you make a good argument for
display
. Good point above illustrator not likingvisibility
👍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.
done in 9becb7c