分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

cytoscape.js在vue项目中的安装及案例

发布时间:2023-09-06 02:26责任编辑:蔡小小关键词:js

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项目中的安装及案例

原文地址:https://www.cnblogs.com/stella1024/p/10144612.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved