fix: addBehavior support object and string

This commit is contained in:
baizn 2020-12-22 14:15:25 +08:00 committed by Moyee
parent d3e2ae167a
commit 1e4d745ce2
14 changed files with 32 additions and 32 deletions

View File

@ -36,7 +36,7 @@
"scripts": {
"start": "father build --watch",
"build": "npm run clean && father build && npm run build:umd",
"build:umd": "webpack --config webpack.config.js --mode production --profile --json > stats.json",
"build:umd": "webpack --config webpack.config.js --mode production --profile",
"build:dev": "webpack --config webpack.dev.config.js --mode development",
"ci": "npm run build && npm run coverage",
"clean": "rimraf es esm lib dist",

View File

@ -445,8 +445,10 @@ export default class ItemController {
// 已经存在要设置的 state或不存在 state 的样式为 undefined
if (
(item.hasState(stateName) === value && value) // 当该状态已经存在且现在需要设置为 true 时,不需要继续。当该状态不存在,且设置为 false 时,需要继续
|| (isString(value) && item.hasState(stateName))) { // 当该状态 value 是字符串,且已经存在该状态,不需要继续
(item.hasState(stateName) === value && value) || // 当该状态已经存在且现在需要设置为 true 时,不需要继续。当该状态不存在,且设置为 false 时,需要继续
(isString(value) && item.hasState(stateName))
) {
// 当该状态 value 是字符串,且已经存在该状态,不需要继续
return;
}

View File

@ -65,7 +65,7 @@ export default class ModeController {
const behaves: IBehavior[] = [];
let behave: IBehavior;
each(behaviors || [], (behavior) => {
const BehaviorInstance = Behavior.getBehavior(behavior.type);
const BehaviorInstance = Behavior.getBehavior(behavior.type || behavior);
if (!BehaviorInstance) {
return;
}

View File

@ -585,7 +585,7 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
* @param {object} padding
*/
public fitView(padding?: Padding): void {
console.log('fiut veiuw')
console.log('fiut veiuw');
if (padding) {
this.set('fitViewPadding', padding);
}
@ -1212,7 +1212,7 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
*/
public render(): void {
const self = this;
console.log('render', self.get('fitView'))
console.log('render', self.get('fitView'));
this.set('comboSorted', false);
const data: GraphData = this.get('data');
@ -2751,9 +2751,9 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
const stackData = data
? clone(data)
: {
before: {},
after: clone(this.save()),
};
before: {},
after: clone(this.save()),
};
if (stackType === 'redo') {
this.redoStack.push({

View File

@ -30,7 +30,7 @@ export {
registerEdge,
registerBehavior,
AbstractLayout,
AbstractEvent
AbstractEvent,
};
export * from './types';

View File

@ -350,17 +350,17 @@ export default class ItemBase implements IItemBase {
/**
*
*/
protected beforeDraw() { }
protected beforeDraw() {}
/**
*
*/
protected afterDraw() { }
protected afterDraw() {}
/**
*
*/
protected afterUpdate() { }
protected afterUpdate() {}
/**
* draw shape

View File

@ -126,17 +126,17 @@ const ShapeFramework = {
/**
*
*/
drawShape(/* cfg, group */) { },
drawShape(/* cfg, group */) {},
/**
* 便
*/
afterDraw(/* cfg, group */) { },
afterDraw(/* cfg, group */) {},
// update(cfg, item) // 默认不定义
afterUpdate(/* cfg, item */) { },
afterUpdate(/* cfg, item */) {},
/**
*
*/
setState(/* name, value, item */) { },
setState(/* name, value, item */) {},
/**
*
* @param {Object} cfg

View File

@ -73,7 +73,7 @@ export const shapeBase: ShapeOptions = {
fontFamily:
typeof window !== 'undefined'
? window.getComputedStyle(document.body, null).getPropertyValue('font-family') ||
'Arial, sans-serif'
'Arial, sans-serif'
: 'Arial, sans-serif',
},
},
@ -82,7 +82,7 @@ export const shapeBase: ShapeOptions = {
fontFamily:
typeof window !== 'undefined'
? window.getComputedStyle(document.body, null).getPropertyValue('font-family') ||
'Arial, sans-serif'
'Arial, sans-serif'
: 'Arial, sans-serif',
},
},
@ -114,7 +114,7 @@ export const shapeBase: ShapeOptions = {
* @param group
* @param keyShape
*/
afterDraw(cfg?: ModelConfig, group?: IGroup, keyShape?: IShape) { },
afterDraw(cfg?: ModelConfig, group?: IGroup, keyShape?: IShape) {},
drawShape(cfg?: ModelConfig, group?: IGroup): IShape {
return null as any;
},
@ -335,7 +335,7 @@ export const shapeBase: ShapeOptions = {
},
// update(cfg, item) // 默认不定义
afterUpdate(cfg?: ModelConfig, item?: Item) { },
afterUpdate(cfg?: ModelConfig, item?: Item) {},
/**
* draw
* selectedactive

View File

@ -50,7 +50,7 @@ describe('view', () => {
graph.render();
bbox = graph.get('canvas').getCanvasBBox();
console.log(bbox)
console.log(bbox);
expect(numberEqual(bbox.x, 90, 1)).toBe(true);
expect(numberEqual(bbox.maxX, 410, 1)).toBe(true);
@ -78,7 +78,7 @@ describe('view', () => {
graph.render();
graph.fitView([50, 50]);
const bbox = graph.get('canvas').getCanvasBBox();
console.log(bbox)
console.log(bbox);
expect(numberEqual(bbox.x, 116, 1)).toBe(true);
expect(numberEqual(bbox.y, 50)).toBe(true);
expect(numberEqual(bbox.width, 266, 1)).toBe(true);

View File

@ -16,9 +16,9 @@ class Graph extends AbstractGraph {
super(cfg);
}
initEventController() { }
initEventController() {}
initLayoutController() { }
initLayoutController() {}
initCanvas() {
let container: string | HTMLElement | Element | null = this.get('container');
@ -48,7 +48,7 @@ class Graph extends AbstractGraph {
this.set('canvas', canvas);
}
initPlugins() { }
initPlugins() {}
}
describe('graph', () => {

View File

@ -6,9 +6,9 @@ export default class Graph extends AbstractGraph {
super(cfg);
}
initEventController() { }
initEventController() {}
initLayoutController() { }
initLayoutController() {}
initCanvas() {
let container: string | HTMLElement | Element | null = this.get('container');
@ -38,5 +38,5 @@ export default class Graph extends AbstractGraph {
this.set('canvas', canvas);
}
initPlugins() { }
initPlugins() {}
}

View File

@ -251,6 +251,5 @@ describe('shape node test', () => {
it('clear', () => {
canvas.destroy();
});
});
});

View File

@ -222,6 +222,5 @@ describe('circle test', () => {
graph.destroy();
expect(graph.destroyed).toBe(true);
});
});
});

View File

@ -110,7 +110,7 @@ describe('rect test', () => {
},
});
const group = node.get('group');
console.log(group)
console.log(group);
expect(group.getCount()).toEqual(2);
const keyShape = node.getKeyShape();
expect(keyShape.attr('width')).toBe(30);