前端知识框架 前端知识框架
首页
基础
框架
插件
Node
地图
更多
前端须知
  • 分类
  • 标签
  • 归档

BestIdea

首页
基础
框架
插件
Node
地图
更多
前端须知
  • 分类
  • 标签
  • 归档
  • JointJS入门
    • 快速开始
    • 点击事件
    • 增加输入输出点
    • 微视图
    • 转化为 json 数据
  • lottie动态图标以及超图中的使用
  • js实现前端pdf预览
  • js实现预览简版
  • 富文本实现图片粘贴
  • 移动端表单组件点击延迟问题解决办法
  • 在线预览解决方案
  • antv-x6 入门
  • antv-g2入门
  • antv-g2Plot
  • antv-s2 入门
  • antv-l7Plot
  • avtv-f2入门
  • Vue实现pdf、doc、txt、xlsx等的预览
  • micro-app使用
  • VueUse使用
  • webpack打包替换类名命名空间
  • 插件
郝东建
2022-03-26
目录

JointJS入门

# JointJS

JointJS 是一个开源的前端流程图框架,基于 SVG 进行绘制

  • API 文档 (opens new window)
  • 官网案例 (opens new window)
  • 快速开始 (opens new window)
  • git (opens new window)

# 快速开始

  • 引入基本的 JS 文件
<link rel="stylesheet" type="text/css" href="./joint.css" />
<script src="./jquery.js"></script>
<script src="./lodash.js"></script>
<script src="./backbone.js"></script>
<script src="./joint.js"></script>
1
2
3
4
5
  • 初始化模型
var graph = new joint.dia.Graph();
1
  • 初始化画布
var paper = new joint.dia.Paper({
  el: document.getElementById("myholder"),
  model: graph,
  width: 600,
  height: 100,
  gridSize: 1,
});
1
2
3
4
5
6
7
  • 绘制模块
var rect = new joint.shapes.standard.Rectangle();
rect.position(100, 30);
rect.resize(100, 40);
rect.attr({
  body: {
    fill: "blue",
  },
  label: {
    text: "Hello",
    fill: "white",
  },
});
rect.addTo(graph);
1
2
3
4
5
6
7
8
9
10
11
12
13
  • 复制模块并链接
var rect2 = rect.clone();
rect2.translate(300, 0);
rect2.attr("label/text", "World!");
rect2.addTo(graph);

var link = new joint.shapes.standard.Link();
link.source(rect);
link.target(rect2);
link.addTo(graph);
1
2
3
4
5
6
7
8
9

# 点击事件

joint 可以为画布绑定事件,其中包括点击空白,双击空白,点击线,点击模块,双击模块,点击连接点等事件

文档地址 (opens new window)

paper.on("blank:pointerdblclick", function () {
  resetAll(this);

  info.attr("body/visibility", "hidden");
  info.attr("label/visibility", "hidden");

  this.drawBackground({
    color: "orange",
  });
});
1
2
3
4
5
6
7
8
9
10

# 增加输入输出点


(function() {

    var graph = new joint.dia.Graph;
    new joint.dia.Paper({ el: $('#paper-create'), width: 650, height: 200, gridSize: 1, model: graph });

    var m1 = new joint.shapes.devs.Model({
        position: { x: 50, y: 50 },
        size: { width: 90, height: 90 },
        inPorts: ['in1','in2'],
        outPorts: ['out'],
        ports: {
            groups: {
                'in': {
                    attrs: {
                        '.port-body': {
                            fill: '#16A085'
                        }
                    }
                },
                'out': {
                    attrs: {
                        '.port-body': {
                            fill: '#E74C3C'
                        }
                    }
                }
            }
        },
        attrs: {
            '.label': { text: 'Model', 'ref-x': .5, 'ref-y': .2 },
            rect: { fill: '#2ECC71' }
        }
    });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

# 微视图

微视图

<div style="position: relative; padding-bottom: 100px;">
  <div
    class="paper"
    id="paper-multiple-papers"
    style="position: absolute;"
  ></div>
  <div
    class="paper"
    id="paper-multiple-papers-small"
    style="position: absolute; top: 75px; left: 450px;"
  ></div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
(function multiplePapers() {
  // shared graph model
  var graph = new joint.dia.Graph();

  // main paper view
  new joint.dia.Paper({
    el: document.getElementById("paper-multiple-papers"),
    model: graph,
    width: 600,
    height: 100,
    gridSize: 1,
  });

  // minimap paper view
  var paperSmall = new joint.dia.Paper({
    el: document.getElementById("paper-multiple-papers-small"),
    model: graph,
    width: 150,
    height: 25,
    gridSize: 1,
    interactive: false,
  });
  paperSmall.scale(0.25);

  // graph contents
  var rect = new joint.shapes.standard.Rectangle();
  rect.position(100, 30);
  rect.resize(100, 40);
  rect.attr({
    body: {
      fill: "blue",
    },
    label: {
      text: "Hello",
      fill: "white",
    },
  });
  rect.addTo(graph);

  var rect2 = rect.clone();
  rect2.translate(300, 0);
  rect2.attr("label/text", "World!");
  rect2.addTo(graph);

  var link = new joint.shapes.standard.Link();
  link.source(rect);
  link.target(rect2);
  link.addTo(graph);
})();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

# 转化为 json 数据

graph.toJSON();
1
上次更新: 2024/01/18, 10:44:15
lottie动态图标以及超图中的使用

lottie动态图标以及超图中的使用→

最近更新
01
webpack打包替换类名命名空间
05-01
02
Vite常用配置
02-26
03
crypto前端加密
01-18
更多文章>
Theme by Vdoing | Copyright © 2022-2024
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式