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

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

使用 Dash-Cytoscape 更改單個節點的大小

使用 Dash-Cytoscape 更改單個節點的大小

POPMUISE 2022-10-18 17:50:33
我已經使用 Dash-Cytoscape 兩天了,我嘗試了很多方法來單獨更改節點大小。我試過了,但沒有用:import dashimport dash_cytoscape as cytoimport dash_html_components as htmlapp = dash.Dash(__name__)app.layout = html.Div([    cyto.Cytoscape(        id="cytospace",        elements=[            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}, 'size':20},            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}, 'size':70},            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}        ],        layout={'name':'preset'},        style={'height': '95vh',               'width': '100%'}    )])if __name__ == "__main__":    app.run_server(debug=True)
查看完整描述

2 回答

?
LEATH

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

這是一個更詳細和通用的版本。您可以通過 css 樣式更改單個節點的大小。您可以編輯單個節點的寬度和高度屬性。如果您已經在元素數據中存儲了大小,請使用mappers將存儲的數據映射到節點大小。這是我在 Cytoscape.js 文檔中找到的內容。

mapData()指定到元素數據字段的線性映射。例如,mapData(weight, 0, 100, blue, red)將元素的權重映射到藍色和紅色之間的顏色,權重在 0 到 100 之間。例如,將帶有的元素ele.data("weight") === 0映射到藍色。值超出指定范圍的元素將映射到極值。在前面的示例中,帶有 的元素ele.data("weight") === -1將被映射到藍色。

import dash

import dash_cytoscape as cyto

import dash_html_components as html


app = dash.Dash(__name__)


default_stylesheet = [

    {

        "selector": "node",

        "style": {

            "width": "mapData(size, 0, 100, 20, 60)",

            "height": "mapData(size, 0, 100, 20, 60)",

            "content": "data(label)",

            "font-size": "12px",

            "text-valign": "center",

            "text-halign": "center",

        }

    }

]


app.layout = html.Div([

    cyto.Cytoscape(

        id="cytospace",

        elements=[

            {'data': {'id': 'one', 'label': 'Node 1', 'size': 10}, 'position': {'x': 50, 'y': 50}},

            {'data': {'id': 'two', 'label': 'Node 2', 'size': 120}, 'position': {'x': 200, 'y': 200}},

            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}

        ],

        layout={'name':'preset'},

        stylesheet=default_stylesheet

    )

])


if __name__ == "__main__":

    app.run_server(debug=True)


查看完整回答
反對 回復 2022-10-18
?
慕娘9325324

TA貢獻1783條經驗 獲得超4個贊

對我來說,以下代碼允許調整節點大?。?/p>


import dash

import dash_cytoscape as cyto

import dash_html_components as html


app = dash.Dash(__name__)


default_stylesheet = [

    {

        'selector': 'node',

        'style': {

            'background-color': '#BFD7B5',

            'label': 'data(label)',

            'width': "30%",

            'height': "50%"

        }

    }

]


app.layout = html.Div([

    cyto.Cytoscape(

        id="cytospace",

        elements=[

            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 50, 'y': 50}, 'size':20},

            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}, 'size':70},

            {'data': {'source': 'one', 'target': 'two','label': 'Node 1 to 2'}}

        ],

        layout={'name':'preset'},

        stylesheet=default_stylesheet

    )

])


if __name__ == "__main__":

    app.run_server(debug=True)


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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