cytoscape/cytoscape-explore

Inconsistencies in how CE initializes node label position bypasses and how they are initialized in CX

Closed this issue · 3 comments

Describe the bug

When CX Networks that have bypasses for node label positions are imported into CE, the resulting bypass is:

{
  "text-halign": {
    "type": "STRING",
    "mapping": "VALUE",
    "value": {
      "type": "STRING",
      "mapping": "VALUE",
      "value": {
        "type": "STRING",
        "mapping": "VALUE",
        "value": "center",
        "stringValue": "center"
      },
      "stringValue": "[object Object]"
    },
    "stringValue": "[object Object]"
  },
  "text-valign": {
    "type": "STRING",
    "mapping": "VALUE",
    "value": {
      "type": "STRING",
      "mapping": "VALUE",
      "value": {
        "type": "STRING",
        "mapping": "VALUE",
        "value": "bottom",
        "stringValue": "bottom"
      },
      "stringValue": "[object Object]"
    },
    "stringValue": "[object Object]"
  }
}

When a user in CE creates a node bypass for label location, the resulting bypass object looks like this:

{
  "text-halign": {
    "type": "STRING",
    "mapping": "VALUE",
    "value": "center",
    "stringValue": "center"
  },
  "text-valign": {
    "type": "STRING",
    "mapping": "VALUE",
    "value": "bottom",
    "stringValue": "bottom"
  }
}

This leads me to believe that the way that the CX importer applies node label position bypasses is wrong.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the demo page
  2. Click import network from NDEx
  3. Import the network id 'ddca02dd-36a5-11ec-a229-525400c25d22'
  4. open the browser dev console
  5. type cy.exportCX2()
  6. the exported CX2 bypasses will have the wrong object output for NODE_LABEL_POSITION

This leads to an error when round tripping a CX network with NODE_LABEL_POSITION properties.

I think the bug is related to:
labelLocationMapper.valueCvtr https://github.com/cytoscape/cytoscape-explore/blob/master/src/model/import-export/cx.js#L196
and the way that bypasses are applied:
https://github.com/cytoscape/cytoscape-explore/blob/master/src/model/import-export/cx.js#L408

But I am still unsure how they are related. It is not clear to me what is causing these values to become nested.

This statement is actually mutating the node label position look up table.

This means that after the first style that is generated from the style factory, it will mutate the lookup table and then subsequent calls to the lookup table will produce the wrong style values.

To fix this, I can use _.cloneDeep to make a copy of the lookup value result everytime the call to stylefactory. Or I can create the new return object.