Are you aware our embed mode? It lets you do all this using an iframe and a simple postmessage protocol. Examples are on github.
Are you aware our embed mode? It lets you do all this using an iframe and a simple postmessage protocol. Examples are on github.
window.addEventListener('message', receive);iframe.setAttribute('src', editor);document.body.appendChild(iframe);
'https://www.draw.io/?embed=1&ui=atlas&spin=1&modified=unsavedChanges&proto=json'
https://github.com/jgraph/drawio-html5 is a good example.
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'load', xmlpng: source.getAttribute('src')}), '*');
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'load', xmlsvg: source}), '*');
Have you tried xml instead of xmlsvg, see first line in the "Description of the JSON protocol" at https://desk.draw.io/support/solutions/articles/16000042544
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'load', xml: source}), '*');
source should be a string.
var source = evt.srcElement || evt.target;
all actions and events should be fully specified in that page.
Hmm... ok. So in the original code from the embed example page you linked me to, it hasvar source = evt.srcElement || evt.target;I do see in the original code, it is looking at the src attribute of the PNG. That makes sense because the IMG tag uses the src to render the image. SVG, however, uses the entire contents of the tag. Please forgive my ignorance but I don't see how I can convert it to a string (using straight javascript). I've seen some references to how it can be done using jQuery but I'm not sure exactly what draw.io is expecting to receive.
(new XMLSerializer()).serializeToString(source);
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'load', xml: (new XMLSerializer()).serializeToString(source)}), '*');
Have you tried xml instead of xmlsvg, see first line in the "Description of the JSON protocol" at https://desk.draw.io/support/solutions/articles/16000042544
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'load', xml: (new XMLSerializer()).serializeToString(source)}), '*');
source.drawIoWindow.contentWindow.postMessage(JSON.stringify({action: 'export', format: 'xmlsvg'}), '*');
source.setAttribute('src', msg.data);
source.setAttribute('content', msg.xml);
elt.innerHTML = atob(msg.data.substring(msg.data.indexOf(',') + 1));
see http://jgraph.github.io/drawio-html5/localstorage-svg.html#default
and before you ask: keep in mind that foreignObject, which is used for labels in draw.io, is not supported in IE 11 and earlier.
msg.data is an SVG image (data URI). why are you using an SVG element and not an SVG image?
basic idea to obtain the SVG and add it to the DOM:
elt.innerHTML = atob(msg.data.substring(msg.data.indexOf(',') + 1));
see http://jgraph.github.io/drawio-html5/localstorage-svg.html#default
and before you ask: keep in mind that foreignObject, which is used for labels in draw.io, is not supported in IE 11 and earlier.
atob(msg.data.substring(msg.data.indexOf(',') + 1))