mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 11:48:29 +08:00
feat: update the getConstructor()
This commit is contained in:
parent
39db43e941
commit
42c06c60b6
@ -32,13 +32,6 @@ class Base extends EventEmitter {
|
||||
this.removeAllListeners();
|
||||
this.destroyed = true;
|
||||
}
|
||||
|
||||
getConstructor(CanvasCons, SvgCons, render) {
|
||||
if (render === 'svg') {
|
||||
return SvgCons;
|
||||
}
|
||||
return CanvasCons;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Base;
|
||||
|
27
src/graph.js
27
src/graph.js
@ -189,7 +189,6 @@ class Graph extends Base {
|
||||
const width = this.get('width');
|
||||
const height = this.get('height');
|
||||
const fontFamily = this.get('fontFamily');
|
||||
const render = this.get('render');
|
||||
const canvasCfg = {
|
||||
width,
|
||||
height,
|
||||
@ -198,20 +197,10 @@ class Graph extends Base {
|
||||
containerDOM: graphContainer
|
||||
};
|
||||
|
||||
const Constructor = this.getConstructor(Canvas, SVG, render);
|
||||
const Constructor = this.getConstructor(Canvas, SVG);
|
||||
const canvas = new Constructor(canvasCfg);
|
||||
const frontCanvas = new Constructor(canvasCfg);
|
||||
|
||||
// let canvas;
|
||||
// let frontCanvas;
|
||||
// if (render === 'svg') {
|
||||
// canvas = new SVG(canvasCfg);
|
||||
// frontCanvas = new SVG(canvasCfg);
|
||||
// } else {
|
||||
// canvas = new Canvas(canvasCfg);
|
||||
// frontCanvas = new Canvas(canvasCfg);
|
||||
// }
|
||||
|
||||
const frontEl = frontCanvas.get('el');
|
||||
const htmlElementContaniner = graphContainer.appendChild(Util.createDOM('<div class="graph-container-html-Elements"></div>'));
|
||||
canvas.on('beforedraw', () => {
|
||||
@ -236,7 +225,7 @@ class Graph extends Base {
|
||||
mouseEventWarrper.setAttribute('tabindex', TAB_INDEX);
|
||||
canvas.set('htmlElementContaniner', htmlElementContaniner);
|
||||
|
||||
const RootGroup = this.getConstructor(CanvasRootGroup, SvgRootGroup, render);
|
||||
const RootGroup = this.getConstructor(CanvasRootGroup, SvgRootGroup);
|
||||
const rootGroup = canvas.addGroup(RootGroup);
|
||||
const frontRootGroup = frontCanvas.addGroup(RootGroup);
|
||||
|
||||
@ -363,6 +352,18 @@ class Graph extends Base {
|
||||
item && !item.destroyed && item.destroy();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param {function} CanvasCons option 1
|
||||
* @param {function} SvgCons option 2
|
||||
* @return {function} function
|
||||
*/
|
||||
getConstructor(CanvasCons, SvgCons) {
|
||||
const render = this.get('render');
|
||||
if (render === 'svg') {
|
||||
return SvgCons;
|
||||
}
|
||||
return CanvasCons;
|
||||
}
|
||||
/**
|
||||
* @param {string} type item type
|
||||
* @param {object} model data model
|
||||
|
@ -59,7 +59,7 @@ module.exports = {
|
||||
const graphPixelRatio = graphCanvas.get('pixelRatio');
|
||||
tranScale = pixelRatio / graphPixelRatio;
|
||||
graphCanvas.scale(tranScale, tranScale);
|
||||
const Constructor = graph.getConstructor(Canvas, SVG, graph.get('render'));
|
||||
const Constructor = graph.getConstructor(Canvas, SVG);
|
||||
canvas = new Constructor({
|
||||
containerDOM,
|
||||
width: width * tranScale,
|
||||
|
@ -1,6 +1,6 @@
|
||||
const G6 = require('../../../src/index');
|
||||
const Global = require('../../../src/global');
|
||||
const Graph = G6.Graph;
|
||||
const Graph = G6.Graph;
|
||||
const expect = require('chai').expect;
|
||||
const Util = require('../../../src/util/');
|
||||
const data = require('../../fixtures/sample-graph-data.json');
|
||||
|
Loading…
Reference in New Issue
Block a user