Измените цвет ребра при нажатии на узел в cytoscape.js

Вот еще один способ:

>>> ("%.4f" % k).lstrip('0')
'.1337'

Он немного более общий, чем [1:], поскольку он также работает с числами> = 1.

Ни один из методов не корректно обрабатывает отрицательные номера, однако. В этом отношении лучше:

>>> re.sub('0(?=[.])', '', ("%0.4f" % -k))
'-.1337'

Не особенно изящно, но сейчас я не могу придумать лучшего метода.

1
задан ProgrammerPer 5 March 2019 в 08:15
поделиться

1 ответ

Cytoscape.js предоставляет несколько удобных функций для фильтрации узлов:

var cy = (window.cy = cytoscape({
  container: document.getElementById("cy"),

  boxSelectionEnabled: false,
  autounselectify: true,

  style: [{
      selector: "node",
      css: {
        content: "data(id)",
        "text-valign": "center",
        "text-halign": "center",
        height: "60px",
        width: "100px",
        shape: "rectangle",
        "background-color": "data(faveColor)"
      }
    },
    {
      selector: "edge",
      css: {
        "curve-style": "bezier",
        "control-point-step-size": 40,
        "target-arrow-shape": "triangle"
      }
    }
  ],

  elements: {
    nodes: [{
        data: {
          id: "Top",
          faveColor: "#2763c4"
        }
      },
      {
        data: {
          id: "yes",
          faveColor: "#37a32d"
        }
      },
      {
        data: {
          id: "no",
          faveColor: "#2763c4"
        }
      },
      {
        data: {
          id: "Third",
          faveColor: "#2763c4"
        }
      },
      {
        data: {
          id: "Fourth",
          faveColor: "#56a9f7"
        }
      }
    ],
    edges: [{
        data: {
          source: "Top",
          target: "yes"
        }
      },
      {
        data: {
          source: "Top",
          target: "no"
        }
      },
      {
        data: {
          source: "no",
          target: "Third"
        }
      },
      {
        data: {
          source: "Third",
          target: "Fourth"
        }
      }
    ]
  },
  layout: {
    name: "dagre"
  }
}));

cy.unbind('click');
cy.bind('click', 'node', function(node) {
  console.log(node.target.predecessors().edges());
  node.target.predecessors().edges().animate({
    style: {
      lineColor: "red"
    }
  });
});
body {
  font: 14px helvetica neue, helvetica, arial, sans-serif;
}

#cy {
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  float: left;
  position: absolute;
}
<html>

<head>
  <meta charset=utf-8 />
  <meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
  <script src="https://unpkg.com/cytoscape@3.3.0/dist/cytoscape.min.js">
  </script>
  <!-- cyposcape dagre -->
  <script src="https://unpkg.com/dagre@0.7.4/dist/dagre.js"></script>
  <script src="https://cdn.rawgit.com/cytoscape/cytoscape.js-dagre/1.5.0/cytoscape-dagre.js"></script>
</head>

<body>
  <div id="cy"></div>
</body>

</html>

0
ответ дан Stephan T. 5 March 2019 в 08:15
поделиться
Другие вопросы по тегам:

Похожие вопросы: