python - 如何在 python dash_cytoscape 中设置同心圆布局参数?
问题描述
我定义了我的元素,比如 level 指的是我想要那个节点的圆圈层。
elements = [{'data': {'id': 'a', 'label': 'a', 'level': 1},
{'data': {'id': 'b', 'label': 'b', 'level': 1},
{'data': {'id': 'c', 'label': 'c', 'level': 2},
.......]
我尝试了以下不起作用(错误加载布局)
app.layout = html.Div([
cyto.Cytoscape(
id='cytoscape',
elements= elements,
layout={'name': 'concentric', 'concentric': lambda x: x['data']['level']}
)
])
javascript 文档在这里https://js.cytoscape.org/#layouts并指定
let options = {
name: 'concentric',
concentric: function( node ){ // returns numeric value for each node, placing higher nodes in levels towards the centre
return node.degree();
}
如何设置这个同心参数?
干杯
解决方案
不幸的是,无法将 python 函数传递layout
给组件中的参数cyto.Cytoscape
。这是因为该函数不会被转译为 JS 函数,而这正是concentric
密钥在内部工作所需要的options
。
替代方案是:
- 使用 python 网络库(例如 networkX)基于同心算法分配 x/y 位置,然后使用 dash-cytoscape 中的自定义布局(而不是同心布局)返回确切位置。
- 修改您想要用于同心布局
cyto.Cytoscape
的 JS 的源代码和硬编码。function
您需要按照贡献说明来构建和创建自定义安装。
推荐阅读
- css - 基于滚动位置的反应样式
- python - python tkinter 不区分按钮
- flutter - 消费者不更新状态?
- html - 放大和缩小不应影响我在 HTML 和 CSS 中的弹出高度和宽度
- cloud-foundry - ubuntu vm 上的 PCF 安装失败
- weaviate - 元信息不显示已安装的变压器模块
- python - python threading.Thread函数返回问题
- javascript - 计算行长时有没有办法忽略缩进?
- selenium - 独立运行时的 Selenium Grid 关闭命令
- laravel - Voyager Bread 更新函数 URL