mirror of
https://gitee.com/antv/g6.git
synced 2024-11-30 02:38:20 +08:00
refactor(pc):import pc-plugins into pc
This commit is contained in:
parent
d1672380d1
commit
7b719f8553
@ -75,6 +75,7 @@
|
||||
"@antv/g-svg": "^0.5.1",
|
||||
"@antv/g-webgpu": "^0.5.1",
|
||||
"@antv/g6-core": "*",
|
||||
"@antv/g6-plugins": "*",
|
||||
"@antv/algorithm": "^0.0.4",
|
||||
"@antv/hierarchy": "^0.6.2",
|
||||
"@antv/layout": "^0.0.10",
|
||||
|
@ -6,20 +6,20 @@ import TreeGraph from './graph/tree-graph';
|
||||
import { Layout, registerLayout } from './layout';
|
||||
import Global from './global';
|
||||
import Util from './util';
|
||||
// import Plugins from './plugins';
|
||||
import Plugins from './plugins';
|
||||
import * as Algorithm from '@antv/algorithm';
|
||||
|
||||
// const registerLayout = Layout.registerLayout;
|
||||
// const Minimap = Plugins.Minimap;
|
||||
// const Grid = Plugins.Grid;
|
||||
// const Bundling = Plugins.Bundling;
|
||||
// const Menu = Plugins.Menu;
|
||||
// const Fisheye = Plugins.Fisheye;
|
||||
// const ToolBar = Plugins.ToolBar;
|
||||
// const Tooltip = Plugins.Tooltip;
|
||||
// const TimeBar = Plugins.TimeBar;
|
||||
// const ImageMinimap = Plugins.ImageMinimap;
|
||||
// const EdgeFilterLens = Plugins.EdgeFilterLens;
|
||||
const Minimap = Plugins.Minimap;
|
||||
const Grid = Plugins.Grid;
|
||||
const Bundling = Plugins.Bundling;
|
||||
const Menu = Plugins.Menu;
|
||||
const Fisheye = Plugins.Fisheye;
|
||||
const ToolBar = Plugins.ToolBar;
|
||||
const Tooltip = Plugins.Tooltip;
|
||||
const TimeBar = Plugins.TimeBar;
|
||||
const ImageMinimap = Plugins.ImageMinimap;
|
||||
const EdgeFilterLens = Plugins.EdgeFilterLens;
|
||||
|
||||
export * from '@antv/g6-core';
|
||||
export { IGraph } from './interface/graph';
|
||||
@ -34,18 +34,18 @@ export {
|
||||
Layout,
|
||||
Global,
|
||||
// registerLayout,
|
||||
// Minimap,
|
||||
// Grid,
|
||||
// Bundling,
|
||||
// Menu,
|
||||
// Fisheye,
|
||||
Minimap,
|
||||
Grid,
|
||||
Bundling,
|
||||
Menu,
|
||||
Fisheye,
|
||||
// registerBehavior,
|
||||
// Algorithm,
|
||||
// ToolBar,
|
||||
// Tooltip,
|
||||
// TimeBar,
|
||||
// ImageMinimap,
|
||||
// EdgeFilterLens,
|
||||
Algorithm,
|
||||
ToolBar,
|
||||
Tooltip,
|
||||
TimeBar,
|
||||
ImageMinimap,
|
||||
EdgeFilterLens,
|
||||
};
|
||||
|
||||
export default {
|
||||
@ -60,16 +60,16 @@ export default {
|
||||
registerCombo,
|
||||
registerEdge,
|
||||
registerNode,
|
||||
// Minimap: Plugins.Minimap,
|
||||
// Grid: Plugins.Grid,
|
||||
// Bundling: Plugins.Bundling,
|
||||
// Menu: Plugins.Menu,
|
||||
// ToolBar: Plugins.ToolBar,
|
||||
// Tooltip: Plugins.Tooltip,
|
||||
// TimeBar,
|
||||
// Fisheye,
|
||||
// ImageMinimap,
|
||||
// EdgeFilterLens,
|
||||
Minimap: Plugins.Minimap,
|
||||
Grid: Plugins.Grid,
|
||||
Bundling: Plugins.Bundling,
|
||||
Menu: Plugins.Menu,
|
||||
ToolBar: Plugins.ToolBar,
|
||||
Tooltip: Plugins.Tooltip,
|
||||
TimeBar,
|
||||
Fisheye,
|
||||
ImageMinimap,
|
||||
EdgeFilterLens,
|
||||
Algorithm,
|
||||
// Arrow,
|
||||
// Marker,
|
||||
|
@ -1,110 +0,0 @@
|
||||
import { wrapBehavior, each, deepMix } from '@antv/util';
|
||||
import Graph from '../graph/graph';
|
||||
import { IG6GraphEvent } from '@antv/g6-core';
|
||||
|
||||
export interface IPluginBaseConfig {
|
||||
container?: HTMLDivElement | string | null;
|
||||
className?: string;
|
||||
graph?: Graph;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface EventMapType {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export default abstract class PluginBase {
|
||||
private _events: EventMapType;
|
||||
|
||||
public _cfgs: IPluginBaseConfig;
|
||||
|
||||
public destroyed: boolean;
|
||||
|
||||
/**
|
||||
* 插件基类的构造函数
|
||||
* @param cfgs 插件的配置项
|
||||
*/
|
||||
constructor(cfgs?: IPluginBaseConfig) {
|
||||
this._cfgs = deepMix(this.getDefaultCfgs(), cfgs);
|
||||
this._events = {};
|
||||
this.destroyed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认的插件配置
|
||||
*/
|
||||
public getDefaultCfgs() {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化插件
|
||||
* @param graph Graph 实例
|
||||
*/
|
||||
public initPlugin(graph: Graph) {
|
||||
const self = this;
|
||||
self.set('graph', graph);
|
||||
|
||||
const events = self.getEvents();
|
||||
|
||||
const bindEvents: EventMapType = {};
|
||||
|
||||
each(events, (v, k) => {
|
||||
const event = wrapBehavior(self, v) as (e: IG6GraphEvent) => void;
|
||||
bindEvents[k] = event;
|
||||
graph.on(k, event);
|
||||
});
|
||||
this._events = bindEvents;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化方法,供子类实现
|
||||
*/
|
||||
public init() {}
|
||||
|
||||
/**
|
||||
* 获取插件中的事件和事件处理方法,供子类实现
|
||||
*/
|
||||
public getEvents() {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置项中的某个值
|
||||
* @param key 键值
|
||||
*/
|
||||
public get(key: string) {
|
||||
return this._cfgs[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定的值存储到 cfgs 中
|
||||
* @param key 键值
|
||||
* @param val 设置的值
|
||||
*/
|
||||
public set(key: string, val: any) {
|
||||
this._cfgs[key] = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁方法,供子类复写
|
||||
*/
|
||||
public destroy() {}
|
||||
|
||||
/**
|
||||
* 销毁插件
|
||||
*/
|
||||
public destroyPlugin() {
|
||||
this.destroy();
|
||||
const graph = this.get('graph');
|
||||
const events = this._events;
|
||||
each(events, (v, k) => {
|
||||
graph.off(k, v);
|
||||
});
|
||||
(this._events as EventMapType | null) = null;
|
||||
(this._cfgs as IPluginBaseConfig | null) = null;
|
||||
this.destroyed = true;
|
||||
}
|
||||
}
|
1
packages/pc/src/plugins/index.tsx
Normal file
1
packages/pc/src/plugins/index.tsx
Normal file
@ -0,0 +1 @@
|
||||
export * as default from '@antv/g6-plugins';
|
Loading…
Reference in New Issue
Block a user