亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

葉節點細胞景觀的不同行為

葉節點細胞景觀的不同行為

瀟湘沐 2022-10-21 15:02:19
輸出應該是什么樣子 我需要使用 cytoscape.js 為我的學士論文創建特定的樹(系統發育樹),對于這些,將內部節點著色為不同于子節點(或葉節點 = 沒有任何后代的節點,見圖片)。我是一個完整的 html 新手,所以在回答時請記住這一點。我查看了 Cytoscape 的手冊,但找不到解決方案。通過使用選擇節點cy.nodes(':child').not(':parent');不知何故沒有工作。非常感謝您的回答!編輯:它現在在 klay 中工作,但可視化并不完美,我想得到一些看起來像圖片的東西。
查看完整描述

1 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊

您可以只使用內置函數cy.nodes().leaves().addClass(...),其中 ... 是樣式表中定義所需 css 的類。

編輯

document.addEventListener("DOMContentLoaded", function() {

  var cy = (window.cy = cytoscape({

    container: document.getElementById("cy"),


    // demo your layout

    layout: {

      name: "klay"


      // some more options here...

    },


    style: [{

        selector: "node",

        style: {

          "background-color": "#dd4de2"

        }

      },

      {

        selector: ".leaf",

        style: {

          "background-color": "#000"

        }

      },

      {

        selector: "edge",

        style: {

          "curve-style": "bezier",

          "target-arrow-shape": "triangle",

          "line-color": "#dd4de2",

          "target-arrow-color": "#dd4de2",

          opacity: 0.5

        }

      }

    ],

    elements: {

      nodes: [{

          data: {

            id: "n0"

          }

        },

        {

          data: {

            id: "n1"

          }

        },

        {

          data: {

            id: "n2"

          }

        },

        {

          data: {

            id: "n3"

          }

        },

        {

          data: {

            id: "n4"

          }

        },

        {

          data: {

            id: "n5"

          }

        },

        {

          data: {

            id: "n6"

          }

        },

        {

          data: {

            id: "n7"

          }

        },

        {

          data: {

            id: "n8"

          }

        },

        {

          data: {

            id: "n9"

          }

        },

        {

          data: {

            id: "n10"

          }

        },

        {

          data: {

            id: "n11"

          }

        },

        {

          data: {

            id: "n12"

          }

        },

        {

          data: {

            id: "n13"

          }

        },

        {

          data: {

            id: "n14"

          }

        },

        {

          data: {

            id: "n15"

          }

        }

      ],

      edges: [{

          data: {

            source: "n0",

            target: "n1"

          }

        },

        {

          data: {

            source: "n1",

            target: "n2"

          }

        },

        {

          data: {

            source: "n1",

            target: "n3"

          }

        },

        {

          data: {

            source: "n2",

            target: "n4"

          }

        },

        {

          data: {

            source: "n4",

            target: "n5"

          }

        },

        {

          data: {

            source: "n4",

            target: "n6"

          }

        },

        {

          data: {

            source: "n6",

            target: "n7"

          }

        },

        {

          data: {

            source: "n6",

            target: "n8"

          }

        },

        {

          data: {

            source: "n8",

            target: "n9"

          }

        },

        {

          data: {

            source: "n8",

            target: "n10"

          }

        },

        {

          data: {

            source: "n10",

            target: "n11"

          }

        },

        {

          data: {

            source: "n11",

            target: "n12"

          }

        },

        {

          data: {

            source: "n12",

            target: "n13"

          }

        },

        {

          data: {

            source: "n13",

            target: "n14"

          }

        },

        {

          data: {

            source: "n13",

            target: "n15"

          }

        }

      ]

    }

  }));


  cy.nodes().leaves().addClass("leaf");

});

body {

  font-family: helvetica neue, helvetica, liberation sans, arial, sans-serif;

  font-size: 14px;

}


#cy {

  position: absolute;

  left: 0;

  top: 0;

  bottom: 0;

  right: 0;

  z-index: 999;

}

<html>


<head>

  <script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>

  <script src="https://unpkg.com/[email protected]/klay.js"></script>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/cytoscape-klay.min.js"></script>

</head>


<body>

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

</body>


</html>


查看完整回答
反對 回復 2022-10-21
  • 1 回答
  • 0 關注
  • 156 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號