From 559220b6980f2b310f7b3365141d9a8aafbd7633 Mon Sep 17 00:00:00 2001 From: Yanyan-Wang Date: Wed, 19 May 2021 12:04:28 +0800 Subject: [PATCH] lint: fix lint --- packages/mobile/.eslintrc.js | 1 + .../mobile/src/behavior/activate-relations.ts | 12 +++---- packages/mobile/src/behavior/drag-canvas.ts | 2 +- packages/mobile/src/behavior/drag-node.ts | 10 +++--- packages/mobile/src/behavior/zoom-canvas.ts | 10 ++---- packages/mobile/src/graph/controller/event.ts | 4 +-- .../mobile/src/graph/controller/layout.ts | 2 +- packages/mobile/src/graph/graph.ts | 2 +- packages/mobile/src/index.ts | 36 ++++++++++--------- packages/mobile/src/interface/graph.ts | 36 +++++++++---------- packages/mobile/src/util/index.ts | 1 + 11 files changed, 58 insertions(+), 58 deletions(-) diff --git a/packages/mobile/.eslintrc.js b/packages/mobile/.eslintrc.js index daaa408841..29b7b55a6c 100644 --- a/packages/mobile/.eslintrc.js +++ b/packages/mobile/.eslintrc.js @@ -22,6 +22,7 @@ module.exports = { 'guard-for-in': 0, 'no-restricted-globals': 0, 'max-classes-per-file': 0, + "@typescript-eslint/no-this-alias": 0, // 后面需要去掉 'no-restricted-syntax': 0, 'prefer-spread': 0, diff --git a/packages/mobile/src/behavior/activate-relations.ts b/packages/mobile/src/behavior/activate-relations.ts index 68a297ce2f..176b0fbb12 100644 --- a/packages/mobile/src/behavior/activate-relations.ts +++ b/packages/mobile/src/behavior/activate-relations.ts @@ -18,15 +18,15 @@ export default { }; }, setAllItemStates(e: IG6GraphEvent) { + const self = this; const item: INode = e.item as INode; - const graph = this.graph; - this.item = item; - if (!this.shouldUpdate(e.item, { event: e, action: 'activate' })) { + const graph = self.graph; + self.item = item; + if (!self.shouldUpdate(e.item, { event: e, action: 'activate' })) { return; } - const self = this; - const activeState = this.activeState; - const inactiveState = this.inactiveState; + const activeState = self.activeState; + const inactiveState = self.inactiveState; const nodes = graph.getNodes(); const edges = graph.getEdges(); const nodeLength = nodes.length; diff --git a/packages/mobile/src/behavior/drag-canvas.ts b/packages/mobile/src/behavior/drag-canvas.ts index 62a4d8c37f..73bff2b286 100644 --- a/packages/mobile/src/behavior/drag-canvas.ts +++ b/packages/mobile/src/behavior/drag-canvas.ts @@ -174,7 +174,7 @@ export default { this.updateViewport(e); } e.type = 'dragend'; - //graph.emit('canvas:dragend', e); + // graph.emit('canvas:dragend', e); this.endDrag(); }, endDrag() { diff --git a/packages/mobile/src/behavior/drag-node.ts b/packages/mobile/src/behavior/drag-node.ts index bd9f15b466..1f25515b1f 100644 --- a/packages/mobile/src/behavior/drag-node.ts +++ b/packages/mobile/src/behavior/drag-node.ts @@ -252,10 +252,10 @@ export default { * @param evt */ onDropNode(evt: IG6GraphEvent) { - if (!this.targets || this.targets.length === 0) return; const self = this; + if (!self.targets || self.targets.length === 0) return; const item = evt.item as INode; - this.updatePositions(evt); + self.updatePositions(evt); const graph: IGraph = self.graph; const comboId = item.getModel().comboId as string; @@ -265,7 +265,7 @@ export default { if (self.comboActiveState) { graph.setItemState(combo, self.comboActiveState, false); } - this.targets.map((node: INode) => { + self.targets.map((node: INode) => { const nodeModel = node.getModel(); if (comboId !== nodeModel.comboId) { graph.updateComboTree(node, comboId); @@ -273,7 +273,7 @@ export default { }); graph.updateCombo(combo as ICombo); } else { - this.targets.map((node: INode) => { + self.targets.map((node: INode) => { const model = node.getModel(); if (model.comboId) { graph.updateComboTree(node); @@ -283,7 +283,7 @@ export default { // 将节点拖动到另外个节点上面,emit 事件抛出当前操作的节点及目标节点 graph.emit('dragnodeend', { - items: this.targets, + items: self.targets, targetItem: item, }); }, diff --git a/packages/mobile/src/behavior/zoom-canvas.ts b/packages/mobile/src/behavior/zoom-canvas.ts index 0a653b82ac..f5102ba84c 100644 --- a/packages/mobile/src/behavior/zoom-canvas.ts +++ b/packages/mobile/src/behavior/zoom-canvas.ts @@ -1,8 +1,4 @@ -import { G6Event, IG6GraphEvent } from '@antv/g6-core'; -import { mat3 } from '@antv/matrix-util'; -import { clone } from '@antv/util'; - -const DELTA = 0.05; +import { G6Event } from '@antv/g6-core'; export default { firstScale: null, @@ -37,8 +33,8 @@ export default { }; }, onPinch(evt) { - evt.preventDefault || evt.preventDefault(); - evt.originalEvent.preventDefault || evt.originalEvent.preventDefault(); + if (evt.preventDefault) evt.preventDefault(); + if (evt.originalEvent.preventDefault) evt.originalEvent.preventDefault(); const pointers = evt.originalEvent.pointers; if (pointers.length < 2) return; diff --git a/packages/mobile/src/graph/controller/event.ts b/packages/mobile/src/graph/controller/event.ts index fdc86e6839..d2ed1b59c9 100644 --- a/packages/mobile/src/graph/controller/event.ts +++ b/packages/mobile/src/graph/controller/event.ts @@ -1,8 +1,8 @@ -import { addEventListener } from '@antv/dom-util'; import { ICanvas, IGroup, IShape } from '@antv/g-base'; -import { each, isNil, wrapBehavior } from '@antv/util'; +import { each, wrapBehavior } from '@antv/util'; import { AbstractEvent, IG6GraphEvent, Matrix, Item, Util } from '@antv/g6-core'; import Graph from '../graph'; + const { cloneEvent, isViewportChanged } = Util; type Fun = () => void; diff --git a/packages/mobile/src/graph/controller/layout.ts b/packages/mobile/src/graph/controller/layout.ts index 47dc8f14c2..1cd0a42f98 100644 --- a/packages/mobile/src/graph/controller/layout.ts +++ b/packages/mobile/src/graph/controller/layout.ts @@ -138,7 +138,7 @@ export default class LayoutController extends AbstractLayout { private execLayoutMethod(layoutCfg, order): Promise { return new Promise((reslove, reject) => { const { graph } = this; - let layoutType = layoutCfg.type; + const layoutType = layoutCfg.type; // 每个布局方法都需要注册 layoutCfg.onLayoutEnd = () => { diff --git a/packages/mobile/src/graph/graph.ts b/packages/mobile/src/graph/graph.ts index 21db15284a..fa63e39273 100644 --- a/packages/mobile/src/graph/graph.ts +++ b/packages/mobile/src/graph/graph.ts @@ -261,7 +261,7 @@ export default class Graph extends AbstractGraph implements IGraph { context.globalCompositeOperation = compositeOperation; } } - callback && callback(dataURL); + if (callback) callback(dataURL); }, 16); } diff --git a/packages/mobile/src/index.ts b/packages/mobile/src/index.ts index d57f7f1c91..708b1b36e2 100644 --- a/packages/mobile/src/index.ts +++ b/packages/mobile/src/index.ts @@ -16,6 +16,23 @@ import Util from './util'; import './element'; import './behavior'; +const G6 = { + version: Global.version, + Graph, + Util, + Layout, + registerLayout, + Global, + registerBehavior, + registerCombo, + registerEdge, + registerNode, + Algorithm, + Arrow, + Marker, + Shape +}; + function registerExtenderWrapper( registerExtender: (registerName: T1, registerFunction: T2, global: Object) => Object, ): (registerName: T1, registerFunction: T2) => Object { @@ -26,23 +43,8 @@ function registerExtenderWrapper( const registerGraph = registerExtenderWrapper(oRegisterGraph); -const G6 = { - version: Global.version, - Graph, - Util, - Layout, - registerLayout, - registerGraph, - Global, - registerBehavior, - registerCombo, - registerEdge, - registerNode, - Algorithm, - Arrow, - Marker, - Shape, -}; +(G6 as any).registerGraph = registerGraph; + export * from '@antv/g6-core'; export * from './types'; diff --git a/packages/mobile/src/interface/graph.ts b/packages/mobile/src/interface/graph.ts index 74fe874467..0057227272 100644 --- a/packages/mobile/src/interface/graph.ts +++ b/packages/mobile/src/interface/graph.ts @@ -9,13 +9,13 @@ export interface IGraph extends IAbstractGraph { /** * 返回图表的 dataUrl 用于生成图片 */ - toDataURL(): string; + toDataURL: () => string; /** * 画布导出图片 * @param {String} name 图片的名称 */ - downloadImage(name?: string, type?: DataUrlType, backgroundColor?: string): void; + downloadImage: (name?: string, type?: DataUrlType, backgroundColor?: string) => void; /** * 导出包含全图的图片 @@ -23,11 +23,11 @@ export interface IGraph extends IAbstractGraph { * @param {String} type 图片类型,可选值:"image/png" | "image/jpeg" | "image/webp" | "image/bmp" * @param {Object} imageConfig 图片配置项,包括背景色和上下左右的 padding */ - downloadFullImage( + downloadFullImage: ( name?: string, type?: DataUrlType, imageConfig?: { backgroundColor?: string; padding?: number | number[] }, - ): void; + ) => void; /** * 返回整个图(包括超出可见区域的部分)的 dataUrl,用于生成图片 @@ -35,37 +35,37 @@ export interface IGraph extends IAbstractGraph { * @param {String} type 图片类型,可选值:"image/png" | "image/jpeg" | "image/webp" | "image/bmp" * @param {Object} imageConfig 图片配置项,包括背景色和上下左右的 padding */ - toFullDataURL( + toFullDataURL: ( callback: (res: string) => any, type?: DataUrlType, imageConfig?: { backgroundColor?: string; padding?: number | number[] }, - ): void; + ) => void; /** * 添加插件 * @param {object} plugin 插件实例 */ - addPlugin(plugin: PluginBase): void; + addPlugin: (plugin: PluginBase) => void; /** * 添加插件 * @param {object} plugin 插件实例 */ - removePlugin(plugin: PluginBase): void; + removePlugin: (plugin: PluginBase) => void; /** * 设置图片水印 * @param {string} imgURL 图片水印的url地址 * @param {WaterMarkerConfig} config 文本水印的配置项 */ - setImageWaterMarker(imgURL: string, config: WaterMarkerConfig); + setImageWaterMarker: (imgURL: string, config: WaterMarkerConfig) => void; /** * 设置文本水印 * @param {string[]} texts 水印的文本内容 * @param {WaterMarkerConfig} config 文本水印的配置项 */ - setTextWaterMarker(texts: string[], config?: WaterMarkerConfig); + setTextWaterMarker: (texts: string[], config?: WaterMarkerConfig) => void; } export interface ITreeGraph extends IGraph { @@ -74,20 +74,20 @@ export interface ITreeGraph extends IGraph { * @param {TreeGraphData} data 子树数据模型 * @param {string | Item} parent 子树的父节点id */ - addChild(data: TreeGraphData, parent: string | Item): void; + addChild: (data: TreeGraphData, parent: string | Item) => void; /** * 更新源数据,差量更新子树 * @param {TreeGraphData} data 子树数据模型 * @param {string} parent 子树的父节点id */ - updateChild(data: TreeGraphData, parent?: string): void; + updateChild: (data: TreeGraphData, parent?: string) => void; /** * 删除子树 * @param {string} id 子树根节点id */ - removeChild(id: string): void; + removeChild: (id: string) => void; /** * 根据id获取对应的源数据 @@ -95,14 +95,14 @@ export interface ITreeGraph extends IGraph { * @param {TreeGraphData | undefined} parent 从哪个节点开始寻找,为空时从根节点开始查找 * @return {TreeGraphData} 对应源数据 */ - findDataById(id: string, parent?: TreeGraphData | undefined): TreeGraphData | null; + findDataById: (id: string, parent?: TreeGraphData | undefined) => TreeGraphData | null; /** * 布局动画接口,用于数据更新时做节点位置更新的动画 * @param {TreeGraphData} data 更新的数据 * @param {function} onFrame 定义节点位置更新时如何移动 */ - layoutAnimate( + layoutAnimate: ( data: TreeGraphData, onFrame?: ( item: Item, @@ -110,18 +110,18 @@ export interface ITreeGraph extends IGraph { originAttrs?: ShapeStyle, data?: TreeGraphData, ) => unknown, - ): void; + ) => void; /** * 立即停止布局动画 */ - stopLayoutAnimate(): void; + stopLayoutAnimate: () => void; /** * 是否在布局动画 * @return {boolean} 是否有布局动画 */ - isLayoutAnimating(): boolean; + isLayoutAnimating: () => boolean; } export class G6GraphEvent extends GraphEvent implements IG6GraphEvent { diff --git a/packages/mobile/src/util/index.ts b/packages/mobile/src/util/index.ts index 74cf64a247..c51da19f61 100644 --- a/packages/mobile/src/util/index.ts +++ b/packages/mobile/src/util/index.ts @@ -1,6 +1,7 @@ import * as ColorUtil from './color'; import * as LayoutUtil from './layout'; import { Util } from '@antv/g6-core'; + const G6Util: any = { ...Util, ...ColorUtil, ...LayoutUtil }; export default G6Util;