Last active
November 21, 2018 14:05
-
-
Save webbres/d8fdee6ee6f28779e407088d60158fc2 to your computer and use it in GitHub Desktop.
Working SVG export in KNIME 3.6 onwards - configure with chromium or chrome
This file contains 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
// Remove an element with a specific class from the DOM | |
function removeElementsByClass(className){ | |
var elements = document.getElementsByClassName(className); | |
while(elements.length > 0){ | |
elements[0].parentNode.removeChild(elements[0]); | |
} | |
} | |
// Remove the curso-crosshair class which is the interactive layer | |
// If this layer is present a series of black boxes will be added | |
// to the SVG render | |
removeElementsByClass('cursor-crosshair'); | |
try | |
{ // Create a new serializer object which is needed to create | |
// the string for the KNIME output | |
var serializer = new XMLSerializer(); | |
// Get the graph element which is in the first 'main-svg' classed element | |
// Plotly doesn't appear to use IDs we can use | |
var svgElement = document.getElementsByClassName("main-svg")[0]; | |
// Get the info layer which is within the second 'main-svg' element | |
// and can be fetched from the 'infolayer' class | |
var infoLayer = document.getElementsByClassName("infolayer")[0]; | |
// Now add the info layer top the main element | |
svgElement.appendChild(infoLayer); | |
// Serialize | |
var graph = serializer.serializeToString(svgElement); | |
return graph; | |
} catch (err) | |
{ | |
return "<svg></svg>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment