Skip to content

Instantly share code, notes, and snippets.

@webbres
Last active November 21, 2018 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webbres/d8fdee6ee6f28779e407088d60158fc2 to your computer and use it in GitHub Desktop.
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
// 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