mirror of
https://gitee.com/antv/g6.git
synced 2024-11-29 18:28:19 +08:00
fix: addBehavior support object and string
This commit is contained in:
parent
d3e2ae167a
commit
1e4d745ce2
@ -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",
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -30,7 +30,7 @@ export {
|
||||
registerEdge,
|
||||
registerBehavior,
|
||||
AbstractLayout,
|
||||
AbstractEvent
|
||||
AbstractEvent,
|
||||
};
|
||||
|
||||
export * from './types';
|
||||
|
@ -350,17 +350,17 @@ export default class ItemBase implements IItemBase {
|
||||
/**
|
||||
* 渲染前的逻辑,提供给子类复写
|
||||
*/
|
||||
protected beforeDraw() { }
|
||||
protected beforeDraw() {}
|
||||
|
||||
/**
|
||||
* 渲染后的逻辑,提供给子类复写
|
||||
*/
|
||||
protected afterDraw() { }
|
||||
protected afterDraw() {}
|
||||
|
||||
/**
|
||||
* 更新后做一些工作
|
||||
*/
|
||||
protected afterUpdate() { }
|
||||
protected afterUpdate() {}
|
||||
|
||||
/**
|
||||
* draw shape
|
||||
|
@ -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 节点、边的配置项
|
||||
|
@ -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 方法中实现
|
||||
* 单图形的节点仅考虑 selected、active 状态,有其他状态需求的用户自己复写这个方法
|
||||
|
@ -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);
|
||||
|
@ -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', () => {
|
||||
|
@ -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() {}
|
||||
}
|
||||
|
@ -251,6 +251,5 @@ describe('shape node test', () => {
|
||||
it('clear', () => {
|
||||
canvas.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -222,6 +222,5 @@ describe('circle test', () => {
|
||||
graph.destroy();
|
||||
expect(graph.destroyed).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user