| 20 | * This class is immutable (but has internal state) and shouldn't be extended. |
| 21 | */ |
| 22 | export class CanvasDrawer implements IDrawer { |
| 23 | |
| 24 | /** |
| 25 | * @param _context The context for a canvas that this drawer will draw to. |
| 26 | * @param _drawStep The draw step logic that actually draws. |
| 27 | */ |
| 28 | constructor(private _context: CanvasRenderingContext2D, private _drawStep: CanvasDrawStep) { |
| 29 | } |
| 30 | |
| 31 | // public for testing |
| 32 | public getDrawStep() { |
| 33 | return this._drawStep; |
| 34 | } |
| 35 | |
| 36 | public draw(data: any[], appliedDrawSteps: AppliedDrawStep[]) { |
| 37 | const projector = appliedDrawSteps[appliedDrawSteps.length - 1].attrToAppliedProjector; |
| 38 | |
| 39 | // don't support animations for now; just draw the last draw step immediately |
| 40 | this._context.save(); |
| 41 | this._drawStep(this._context, data, projector); |
| 42 | this._context.restore(); |
| 43 | } |
| 44 | |
| 45 | public getVisualPrimitives(): Element[] { |
| 46 | return []; |
| 47 | } |
| 48 | |
| 49 | public getVisualPrimitiveAtIndex(index: number): Element { |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | public remove() { |
| 54 | // NO op - canvas element owns the canvas; context is free |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | export const ContextStyleAttrs = [ |
| 59 | "fill-opacity", |
nothing calls this directly
no outgoing calls
no test coverage detected