NxTIC/js/lib/sigma/plugins/sigma.renderers.snapshot.mi...

1 line
1.4 KiB
JavaScript
Executable File

(function(){function a(a,b,c){var d=document.createElement("a");d.setAttribute("href",a),d.setAttribute("download",c||"graph."+b);var e=document.createEvent("MouseEvent");e.initMouseEvent("click",!0,!1,window,0,0,0,0,0,!1,!1,!1,!1,0,null),d.dispatchEvent(e),delete d}function b(b){if(b=b||{},b.format&&!(b.format in d))throw Error('sigma.renderers.snaphot: unsupported format "'+b.format+'".');var e=this,f=this instanceof sigma.renderers.webgl,g=[],h=document.createElement("canvas"),i=h.getContext("2d"),j=!1;c.forEach(function(a){if(e.contexts[a]&&(b.labels!==!1||"labels"!==a)){var c=e.domElements[a]||e.domElements.scene,d=e.contexts[a];~g.indexOf(d)||(j||(h.width=f&&d instanceof WebGLRenderingContext?c.width/2:c.width,h.height=f&&d instanceof WebGLRenderingContext?c.height/2:c.height,j=!0,b.background&&(i.rect(0,0,h.width,h.height),i.fillStyle=b.background,i.fill())),d instanceof WebGLRenderingContext?i.drawImage(c,0,0,c.width/2,c.height/2):i.drawImage(c,0,0),g.push(d))}});var k=h.toDataURL(d[b.format||"png"]);return b.download&&a(k,b.format||"png",b.filename),delete i,delete h,delete g,k}if("undefined"==typeof sigma)throw"sigma.renderers.snapshot: sigma not in scope.";var c=["scene","edges","nodes","labels"],d={png:"image/png",jpg:"image/jpeg",gif:"image/gif",tiff:"image/tiff"};sigma.renderers.canvas.prototype.snapshot=b,sigma.renderers.webgl.prototype.snapshot=b}).call(this);