import { CanvasRenderingTarget2D } from 'fancy-canvas'; import { IPrimitivePaneRenderer } from 'lightweight-charts'; import { ViewPoint } from './pane-view'; import { positionsBox } from './helpers/dimensions/positions'; export class _CLASSNAME_PaneRenderer implements IPrimitivePaneRenderer { _p1: ViewPoint; _p2: ViewPoint; _fillColor: string; constructor(p1: ViewPoint, p2: ViewPoint, fillColor: string) { this._p1 = p1; this._p2 = p2; this._fillColor = fillColor; } draw(target: CanvasRenderingTarget2D) { target.useBitmapCoordinateSpace(scope => { if ( this._p1.x === null || this._p1.y === null || this._p2.x === null || this._p2.y === null ) return; const ctx = scope.context; const horizontalPositions = positionsBox( this._p1.x, this._p2.x, scope.horizontalPixelRatio ); const verticalPositions = positionsBox( this._p1.y, this._p2.y, scope.verticalPixelRatio ); ctx.fillStyle = this._fillColor; ctx.fillRect( horizontalPositions.position, verticalPositions.position, horizontalPositions.length, verticalPositions.length ); }); } }