Comments (5)
@cherno-alpha thanks for reaching out.
The two features are completely independent. To better understand the issue you're experiencing, it's easier if you could create a small example on https://codepen.io/ that reproduces the problem.
from force-graph.
I'm new to github and codepen, so a cautious heads up.
I used your Load JSON example and want to set images as nodes with nodeCanvasObject(). What do I need to write in the function?
Here is the Link to Codepen:
https://codepen.io/cherno-alpha/pen/oNamadd
from force-graph.
@cherno-alpha you just need to refer to this example to see how to write your canvas code to paint images:
force-graph/example/img-nodes/index.html
Lines 32 to 35 in 06e372d
from force-graph.
@cherno-alpha - this was exactly what I wanted to ask! The JSON fetch is what I need for a large family tree:
https://quickening.zapto.org/fg-network.html
But I want images on the nodes, with attached labels:
https://quickening.zapto.org/fg-images.html
I can see the network example creating a data object with methods that refer to "node object accessor", but I don't know how to change nodeCanvasObject to work with that data object. It just tells me img undefined:
`fetch('Tree/links.json').then(res => res.json()).then(data => {
const Graph = ForceGraph()
(document.getElementById('graph'))
.nodeCanvasObject(({ img, x, y }, ctx) => {
const sizeX = 200;
const sizeY = 237;
const url = img.currentSrc;
const label = decodeURI(url.substring(url.lastIndexOf('/')+1).slice(0, -4));
const textWidth = ctx.measureText(label).width;
ctx.drawImage(img, x - sizeX / 2, y - sizeY / 2, sizeX, sizeY);
ctx.font = "11px Arial";
ctx.fillText( label, x - sizeX / 2 + ( sizeX / 2 - textWidth / 2), y + sizeY / 2 + 20);
})
`
I'm guessing "{img, x, y}" is the node object...
from force-graph.
@KyleDave yes that is the node object. So, basically you first need to add your image objects to each of your nodes, under the img
attribute. This example shows that:
force-graph/example/img-nodes/index.html
Lines 12 to 21 in 06e372d
from force-graph.
Related Issues (20)
- Conditional node styling based on data values/accessor method (i.e. circles for person, squares for place) HOT 2
- mousedown event not working after adding it HOT 2
- Link offsets? HOT 1
- How to conditionally change linkLineDash between nodes HOT 1
- Curved arrows HOT 2
- How to draw nodes around a circle HOT 2
- How to avoid collisions of nodes. HOT 1
- Problems with labels, and dragging when openin from Brave browser with shield on. HOT 1
- Conditional in linkDirectionalParticles does not use correct return value HOT 1
- Option to always show node labels HOT 2
- How to implement incremental graphData update on zoom and pan? HOT 4
- [Bug]: When nodes are rapidly dragged multiple times in succession, it will be recognized as dragging the canvas
- Discrepency between .json files used in demo and syntax on README HOT 2
- Detecting right click when mouse is moving HOT 1
- Constant node size, independent of zoom HOT 1
- onNodeRightClick doesnt on macbook keyboard+trackpad HOT 2
- How to display nodes together that are identical HOT 1
- Node is not below its parent when creating the tree HOT 1
- unconnected nodes drifting infinitely away HOT 1
- Scrolling on mobile browser
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 force-graph.