-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Nested <svg> removal #415
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
Nested <svg> removal #415
Changes from 5 commits
f213006
ab0b6bf
d0d5577
4d48fb1
75897f3
787c903
21f5cc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,9 +322,9 @@ Plotly.plot = function(gd, data, layout, config) { | |
var donePlotting = Lib.syncOrAsync([ | ||
Plots.previousPromises, | ||
marginPushers, | ||
layoutStyles, | ||
marginPushersAgain, | ||
positionAndAutorange, | ||
layoutStyles, | ||
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. why? 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.
This image diff shows the improper clip. It's sort of hard to see, but the right side of the longest bars is clipped. |
||
drawAxes, | ||
drawData, | ||
finalDraw | ||
|
@@ -2753,7 +2753,7 @@ function makeCartesianPlotFramwork(gd, subplots) { | |
plotinfo.overgrid = plotgroup.append('g'); | ||
plotinfo.zerolinelayer = plotgroup.append('g'); | ||
plotinfo.overzero = plotgroup.append('g'); | ||
plotinfo.plot = plotgroup.append('svg').call(plotLayers); | ||
plotinfo.plot = plotgroup.append('g').call(plotLayers); | ||
plotinfo.overplot = plotgroup.append('g'); | ||
plotinfo.xlines = plotgroup.append('path'); | ||
plotinfo.ylines = plotgroup.append('path'); | ||
|
@@ -2779,7 +2779,7 @@ function makeCartesianPlotFramwork(gd, subplots) { | |
|
||
plotinfo.gridlayer = mainplot.overgrid.append('g'); | ||
plotinfo.zerolinelayer = mainplot.overzero.append('g'); | ||
plotinfo.plot = mainplot.overplot.append('svg').call(plotLayers); | ||
plotinfo.plot = mainplot.overplot.append('g').call(plotLayers); | ||
plotinfo.xlines = mainplot.overlines.append('path'); | ||
plotinfo.ylines = mainplot.overlines.append('path'); | ||
plotinfo.xaxislayer = mainplot.overaxes.append('g'); | ||
|
@@ -2790,9 +2790,6 @@ function makeCartesianPlotFramwork(gd, subplots) { | |
subplots.forEach(function(subplot) { | ||
var plotinfo = fullLayout._plots[subplot]; | ||
|
||
plotinfo.plot | ||
.attr('preserveAspectRatio', 'none') | ||
.style('fill', 'none'); | ||
plotinfo.xlines | ||
.style('fill', 'none') | ||
.classed('crisp', true); | ||
|
@@ -2841,9 +2838,28 @@ function lsInner(gd) { | |
xa._length+2*gs.p, ya._length+2*gs.p) | ||
.call(Color.fill, fullLayout.plot_bgcolor); | ||
} | ||
plotinfo.plot | ||
.call(Drawing.setRect, | ||
xa._offset, ya._offset, xa._length, ya._length); | ||
|
||
// Clip so that data only shows up on the plot area. | ||
var clips = fullLayout._defs.selectAll('g.clips'), | ||
clipId = 'clip' + fullLayout._uid + subplot + 'plot'; | ||
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. 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. Sure thang. I was just copying the id format from |
||
|
||
clips.selectAll('#' + clipId) | ||
.data([0]) | ||
.enter().append('clipPath') | ||
.attr({ | ||
'class': 'plotclip', | ||
'id': clipId | ||
}) | ||
.append('rect') | ||
.attr({ | ||
'width': xa._length, | ||
'height': ya._length | ||
}); | ||
|
||
plotinfo.plot.attr({ | ||
'transform': 'translate(' + xa._offset + ', ' + ya._offset + ')', | ||
'clip-path': 'url(#' + clipId + ')' | ||
}); | ||
|
||
var xlw = Drawing.crispRound(gd, xa.linewidth, 1), | ||
ylw = Drawing.crispRound(gd, ya.linewidth, 1), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
var Snapshot = require('@src/snapshot'); | ||
var Plotly = require('@lib/index'); | ||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var subplotMock = require('../../image/mocks/multiple_subplots.json'); | ||
var annotationMock = require('../../image/mocks/annotations.json'); | ||
|
||
describe('Test Snapshot.clone', function() { | ||
describe('Plotly.Snapshot', function() { | ||
'use strict'; | ||
|
||
describe('Test clone', function() { | ||
describe('clone', function() { | ||
|
||
var data, | ||
layout, | ||
|
@@ -76,7 +80,7 @@ describe('Test Snapshot.clone', function() { | |
setBackground: 'opaque' | ||
}; | ||
|
||
var themeTile = Snapshot.clone(dummyGraphObj, themeOptions); | ||
var themeTile = Plotly.Snapshot.clone(dummyGraphObj, themeOptions); | ||
expect(themeTile.layout.height).toEqual(THEMETILE_DEFAULT_LAYOUT.height); | ||
expect(themeTile.layout.width).toEqual(THEMETILE_DEFAULT_LAYOUT.width); | ||
expect(themeTile.td.defaultLayout).toEqual(THEMETILE_DEFAULT_LAYOUT); | ||
|
@@ -101,7 +105,7 @@ describe('Test Snapshot.clone', function() { | |
'annotations': [] | ||
}; | ||
|
||
var thumbTile = Snapshot.clone(dummyGraphObj, thumbnailOptions); | ||
var thumbTile = Plotly.Snapshot.clone(dummyGraphObj, thumbnailOptions); | ||
expect(thumbTile.layout.hidesources).toEqual(THUMBNAIL_DEFAULT_LAYOUT.hidesources); | ||
expect(thumbTile.layout.showlegend).toEqual(THUMBNAIL_DEFAULT_LAYOUT.showlegend); | ||
expect(thumbTile.layout.borderwidth).toEqual(THUMBNAIL_DEFAULT_LAYOUT.borderwidth); | ||
|
@@ -115,7 +119,7 @@ describe('Test Snapshot.clone', function() { | |
width: 888 | ||
}; | ||
|
||
var customTile = Snapshot.clone(dummyGraphObj, customOptions); | ||
var customTile = Plotly.Snapshot.clone(dummyGraphObj, customOptions); | ||
expect(customTile.layout.height).toEqual(customOptions.height); | ||
expect(customTile.layout.width).toEqual(customOptions.width); | ||
}); | ||
|
@@ -125,23 +129,54 @@ describe('Test Snapshot.clone', function() { | |
tileClass: 'notarealclass' | ||
}; | ||
|
||
var vanillaPlotTile = Snapshot.clone(dummyGraphObj, vanillaOptions); | ||
var vanillaPlotTile = Plotly.Snapshot.clone(dummyGraphObj, vanillaOptions); | ||
expect(vanillaPlotTile.data[0].x).toEqual(data[0].x); | ||
expect(vanillaPlotTile.layout).toEqual(layout); | ||
expect(vanillaPlotTile.layout.height).toEqual(layout.height); | ||
expect(vanillaPlotTile.layout.width).toEqual(layout.width); | ||
}); | ||
|
||
it('should set the background parameter appropriately', function() { | ||
var pt = Snapshot.clone(dummyGraphObj, { | ||
var pt = Plotly.Snapshot.clone(dummyGraphObj, { | ||
setBackground: 'transparent' | ||
}); | ||
expect(pt.config.setBackground).not.toBeDefined(); | ||
|
||
pt = Snapshot.clone(dummyGraphObj, { | ||
pt = Plotly.Snapshot.clone(dummyGraphObj, { | ||
setBackground: 'blue' | ||
}); | ||
expect(pt.config.setBackground).toEqual('blue'); | ||
}); | ||
}); | ||
|
||
describe('toSVG', function() { | ||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
|
||
it('should not return any nested svg tags of plots', function(done) { | ||
Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() { | ||
return Plotly.Snapshot.toSVG(gd); | ||
}).then(function(svg) { | ||
var splitSVG = svg.split('<svg'); | ||
|
||
expect(splitSVG.length).toBe(2); | ||
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. Could we make this test even better by searching for one and only one |
||
}).then(done); | ||
}); | ||
|
||
it('should not return any nested svg tags of annotations', function(done) { | ||
Plotly.plot(gd, annotationMock.data, annotationMock.layout).then(function() { | ||
return Plotly.Snapshot.toSVG(gd); | ||
}).then(function(svg) { | ||
var splitSVG = svg.split('<svg'); | ||
|
||
expect(splitSVG.length).toBe(2); | ||
}).then(done); | ||
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. nicely done 🎉 |
||
}); | ||
}); | ||
}); |
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.
is this necessary?
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.
Yep - the call to
setPosition
only setsx
andy
attributes - for<g>
's, we need to position usingtransform
.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 suppose we could add a
drawing.setTranslate
method though too. Thoughts?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.
Oh. I meant,
'transform', 'translate(0,0)'
as no effects, right?By the why, I like the idea of having a
drawing.setTranslate
method. No need to do that right now though.