Skip to content

Commit

Permalink
remove circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekucera committed Dec 2, 2024
1 parent aef0ba4 commit 68ebbb6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/extensions/renderer/canvas/webgl/atlas.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as util from './webgl-util';
import * as cyutil from '../../../../util';
import { mat3 } from 'gl-matrix';
import { initRenderTypeDefaults } from './drawing-redraw-webgl';

// A "texture atlas" is a big image/canvas, and sections of it are used as textures for nodes/labels.

Expand Down Expand Up @@ -459,7 +458,7 @@ export class AtlasManager {

addRenderType(type, renderTypeOptions) {
const atlasCollection = new AtlasCollection(this.r, this.globalOptions);
const typeOpts = initRenderTypeDefaults(renderTypeOptions);
const typeOpts = renderTypeOptions;
this.renderTypes.set(type, cyutil.extend( { type, atlasCollection}, typeOpts ) );
}

Expand Down
17 changes: 17 additions & 0 deletions src/extensions/renderer/canvas/webgl/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defaults } from '../../../../util';

export const RENDER_TARGET = {
SCREEN: { name: 'screen', screen: true },
PICKING: { name: 'picking', picking: true },
};

export const renderDefaults = defaults({
getKey: null,
drawElement: null,
getBoundingBox: null,
getRotation: null,
getRotationPoint: null,
getRotationOffset: null,
isVisible: null,
getPadding: null,
});
5 changes: 2 additions & 3 deletions src/extensions/renderer/canvas/webgl/drawing-edges-webgl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as util from './webgl-util';
import { mat3 } from 'gl-matrix';
import { AtlasManager } from './atlas';
import { RENDER_TARGET } from './drawing-redraw-webgl';
import { initRenderTypeDefaults } from './drawing-redraw-webgl';
import { RENDER_TARGET } from './defaults';

// The canvas renderer uses a mask to remove the part of the edge line that's under
// a translucent edge arrow (see the part of CRp.drawArrowhead that uses globalCompositeOperation).
Expand Down Expand Up @@ -33,7 +32,7 @@ export class EdgeDrawing {
this.atlasSize = opts.webglTexSize;
this.bgColor = opts.bgColor;

this.labelOpts = initRenderTypeDefaults(labelRenderOptions);
this.labelOpts = labelRenderOptions;

// with the current strategy we don't have enough shader attributes for wrapped textures
opts.enableWrapping = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// For rendering nodes
import * as util from './webgl-util';
import { AtlasManager } from './atlas';
import { RENDER_TARGET } from './drawing-redraw-webgl';
import { RENDER_TARGET } from './defaults';


export class NodeDrawing {
Expand Down
39 changes: 12 additions & 27 deletions src/extensions/renderer/canvas/webgl/drawing-redraw-webgl.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import { EdgeDrawing } from './drawing-edges-webgl';
import { NodeDrawing } from './drawing-nodes-webgl';
import { RENDER_TARGET, renderDefaults } from './defaults';
import { OverlayUnderlayRenderer } from './drawing-overlay';
import * as util from './webgl-util';
import * as eleTextureCache from '../ele-texture-cache';
import { defaults, debounce } from '../../../../util';
import { debounce } from '../../../../util';
import { color2tuple } from '../../../../util/colors';
import { mat3 } from 'gl-matrix';



export const RENDER_TARGET = {
SCREEN: { name: 'screen', screen: true },
PICKING: { name: 'picking', picking: true },
};

export const initRenderTypeDefaults = defaults({
getKey: null,
drawElement: null,
getBoundingBox: null,
getRotation: null,
getRotationPoint: null,
getRotationOffset: null,
isVisible: null,
getPadding: null,
});

function getBGColor(container) {
const cssColor = (container && container.style && container.style.backgroundColor) || 'white';
return color2tuple(cssColor);
Expand Down Expand Up @@ -63,51 +48,51 @@ CRp.initWebgl = function(opts, fns) {
return label && label.value;
};

r.edgeDrawing = new EdgeDrawing(r, gl, opts, {
r.edgeDrawing = new EdgeDrawing(r, gl, opts, renderDefaults({
getKey: fns.getLabelKey,
getBoundingBox: fns.getLabelBox,
drawElement: fns.drawLabel,
getRotation: getLabelRotation,
getRotationPoint: fns.getLabelRotationPoint,
getRotationOffset: fns.getLabelRotationOffset,
isVisible: isLabelVisible,
});
}));

r.nodeDrawing = new NodeDrawing(r, gl, opts);
const our = new OverlayUnderlayRenderer(r);

r.nodeDrawing.addRenderType('node-body', {
r.nodeDrawing.addRenderType('node-body', renderDefaults({
getKey: fns.getStyleKey,
getBoundingBox: fns.getElementBox,
drawElement: fns.drawElement,
isVisible: ele => ele.visible(),
});
}));

r.nodeDrawing.addRenderType('node-label', {
r.nodeDrawing.addRenderType('node-label', renderDefaults({
getKey: fns.getLabelKey,
getBoundingBox: fns.getLabelBox,
drawElement: fns.drawLabel,
getRotation: getLabelRotation,
getRotationPoint: fns.getLabelRotationPoint,
getRotationOffset: fns.getLabelRotationOffset,
isVisible: isLabelVisible,
});
}));

r.nodeDrawing.addRenderType('node-overlay', {
r.nodeDrawing.addRenderType('node-overlay', renderDefaults({
getBoundingBox: fns.getElementBox,
getKey: ele => our.getStyleKey('overlay', ele),
drawElement: (ctx, ele, bb) => our.draw('overlay', ctx, ele, bb),
isVisible: ele => our.isVisible('overlay', ele),
getPadding: ele => our.getPadding('overlay', ele),
});
}));

r.nodeDrawing.addRenderType('node-underlay', {
r.nodeDrawing.addRenderType('node-underlay', renderDefaults({
getBoundingBox: fns.getElementBox,
getKey: ele => our.getStyleKey('underlay', ele),
drawElement: (ctx, ele, bb) => our.draw('underlay', ctx, ele, bb),
isVisible: ele => our.isVisible('underlay', ele),
getPadding: ele => our.getPadding('underlay', ele),
});
}));

// this is a very simplistic way of triggering garbage collection
const setGCFlag = debounce(() => {
Expand Down

0 comments on commit 68ebbb6

Please sign in to comment.