-
Notifications
You must be signed in to change notification settings - Fork 607
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
wkexinpd
wants to merge
13
commits into
alibaba:master
Choose a base branch
from
wkexinpd:ke-layout-master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kedor layout master #854
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4d3784
first
634ee50
first
4a21e3c
kedro
5adda61
column
603f29c
first
32a8f76
kedro-layout
eca0db6
Merge branch 'master' of https://github.com/alibaba/butterfly into ke…
0614fc2
kedro-layout
c230fed
publish+文档
362dafa
publish+文档
4896d9d
publish+文档
3615d3c
fix:文档完善
0d97565
feat:避障贝塞尔曲线
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ npm install | |
npm start | ||
``` | ||
## 快速上手 | ||
### graphviz layout | ||
``` js | ||
import {graphvizLayout} from 'butterfly-plugins-layout'; | ||
|
||
|
@@ -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} | ||
}, //布局设置(选填),可使用集成的,也可自定义布局 | ||
zoomable: true, //可缩放(选填) | ||
moveable: true, //可平移(选填) | ||
draggable: true, //节点可拖动(选填) | ||
linkable: true, //节点可连接(选填) | ||
disLinkable: true, //节点可取消连接(选填) | ||
avoidPoints: obstacleAvoidancePoints //避障贝塞尔曲线 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -64,3 +94,56 @@ import graphvizLayout, {GraphvizEdge} from 'butterfly-plugins-layout/graphvizLay | |
##### ranksep _`<Double>`_ (选填) | ||
|
||
节点布局不同等级之间的间隔;值类型 `double`,默认0.5,最小0.02 | ||
|
||
### kedroviz layout | ||
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)的类 | ||
|
||
### 避障贝塞尔曲线 | ||
避障贝塞尔曲线在节点连线时会自动避开中间节点。 | ||
|
||
注:使用该曲线时,Edge需要继承KedrovizEdge类。需要在Canvas中传入avoidPoints参数 | ||
|
||
#### 代码演示 | ||
|
||
``` js | ||
|
||
import {KedrovizEdge, obstacleAvoidancePoints} from 'butterfly-plugins-layout'; | ||
|
||
this.canvas = new Canvas({ | ||
avoidPoints: obstacleAvoidancePoints | ||
}); | ||
|
||
``` | ||
|
||
#### API | ||
|
||
| 名称 | 类型 | 是否必须 | 默认值 | 可选值 | 说明 | ||
| :------ | :------ | :------ | :------ | :------ | :------ | ||
| avoidPoints | Function | 是 | | obstacleAvoidancePoints | 计算避障节点的方法 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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}