Skip to content
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

Fix toImage for marker gradient #1694

Merged
merged 1 commit into from
May 18, 2017
Merged

Conversation

etpinard
Copy link
Contributor

fixes https://github.com/plotly/support-assets/issues/87

The Plotly.toImage as well as the to-image modebar button are currently broken for graphs with set marker.gradient (added in #1620). Note that the image tests work fine inside the image test container - I'm thinking this has to do with nw.js 0.12 which uses a much older Chromium version (we gotta upgrade that thing soon).

The fix applies the same logic as in #604. In #604, the " surrounding font-family property value (e.g. style="font-family: "Times New Roman"") were stripped before serializing with XMLSerializer and then put back after. In this PR, the " surrounding the fill property value for gradients (e.g. style="fill: url("#dgfdakngkda")") are given the same treatment.

Note that, we don't have to the same with clip-path attributes, XMLSerializer handles those fine.


In future PRs, we should make that all new attributes that generate DOM style properties wrapped in " go through this process to avoid bugs like this one.

@alexcjohnson

- style="fill: url("#...")" break the XML seriliazer,
- we need to swap those inner \" before seriliazing
  and bring those back in the SVG after, similar to how
  'font-family' properties are handled.
@etpinard etpinard added status: reviewable bug something broken labels May 17, 2017
}

var pointElements = svgDOM.getElementsByClassName('point');
expect(pointElements.length).toEqual(3);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this patch, pointElement.length was 0 i.e. Snapshot.toSVG failed to process them.

@@ -16,6 +16,9 @@ var Drawing = require('../components/drawing');
var Color = require('../components/color');

var xmlnsNamespaces = require('../constants/xmlns_namespaces');
var DOUBLEQUOTE_REGEX = /"/g;
var DUMMY_SUB = 'TOBESTRIPPED';
Copy link
Collaborator

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?

Copy link
Contributor Author

@etpinard etpinard May 17, 2017

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 if font.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.

Copy link
Collaborator

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:

Plotly.relayout(gd,{'yaxis.title':'"TOBESTRIPPED"'})

on screen:
screen shot 2017-05-17 at 5 42 03 pm

download:
newplot 2

So you're not making a new bug, but we do need something better for this.

Copy link
Contributor Author

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?

  • We could make the regex more precise here so that it grabs only TOBESTRIPPED inside style= props.
  • Use another (more esoteric) dummy string
  • Use another seriliazer than what's the browsers give us on the window object?

Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess only style attributes get these extra quotes.

Exactly!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue ➡️ #1697

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue ➡️ #1697

thanks!

@alexcjohnson
Copy link
Collaborator

💃

@etpinard etpinard merged commit e83c216 into master May 18, 2017
@etpinard etpinard deleted the fix-tosvg-for-marker-gradients branch May 18, 2017 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants