refactor(pc):import pc-plugins into pc

This commit is contained in:
pomelo-nwu 2020-12-18 13:41:59 +08:00
parent d1672380d1
commit 7b719f8553
4 changed files with 34 additions and 142 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
export * as default from '@antv/g6-plugins';