kaluginserg / cytoscape-node-html-label

Labels for cytoscape node. Demo:
https://kaluginserg.github.io/cytoscape-node-html-label/
MIT License
102 stars 43 forks source link

Bug: Updating cyInstance Data -> "Uncaught TypeError: target.is is not a function" #41

Open LinusHe opened 4 years ago

LinusHe commented 4 years ago

Hi :)

A console error occurs when I change data in the Cytoscape instance:

image

For example, I set the data object "test" to the value "123" using cyInstance.data ("test", "123").

When I do this in a project in which I have installed the HTML node plugin, the following bug appears:

Here is an example:

      // create Cy instance
      var cyInstance = cytoscape({
        container: document.getElementById("cy"),
        layout: {
          name: "random",
        },
        elements: [
          // your cy elements
          { group: "nodes", data: { id: "a1", name: "a10" }, classes: "l2" },
        ],
      });

      // set nodeHtmlLabel for your Cy instance
      cyInstance.nodeHtmlLabel([
        {
          query: ".l2",
          tpl: function (data) {
            return '<p class="cy-title__p1">' + data.id + "</p>" + '<p  class="cy-title__p2">' + data.name + "</p>";
          },
        },
      ]);

      // update node data --> cytoscape-node-html-label.js:215 --> Uncaught TypeError: target.is is not a function
      cyInstance.data("test", "123");
josejulio commented 4 years ago

Thanks, the problem is that the updateDataOrStyleCyHandler function is expecting only elements data updates, when we get a cy data change the crash occurs.

I think we should trigger an update on every element, as any element could use that from within their template.