g-plugin-canvas-renderer
Previous
g-plugin-device-renderer
Next
g-plugin-canvaskit-renderer
Loading...
Provides Canvas2D-based rendering capabilities.
The g-canvas renderer is built in by default, so there is no need to introduce it manually.
import { Renderer as CanvasRenderer } from '@antv/g-canvas';// Create a renderer with the plugin built inconst canvasRenderer = new CanvasRenderer();
When rendering the base graphics using CanvasRenderingContext2D, you can implement this interface after using g-plugin- canvas-path-generator to generate the graphical path, implement this interface to finish drawing the style.
export interface StyleRenderer {render: (context: CanvasRenderingContext2D,parsedStyle: ParsedBaseStyleProps,object: DisplayObject,renderingService: RenderingService,) => void;}
We provide different extension points for different types of graphics. For example, in g-plugin-rough-canvas-renderer, we use the API provided by rough.js for Circle to add a hand-drawn style.
@singleton({token: CanvasRenderer.CircleRendererContribution,})export class CircleRenderer implements CanvasRenderer.StyleRenderer {render(context: CanvasRenderingContext2D,parsedStyle: ParsedCircleStyleProps,object: DisplayObject<any, any>,) {const { r } = parsedStyle as ParsedCircleStyleProps;// rough.js use diameter instead of radius// @see https://github.com/rough-stuff/rough/wiki#circle-x-y-diameter--optionscontext.roughCanvas.circle(r.value, r.value, r.value * 2, generateRoughOptions(object));}}