Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isObject(val)) {
model[cfg] = clone(val);
} else {
model[cfg] = defaultModel[cfg];
}
}
});
}
graph.emit('beforeadditem', { type, model });
if(type === EDGE) {
let source: string | Item = (model as EdgeConfig).source
let target: string | Item = (model as EdgeConfig).target
if (source && isString(source)) {
source = graph.findById(source);
}
if (target && isString(target)) {
target = graph.findById(target);
}
if (!source || !target) {
throw new Error('The source or target node of edge ' + model.id + ' does not exist!')
// console.warn('The source or target node of edge ' + model.id + ' does not exist!');
// return;
}
item = new Edge({
model,
source,
target,
public removeItem(item: Item): void {
// 如果item是字符串,且查询的节点实例不存在,则认为是删除group
let nodeItem = null;
if (isString(item)) {
nodeItem = this.findById(item);
}
if (!nodeItem && isString(item)) {
this.get('customGroupControll').remove(item);
} else {
this.get('itemController').removeItem(item);
}
}
calculationGroupPosition() {
const graph = this.graph;
const nodes = graph.findAllByState('node', 'selected');
let minx = Infinity;
let maxx = -Infinity;
let miny = Infinity;
let maxy = -Infinity;
// 获取已节点的所有最大最小x y值
for (const id of nodes) {
const element = isString(id) ? graph.findById(id) : id;
const bbox = element.getBBox();
const { minX, minY, maxX, maxY } = bbox;
if (minX < minx) {
minx = minX;
}
if (minY < miny) {
miny = minY;
}
if (maxX > maxx) {
maxx = maxX;
}
if (maxY > maxy) {
maxy = maxY;
public setGroupStyle(keyShape: ShapeBase, style: string | object) {
if (!keyShape || keyShape.get('destroyed')) {
return;
}
let styles = {};
const { hover: hoverStyle, default: defaultStyle } = this.styles;
if (isString(style)) {
if (style === 'default') {
styles = deepMix({}, defaultStyle);
} else if (style === 'hover') {
styles = deepMix({}, hoverStyle);
}
} else {
styles = deepMix({}, defaultStyle, style);
}
// tslint:disable-next-line:forin
for (const s in styles) {
keyShape.attr(s, styles[s]);
}
}
public updateLayout(cfg): void {
const layoutController = this.get('layoutController');
let newLayoutType;
if (isString(cfg)) {
newLayoutType = cfg;
cfg = {
type: newLayoutType
};
} else {
newLayoutType = cfg.type;
}
const oriLayoutCfg = this.get('layout');
const oriLayoutType = oriLayoutCfg ? oriLayoutCfg.type : undefined;
if (!newLayoutType || oriLayoutType === newLayoutType) {
// no type or same type, update layout
const layoutCfg: any = {};
Object.assign(layoutCfg, oriLayoutCfg, cfg);
layoutCfg.type = oriLayoutType ? oriLayoutType : 'random';
public removeItem(item: Item): void {
// 如果item是字符串,且查询的节点实例不存在,则认为是删除group
let nodeItem = null;
if (isString(item)) {
nodeItem = this.findById(item);
}
if (!nodeItem && isString(item)) {
this.get('customGroupControll').remove(item);
} else {
this.get('itemController').removeItem(item);
}
}
public setItemState(item: Item, state: string, enabled: boolean): void {
if (isString(item)) {
item = this.findById(item);
}
this.get('itemController').setItemState(item, state, enabled);
this.get('stateController').updateState(item, state, enabled);
}
export const formatPadding = (padding: IPadding): number[] => {
let top = 0;
let left = 0;
let right = 0;
let bottom = 0;
if (isNumber(padding)) {
top = left = right = bottom = padding;
} else if(isString(padding)) {
const intPadding = parseInt(padding, 10)
top = left = right = bottom = intPadding;
} else if (isArray(padding)) {
top = padding[0];
right = !isNil(padding[1]) ? padding[1] : padding[0];
bottom = !isNil(padding[2]) ? padding[2] : padding[0];
left = !isNil(padding[3]) ? padding[3] : right;
}
return [ top, right, bottom, left ];
}
private initCanvas() {
let container: string | HTMLElement = this.get('container')
if(isString(container)) {
container = document.getElementById(container)
this.set('container', container)
}
if(!container) {
throw new Error('invalid container')
}
const width: number = this.get('width')
const height: number = this.get('height')
const pixelRatio: number = this.get('pixelRatio')
const canvas = new GCanvas({
container,
width,
height,