Skip to content

Commit

Permalink
refactor: canvas add getRenderer API
Browse files Browse the repository at this point in the history
  • Loading branch information
Aarebecca committed Jul 15, 2024
1 parent 1dd1216 commit 39932e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/g6-extension-3d/src/elements/base-node-3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class BaseNode3D<S extends BaseNode3DStyleProps> extends BaseNod
public type = 'node-3d';

protected get plugin() {
const renderer = this.attributes.context!.canvas.renderers['main'];
const renderer = this.context.canvas.getRenderer('main');
const plugin = renderer.getPlugin('device-renderer');
return plugin as unknown as Plugin;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/g6/src/runtime/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ export class Canvas extends GCanvas {
return this.extends.layers;
}

/**
* <zh/> 获取渲染器
*
* <en/> Get renderer
* @param layer - <zh/> 图层 <en/> Layer
* @returns <zh/> 渲染器 <en/> Renderer
*/
public getRenderer(layer: CanvasLayer) {
return this.extends.renderers[layer];
}

constructor(config: CanvasConfig) {
const { renderer, background, cursor, ...restConfig } = config;
const renderers = createRenderers(renderer);
Expand Down

0 comments on commit 39932e3

Please sign in to comment.