Skip to content

Commit

Permalink
fix: 调整类型申明
Browse files Browse the repository at this point in the history
  • Loading branch information
baizn authored and Yanyan-Wang committed May 18, 2020
1 parent 9860d19 commit 3691cb5
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 177 deletions.
2 changes: 1 addition & 1 deletion src/behavior/click-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import each from '@antv/util/lib/each';
import { G6Event, IG6GraphEvent } from '../types';

const DEFAULT_TRIGGER = 'shift';
const ALLOW_EVENTS = ['shift', 'ctrl', 'alt', 'control'];
const ALLOW_EVENTS = ['shift', 'ctrl', 'alt', 'control'];

export default {
getDefaultCfg(): object {
Expand Down
76 changes: 38 additions & 38 deletions src/graph/controller/customGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ export default class CustomGroup {
// 更新群组及属性样式
this.setDeletageGroupByStyle(groupId, nodeGroup, { width, height, x: cx, y: cy, r: lastR });
} else {

const rectPadding = paddingValue * defaultStyle.disCoefficient;

keyShape = nodeGroup.addShape('rect', {
attrs: {
...defaultStyle,
Expand Down Expand Up @@ -382,61 +382,61 @@ export default class CustomGroup {
* @param {string} parentId 父节点的键值
* @return {array} 转成的树形结构数据
*/
public flatToTree(data, value = 'id', parentId = 'parentId') {
const children = 'children';
const valueMap = [];
const tree = [];

data.forEach(v => {
valueMap[v[value]] = v;
});

data.forEach(v => {
const parent = valueMap[v[parentId]];
if (parent) {
!parent[children] && (parent[children] = []);
parent[children].push(v);
} else {
tree.push(v);
}
});
public flatToTree(data, value = 'id', parentId = 'parentId') {
const children = 'children';
const valueMap = [];
const tree = [];

return tree;
}
data.forEach(v => {
valueMap[v[value]] = v;
});

data.forEach(v => {
const parent = valueMap[v[parentId]];
if (parent) {
!parent[children] && (parent[children] = []);
parent[children].push(v);
} else {
tree.push(v);
}
});

return tree;
}

/**
* 当group中含有group时,获取padding值
* @param {string} groupId 节点分组ID
* @return {number} 在x和y方向上的偏移值
*/
public getGroupPadding(groupId: string): number {

const { graph } = this;
const { default: defaultStyle } = this.styles;
// 检测操作的群组中是否包括子群组
const groups = graph.get('groups');


// 计算每个 groupId 包含的组的数量
const currentGroups = groups.filter(g => g.parentId === groupId)

let count = 1
if(currentGroups.length > 0) {
if(!treeGroup) {
if (currentGroups.length > 0) {
if (!treeGroup) {
treeGroup = this.flatToTree(groups)
}

traverseTree(treeGroup[0], (param) => {
if(param.parentId === groupId && param.children) {
if (param.parentId === groupId && param.children) {
count += param.children.length
return true
}
})
}


const big = groups.filter(g => g.id === groupId && !g.parentId)
if(big.length > 0) {
if (big.length > 0) {
count += 1
}
const hasSubGroup = !!(groups.filter(g => g.parentId === groupId).length > 0);
Expand Down Expand Up @@ -638,7 +638,7 @@ export default class CustomGroup {
const { groupId } = model;
if (groupId && groupId !== id) {
// 存在群组,则隐藏
const currentGroup = this.getDeletageGroupById(groupId);
const currentGroup = this.getDeletageGroupById(groupId as string);
const { nodeGroup: currentNodeGroup } = currentGroup;
currentNodeGroup.hide();
}
Expand Down Expand Up @@ -816,7 +816,7 @@ export default class CustomGroup {
const { groupId } = model;
if (groupId && groupId !== id) {
// 存在群组,则显示
const currentGroup = this.getDeletageGroupById(groupId);
const currentGroup = this.getDeletageGroupById(groupId as string);
const { nodeGroup: currentNodeGroup } = currentGroup;
currentNodeGroup.show();
const hasHidden = currentNodeGroup.get('hasHidden');
Expand Down Expand Up @@ -1231,13 +1231,13 @@ export default class CustomGroup {
const { graph } = this;
const groupType = graph.get('groupType');
const groupNodes = graph.get('groupNodes');
const nodes = groupNodes[groupId];
const nodes = groupNodes[groupId as string];

// 拖出节点后,根据最新的节点数量,重新计算群组大小
// 如果只有一个节点,拖出后,则删除该组
if (nodes.length === 0) {
// step 1: 从groupNodes中删除
delete groupNodes[groupId];
delete groupNodes[groupId as string];

// step 2: 从groups数据中删除
const groupsData = graph.get('groups');
Expand All @@ -1251,7 +1251,7 @@ export default class CustomGroup {
} else {
const { x, y, width, height } = this.calculationGroupPosition(nodes);
// 检测操作的群组中是否包括子群组
const paddingValue = this.getGroupPadding(groupId);
const paddingValue = this.getGroupPadding(groupId as string);

let titleX = 0;
let titleY = 0;
Expand Down Expand Up @@ -1280,7 +1280,7 @@ export default class CustomGroup {
}

// 如果存在标题,则更新标题位置
this.updateGroupTitle(currentGroup, groupId, titleX, titleY);
this.updateGroupTitle(currentGroup, groupId as string, titleX, titleY);
}
this.setGroupStyle(keyShape, 'default');
}
Expand Down
4 changes: 2 additions & 2 deletions src/graph/controller/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ export default class ItemController {
* 更新节点或边
*
* @param {Item} item ID 或 实例
* @param {(EdgeConfig | NodeConfig)} cfg 数据模型
* @param {(EdgeConfig | Partial<NodeConfig>)} cfg 数据模型
* @returns
* @memberof ItemController
*/
public updateItem(item: Item | string, cfg: EdgeConfig | NodeConfig) {
public updateItem(item: Item | string, cfg: EdgeConfig | Partial<NodeConfig>) {
const { graph } = this;

if (isString(item)) {
Expand Down
22 changes: 11 additions & 11 deletions src/graph/controller/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import isString from '@antv/util/lib/is-string';
import Behavior from '../../behavior/behavior';
import { IBehavior } from '../../interface/behavior';
import { IGraph } from '../../interface/graph';
import { IMode, IModeType } from '../../types'
import { ModeType, Modes } from '../../types'
import Graph from '../graph';

export default class ModeController {
Expand All @@ -22,10 +22,10 @@ export default class ModeController {
* }
*
* @private
* @type {IMode}
* @type {Modes}
* @memberof Mode
*/
public modes: IMode;
public modes: Modes;

/**
* mode = 'drag-node'
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class ModeController {
this.currentBehaves = behaves;
}

private static mergeBehaviors(modeBehaviors: IModeType[], behaviors: IModeType[]): IModeType[] {
private static mergeBehaviors(modeBehaviors: ModeType[], behaviors: ModeType[]): ModeType[] {
each(behaviors, behavior => {
if (modeBehaviors.indexOf(behavior) < 0) {
if (isString(behavior)) {
Expand All @@ -95,8 +95,8 @@ export default class ModeController {
return modeBehaviors;
}

private static filterBehaviors(modeBehaviors: IModeType[], behaviors: IModeType[]): IModeType[] {
const result: IModeType[] = [];
private static filterBehaviors(modeBehaviors: ModeType[], behaviors: ModeType[]): ModeType[] {
const result: ModeType[] = [];
modeBehaviors.forEach(behavior => {
let type: string = '';
if (isString(behavior)) {
Expand Down Expand Up @@ -140,18 +140,18 @@ export default class ModeController {
/**
* 动态增加或删除 Behavior
*
* @param {IModeType[]} behaviors
* @param {(IModeType[] | IModeType)} modes
* @param {ModeType[]} behaviors
* @param {(ModeType[] | ModeType)} modes
* @param {boolean} isAdd
* @returns {Mode}
* @memberof Mode
*/
public manipulateBehaviors(
behaviors: IModeType[] | IModeType,
behaviors: ModeType[] | ModeType,
modes: string[] | string,
isAdd: boolean,
): ModeController {
let behaves: IModeType[];
let behaves: ModeType[];
if (!isArray(behaviors)) {
behaves = [behaviors];
} else {
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class ModeController {

public destroy() {
(this.graph as Graph | null) = null;
(this.modes as IMode | null) = null;
(this.modes as Modes | null) = null;
(this.currentBehaves as IBehavior[] | null) = null;
this.destroyed = true;
}
Expand Down
16 changes: 8 additions & 8 deletions src/graph/controller/state.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import each from '@antv/util/lib/each';
import isString from '@antv/util/lib/is-string';
import { Item, IStates } from '../../types';
import { Item, States } from '../../types';
import Graph from '../graph';
import { INode } from '../../interface/item';

interface ICachedStates {
enabled: IStates;
disabled: IStates;
interface CachedStates {
enabled: States;
disabled: States;
}

let timer: any = null;

export default class StateController {
private graph: Graph;

private cachedStates: ICachedStates;
private cachedStates: CachedStates;

public destroyed: boolean;

Expand Down Expand Up @@ -64,7 +64,7 @@ export default class StateController {
* @param {object} states
* @memberof State
*/
private static cacheState(item: Item, state: string, states: IStates) {
private static cacheState(item: Item, state: string, states: States) {
if (!states[state]) {
states[state] = [];
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export default class StateController {
* @memberof State
*/
public updateGraphStates() {
const states = this.graph.get('states') as IStates;
const states = this.graph.get('states') as States;
const { cachedStates } = this;

each(cachedStates.disabled, (val, key) => {
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class StateController {

public destroy() {
(this.graph as Graph | null) = null;
(this.cachedStates as ICachedStates | null) = null;
(this.cachedStates as CachedStates | null) = null;
if (timer) {
clearTimeout(timer);
}
Expand Down
19 changes: 11 additions & 8 deletions src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import {
Padding,
TreeGraphData,
ComboConfig,
ComboTree,
ModeOption,
ModeType,
States,
ComboTree
} from '../types';
import { getAllNodeInGroups } from '../util/group';
import { move, translate } from '../util/math';
Expand Down Expand Up @@ -89,7 +92,7 @@ export interface PrivateGraphOption extends GraphOptions {
* selected: [Node]
* }
*/
states: IStates;
states: States;
}

export default class Graph extends EventEmitter implements IGraph {
Expand Down Expand Up @@ -588,12 +591,12 @@ export default class Graph extends EventEmitter implements IGraph {

/**
* 新增行为
* @param {string | IModeOption | IModeType[]} behaviors 添加的行为
* @param {string | ModeOption | ModeType[]} behaviors 添加的行为
* @param {string | string[]} modes 添加到对应的模式
* @return {Graph} Graph
*/
public addBehaviors(
behaviors: string | IModeOption | IModeType[],
behaviors: string | ModeOption | ModeType[],
modes: string | string[],
): Graph {
const modeController: ModeController = this.get('modeController');
Expand All @@ -603,12 +606,12 @@ export default class Graph extends EventEmitter implements IGraph {

/**
* 移除行为
* @param {string | IModeOption | IModeType[]} behaviors 移除的行为
* @param {string | ModeOption | ModeType[]} behaviors 移除的行为
* @param {string | string[]} modes 从指定的模式中移除
* @return {Graph} Graph
*/
public removeBehaviors(
behaviors: string | IModeOption | IModeType[],
behaviors: string | ModeOption | ModeType[],
modes: string | string[],
): Graph {
const modeController: ModeController = this.get('modeController');
Expand Down Expand Up @@ -845,7 +848,7 @@ export default class Graph extends EventEmitter implements IGraph {
const newCombo: ComboTree = {
id: model.id as string,
depth: child.depth + 1,
...model
...model as ComboTree
}
if (child.children) child.children.push(newCombo);
else child.children = [newCombo];
Expand Down Expand Up @@ -1239,7 +1242,7 @@ export default class Graph extends EventEmitter implements IGraph {
});

each(this.get('edges'), (edge: IEdge) => {
edges.push(edge.getModel());
edges.push(edge.getModel() as EdgeConfig);
});

each(this.get('combos'), (combo: ICombo) => {
Expand Down
Loading

0 comments on commit 3691cb5

Please sign in to comment.