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

Feat relation books demo #307

Open
wants to merge 3 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
413 changes: 413 additions & 0 deletions example/demo/mindMap-new/data.js

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions example/demo/mindMap-new/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use strict';
import React, {Component} from 'react';
import mockData from './data.js';
const Canvas = require('../../../index.js').TreeCanvas;
require('./index.less');

class MindMapNew extends Component {
constructor() {
super();
}
componentDidMount() {
let root = document.getElementById('dag-canvas');
this.canvas = new Canvas({
root: root,
disLinkable: true, // 可删除连线
linkable: true, // 可连线
draggable: true, // 可拖动
zoomable: true, // 可放大
moveable: true, // 可平移
theme: {
edge: {
type: 'AdvancedBezier',
}
},
layout: {
type: 'mindmap',
options: {
direction: 'H',
getSide(d) {
return d.data.side || 'right';
},
getHeight(d) {
return 10;
},
getWidth(d) {
return 40;
},
getHGap(d) {
return 50;
},
getVGap(d) {
return 20;
},
}
}
});
this.canvas.draw(mockData, {}, () => {
this.canvas.focusCenterWithAnimate();
}
);
this.canvas.on('events', (data) => {
console.log(data);
});
}
render() {
return (
<div className='mind-map-new'>
<div className="compactBoxTree-canvas" id="dag-canvas">
</div>
</div>
);
}
}

module.exports = MindMapNew;
41 changes: 41 additions & 0 deletions example/demo/mindMap-new/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.mind-map-new {
width: 100%;
height: 100%;
text-align: center;
background: #fff;
.compactBoxTree-canvas {
width: 100%;
height: 100%;
.butterfly-wrapper {
#Root {
border-radius: 10px;
font-weight: 500;
border: 1px solid #d9d9d9;
padding: 8px 16px;
.iconfont {
background: #9254DE;
}
.title {
color: #333;
}
}
.mind-map-node {
position: absolute;
background: #fff;
border: 1px solid #d9d9d9;
border-radius: 10px;
padding: 8px 8px;
display: flex;
justify-content: space-between;
.iconfont {
background: #40A9FF;
padding: 6px;
border-radius: 50%;
}
.title {
color: #333;
}
}
}
}
}
29 changes: 29 additions & 0 deletions example/demo/mindMap-new/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const Node = require('../../../index.js').TreeNode;
const $ = require('jquery');

class BaseNode extends Node {
constructor(opts) {
super(opts);
}

draw = (opts) => {
console.log('opts: ', opts);
let container = $('<div class="mind-map-node"></div>')
.css('top', opts.top)
.css('left', opts.left)
.attr('id', opts.id);
let titleDom = $(`
<div class="title">
<i class="iconfont">${opts.id === 'Root' ? '&#xe8b3;' : '&#xe6ff;'}</i>
${opts.options.title}
<div>`);

container.append(titleDom);

return container[0];
}
}

module.exports = BaseNode;
76 changes: 76 additions & 0 deletions example/demo/relationalBooks-new/alis-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

const Node = require('../../../index.js').Node;
const $ = require('jquery');

class AlisBaseNode extends Node {
constructor(opts) {
super(opts);
this.options = opts;
}

draw = (opts) => {
let className = this.options.type;
let container = $('<div class="group-node"></div>')
.css('top', opts.top + 'px')
.css('left', opts.left + 'px')
.addClass(className)
.attr('id', opts.id);

this._createTitle(container);
this._createContent(container);
this._onRemoveNode(container);

return container[0];
}

_createTitle = (dom) => {
let title = $(
`<div class="title">
<span class="title-text">${this.options.name}</span>
</div>`);

dom.append(title);
this._editNode(title);
}

_createContent(dom) {
let con = $(`
<div class="container" >
<p class="title-text">${this.options.data.content}</p>
<span class="alis-node-edit"><i class="iconfont">&#xe66d;</i></span>
</div>`);

dom.append(con);
this._editNode(con);
}

_onRemoveNode(dom) {
$(dom).find('#close').click(function () {
dom[0].remove();
});
}

_editNode = (dom) => {
dom.find('.alis-node-edit').click(function (e) {
const oldNode = $(this).prev('.title-text');
const oldNodeText = $(this).prev('.title-text').text();

if (dom[0] === $('.group-node > .title')[0]) {
oldNode.html(`<input type=text class=input-text />`);
$(oldNode).find('input').focus().val(oldNodeText);
} else {
oldNode.html(`<textarea></textarea>`);
$(oldNode).find('textarea').focus().val(oldNodeText);
}
oldNode.children().keyup(function (event) {
if (event.keyCode === 13 || event.keyCode === 27) {
const oldInputText = $(this).val();

$(this).parent('.title-text').text(oldInputText);
}
});
})
}
}
module.exports = AlisBaseNode;
134 changes: 134 additions & 0 deletions example/demo/relationalBooks-new/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
'use strict';

const BaseNode = require('./node.js');
const AlisBaseNode = require('./alis-node.js');
const $ = require('jquery');

module.exports = {
nodes: [{
id: '0',
name: 'Book',
top: 264,
left: 172,
data: {
content: ['id', 'isbn', 'title']
},
endpoints: [{
id: 'point_1',
type: 'source',
orientation: [1, 0],
pos: [0, 1.5]

}, {
id: 'point_2',
type: 'target',
orientation: [-1, 0],
pos: [0, 1.5]
}],
Class: BaseNode
}, {
id: '1',
name: 'BookPublisher',
top: 488,
left: 374,
data: {
content: ['book_id', 'publisher_id']
},
endpoints: [{
id: 'point_1',
type: 'target',
orientation: [-1, 0],
pos: [0, 1.5]
}, {
id: 'point_2',
type: 'source',
orientation: [1, 0],
pos: [0, 2.5]
}],
Class: BaseNode
}, {
id: '2',
name: 'Author',
top: 488,
left: 750,
data: {
content: ['id', 'name']
},
endpoints: [{
id: 'point_1',
type: 'target',
orientation: [-1, 0],
pos: [0, 1.5]
}],
Class: BaseNode
}, {
id: '3',
name: 'BookAuthor',
top: 754,
left: -36,
data: {
content: ['book_id', 'author_id']
},
endpoints: [{
id: 'point_1',
type: 'source',
orientation: [1, 0],
pos: [0, 1.5]
}, {
id: 'point_2',
type: 'source',
orientation: [1, 0],
pos: [0, 2.5]
}],
Class: BaseNode
}, {
id: '4',
name: 'Publisher',
data: {
content: ['id', 'name']
},
top: 754,
left: 374,
endpoints: [{
id: 'point_1',
type: 'target',
orientation: [-1, 0],
pos: [0, 1.5]
}],
Class: BaseNode
}, {
id: '5',
name: 'Books By Author',
data: {
content: 'SELECT * FROM b INNER JOIN book_author ba ON b.id = ba.book_id GROUP BY ba.author_id'
},
top: 744,
left: 900,
Class: AlisBaseNode
}],
edges: [{
source: 'point_1',
target: 'point_1',
sourceNode: '0',
targetNode: '1',
type: 'endpoint',
}, {
source: 'point_2',
target: 'point_1',
sourceNode: '1',
targetNode: '4',
type: 'endpoint',
}, {
source: 'point_1',
target: 'point_2',
sourceNode: '3',
targetNode: '0',
type: 'endpoint',
}, {
source: 'point_2',
target: 'point_1',
sourceNode: '3',
targetNode: '2',
type: 'endpoint',
}],
};
44 changes: 44 additions & 0 deletions example/demo/relationalBooks-new/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
import React, {Component} from 'react';
const Canvas = require('../../../index.js').Canvas;
const mockData = require('./data.js');

require('./index.less');
require('butterfly-dag/dist/index.css');

class RelationalBooksNew extends Component {
constructor() {
super();
this.canvas = null;
}
componentDidMount() {
let root = document.getElementById('dag-canvas');
this.canvas = new Canvas({
root: root,
disLinkable: true, // 可删除连线
linkable: true, // 可连线
draggable: true, // 可拖动
zoomable: true, // 可放大
moveable: true, // 可平移
theme: {
edge: {
type: 'Straight',
},
}
});
this.canvas.setMinimap(true);
this.canvas.draw(mockData, () => {
this.canvas.focusCenterWithAnimate();
});
}
render() {
return (
<div className='relational-books-page'>
<div className="flow-canvas" id="dag-canvas">
</div>
</div>
);
}
}

module.exports = RelationalBooksNew;
Loading