cytoscape.js在vue项目中的安装及案例
1. 安装:
npm i cytoscape --save
2. 引入:main.js
import cytoscape from 'cytoscape';
Vue.prototype.$cytoscape = cytoscape;
3. demo代码:
<template>
<div id="MainCy" style="width: 100%;height: 100%;"></div>
</template>
<script>
export default {
mounted() {
var cy = this.$cytoscape({
container: document.getElementById('MainCy'), layout: {
name: 'grid',
rows: 2,
cols: 2
}, style: [{
selector: 'node',
style: {
'content': 'data(name)',
'background-color': 'magenta',
'background-image': 'url(img/shixian.png)',
}
}, {
selector: 'edge',
style: {
'content': 'data(relationship)',
'curve-style': 'bezier',
'target-arrow-shape': 'triangle',
'color': 'red',
}
}, // some style for the extension {
selector: '.eh-handle',
style: {
'background-color': 'red',
'width': 12,
'height': 12,
'shape': 'ellipse',
'overlay-opacity': 0,
'border-width': 12, // makes the handle easier to hit
'border-opacity': 0
}
}, {
selector: '.eh-hover',
style: {
'background-color': 'red'
}
}, {
selector: '.eh-source',
style: {
'border-width': 2,
'border-color': 'red'
}
}, {
selector: '.eh-target',
style: {
'border-width': 2,
'border-color': 'red'
}
}, {
selector: '.eh-preview, .eh-ghost-edge',
style: {
'background-color': 'red',
'line-color': 'red',
'target-arrow-color': 'red',
'source-arrow-color': 'red'
}
}, {
selector: '.eh-ghost-edge.eh-preview-active',
style: {
'opacity': 0
}
}
], elements: {
nodes: [{
data: {
id: 'j',
name: 'Jerry'
}
},
{
data: {
id: 'e',
name: 'Elaine'
}
},
{
data: {
id: 'k',
name: 'Kramer'
}
},
{
data: {
id: 'g',
name: 'George'
}
}
],
edges: [{
data: {
source: 'j',
target: 'e'
}
},
{
data: {
source: 'j',
target: 'k'
}
},
{
data: {
source: 'j',
target: 'g'
}
},
{
data: {
source: 'e',
target: 'j'
}
},
{
data: {
source: 'e',
target: 'k',
relationship: '1'
}
},
{
data: {
source: 'k',
target: 'j',
relationship: '2'
}
},
{
data: {
source: 'k',
target: 'e',
relationship: '3'
}
},
{
data: {
source: 'k',
target: 'g',
relationship: '4'
}
},
{
data: {
source: 'g',
target: 'j',
relationship: '5'
}
}
]
}
});
cy.nodes().on('click', (evt) => {
console.log(evt)
});
cy.edges().on('click', (evt) => {
console.log(evt)
}); },
}
</script>
demo效果:

cytoscape.js在vue项目中的安装及案例的更多相关文章
- d3.js在vue项目中的安装及案例
1. 安装: npm i d3 --save 2. 引入:main.js import * as d3 from "d3"; Vue.prototype.$d3 = d3; win ...
- vue项目中npm安装sass,less,stylus
用vue-cli脚手架搭建出来的,默认是用标准css的.如果你想用sass,less,stylus就需要自己手动安装一下了. 进入项目文件夹,然后安装(这里以stylus为例)stylus和stylu ...
- 【bcrypt】vue项目中bcrypt安装报错
[报错] 报错时安装方法: npm install bcrypt [解决方法] npm install bcryptjs 用 bcryptjs 替换 bcrypt 即可.
- 在vue项目中的axios使用配置记录
默认vue项目中已经安装axios,基于element-ui开发,主要记录配置的相关. axiosConfig.js import Vue from 'vue' import axios from ' ...
- 在vue项目中使用canvas-nest.js,报parameter 1 is not of type 'Element'
canvas-nest.js是一款轻量的网页特效,如图: github地址:https://github.com/hustcc/canvas-nest.js 在普通的html项目中,只要将<sc ...
- vue 项目中安装npm--save-dev 和 --save 命令
在vue项目中我们常用npm install 安装模块或插件 有两种命令把他们写入到 package.json 文件里面去 例如安装axios 安装到开发环境npm axios --save-dev ...
- vue 项目中实用的小技巧
# 在Vue 项目中引入Bootstrap 有时在vue项目中会根据需求引入Bootstrap,而Bootstrap又是依赖于jQuery的,在使用npm按照时,可能会出现一系列的错误 1.安装jQu ...
- 如何在VUE项目中添加ESLint
如何在VUE项目中添加ESLint 1. 首先在项目的根目录下 新建 .eslintrc.js文件,其配置规则可以如下:(自己小整理了一份),所有的代码如下: // https://eslint.or ...
- 浅谈 Axios 在 Vue 项目中的使用
介绍 Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中. 特性 它主要有如下特性: 浏览器端发起XMLHttpRequests请求 Node端发起http ...
随机推荐
- mybatis拦截器案例之获取结果集总条数
最近做的项目前端是外包出去的,所以在做查询分页的时候比较麻烦 我们需要先吧结果集的条数返回给前端,然后由前端根据页面情况(当前页码,每页显示条数)将所需参数传到后端. 由于在项目搭建的时候,是没有考虑 ...
- gj13 asyncio并发编程
13.1 事件循环 asyncio 包含各种特定系统实现的模块化事件循环 传输和协议抽象 对TCP.UDP.SSL.子进程.延时调用以及其他的具体支持 模仿futures模块但适用于事件循环使用的Fu ...
- excel的小bug
http://muchong.com/html/201710/3913047.html Excel也有相同现象,试着计算:exp(-1.5^2),exp(0-1.5^2),exp(-(1.5)^2)看 ...
- Oracle数据库常用的sql语句
1. select * from emp; 2. select empno, ename, job from emp; 3. select empno 编号, ename 姓名, job 工作 fro ...
- SHELL脚本之awk妙用
对于一个sougou文本文件,解压后大概4G,要求在其基础上切出第一列时间年月日时分秒增加在列中,作为hive的一个索引.先将文件head一下展示格式: [root@Master date]# hea ...
- estimator = KerasClassifier
如何在scikit-learn模型中使用Keras 通过用 KerasClassifier 或 KerasRegressor 类包装Keras模型,可将其用于scikit-learn. 要使用这些包装 ...
- Zookeeper C++编程实战之主备切换
默认zookeeper日志输出到stderr,可以调用zoo_set_log_stream(FILE*)设置输出到文件中还可以调用zoo_set_debug_level(ZooLogLevel)控制日 ...
- TypeError: 'MongoClient' object is not callable
在声明数据库的时候,将中括号[ ]换成了圆括号() 错误:
- UIActivityIndicatorView 的使用
// // UIActivityIndicator.m // ToolBar // // Created by lanouhn on 15/1/3. // Copyright (c) 2015 ...
- eclipse生成可执行jar包(引入第三方.jar文件)
1. eclipse建立普通的java project项目(项目名aa) 2. 项目正常组织通过buildpath加载各种jar包入项目aa比如例子项目里,加入了spring 各种jar包加入各种配置 ...