Cytoscape.js 学习

官网 有多种 layout,可根据业务场景选择合适的 layout。由于项目业务涉及产品及成分关系的研究,选用 CoSE Bilkent 和 fCoSE 2种 layout,比较美观、清晰。

                                                                               fCoSE Layout如图

节点的关系获取方式 与 jQuery 操作DOM元素高度相似,支持链式调用。

几个概念:cy(cy 示例对象),elements(包括节点node、线edge)

常用的方法:

1.cy.add(eles); 点击播放按钮可以查看示例运行效果

2.cy.remove(eles); 移除节点 

3.cy.on( events [, selector], function(event) ); 事件绑定

常用事件

  • mousedown : when the mouse button is pressed

  • mouseup : when the mouse button is released

  • click : after mousedown then mouseup

  • mouseover : when the cursor is put on top of the target

  • mouseout : when the cursor is moved off of the target

  • mousemove : when the cursor is moved somewhere on top of the target

  • touchstart : when one or more fingers starts to touch the screen

  • touchmove : when one or more fingers are moved on the screen

  • touchend : when one or more fingers are removed from the screen

4.获取element的几种方法:cy.getElementById( id )  cy.$()  等

5.eles.select(); 设置element的选中状态

6.cy.data('id')   获取数据对象

7.eles.addClass('add')  添加类

8.eles.outgoers() element的outgoers 输出子代nodes和edges

9.eles.successors()  element的the outgoers, the outgoers' outgoers, ...,可理解为所有子孙后代nodes和edges

10.eles.incomers()  element的上一级nodes和edges

插件推荐:tooltip (tippy.js)、cytoscape-cose-bilkent、cytoscape-fcose

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue中初始化cytoscape.js可以通过以下步骤实现: 1. 在项目的`main.js`文件中引入cytoscape库,可以使用两种方式进行全局引入。第一种方式是使用`import`语句引入cytoscape并将其赋值给Vue的原型属性`cytoscape`,如所示。第二种方式是使用`import`语句引入cytoscape并将其赋值给Vue的`$cytoscape`属性,如所示。 2. 定义一个Vue组件,在该组件中使用cytoscape.js来创建和展示图形。在组件的`mounted`生命周期钩子函数中,通过`this.$cytoscape`或`this.cytoscape`来调用cytoscape库进行初始化。你可以通过传递一个容器元素、元素数据和样式信息来创建并渲染图形。其中,容器元素可以通过`$refs`来获取,元素和样式信息可以根据实际需求自定义或从后端获取,布局信息可以选择使用cytoscape.js提供的布局算法或自定义布局。 以下是一个示例代码,展示了如何在Vue中初始化cytoscape.js: ```javascript <template> <div ref="cyContainer" style="width: 100%; height: 100%;"></div> </template> <script> import cytoscape from 'cytoscape'; export default { mounted() { const container = this.$refs.cyContainer; const elements = [ // 插入元素数据 ]; const style = [ // 定义样式信息 ]; const layout = { // 定义布局信息 }; this.$cytoscape({ container, elements, style, layout }); } } </script> ``` 请根据你的具体项目需求进行相应的配置和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue内使用 cytoscape.js学习(一)](https://blog.csdn.net/weixin_43753330/article/details/95620160)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [网络图库Cytoscape.js的使用(一):初始化配置](https://blog.csdn.net/weixin_44001906/article/details/127513117)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值