-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Image and shape clip paths #1453
Conversation
particularly in cases of partial data referencing and layer: below
Note: annotations do not have these issues, as they don't use clip paths. We will happily allow the arrow and text box of an annotation to go outside the plot area as long as its reference point is visible. |
thisImage.call(Drawing.setClipUrl, clipAxes ? | ||
('clip' + fullLayout._uid + clipAxes) : | ||
null | ||
); |
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.
Needed to unset the clip path if you change from data-referenced to fully paper-referenced.
|
||
function getShape(index) { | ||
var s = d3.selectAll('path[data-index="' + index + '"]'); | ||
expect(s.size()).toBe(1); |
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.
before the fix above, the shape was drawn twice in its initial configuration xref: 'x', yref: 'paper'
: once on subplot xy
and again on xy2
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.
Good eyes. Thanks very much!
|
||
path.call(Drawing.setClipUrl, clipAxes ? | ||
('clip' + gd._fullLayout._uid + clipAxes) : | ||
null |
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.
Nice way to unset a clip path. 👍
@@ -425,23 +425,38 @@ describe('images log/linear axis changes', function() { | |||
// we don't try to figure out the position on a new axis / canvas | |||
// automatically when you change xref / yref, we leave it to the caller. | |||
|
|||
// initial clip path should end in 'xy' to match xref/yref | |||
expect(d3.select('image').attr('clip-path') || '').toMatch(/xy\)$/); |
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.
Ha. I didn't know about .toMatch
. Pretty handy 🔨
expect(d3.select('image').attr('clip-path') || '').toMatch(/x\)$/); | ||
|
||
// change to full paper-referenced, to make sure the clip path disappears | ||
return Plotly.relayout(gd, {'images[0].xref': 'paper'}); |
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.
I'm surprised we weren't testing this before. Oh well, now it's 🔒 ed
Hmm, maybe #1452 needs to be addressed together with this PR after all, that's what's going on here. You'll see that the data in the lower left subplot gets covered up in the new result for that image. But the original is clearly wrong in how it breaks the two shapes that span that subplot and either the one above or to the right into two disjoint pieces. From a slack chat:
@etpinard suggested:
That would certainly make this easier (the restriction would only apply to So I'm leaning toward the "trickier thing": pulling the plot backgrounds back to their own layer except for inset plots. Thoughts? |
#1390 is wrapped up in this too... better fix that at the same time. |
This is definitely the best solution from a user's perspective. If you feel like taking a shot at this, go for it 👍 |
|
||
// filter out overlaid plots (which havd their images on the main plot) | ||
// and gl2d plots (which don't support below images, at least not yet) | ||
if(!subplotObj.imagelayer) continue; |
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.
Looks good 👍
@@ -308,8 +308,7 @@ Plotly.plot = function(gd, data, layout, config) { | |||
|
|||
// keep reference to shape layers in subplots | |||
var layerSubplot = fullLayout._paper.selectAll('.layer-subplot'); | |||
fullLayout._imageSubplotLayer = layerSubplot.selectAll('.imagelayer'); | |||
fullLayout._shapeSubplotLayer = layerSubplot.selectAll('.shapelayer'); | |||
fullLayout._shapeSubplotLayers = layerSubplot.selectAll('.shapelayer'); |
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.
✏️ nicely done
expect(gd.querySelectorAll('.bg').length).toBe(behindCount + x2y2Count); | ||
} | ||
|
||
Plotly.plot(gd, [ |
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.
Fantastic test 🎉
In testing axis reference changes for integrating v1.24 into the workspace, I noticed some strange situations with clip paths for shapes and images. Turns out they had different issues but related symptoms. There's one particular edge case that I didn't sort out here because it's a much bigger structural question, so I described it in #1452 instead.
@etpinard please review.