|
1 | | -/// <reference types="node" /> |
2 | | -import { Readable } from 'stream'; |
3 | | -import { Chart as ChartJS, ChartConfiguration, ChartComponentLike } from 'chart.js'; |
4 | | -export declare type ChartJSNodeCanvasPlugins = { |
5 | | - /** |
6 | | - * Global plugins, see https://www.chartjs.org/docs/latest/developers/plugins.html. |
7 | | - */ |
8 | | - readonly modern?: ReadonlyArray<string | ChartComponentLike>; |
9 | | - /** |
10 | | - * This will work for plugins that `require` ChartJS themselves. |
11 | | - */ |
12 | | - readonly requireChartJSLegacy?: ReadonlyArray<string>; |
13 | | - /** |
14 | | - * This should work for any plugin that expects a global Chart variable. |
15 | | - */ |
16 | | - readonly globalVariableLegacy?: ReadonlyArray<string>; |
17 | | - /** |
18 | | - * This will work with plugins that just return a plugin object and do no specific loading themselves. |
19 | | - */ |
20 | | - readonly requireLegacy?: ReadonlyArray<string>; |
21 | | -}; |
22 | | -export declare type ChartCallback = (chartJS: typeof ChartJS) => void | Promise<void>; |
23 | | -export declare type CanvasType = 'pdf' | 'svg'; |
24 | | -export declare type MimeType = 'image/png' | 'image/jpeg'; |
25 | | -export interface ChartJSNodeCanvasOptions { |
26 | | - /** |
27 | | - * The width of the charts to render, in pixels. |
28 | | - */ |
29 | | - readonly width: number; |
30 | | - /** |
31 | | - * The height of the charts to render, in pixels. |
32 | | - */ |
33 | | - readonly height: number; |
34 | | - /** |
35 | | - * Optional callback which is called once with a new ChartJS global reference as the only parameter. |
36 | | - */ |
37 | | - readonly chartCallback?: ChartCallback; |
38 | | - /** |
39 | | - * Optional canvas type ('PDF' or 'SVG'), see the [canvas pdf doc](https://github.com/Automattic/node-canvas#pdf-output-support). |
40 | | - */ |
41 | | - readonly type?: CanvasType; |
42 | | - /** |
43 | | - * Optional plugins to register. |
44 | | - */ |
45 | | - readonly plugins?: ChartJSNodeCanvasPlugins; |
46 | | - /** |
47 | | - * Optional background color for the chart, otherwise it will be transparent. Note, this will apply to all charts. See the [fillStyle](https://www.w3schools.com/tags/canvas_fillstyle.asp) canvas API used for possible values. |
48 | | - */ |
49 | | - readonly backgroundColour?: string; |
50 | | -} |
51 | | -export declare class ChartJSNodeCanvas { |
52 | | - private readonly _width; |
53 | | - private readonly _height; |
54 | | - private readonly _chartJs; |
55 | | - private readonly _createCanvas; |
56 | | - private readonly _registerFont; |
57 | | - private readonly _image; |
58 | | - private readonly _type?; |
59 | | - /** |
60 | | - * Create a new instance of CanvasRenderService. |
61 | | - * |
62 | | - * @param options Configuration for this instance |
63 | | - */ |
64 | | - constructor(options: ChartJSNodeCanvasOptions); |
65 | | - /** |
66 | | - * Render to a data url. |
67 | | - * @see https://github.com/Automattic/node-canvas#canvastodataurl |
68 | | - * |
69 | | - * @param configuration The Chart JS configuration for the chart to render. |
70 | | - * @param mimeType The image format, `image/png` or `image/jpeg`. |
71 | | - */ |
72 | | - renderToDataURL(configuration: ChartConfiguration, mimeType?: MimeType): Promise<string>; |
73 | | - /** |
74 | | - * Render to a data url synchronously. |
75 | | - * @see https://github.com/Automattic/node-canvas#canvastodataurl |
76 | | - * |
77 | | - * @param configuration The Chart JS configuration for the chart to render. |
78 | | - * @param mimeType The image format, `image/png` or `image/jpeg`. |
79 | | - */ |
80 | | - renderToDataURLSync(configuration: ChartConfiguration, mimeType?: MimeType): string; |
81 | | - /** |
82 | | - * Render to a buffer. |
83 | | - * @see https://github.com/Automattic/node-canvas#canvastobuffer |
84 | | - * |
85 | | - * @param configuration The Chart JS configuration for the chart to render. |
86 | | - * @param mimeType A string indicating the image format. Valid options are `image/png`, `image/jpeg` (if node-canvas was built with JPEG support) or `raw` (unencoded ARGB32 data in native-endian byte order, top-to-bottom). Defaults to `image/png` for image canvases, or the corresponding type for PDF or SVG canvas. |
87 | | - */ |
88 | | - renderToBuffer(configuration: ChartConfiguration, mimeType?: MimeType): Promise<Buffer>; |
89 | | - /** |
90 | | - * Render to a buffer synchronously. |
91 | | - * @see https://github.com/Automattic/node-canvas#canvastobuffer |
92 | | - * |
93 | | - * @param configuration The Chart JS configuration for the chart to render. |
94 | | - * @param mimeType A string indicating the image format. Valid options are `image/png`, `image/jpeg` (if node-canvas was built with JPEG support), `raw` (unencoded ARGB32 data in native-endian byte order, top-to-bottom), `application/pdf` (for PDF canvases) and image/svg+xml (for SVG canvases). Defaults to `image/png` for image canvases, or the corresponding type for PDF or SVG canvas. |
95 | | - */ |
96 | | - renderToBufferSync(configuration: ChartConfiguration, mimeType?: MimeType | 'application/pdf' | 'image/svg+xml'): Buffer; |
97 | | - /** |
98 | | - * Render to a stream. |
99 | | - * @see https://github.com/Automattic/node-canvas#canvascreatepngstream |
100 | | - * |
101 | | - * @param configuration The Chart JS configuration for the chart to render. |
102 | | - * @param mimeType A string indicating the image format. Valid options are `image/png`, `image/jpeg` (if node-canvas was built with JPEG support), `application/pdf` (for PDF canvases) and image/svg+xml (for SVG canvases). Defaults to `image/png` for image canvases, or the corresponding type for PDF or SVG canvas. |
103 | | - */ |
104 | | - renderToStream(configuration: ChartConfiguration, mimeType?: MimeType | 'application/pdf'): Readable; |
105 | | - /** |
106 | | - * Use to register the font with Canvas to use a font file that is not installed as a system font, this must be done before the Canvas is created. |
107 | | - * |
108 | | - * @param path The path to the font file. |
109 | | - * @param options The font options. |
110 | | - * @example |
111 | | - * registerFont('comicsans.ttf', { family: 'Comic Sans' }); |
112 | | - */ |
113 | | - registerFont(path: string, options: { |
114 | | - readonly family: string; |
115 | | - readonly weight?: string; |
116 | | - readonly style?: string; |
117 | | - }): void; |
118 | | - private initialize; |
119 | | - private renderChart; |
120 | | -} |
| 1 | +export * from './animatedChartJSNodeCanvas'; |
| 2 | +export * from './chartJSNodeCanvas'; |
| 3 | +export * from './chartJSNodeCanvasBase'; |
0 commit comments