Code Monkey home page Code Monkey logo

vue-topo's Introduction

996.icu

vue2.0拓扑组件

demo演示地址

https://mirror198829.github.io/vue-topo/dist/index.html

2016年9月接到html5替换flash的拓扑图任务,历时3月整,使用jquery+SVG技术完成第一款拓扑图组件,涵盖拖拽、缩放、删除、选中区域、连线、导入、保存图片、多种布局显示等功能,但当node数高达百位时,因dom的操作,出现了非常可怕的性能问题。
2017年10月20日,因新公司项目需要,果断决定结合当下流行的VUE2.0框架 + SVG技术 重写拓扑组件,并将此开源,希望大家多提意见

技术选型

  • VUE2.0
  • SVG
  • Element-UI

功能分析及技术点

功能 技术点
toolbar拖拽 记录鼠标位置;
拖拽物体的显示隐藏;
连接关系:创建连线 绘制时:使用svg的 <line>,需正确获取起始和终止点;
结束绘制:使用<path>路径绘制连线形态,根据两者节点位置不同,共计4种连线形态展示;
包含关系:单层嵌套 依据最终的位置判断是否为包含关系(这里的算法有待优化);
重新计算父节点宽高: 父结点宽高为子节点宽高+边距
重新计算子节点的位置信息:父节点位置信息 - 边距
包含关系:多层嵌套 通过递归的方式完成嵌套布局
包含关系:并列嵌套 父节点宽高:内部子节点宽度之和 + 边距,父节点高度:最高子节点高度 + 边距;
每个子节点位置:当前节点位置 = 前一个节点位置 + 前一个节点宽度 + 间隔边距
删除:单结点 删除节点同时删除关联连线(source&target
删除:包含关系 删除包含关系同时恢复父节点的宽高同时刷新并列节点位置
删除:连线 刷新原本有连线的连接点样式
删除:多节点 使用for循环,注意i--
框选 使用<reat>,根据鼠标移动位移的正负数,选择不同的x和y值
svg的viewbox的移动功能 记录鼠标移动的位移,修改viewbox的视图位置

Usage

NPM

npm i vue-topo -save 
import vTopo from 'vue-topo'
import 'vue-topo/dist/vue-topo.min.css'
Vue.use(vTopo)

github源码使用

npm install
npm run dev  //启动服务

引入组件

// xxx.vue
 <v-topo 
  :editable="true"
  :topo-data="topoData1">
 </v-topo>

Attributes

参数 说明 类型 可选值 默认值 必填
editable 是否可编辑 boolean true/false true
topo-data topo初始值 object {nodes:[],connectors:[]}

说明

代码开源,欢迎码农们提出宝贵意见,bug请提issues,本人将及时修改。最后著作权归一步工程师,请大家注明代码来源:https://github.com/Mirror198829/vue-topo

vue-topo's People

Contributors

dependabot[bot] avatar mirror198829 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-topo's Issues

del keycode在mack pro下无反应

感谢sougou Kevin.XU及团队 发现此bug 并定位到问题原因。
经测,在mac pro 下 del keycode==46 无反应。因为mac pro下del的keycode为8.
解决:增加keycode == 8 ,因此win下点击backspace也会删除节点

对于放大缩小的toolbar

看到工程里面有放大缩小的toolbar,但没实现,所以斗胆增加了该功能,写的比较简单,还望楼主整合下☺
1
2

npm run dev 在虚拟机上无法用ip访问

问题:用新版vue-cli在虚拟机上使用npm run dev启动服务,通过ip无法访问页面

原因:在新版vue-cli中的config/index.js

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: 'locahost', // can be overwritten by process.env.HOST
    
    ……

host设置为了localhost。

解决方法:讲localhost修改为0.0.0.0

module.exports = {
  dev: {

    // Paths
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {},

    // Various Dev Server settings
    host: '0.0.0.0', // can be overwritten by process.env.HOST

建议升级全部包

主要是升级 webpack, 因为我下载完了包,运行的时候总是跑不起来。还有改webpack依赖等

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.