-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix toImage for marker gradient #1694
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
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ var Plotly = require('@lib/index'); | |
var d3 = require('d3'); | ||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
var fail = require('../assets/fail_test'); | ||
|
||
var subplotMock = require('../../image/mocks/multiple_subplots.json'); | ||
var annotationMock = require('../../image/mocks/annotations.json'); | ||
|
@@ -191,16 +192,15 @@ describe('Plotly.Snapshot', function() { | |
}); | ||
|
||
describe('toSVG', function() { | ||
var parser = new DOMParser(), | ||
gd; | ||
var parser = new DOMParser(); | ||
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); | ||
|
@@ -245,5 +245,53 @@ describe('Plotly.Snapshot', function() { | |
done(); | ||
}); | ||
}); | ||
|
||
it('should handle quoted style properties', function(done) { | ||
Plotly.plot(gd, [{ | ||
y: [1, 2, 1], | ||
marker: { | ||
gradient: { | ||
type: 'radial', | ||
color: '#fff' | ||
}, | ||
color: ['red', 'blue', 'green'] | ||
} | ||
}], { | ||
font: { family: 'Times New Roman' } | ||
}) | ||
.then(function() { | ||
d3.selectAll('text').each(function() { | ||
var tx = d3.select(this); | ||
expect(tx.style('font-family')).toEqual('\"Times New Roman\"'); | ||
}); | ||
|
||
d3.selectAll('.point').each(function() { | ||
var pt = d3.select(this); | ||
expect(pt.style('fill').substr(0, 6)).toEqual('url(\"#'); | ||
}); | ||
|
||
return Plotly.Snapshot.toSVG(gd); | ||
}) | ||
.then(function(svg) { | ||
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); | ||
var i; | ||
|
||
var textElements = svgDOM.getElementsByTagName('text'); | ||
expect(textElements.length).toEqual(11); | ||
|
||
for(i = 0; i < textElements.length; i++) { | ||
expect(textElements[i].style['font-family']).toEqual('\"Times New Roman\"'); | ||
} | ||
|
||
var pointElements = svgDOM.getElementsByClassName('point'); | ||
expect(pointElements.length).toEqual(3); | ||
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. Before this patch, |
||
|
||
for(i = 0; i < pointElements.length; i++) { | ||
expect(pointElements[i].style.fill.substr(0, 6)).toEqual('url(\"#'); | ||
} | ||
}) | ||
.catch(fail) | ||
.then(done); | ||
}); | ||
}); | ||
}); |
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.
is there any way this can occur in other contexts in the SVG string? Or a way to add characters that make it more obviously impossible?
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.
Not that I can think of.
The gradient
fill
property is set by us and even iffont.family: 'TOBESTRIPPED'
then in the DOM this will look like:font-family: TOBESTRIPPED
(no double quotes) which won't trigger that.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB)
call.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.
hmm, looks like this is already a problem in master:
on screen:

download:

So you're not making a new bug, but we do need something better for this.
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.
OK. What's the solution then?
TOBESTRIPPED
insidestyle=
props.window
object?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 don't know, I can't see an easy bulletproof solution. Lets just make an issue for the moment since the problem isn't new. Otherwise this looks great. I was surprised that this showed up in gradients since it didn't show up in clip paths (which also use these urls) but I guess only style attributes get these extra quotes.
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.
Exactly!
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.
Issue ➡️ #1697
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.
thanks!