Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

findLinkDataForKey always return null

$
0
0

@tri wrote:

Hi all,

I am about to change the opacity of links base on some filter. But I am not able to get the link data via findLinkDataForKey to set the new property value for it.
It works for node but not link.

How I find and set new property

myDiagram.startTransaction('render opacity');
    // node
    for(let i = 0; i < myDiagram.model.nodeDataArray.length; i++) {
      let item = myDiagram.model.nodeDataArray[i];
      let opacity = newV.indexOf(item.pipelineId) > -1 ? 1 : 0.5;

      if (item.opacityNumber != opacity) {
        var nodeData = myDiagram.model.findNodeDataForKey(i);
        myDiagram.model.setDataProperty(nodeData, "opacityNumber", opacity);
      }
    }

    // link
    for (let i = 0; i < myDiagram.model.linkDataArray.length; i++) {
      let linkItem = myDiagram.model.linkDataArray[i];
      let opacity = newV.indexOf(linkItem.pipelineId) > -1 ? 1 : 0.5;

      if (linkItem.opacityNumber != opacity) {
        var linkData = myDiagram.model.findLinkDataForKey(i);
        // it is always null here, so the view won't update
        myDiagram.model.setDataProperty(linkData, "opacityNumber", opacity);
        //myDiagram.model.raiseDataChanged(linkData, "opacityNumber", linkItem.opacityNumber, opacity);
      }
    }

    myDiagram.rebuildParts();
    myDiagram.commitTransaction('render opacity');

I already set up a unique key when init the linkDataArray

linkDataArray.push({
      key: i,
      from: index1,
      to: index2,
      fromNode: item.raw.endNode1,
      toNode: item.raw.endNode2,
      isHeating: item.raw.isHeating == 'true',
      pipelineId: item.raw.pipelineId,
      opacityNumber: 1,
      points
    });

Even I tried to set the key manually for links:

var model = go.Model.fromJson(vm.chartData);
  model.makeUniqueLinkKeyFunction = function (model, data) {
    return data.key;
  };
  myDiagram.model = model;

Can you guys tell me what did I do wrongly? Thank you all in advance !!!
Marcus

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles