FIX:修复某些bug

This commit is contained in:
黎智洲 2021-06-05 13:45:53 +08:00
parent 32f403b5aa
commit a7d9aed4ab
8 changed files with 82 additions and 27 deletions

2
dist/sv.js vendored

File diff suppressed because one or more lines are too long

View File

@ -213,11 +213,28 @@ export class ModelConstructor {
*/ */
private createElement(sourceElement: SourceElement, elementName: string, groupName: string, layouterName: string, options: ElementOption): Element { private createElement(sourceElement: SourceElement, elementName: string, groupName: string, layouterName: string, options: ElementOption): Element {
let element: Element = undefined, let element: Element = undefined,
label = options.label? this.parserElementContent(sourceElement, options.label): '', label: string | string[] = '',
id = elementName + '.' + sourceElement.id.toString(); id = elementName + '.' + sourceElement.id.toString();
if(label === null || label === 'undefined') { if(options.label) {
label = ''; if(Array.isArray(options.label)) {
label = options.label.map(item => {
let res = this.parserElementContent(sourceElement, item);
if(res === null || label === 'undefined') {
return '';
}
return res;
});
}
else {
label = this.parserElementContent(sourceElement, options.label);
if(label === null || label === 'undefined') {
label = '';
}
}
} }
element = new Element(id, elementName, groupName, layouterName, sourceElement); element = new Element(id, elementName, groupName, layouterName, sourceElement);

View File

@ -13,7 +13,7 @@ export interface G6NodeModel {
type: string; type: string;
size: number | [number, number]; size: number | [number, number];
anchorPoints: [number, number]; anchorPoints: [number, number];
label: string; label: string | string[];
style: Style; style: Style;
labelCfg: ElementLabelOption; labelCfg: ElementLabelOption;
externalPointerId: string; externalPointerId: string;

View File

@ -59,8 +59,9 @@ export default G6.registerNode('binary-tree-node', {
getAnchorPoints() { getAnchorPoints() {
return [ return [
[0.5, 0], [0.5, 0],
[0.125, 0.5], [0.875, 0.5],
[0.875, 0.5] [0.5, 1],
[0.125, 0.5]
]; ];
}, },
}); });

View File

@ -60,6 +60,7 @@ export default G6.registerNode('link-list-node', {
[0.5, 0], [0.5, 0],
[5 / 6, 0], [5 / 6, 0],
[5 / 6, 0.5], [5 / 6, 0.5],
[1, 0.5],
[5 / 6, 1], [5 / 6, 1],
[0.5, 1], [0.5, 1],
[0, 0.5] [0, 0.5]

View File

@ -34,22 +34,58 @@ export default G6.registerNode('two-cell-node', {
draggable: true draggable: true
}); });
const style = (cfg.labelCfg && cfg.labelCfg.style) || {};
if (cfg.label) { if (cfg.label) {
const style = (cfg.labelCfg && cfg.labelCfg.style) || {}; if(Array.isArray(cfg.label)) {
group.addShape('text', { let tag = cfg.label[0], data = cfg.label[1];
attrs: {
x: width * (3 / 4), group.addShape('text', {
y: height, attrs: {
textAlign: 'center', x: width * (3 / 4),
textBaseline: 'middle', y: height,
text: cfg.label, textAlign: 'center',
fill: style.fill || '#000', textBaseline: 'middle',
fontSize: style.fontSize || 16, text: tag,
cursor: cfg.style.cursor, fill: style.fill || '#000',
}, fontSize: style.fontSize || 16,
name: 'text', cursor: cfg.style.cursor,
draggable: true },
}); name: 'text',
draggable: true
});
group.addShape('text', {
attrs: {
x: width * (5 / 4),
y: height,
textAlign: 'center',
textBaseline: 'middle',
text: data,
fill: style.fill || '#000',
fontSize: style.fontSize || 16,
cursor: cfg.style.cursor,
},
name: 'text',
draggable: true
});
}
else {
group.addShape('text', {
attrs: {
x: width * (3 / 4),
y: height,
textAlign: 'center',
textBaseline: 'middle',
text: cfg.label,
fill: style.fill || '#000',
fontSize: style.fontSize || 16,
cursor: cfg.style.cursor,
},
name: 'text',
draggable: true
});
}
} }
return wrapperRect; return wrapperRect;
@ -57,9 +93,10 @@ export default G6.registerNode('two-cell-node', {
getAnchorPoints() { getAnchorPoints() {
return [ return [
[0, 0.5], [0.5, 0],
[3 / 4, 0.5], [3 / 4, 0.5],
[0.5, 0] [0.5, 1],
[0, 0.5]
]; ];
} }
}); });

View File

@ -59,7 +59,7 @@ export class Layouter {
item.set({ item.set({
x: pointerPosition[0], x: pointerPosition[0],
y: pointerPosition[1], y: pointerPosition[1],
rotation: angle rotation: Math.sign(anchorVector[0]) * angle
}); });
}); });
} }

View File

@ -1,4 +1,3 @@
import { LayoutGroup } from "./Model/modelConstructor";
import { Element } from "./Model/modelData"; import { Element } from "./Model/modelData";
import { SourceElement } from "./sources"; import { SourceElement } from "./sources";
@ -38,7 +37,7 @@ export interface ElementOption {
size: number | [number, number]; size: number | [number, number];
rotation: number; rotation: number;
anchorPoints: [number, number]; anchorPoints: [number, number];
label: string; label: string | string[];
labelOptions: ElementLabelOption; labelOptions: ElementLabelOption;
style: Style; style: Style;
} }