Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aedaff0

Browse files
fix: drag edge bug
fix: click label bug
2 parents 03b95a3 + 4c0ae06 commit aedaff0

File tree

5 files changed

+57
-18
lines changed

5 files changed

+57
-18
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-visual-modeling",
3-
"version": "1.0.45",
3+
"version": "1.1.0",
44
"description": "一个基于React的数据可视化建模的DAG图,适用于UML,数据库建模,数据仓库建设等业务",
55
"main": "dist/index.js",
66
"pack": "pack/index.js",

‎src/adaptor.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const diffPropsData = (newData, oldData, options) => {
7575
});
7676

7777
if(!edge) {
78-
return
78+
return;
7979
}
8080

8181
if(isSameLabel(a.label, edge.label)) {

‎src/canvas/canvas.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,19 @@ export default class TableCanvas extends Canvas {
271271
});
272272
}
273273

274+
focusItems(nodes = [], edges = []) {
275+
this.emit('custom.item.focus', {
276+
nodes,
277+
edges
278+
});
279+
nodes.forEach((item) => {
280+
item.focus();
281+
});
282+
edges.forEach((item) => {
283+
item.focus();
284+
});
285+
}
286+
274287
_findChain(nodeId, pointId) {
275288
let resultPoints = [];
276289
let resultEdges = [];

‎src/canvas/edge.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ export default class BaseEdge extends Edge {
8282
span.style.position = 'absolute';
8383
span.style.zIndex = 500;
8484
dom = span;
85-
}
86-
87-
if (label && typeof label === 'string') {
85+
} else if (label && typeof label === 'string') {
8886
let container = $('<span class="butterflies-label visual-modeling-label"></span>');
8987
container.text(label);
9088
dom = container[0];

‎src/index.tsx‎

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,12 @@ export default class TableBuilding extends React.Component<ComProps, any> {
220220

221221
let _addLinks = (links: any) => {
222222
let newLinkOpts = links.map((item: any) => {
223-
let _oldSource = _.get(item, 'sourceEndpoint.id', '');
224-
let _oldTarget = _.get(item, 'targetEndpoint.id', '');
225-
let _newSource = _oldSource.indexOf('-right') !== -1 ? _oldSource : _oldSource + '-right';
226-
let _newTarget = _oldTarget.indexOf('-left') !== -1 ? _oldTarget : _oldTarget + '-left';
227-
223+
let _oldSource = _.get(item, 'sourceEndpoint.id', '').replace('-right', '');
224+
let _oldTarget = _.get(item, 'targetEndpoint.id', '').replace('-left', '');
225+
let _newSource = _oldSource + '-right';
226+
let _newTarget = _oldTarget + '-left';
228227
return {
229-
id: item.options.id,
228+
id: item.options.id||`${item.options.sourceNode}-${_oldSource}-${item.options.targetNode}-${_oldTarget}`,
230229
sourceNode: item.options.sourceNode,
231230
targetNode: item.options.targetNode,
232231
arrowShapeType: item.arrowShapeType,
@@ -247,17 +246,19 @@ export default class TableBuilding extends React.Component<ComProps, any> {
247246
target: _.get(item, 'targetEndpoint.options.originId'),
248247
}));
249248
});
249+
250+
return newEdge;
250251
}
251252

252253
this.canvas.on('system.link.connect', (data: any) => {
253-
_addLinks(data.links || []);
254-
this.onConnectEdges(data.links);
254+
letnewEdges=_addLinks(data.links || []);
255+
this.onConnectEdges(newEdges);
255256
this.forceUpdate();
256257
});
257258

258259
this.canvas.on('system.link.reconnect', (data: any) => {
259-
_addLinks(data.addLinks || []);
260-
this.onReConnectEdges(data.addLinks, data.delLinks);
260+
let_addEdges=_addLinks(data.addLinks || []);
261+
this.onReConnectEdges(_addEdges, data.delLinks);
261262

262263
this.forceUpdate();
263264
});
@@ -322,6 +323,13 @@ export default class TableBuilding extends React.Component<ComProps, any> {
322323
this.onDeleteNodes([data.node]);
323324
});
324325

326+
this.canvas.on('custom.item.focus', (data: any) => {
327+
this._unfocus();
328+
this._focusNodes = this._focusNodes.concat(data.nodes || []);
329+
this._focusLinks = this._focusLinks.concat(data.edges || []);
330+
331+
});
332+
325333
this.canvas.on('table.canvas.expand', () => {
326334
this.forceUpdate();
327335
});
@@ -407,9 +415,23 @@ export default class TableBuilding extends React.Component<ComProps, any> {
407415

408416
onConnectEdges(links) {
409417
let linksInfo = links.map((item) => {
410-
return item.options;
418+
return _.assign(item.options, {
419+
source: _.get(item, 'options.source', '').replace('-right', ''),
420+
target: _.get(item, 'options.target', '').replace('-left', '')
421+
});
411422
});
412423

424+
let newEdges = _.differenceWith(linksInfo, this.canvasData.edges, (a: any, b: any) => {
425+
return (
426+
a.sourceNode === b.sourceNode &&
427+
a.targetNode === b.targetNode &&
428+
a.source === b.source &&
429+
a.target === b.target
430+
);
431+
});
432+
433+
this.canvasData.edges = this.canvasData.edges.concat(newEdges);
434+
413435
this.props.onChange && this.props.onChange({
414436
type: 'system.link.connect',
415437
links: linksInfo
@@ -418,10 +440,16 @@ export default class TableBuilding extends React.Component<ComProps, any> {
418440

419441
onReConnectEdges(addLinks, rmLinks) {
420442
let addLinksInfo = addLinks.map((item) => {
421-
return item.options;
443+
return _.assign(item.options, {
444+
source: _.get(item, 'options.source', '').replace('-right', ''),
445+
target: _.get(item, 'options.target', '').replace('-left', '')
446+
});
422447
});
423448
let rmLinksInfo = rmLinks.map((item) => {
424-
return item.options;
449+
return _.assign(item.options, {
450+
source: _.get(item, 'options.source', '').replace('-right', ''),
451+
target: _.get(item, 'options.target', '').replace('-left', '')
452+
});
425453
});
426454
this.props.onChange && this.props.onChange({
427455
type: 'system.link.reconnect',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /