-
Notifications
You must be signed in to change notification settings - Fork 835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Showing labels front of node #669
Comments
Hi @longlp , I got sprites to work in my React app. Here is my code. down below that I'll show the HTML code that I can not get to work if you can help. Sprites / canvas code : TreeForceGraphComponent.js import React, { useEffect } from 'react'; -function TreeForceGraphComponent({ tree_18_GraphData, targetBAGName, areNodeLabelsOn }) {
} : null;
} export default TreeForceGraphComponent; Here is React code trying to add HTML on each node, but not working: TreeForceGraphComponent.js import React, { useCallback, useEffect, useRef } from 'react'; import ForceGraph3D from 'react-force-graph-3d'; function TreeForceGraphComponent({ tree_18_GraphData, targetBAGName, areNodeLabelsOn, focusNodeId }) { const fgRef = useRef(); const nodeThreeObject = areNodeLabelsOn ? node => {
};
}, []); const nodeAutoColorBy = (node) => { const linkColorDetermine = link => { return ( <ForceGraph3D graphData={tree_18_GraphData} ref={fgRef} onNodeDragStart={node => logEntry('TreeForceGraphComponent', onNodeDragStart: ${node.id} ) }onNodeDragEnd={node => logEntry('TreeForceGraphComponent', onNodeDragEnd: ${node.id} ) }onNodeClick={handleNodeClick} width={1000} height={500} backgroundColor="#B4B5C5" nodeAutoColorBy={nodeAutoColorBy} nodeThreeObject={areNodeLabelsOn ? nodeThreeObject : undefined } nodeThreeObjectExtend={true} // false turns off nodes with nodeThreeObject linkWidth={areNodeLabelsOn ? 2 : 1} linkOpacity={areNodeLabelsOn ? 0.5 : 0.4} linkColor={linkColorDetermine} linkDirectionalParticles={6} nodeLabel={nodes => ${nodes.id || 'SomE ThinG'} :: ${nodes.description || 'Empty Description'} }/> ); } export default TreeForceGraphComponent; |
Just work around and solve my problem with inject the callback function to handle increase fontsize (base on distance between Node and Camera) with control change event
|
Thank you Le Phi for replying. I got some un-referenced variables compiler errors: import { CSS2DRenderer, CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js'; // Is your Graph variable this: // I have this three library import, but you are referencing a THREE.Vector3() // What is your highlight variable defined as ? |
Le, I figured it out how to show labels all the time. I don't need this HTML specific solution. Since I got this to work I'm not sure what advantage the HTML path is? The clue was in https://github.com/vasturiano/3d-force-graph/blob/master/example/text-nodes/index.html I needed to so all I needed was: import React, { useCallback, useEffect, useRef } from 'react'; const fgRef = useRef(); const nodeThreeObject = areNodeLabelsOn ? node => {
} : null; return ( <ForceGraph3D graphData={tree_18_GraphData} ref={fgRef} onNodeDragStart={node => logEntry('TreeForceGraphComponent', onNodeDragStart: ${node.id} ) }onNodeDragEnd={node => logEntry('TreeForceGraphComponent', onNodeDragEnd: ${node.id} ) }onNodeClick={handleNodeClick} width={1000} height={500} backgroundColor="#B4B5C5" nodeAutoColorBy={nodeAutoColorBy} nodeThreeObject={areNodeLabelsOn ? nodeThreeObject : undefined } nodeThreeObjectExtend={true} // false turns off nodes with nodeThreeObject linkWidth={areNodeLabelsOn ? 2 : 1} linkOpacity={areNodeLabelsOn ? 0.5 : 0.4} linkColor={linkColorDetermine} linkDirectionalParticles={6} nodeLabel={areNodeLabelsOn ? undefined : nodes => ${nodes.id || 'SomE ThinG'} :: ${nodes.description || 'Empty Description'} }/> ); |
|
|
By default, when I hover the mouse over a node I get the label displayed, is there any way to use the same mechanism to toggle the label visibility? I would like to toggle the node label visibility on click Do I need Great project BTW 🎉 !! |
You can handle it by using SpriteText or CSS2DObject with default opacity of text color = 0, |
I have try two options for showing labels with node
My requirement is showing the text front of node ( for sprite text the position is center of node)
I’m working around with calculating distance between node and camera and set font size of text but still meet the UX requirements (it’s delayed due to event stop of control trigger with debound function).
I try to set potions of Sprite but the methods to calculate of Sprite text after rotating is complexity and still delay due to debound when rotating)
Can your guy have any ideas to solve this problem or have any others ideas for this requirement plz give me some instructions.
Thank you all.!
The text was updated successfully, but these errors were encountered: