2 回答

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)

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)
添加回答
舉報