|
2 | 2 |
|
3 | 3 | import { ChartJs, Rect2D, SvgCanvas, SvgCanvas2DGradient } from "./deps.ts"; |
4 | 4 |
|
| 5 | +class ChartSvgCanvas extends SvgCanvas { |
| 6 | + public override clearRect(x: number, y: number, w: number, h: number): void { |
| 7 | + this.save(); |
| 8 | + this.fillStyle = "transparent"; |
| 9 | + this.fillRect(x, y, w, h); |
| 10 | + this.restore(); |
| 11 | + } |
| 12 | + |
| 13 | + public resetTransform() { |
| 14 | + this.setTransform(1, 0, 0, 1, 0, 0); |
| 15 | + } |
| 16 | +} |
| 17 | + |
5 | 18 | /** Underlying ChartJS defaults which can be modified. */ |
6 | 19 | export const defaults: ChartJs.Defaults = ChartJs.defaults; |
7 | 20 | /** Underlying ChartJS plugins. */ |
@@ -80,18 +93,13 @@ export function chart< |
80 | 93 | responsive: false, |
81 | 94 | }); |
82 | 95 |
|
83 | | - const ctx: SvgCanvas & SvgCanvasExtras = new SvgCanvas(); |
| 96 | + const ctx: ChartSvgCanvas & SvgCanvasExtras = new ChartSvgCanvas(); |
84 | 97 | ctx.canvas = { |
85 | 98 | width, |
86 | 99 | height, |
87 | 100 | style: { width: `${width}px`, height: `${height}px` }, |
88 | 101 | }; |
89 | 102 | ctx.fontHeightRatio = 2; |
90 | | - ctx.globalAlpha = 1; |
91 | | - // for some reason, SvgCanvas does not provide `.resetTransform()` so using |
92 | | - // `setTransform()` to set to the identity matrix, which is effectively the |
93 | | - // same. |
94 | | - ctx.resetTransform = () => ctx.setTransform(1, 0, 0, 1, 0, 0); |
95 | 103 | // deno-lint-ignore no-explicit-any |
96 | 104 | const el: HTMLCanvasElement = { getContext: () => ctx } as any; |
97 | 105 | const savedGradient = globalThis.CanvasGradient; |
|
0 commit comments