react-diagrams icon indicating copy to clipboard operation
react-diagrams copied to clipboard

After deserializing, links dont get render UNTIL I click on the srd-diagram element

Open frank-martinez-27 opened this issue 7 years ago • 3 comments

Issue:

Every list I have is a model on its own. When I select a list I update the model by adding 2 root nodes (the white node and the plus sign node). I click on the plus sign node to display a menu and I create click on the TASK button to create a new node on the model. After I do that I see the model now has 4 nodes and 2 edges correctly, but only the nodes get rendered. Until I click on the srd-diagram element the edges are shown.

diagrams-issue

Other notes: Before I added engine.repaintCanvas() to the createTask method, neither the second node or the edges were rendered until I made a click. When I added repaintCanvas the 2nd node gets rendered but not the edges, until I click. I tried with forceUpdate but no luck. Im using version 5.2.1

This is the method that gets called when I click on the Task button on the popup menu:

const handleCreateTask = node => {
    console.log('++ Inside handleCreateTask || node =', node);
    const newStep = new StepNodeModel({
      name: 'Step Name',
      assignee: 'Unassigned',
      dashboard: 'No dashboard',
      type: 'step-node',
    });
    newStep.addInPort('In');
    const stepPortOut = newStep.addOutPort('Out');
    const newBtn = new ButtonNodeModel({
      type: 'btn-menu-node',
      handleCreateTask
    });
    const btnPortIn = newBtn.addInPort('In');
    newBtn.addOutPort('Out');
    
    const link = stepPortOut.link(btnPortIn);

    newStep.setPosition(100, 200);

    const newBtnPosition = {
      x: newStep.x + diagramManager.createNodeBtnOffsetX,
      y: newStep.y + diagramManager.nodeTopMargin
    }
    newBtn.setPosition(newBtnPosition.x, newBtnPosition.y);

    engineForCurrentAnaplanList.diagramModel.addAll(newStep, newBtn, link);
    engineForCurrentAnaplanList.recalculatePortsVisually();
    engineForCurrentAnaplanList.repaintCanvas();
    // forceUpdate();
  }```

frank-martinez-27 avatar Aug 07 '19 17:08 frank-martinez-27

Update: I fixed it following the comment on https://github.com/projectstorm/react-diagrams/issues/188. In my react application im using stateless components and hooks so to simulate a forceUpdate I did this inside my component const [, updateState] = useState(); const forceUpdate = useCallback(()=>updateState({}),[]);

frank-martinez-27 avatar Aug 07 '19 21:08 frank-martinez-27

I solved it by just setting the same model again after deserializeModel

let model = new DiagramModel();
engine.setModel(model);
...
      model.deserializeModel(graph, engine);
      engine.setModel(model); // <-- this seems to trigger the update
      engine.repaintCanvas();

Edit: Using the current Beta

saschb2b avatar Oct 23 '19 14:10 saschb2b

@saschb2b In the latest codebase (don't know what it looked like at the time you used it) calling setModel() calls engine.repaintCanvas() anyway so the last line may not be required.

Irrelon avatar Jun 29 '20 14:06 Irrelon