VivaGraphJS icon indicating copy to clipboard operation
VivaGraphJS copied to clipboard

Export to image WebGL

Open slasia opened this issue 8 years ago • 1 comments
trafficstars

Hi! this is my code:

` graph = Viva.Graph.graph(); var layout = Viva.Graph.Layout.forceDirected(graph, { springLength: 100, springCoeff: 0.0008, dragCoeff: 0.02, gravity: -1.2 });

	for (var i = 0; i < 100; ++i) {
		layout.step();
	}

	for (var i = 0; i < nodos.length; ++i) {
		graph.addNode(nodos[i].IDNodo, nodos[i]);
	}
	var dic = new Object();
	for (var i = 0; i < enlaces.length; i++) {
		if (isNaN(dic[enlaces[i].From + "**" + enlaces[i].To])) {
			dic[enlaces[i].From + "**" + enlaces[i].To] = 1;
			graph.addLink(enlaces[i].From, enlaces[i].To, enlaces[i].IDEnlace);
		}
	}

	var container = document.getElementById('editorUltraLite');
	var graphics = Viva.Graph.View.webglGraphics();
	var nodeColor = 0x009ee8;// hex rrggbb
	var circleNode = buildCircleNodeShader();
	graphics.setNodeProgram(circleNode);
                    tamaño = 13;

	graphics.node(function (node) {
		return new WebglCircle(tamaño, nodeColor);
	});


	var events = Viva.Graph.webglInputEvents(graphics, graph);
	events.mouseEnter(function (node) {
	}).click(function (node) {
		layout.pinNode(node, !layout.isNodePinned(node));
	});

	renderer = Viva.Graph.View.renderer(graph, {
		layout: layout,
		graphics: graphics,
		container: container
	});
	renderer.run();
	$("canvas").attr("id", "diagramaWebGL")`  

I need to export to png image... how i can do this?

slasia avatar Jun 09 '17 18:06 slasia

Maybe take a snapshot of your canvas.

window.location.href = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");

https://stackoverflow.com/questions/3371325/how-get-snapshot-of-my-canvas

gg4u avatar Aug 10 '18 07:08 gg4u