cytoscape.jscytoscapecytoscape-webdagre

Is there a way to display a node label at the top inside the node?


I am creating a graph using cytoscape.js and I have compounded nodes which are inside the parent node. I would like to have the title of the main/parent node at the top of the node but inside the node. Is that possible in cytoscape?

I have tried using using halign and valign. Whenever I use top value, it shows outside the box.

Is there a extension or a plugin that lets us do it?

Example with child node: https://stackblitz.com/edit/cytoscape-call-method-child-efmbaj?file=src%2Fapp%2FstylesheetObject.ts


Solution

  • What I understand is that you want to put the parent label inside the box above child? apologies if I'm wrong

    enter image description here

    If so, My solution will be to add a padding and then apply margin for alignment.

    Modified your example

    Styles updated:

    1. 'padding-top':60

      selector: 'node',
      css: {
        content: 'data(label)',
        'text-valign': 'center',
        'text-halign': 'center',
        'font-size': 28,
        'padding-top':60
      }
      
    2. 'text-valign': 'top', and 'text-margin-y': function(node) { return node.height() - 10; }

      selector: 'node[type="parent"]',
      style: {
        shape: 'rectangle',
        'background-color': 'grey',
        width: 300,
        height: 100,
        'font-size': 25.5,
        'font-family': 'Lato, Helvetica Neue, Helvetica, Arial, sans-serif',
        color: 'black',
        'text-valign': 'top',
        'text-halign': 'center',
        'text-margin-y': function(node) {
          return node.height() - 10;
        }
      }