Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kedor layout master #854

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"style-loader": "~3.2.0",
"url-loader": "~4.1.0",
"webpack": "~5.51.0",
"webpack-cli": "~4.8.0"
"webpack-cli": "~4.8.0",
"d3-shape": "^2.1.0"
},
"peerDependencies": {
"jquery": ">=2.0.0",
Expand Down
83 changes: 83 additions & 0 deletions plugins/layout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ npm install
npm start
```
## 快速上手
### graphviz layout
``` js
import {graphvizLayout} from 'butterfly-plugins-layout';

Expand Down Expand Up @@ -41,6 +42,35 @@ graphvizLayout({
import graphvizLayout, {GraphvizEdge} from 'butterfly-plugins-layout/graphvizLayout';
```

### kedroviz layout
``` js
import {kedrovizLayout, KedrovizEdge, BaseLayers, obstacleAvoidancePoints} from 'butterfly-plugins-layout';

// ···

// 可以在画布初始化的时候传入layout参数作为布局方法
let canvas = new Canvas({
// 如下属性
root: dom, //canvas的根节点(必传)
layout: {
type: kedrovizLayout,
options: {rankdir: 'TB', visible: true, Class: BaseLayers}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layout: kedrovizLayout,
layoutOptions: {rankdir: 'TB', visible: true, Class: BaseLayers}

}, //布局设置(选填),可使用集成的,也可自定义布局
zoomable: true, //可缩放(选填)
moveable: true, //可平移(选填)
draggable: true, //节点可拖动(选填)
linkable: true, //节点可连接(选填)
disLinkable: true, //节点可取消连接(选填)
avoidPoints: obstacleAvoidancePoints //避障贝塞尔曲线
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我建议把“ obstacleAvoidancePoints”改个名称,例如canvas.drawPath,类似edge中的calcPath,然后drawPath写在小蝴蝶最基础的baseCanvas中,假如有这个方法就会用这个方法画线,假如没有就会用edge中的calcPath来画线。

});

this.canvas.draw({nodes, edges, layers}, () => {

});
// ···

```

## 布局算法

### graphviz layout
Expand All @@ -64,3 +94,56 @@ import graphvizLayout, {GraphvizEdge} from 'butterfly-plugins-layout/graphvizLay
##### ranksep _`<Double>`_ (选填)

&nbsp;&nbsp;节点布局不同等级之间的间隔;值类型 `double`,默认0.5,最小0.02

### kedroviz layout
&nbsp;&nbsp;&nbsp;&nbsp;Kedroviz layout适合节点分组的布局算法。其根据图数据中节点所属组(layer),自动计算节点的层级及位置。

注:使用这个布局方法,Edge需要继承由kedrovizLayout导出的KedrovizEdge类。Layers需要继承由kedrovizLayout导出的BaseLayers类。

#### 代码演示

``` js
this.canvas = new Canvas({
layout: {
type: kedrovizLayout,
options: {
rankdir: 'TB',
visible: true,
Class: BaseLayers
},
},
avoidPoints: obstacleAvoidancePoints
});
```

#### API


| 名称 | 类型 | 是否必须 | 默认值 | 可选值 | 说明
| :------ | :------ | :------ | :------ | :------ | :------
| rankdir | String | false | TB| "TB/BT/LR/RL" |布局的方向。T:top(上);B:bottom(下);L:left(左);R:right(右)。
| visible | Boolean | false | true | true / false | 节点是否显示分组
| Class | Function | true | | BaseLayers | 分组(layers)的类

### 避障贝塞尔曲线
&nbsp;&nbsp;&nbsp;&nbsp;避障贝塞尔曲线在节点连线时会自动避开中间节点。

注:使用该曲线时,Edge需要继承KedrovizEdge类。需要在Canvas中传入avoidPoints参数

#### 代码演示

``` js

import {KedrovizEdge, obstacleAvoidancePoints} from 'butterfly-plugins-layout';

this.canvas = new Canvas({
avoidPoints: obstacleAvoidancePoints
});

```

#### API

| 名称 | 类型 | 是否必须 | 默认值 | 可选值 | 说明
| :------ | :------ | :------ | :------ | :------ | :------
| avoidPoints | Function | 是 | | obstacleAvoidancePoints | 计算避障节点的方法
2 changes: 1 addition & 1 deletion plugins/layout/example/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './src/app.jsx';
import App from './src/app1.jsx';

ReactDOM.render((
<App />
Expand Down
2 changes: 1 addition & 1 deletion plugins/layout/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"react": "~16.12.0",
"react-dom": "~16.12.0",
"jquery": "^3.4.1",
"butterfly-plugins-layout": "^0.0.3"
"butterfly-plugins-layout": "^0.0.10"
},
"devDependencies": {
"@babel/core": "^7.8.7",
Expand Down
109 changes: 109 additions & 0 deletions plugins/layout/example/src/app1.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import React, {Component} from 'react';
import $ from 'jquery';
import { Canvas, Node, Edge } from '../../../../index';
import './app1.less';
import '../../../../static/butterfly.css';
const treeData = require('./mock_data1.json');
import {kedrovizLayout, KedrovizEdge, BaseLayers, obstacleAvoidancePoints} from 'butterfly-plugins-layout';
import 'butterfly-plugins-layout/dist/index.css';
// import obstacleAvoidancePoints from '../../src/edgeTypes/kedrovizEdge/obstacleAvoidancePoints';
// import {kedrovizLayout, BaseLayers} from '../../../../plugins/layout/src/kedroviz';
// import KedrovizEdge from '../../src/edgeTypes/kedrovizEdge/KedrovizEdge';

class BaseNode extends Node {
constructor(opts) {
super(opts);
this.options = opts;
}
draw (opts) {
const container = $('<div class="kedroviz-base-node"></div>')
.attr('id', opts.id)
.css('top', opts.top + 'px')
.css('left', (opts.left) + 'px')
.css('width', opts.options.width + 'px')
.css('height', opts.options.height + 'px');
$('<span class="tmpText"></span>').text(this.options.name).appendTo(container);


return container[0];
}
}

class Scene extends Component {
componentDidMount() {
let root = document.getElementById('dag-canvas');
this.canvas = new Canvas({
root: root,
disLinkable: false, // 可删除连线
layout: {type: kedrovizLayout, options: {rankdir: 'LR', visible: true, Class: BaseLayers}},
linkable: true, // 可连线
draggable: false, // 可拖动
zoomable: true, // 可放大
moveable: true, // 可平移
theme: {
},
avoidPoints: obstacleAvoidancePoints
});
// 数据格式转换
const nodes = treeData.nodes.map(n => {
const res = {};
res.draggable = true;
res.id = n.id;
res.name = n.name;
res.Class = BaseNode;
res.layer = n.layer;
res.draggable = false;
res.width = n.width;
res.height = n.height;
// res.endpoints = [{
// id: 'down',
// orientation: [0, 1],
// pos: [0.5, 1]
// }, {
// id: 'up',
// orientation: [0, -1],
// pos: [0.5, 1]
// }];
return res;
});
const edges = treeData.edges.map(e => {
const res = {};
// res.type = 'endpoint';
// res.source = 'down';
// res.target = 'up';
res.type = 'node';
res.source = e.source;
res.target = e.target;
// res.sourceNode = e.source;
// res.targetNode = e.target;
res.arrow = true;
res.arrowPosition = 1;
res.Class = KedrovizEdge;
return res;
});

this.canvas.draw({nodes, edges, layers: treeData.layers}, () => {

});
this.canvas.on('events', (data) => {
});
}
render() {
return (
<div className='kedroviz'>
<div className="kedroviz-canvas" id="dag-canvas">
</div>
</div>
);
}
}

function App() {
return (
<div className="App">
<Scene />
</div>
);
}

export default App;
42 changes: 42 additions & 0 deletions plugins/layout/example/src/app1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.App {
position: relative;
width: 100%;
height: 100%;
z-index: 3;
.kedroviz {
width: 100%;
height: 100%;
.kedroviz-canvas {
width: 100%;
height: 100%;
}

.kedroviz-base-node {
position: absolute;
border: 1px gray solid;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
}
.tmpText {
text-align: center;
}

.label {
position: absolute;
font-size: 20px;
background: none;
border: none;
box-shadow: none;
line-height: 23px;
}
.label:hover {
background: none;
border: none;
}
.rotate-down {
transform: rotate(90deg);
}
}
}
6 changes: 4 additions & 2 deletions plugins/layout/example/src/mock_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"nodes": [{
"nodes": [
{
"id": "187bf4c7-10ee-4a60-9501-e1acb39eda8a",
"name": "table_14",
"index": 14
Expand Down Expand Up @@ -88,7 +89,8 @@
"name": "table_12",
"index": 12
}],
"edges": [{
"edges": [
{
"id": "6687aab8-4263-4f5e-b410-661907435c5b",
"source": "70d33391-dbe0-4e83-8832-4084cb1ea01e",
"target": "6c2f8b8a-aa10-4e7d-96f9-d408852810fd"
Expand Down
Loading