Comments (9)
Right, you code isn't selecting a canvas. Change download
to this:
function download(){
if(downloads){
cancelAnimationFrame(a);
} else {
$('#3d-graph canvas')[0].toBlob(function(blob){ //See? Select a canvas, not the div that wraps it.
console.log(blob);
saveAs(blob, 'a.png');
});
}
}
from 3d-force-graph.
@AABoyles Thanks a lot for pointing out my mistake. It is working now. Thanks again.
from 3d-force-graph.
@mhebrard renderer.domElement
simply returns the canvas DOM element, so assuming you're getting the canvas element that is controlled by 3d-force-graph with $('canvas')[0]
, the two instructions should actually be equivalent.
If you're getting an empty image, could it be a timing issue? You'd need to wait until the objects are actually rendered on the canvas before taking the png screenshot.
The background color/transparency can already be set by doing something like: .backgroundColor('rgba(0,0,0,0)')
.
Let me know if you're able to get it working.
from 3d-force-graph.
Oh I see...
Thanks for the reply... I will test that and let you know
from 3d-force-graph.
I just spent a ton of time on this, and I think I've got a working hack.
var a, downloads = 0;
//This can be any event. I've got an export button:
$('#3d_network_export').click(function(){
downloads = 0;
//Calling this kicks off a loop that repeatedly calls the passed function.
a = requestAnimationFrame(download);
});
function download(){
//So we don't call this function a bunch of times, let's cancel the loop after the first
if(downloads){
cancelAnimationFrame(a);
} else {
//Obviously, you should swap this out for a selector that gets only the 3D graph
$('#3d-network canvas')[0].toBlob(function(blob){
//Powered by [FileSaver](https://github.com/eligrey/FileSaver.js/)
saveAs(blob, 'a.png');
});
}
}
This cannot be the right way to accomplish this, but it seems to work.
from 3d-force-graph.
@AABoyles It is not working for me. It shows console error
Uncaught TypeError: $(...)[0].toBlob is not a function at download
from 3d-force-graph.
@nupurbiswas Just sanity checking, here--is your selector (the ...
in your console error) actually selecting a canvas? toBlob is a method of canvas elements.
from 3d-force-graph.
@AABoyles I have used your code and here it is. It is not working for me.
<div id="3d-graph" ></div>
<script>
const elem = document.getElementById('3d-graph');
const Graph = ForceGraph3D()(elem)
.width(300)
.height(300)
.backgroundColor('grey')
.jsonUrl('blocks.json')
</script>
<div id="savebutton" ><button>Save graph as png </button</div>
<script>
var a, downloads = 0;
$('#savebutton').click(function(){
downloads = 0;
a = requestAnimationFrame(download);
});
function download(){
if(downloads){
cancelAnimationFrame(a);
} else {
$('#3d-graph')[0].toBlob(function(blob){
console.log(blob);
saveAs(blob, 'a.png');
});
}
}
</script>
from 3d-force-graph.
requestAnimationFrame is useful
from 3d-force-graph.
Related Issues (20)
- Dynamic Particles do not appear for fixed Nodes HOT 1
- Issue with scene hyper-intensive illumination (probably after 1.73.0) HOT 2
- Shadow for links and nodes HOT 1
- How to add a loader to the node HOT 1
- Html rerendering on drag
- continuous scale node color
- 我画布上的所有节点都没有链接,点击节点之后,节点会向外扩散
- LOD for abnormally large graphs
- onNodeClick work error
- Default Settings for "charge" force not clear in documentation please help!!
- Labels for 'regions' / groups.
- text-nodes example stopped working HOT 2
- When nodeThreeObject is used, three-spritetext gives an error
- Arrow bad positionning when linkCurvature(0)
- The text-links example is broken by the latest three.js release r161 HOT 1
- Progressive WebXR HOT 2
- How to show a - 1M nodes HOT 3
- Showing labels front of node HOT 8
- Best way to add dynamic external object
- How to add custom lighting in nodes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from 3d-force-graph.