Skip to content
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

Foreign Object is not working in my project #22

Open
joeyhe24 opened this issue Apr 29, 2023 · 1 comment
Open

Foreign Object is not working in my project #22

joeyhe24 opened this issue Apr 29, 2023 · 1 comment

Comments

@joeyhe24
Copy link

joeyhe24 commented Apr 29, 2023

Hello,
I tested your project and want to use customized node label, but I don't see it working at all

Step 1: In component

`

function DagreFlow(props){

console.log(props)
const traceRoutes = new TraceRoutes(props.data);
console.log(traceRoutes.traceRoutes[0])

const [state, setState] = useState(false);
setTimeout(()=>{
    setState({
        nodes: traceRoutes.traceRoutes[0]['hops']['graph'].nodes,
        edges: traceRoutes.traceRoutes[0]['hops']['graph'].edges,
        customNodeLabels: {
            foreign: {
                renderer: NodeLabelRender,
                html: true
            }
        },
        customEdgeLabels: {
            foreign: {
                renderer: EdgeLabelRender,
                html: true
            }
        }
    })
});


return (
    state &&
    <svg id="schedule" width={1000} height={1000}>
        <DagreReact
            nodes={state.nodes}
            edges={state.edges}
            customNodeLabels = {state.customNodeLabels}
            customEdgeLabels = {state.customEdgeLabels}
            defaultNodeConfig={DEFAULT_NODE_CONFIG}
            graphOptions={{
                marginx: 15,
                marginy: 15,
                rankdir: 'LR',
                ranksep: 55,
                nodesep: 15,
            }}
        />
    </svg>
);

}

export default DagreFlow;
`

and the customNodeLabel:

import React, {useRef} from 'react'; function NodeLabelRender(props){ return( <div>NodeX</div> ) } export default NodeLabelRender;
But when rendering it, it is still the same as without customer node label render, only default label is rendered, not the foreign object at all,

can you check the issue here?

@bobthekingofegypt
Copy link
Owner

Apologies, I missed the notification for this.

I would guess that the problem is setTimeout. The library would not be picking up a change to the renderers. Try setting the renders to their value directly, not through state, and only modifying the data entries. It's also safer to use the stage variable when changing nodes and edges to forces a new layout pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants