Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
ContributorAuthor 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); | ||
| }); | ||
| }); | ||
| }); | ||
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?
Uh oh!
There was an error while loading. Please reload this page.
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
fillproperty 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?
TOBESTRIPPEDinsidestyle=props.windowobject?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!