【问题标题】:Customize individual node sizes in Dash Cytypscape在 Dash Cytypscape 中自定义单个节点大小
【发布时间】:2021-10-18 11:26:45
【问题描述】:

我希望使用 Dash Cytoscape 根据给定值调整单个节点的大小。但是,我只能理解使用'selector' : 'node' 来调整所有节点的大小。我无法弄清楚如何为单个样本提供特定值(或至少是宽度和高度)。有没有办法手动为单个样本提供节点大小值?我目前所有节点的代码如下:

{       
        'selector': 'node',
        'style': {
                'content': 'data(label)',
                'width': '30%',
                'height': '30%'
        }
}

提前致谢。

【问题讨论】:

    标签: python python-3.x nodes plotly-dash cytoscape


    【解决方案1】:

    是的,您可以为cyto.Cytoscape 对象的elements 参数中列出的任何节点设置一个[n 唯一] ID 值字典键“classes”*。

    例如:

    cyto.Cytoscape(
        id="network-output",
        elements=[
            {
                "data": {"id": "A", "label": "A"},
                "position": {"x": 75, "y": 75},
                "classes": "A",  # ← *This node now can be referenced ".A"  
            },
            {
                "data": {"id": "B", "label": "B"},
                "position": {"x": 200, "y": 200},
                "classes": "B",
            },
            {"data": {"source": "A", "target": "B"}},
        ],
        layout=my_layout,
        style=my_style,
        stylesheet=[
            {"selector": "node", "style": {"width": "50px", "height": "50px"}}
        ],
    )
         
    

    然后在stylesheet参数中:

    stylesheet = [
        {
            "selector": f".{value}",
            "style": {
                "background-color": "#FD8008",
                "background-opacity": "0.8",
                "border-color": "#00C1FF",
                "border-width": "2",
                "width": "55px",
                "height": "55px",
                "label": "data(label)",
            },
        }
    ]
    

    其中变量value 可以是“A”或“B”,或者您根据类键分配给元素中任何节点的任何其他名称。这样,每个节点的样式都可以根据需要进行唯一处理。包括通过回调,其中输出是任何 Cytoscape 的样式表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      相关资源
      最近更新 更多