-
-
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
Try out visibility:inherit default for text #990
Changes from all commits
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 |
---|---|---|
|
@@ -71,12 +71,19 @@ module.exports = function toSVG(gd, format) { | |
svg.selectAll('text') | ||
.attr('data-unformatted', null) | ||
.each(function() { | ||
// hidden text is pre-formatting mathjax, the browser ignores it but it can still confuse batik | ||
var txt = d3.select(this); | ||
|
||
// hidden text is pre-formatting mathjax, | ||
// the browser ignores it but it can still confuse batik | ||
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 seems to make sense 👍 |
||
if(txt.style('visibility') === 'hidden') { | ||
txt.remove(); | ||
return; | ||
} | ||
else { | ||
// force other visibility value to export as visible | ||
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 also makes sense. Presumably it overwrites |
||
// to not potentially confuse non-browser SVG implementations | ||
txt.style('visibility', 'visible'); | ||
} | ||
|
||
// Font family styles break things because of quotation marks, | ||
// so we must remove them *after* the SVG DOM has been serialized | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
var Plotly = require('@lib/index'); | ||
|
||
var d3 = require('d3'); | ||
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'); | ||
|
||
|
@@ -181,5 +184,28 @@ describe('Plotly.Snapshot', function() { | |
expect(svgElements.length).toBe(1); | ||
}).then(done); | ||
}); | ||
|
||
it('should force *visibility: visible* for text elements with *visibility: inherit*', function(done) { | ||
d3.select(gd).style('visibility', 'inherit'); | ||
|
||
Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() { | ||
|
||
d3.select(gd).selectAll('text').each(function() { | ||
expect(d3.select(this).style('visibility')).toEqual('visible'); | ||
}); | ||
|
||
return Plotly.Snapshot.toSVG(gd); | ||
}) | ||
.then(function(svg) { | ||
var svgDOM = parser.parseFromString(svg, 'image/svg+xml'), | ||
textElements = svgDOM.getElementsByTagName('text'); | ||
|
||
for(var i = 0; i < textElements.length; i++) { | ||
expect(textElements[i].style.visibility).toEqual('visible'); | ||
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. Good check. 👍 |
||
} | ||
|
||
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.
This is definitively the first step to take. 👍
My only concern here is possible incompatibilities in Illustrator and svg conversion tools (e.g. Batik).
To avoid any rolling 🎲 , I'm thinking about adding a few lines to the
toSVG
routine making sure all exported images getvisibility: 'visible'
as opposed toinherit
while interactive graphs would get'inherit'
.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 to know about. That's the sort of obscure possibility for interaction that I thought maybe could exist.
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.
Feel free to pull this fix wherever you need or redo it elsewhere. I won't worry further about it.