@formepdf/react 0.7.11 → 0.7.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.d.ts +35 -4
- package/dist/charts.js +3 -3
- package/dist/components.d.ts +58 -1
- package/dist/components.js +67 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/serialize.js +135 -1
- package/dist/types.d.ts +120 -19
- package/package.json +3 -2
package/dist/charts.d.ts
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Style, ChartDataPoint, PieDataPoint } from './types.js';
|
|
3
|
+
interface LegacyBarChartProps {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
data: ChartDataPoint[];
|
|
7
|
+
color?: string;
|
|
8
|
+
barGap?: number;
|
|
9
|
+
showGrid?: boolean;
|
|
10
|
+
showValues?: boolean;
|
|
11
|
+
yAxisTicks?: number;
|
|
12
|
+
style?: Style;
|
|
13
|
+
}
|
|
14
|
+
interface LegacyLineChartProps {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
data: ChartDataPoint[];
|
|
18
|
+
color?: string;
|
|
19
|
+
strokeWidth?: number;
|
|
20
|
+
showDots?: boolean;
|
|
21
|
+
showGrid?: boolean;
|
|
22
|
+
showArea?: boolean;
|
|
23
|
+
style?: Style;
|
|
24
|
+
}
|
|
25
|
+
interface LegacyPieChartProps {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
data: PieDataPoint[];
|
|
29
|
+
showLabels?: boolean;
|
|
30
|
+
innerRadius?: number;
|
|
31
|
+
style?: Style;
|
|
32
|
+
}
|
|
3
33
|
/**
|
|
4
34
|
* A bar chart rendered as SVG + positioned Text labels.
|
|
5
35
|
*
|
|
@@ -10,7 +40,7 @@ import type { BarChartProps, LineChartProps, PieChartProps } from './types.js';
|
|
|
10
40
|
* color="#1a365d" showGrid showValues />
|
|
11
41
|
* ```
|
|
12
42
|
*/
|
|
13
|
-
export declare function
|
|
43
|
+
export declare function LegacyBarChart(props: LegacyBarChartProps): React.ReactElement;
|
|
14
44
|
/**
|
|
15
45
|
* A line chart rendered as SVG + positioned Text labels.
|
|
16
46
|
*
|
|
@@ -21,7 +51,7 @@ export declare function BarChart(props: BarChartProps): React.ReactElement;
|
|
|
21
51
|
* color="#2b6cb0" showDots showGrid showArea />
|
|
22
52
|
* ```
|
|
23
53
|
*/
|
|
24
|
-
export declare function
|
|
54
|
+
export declare function LegacyLineChart(props: LegacyLineChartProps): React.ReactElement;
|
|
25
55
|
/**
|
|
26
56
|
* A pie chart (or donut chart) rendered as SVG + positioned Text labels.
|
|
27
57
|
*
|
|
@@ -38,4 +68,5 @@ export declare function LineChart(props: LineChartProps): React.ReactElement;
|
|
|
38
68
|
* showLabels />
|
|
39
69
|
* ```
|
|
40
70
|
*/
|
|
41
|
-
export declare function
|
|
71
|
+
export declare function LegacyPieChart(props: LegacyPieChartProps): React.ReactElement;
|
|
72
|
+
export {};
|
package/dist/charts.js
CHANGED
|
@@ -58,7 +58,7 @@ const X_AXIS_HEIGHT = 20;
|
|
|
58
58
|
* color="#1a365d" showGrid showValues />
|
|
59
59
|
* ```
|
|
60
60
|
*/
|
|
61
|
-
export function
|
|
61
|
+
export function LegacyBarChart(props) {
|
|
62
62
|
const { width, height, data, color = '#1a365d', barGap = 4, showGrid = false, showValues = false, yAxisTicks = 5, } = props;
|
|
63
63
|
if (data.length === 0) {
|
|
64
64
|
return React.createElement(View, { style: { width, height, ...props.style } });
|
|
@@ -154,7 +154,7 @@ export function BarChart(props) {
|
|
|
154
154
|
* color="#2b6cb0" showDots showGrid showArea />
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
|
-
export function
|
|
157
|
+
export function LegacyLineChart(props) {
|
|
158
158
|
const { width, height, data, color = '#2b6cb0', strokeWidth = 2, showDots = false, showGrid = false, showArea = false, } = props;
|
|
159
159
|
if (data.length === 0) {
|
|
160
160
|
return React.createElement(View, { style: { width, height, ...props.style } });
|
|
@@ -262,7 +262,7 @@ export function LineChart(props) {
|
|
|
262
262
|
* showLabels />
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
|
-
export function
|
|
265
|
+
export function LegacyPieChart(props) {
|
|
266
266
|
const { width, height, data, showLabels = false, innerRadius = 0, } = props;
|
|
267
267
|
const total = data.reduce((sum, d) => sum + d.value, 0);
|
|
268
268
|
if (data.length === 0 || total <= 0) {
|
package/dist/components.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps } from './types.js';
|
|
1
|
+
import type { DocumentProps, PageProps, ViewProps, TextProps, ImageProps, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, CanvasProps, WatermarkProps, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Root document container. Must be the top-level element in every Forme document.
|
|
4
4
|
*
|
|
@@ -273,3 +273,60 @@ export declare function Watermark(_props: WatermarkProps): null;
|
|
|
273
273
|
* ```
|
|
274
274
|
*/
|
|
275
275
|
export declare function PageBreak(_props: object): null;
|
|
276
|
+
/**
|
|
277
|
+
* A bar chart rendered as native vector graphics in the PDF.
|
|
278
|
+
*
|
|
279
|
+
* @param props.data - Array of { label, value, color? } data points
|
|
280
|
+
* @param props.width - Chart width in points
|
|
281
|
+
* @param props.height - Chart height in points
|
|
282
|
+
* @param props.color - Default bar color (hex). Default: "#1a365d"
|
|
283
|
+
* @param props.showLabels - Show X-axis labels. Default: true
|
|
284
|
+
* @param props.showValues - Show value labels above bars. Default: false
|
|
285
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
286
|
+
* @param props.title - Chart title
|
|
287
|
+
*/
|
|
288
|
+
export declare function BarChart(_props: BarChartProps): null;
|
|
289
|
+
/**
|
|
290
|
+
* A line chart rendered as native vector graphics in the PDF.
|
|
291
|
+
*
|
|
292
|
+
* @param props.series - Array of { name, data: number[], color? } series
|
|
293
|
+
* @param props.labels - X-axis labels
|
|
294
|
+
* @param props.width - Chart width in points
|
|
295
|
+
* @param props.height - Chart height in points
|
|
296
|
+
* @param props.showPoints - Show dots at data points. Default: false
|
|
297
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
298
|
+
* @param props.title - Chart title
|
|
299
|
+
*/
|
|
300
|
+
export declare function LineChart(_props: LineChartProps): null;
|
|
301
|
+
/**
|
|
302
|
+
* A pie chart rendered as native vector graphics in the PDF.
|
|
303
|
+
*
|
|
304
|
+
* @param props.data - Array of { label, value, color? } data points
|
|
305
|
+
* @param props.width - Chart width in points
|
|
306
|
+
* @param props.height - Chart height in points
|
|
307
|
+
* @param props.donut - Render as donut chart. Default: false
|
|
308
|
+
* @param props.showLegend - Show legend. Default: false
|
|
309
|
+
* @param props.title - Chart title
|
|
310
|
+
*/
|
|
311
|
+
export declare function PieChart(_props: PieChartProps): null;
|
|
312
|
+
/**
|
|
313
|
+
* An area chart rendered as native vector graphics in the PDF.
|
|
314
|
+
*
|
|
315
|
+
* @param props.series - Array of { name, data: number[], color? } series
|
|
316
|
+
* @param props.labels - X-axis labels
|
|
317
|
+
* @param props.width - Chart width in points
|
|
318
|
+
* @param props.height - Chart height in points
|
|
319
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
320
|
+
* @param props.title - Chart title
|
|
321
|
+
*/
|
|
322
|
+
export declare function AreaChart(_props: AreaChartProps): null;
|
|
323
|
+
/**
|
|
324
|
+
* A dot plot (scatter plot) rendered as native vector graphics in the PDF.
|
|
325
|
+
*
|
|
326
|
+
* @param props.groups - Array of { name, color?, data: [x, y][] } groups
|
|
327
|
+
* @param props.width - Chart width in points
|
|
328
|
+
* @param props.height - Chart height in points
|
|
329
|
+
* @param props.dotSize - Dot radius. Default: 4
|
|
330
|
+
* @param props.showLegend - Show legend. Default: false
|
|
331
|
+
*/
|
|
332
|
+
export declare function DotPlot(_props: DotPlotProps): null;
|
package/dist/components.js
CHANGED
|
@@ -302,3 +302,70 @@ export function Watermark(_props) {
|
|
|
302
302
|
export function PageBreak(_props) {
|
|
303
303
|
return null;
|
|
304
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* A bar chart rendered as native vector graphics in the PDF.
|
|
307
|
+
*
|
|
308
|
+
* @param props.data - Array of { label, value, color? } data points
|
|
309
|
+
* @param props.width - Chart width in points
|
|
310
|
+
* @param props.height - Chart height in points
|
|
311
|
+
* @param props.color - Default bar color (hex). Default: "#1a365d"
|
|
312
|
+
* @param props.showLabels - Show X-axis labels. Default: true
|
|
313
|
+
* @param props.showValues - Show value labels above bars. Default: false
|
|
314
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
315
|
+
* @param props.title - Chart title
|
|
316
|
+
*/
|
|
317
|
+
export function BarChart(_props) {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* A line chart rendered as native vector graphics in the PDF.
|
|
322
|
+
*
|
|
323
|
+
* @param props.series - Array of { name, data: number[], color? } series
|
|
324
|
+
* @param props.labels - X-axis labels
|
|
325
|
+
* @param props.width - Chart width in points
|
|
326
|
+
* @param props.height - Chart height in points
|
|
327
|
+
* @param props.showPoints - Show dots at data points. Default: false
|
|
328
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
329
|
+
* @param props.title - Chart title
|
|
330
|
+
*/
|
|
331
|
+
export function LineChart(_props) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* A pie chart rendered as native vector graphics in the PDF.
|
|
336
|
+
*
|
|
337
|
+
* @param props.data - Array of { label, value, color? } data points
|
|
338
|
+
* @param props.width - Chart width in points
|
|
339
|
+
* @param props.height - Chart height in points
|
|
340
|
+
* @param props.donut - Render as donut chart. Default: false
|
|
341
|
+
* @param props.showLegend - Show legend. Default: false
|
|
342
|
+
* @param props.title - Chart title
|
|
343
|
+
*/
|
|
344
|
+
export function PieChart(_props) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* An area chart rendered as native vector graphics in the PDF.
|
|
349
|
+
*
|
|
350
|
+
* @param props.series - Array of { name, data: number[], color? } series
|
|
351
|
+
* @param props.labels - X-axis labels
|
|
352
|
+
* @param props.width - Chart width in points
|
|
353
|
+
* @param props.height - Chart height in points
|
|
354
|
+
* @param props.showGrid - Show horizontal grid lines. Default: false
|
|
355
|
+
* @param props.title - Chart title
|
|
356
|
+
*/
|
|
357
|
+
export function AreaChart(_props) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* A dot plot (scatter plot) rendered as native vector graphics in the PDF.
|
|
362
|
+
*
|
|
363
|
+
* @param props.groups - Array of { name, color?, data: [x, y][] } groups
|
|
364
|
+
* @param props.width - Chart width in points
|
|
365
|
+
* @param props.height - Chart height in points
|
|
366
|
+
* @param props.dotSize - Dot radius. Default: 4
|
|
367
|
+
* @param props.showLegend - Show legend. Default: false
|
|
368
|
+
*/
|
|
369
|
+
export function DotPlot(_props) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
|
|
2
|
-
export {
|
|
1
|
+
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot } from './components.js';
|
|
2
|
+
export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
|
|
3
3
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
|
4
4
|
export { StyleSheet } from './stylesheet.js';
|
|
5
5
|
export { Font } from './font.js';
|
|
@@ -7,4 +7,4 @@ export type { FontRegistration } from './font.js';
|
|
|
7
7
|
export { createDataProxy, isRefMarker, isEachMarker, isExprMarker } from './template-proxy.js';
|
|
8
8
|
export { expr } from './expr.js';
|
|
9
9
|
export { render, renderToObject } from './render.js';
|
|
10
|
-
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, BarChartProps, LineChartProps, PieChartProps, TextRun, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
|
10
|
+
export type { Style, GridTrackSize, Edges, Corners, EdgeColors, DocumentProps, PageProps, ViewProps, TextProps, ImageProps, ColumnDef, TableProps, RowProps, CellProps, FixedProps, SvgProps, QrCodeProps, BarcodeProps, BarcodeFormat, CanvasProps, CanvasContext, CanvasOp, WatermarkProps, ChartDataPoint, PieDataPoint, ChartSeries, DotPlotGroup, BarChartProps, LineChartProps, PieChartProps, AreaChartProps, DotPlotProps, TextRun, FormeDocument, FormeFont, FormeNode, FormeNodeKind, FormeStyle, FormePageConfig, FormePageSize, FormeEdges, FormeMetadata, FormeColumnDef, FormeColumnWidth, FormeDimension, FormeColor, FormeEdgeValues, FormeCornerValues, FormeGridTrackSize, FormeGridPlacement, } from './types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Components
|
|
2
|
-
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
|
|
3
|
-
export {
|
|
2
|
+
export { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot } from './components.js';
|
|
3
|
+
export { LegacyBarChart, LegacyLineChart, LegacyPieChart } from './charts.js';
|
|
4
4
|
// Serialization
|
|
5
5
|
export { serialize, serializeTemplate, mapStyle, mapDimension, parseColor, expandEdges, expandCorners } from './serialize.js';
|
|
6
6
|
// StyleSheet
|
package/dist/serialize.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isValidElement, Children, Fragment } from 'react';
|
|
2
|
-
import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak } from './components.js';
|
|
2
|
+
import { Document, Page, View, Text, Image, Table, Row, Cell, Fixed, Svg, QrCode, Barcode, Canvas, Watermark, PageBreak, BarChart, LineChart, PieChart, AreaChart, DotPlot } from './components.js';
|
|
3
3
|
import { Font } from './font.js';
|
|
4
4
|
import { isRefMarker, getRefPath, isEachMarker, getEachPath, getEachTemplate, isExprMarker, getExpr, REF_SENTINEL, REF_SENTINEL_END, } from './template-proxy.js';
|
|
5
5
|
const VALID_PARENTS = {
|
|
@@ -232,6 +232,21 @@ function serializeChild(child, parent = null) {
|
|
|
232
232
|
if (element.type === Watermark) {
|
|
233
233
|
return serializeWatermark(element);
|
|
234
234
|
}
|
|
235
|
+
if (element.type === BarChart) {
|
|
236
|
+
return serializeBarChart(element);
|
|
237
|
+
}
|
|
238
|
+
if (element.type === LineChart) {
|
|
239
|
+
return serializeLineChart(element);
|
|
240
|
+
}
|
|
241
|
+
if (element.type === PieChart) {
|
|
242
|
+
return serializePieChart(element);
|
|
243
|
+
}
|
|
244
|
+
if (element.type === AreaChart) {
|
|
245
|
+
return serializeAreaChart(element);
|
|
246
|
+
}
|
|
247
|
+
if (element.type === DotPlot) {
|
|
248
|
+
return serializeDotPlot(element);
|
|
249
|
+
}
|
|
235
250
|
if (element.type === PageBreak) {
|
|
236
251
|
return {
|
|
237
252
|
kind: { type: 'PageBreak' },
|
|
@@ -520,6 +535,115 @@ function serializeWatermark(element) {
|
|
|
520
535
|
sourceLocation: extractSourceLocation(element),
|
|
521
536
|
};
|
|
522
537
|
}
|
|
538
|
+
function serializeBarChart(element) {
|
|
539
|
+
const props = element.props;
|
|
540
|
+
const kind = {
|
|
541
|
+
type: 'BarChart',
|
|
542
|
+
data: props.data.map(d => ({ label: d.label, value: d.value, color: d.color })),
|
|
543
|
+
width: props.width,
|
|
544
|
+
height: props.height,
|
|
545
|
+
show_labels: props.showLabels ?? true,
|
|
546
|
+
show_values: props.showValues ?? false,
|
|
547
|
+
show_grid: props.showGrid ?? false,
|
|
548
|
+
};
|
|
549
|
+
if (props.color !== undefined)
|
|
550
|
+
kind.color = props.color;
|
|
551
|
+
if (props.title !== undefined)
|
|
552
|
+
kind.title = props.title;
|
|
553
|
+
return {
|
|
554
|
+
kind,
|
|
555
|
+
style: mapStyle(props.style),
|
|
556
|
+
children: [],
|
|
557
|
+
sourceLocation: extractSourceLocation(element),
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
function serializeLineChart(element) {
|
|
561
|
+
const props = element.props;
|
|
562
|
+
const kind = {
|
|
563
|
+
type: 'LineChart',
|
|
564
|
+
series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
|
|
565
|
+
labels: props.labels,
|
|
566
|
+
width: props.width,
|
|
567
|
+
height: props.height,
|
|
568
|
+
show_points: props.showPoints ?? false,
|
|
569
|
+
show_grid: props.showGrid ?? false,
|
|
570
|
+
};
|
|
571
|
+
if (props.title !== undefined)
|
|
572
|
+
kind.title = props.title;
|
|
573
|
+
return {
|
|
574
|
+
kind,
|
|
575
|
+
style: mapStyle(props.style),
|
|
576
|
+
children: [],
|
|
577
|
+
sourceLocation: extractSourceLocation(element),
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
function serializePieChart(element) {
|
|
581
|
+
const props = element.props;
|
|
582
|
+
const kind = {
|
|
583
|
+
type: 'PieChart',
|
|
584
|
+
data: props.data.map(d => ({ label: d.label, value: d.value, color: d.color })),
|
|
585
|
+
width: props.width,
|
|
586
|
+
height: props.height,
|
|
587
|
+
donut: props.donut ?? false,
|
|
588
|
+
show_legend: props.showLegend ?? false,
|
|
589
|
+
};
|
|
590
|
+
if (props.title !== undefined)
|
|
591
|
+
kind.title = props.title;
|
|
592
|
+
return {
|
|
593
|
+
kind,
|
|
594
|
+
style: mapStyle(props.style),
|
|
595
|
+
children: [],
|
|
596
|
+
sourceLocation: extractSourceLocation(element),
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
function serializeAreaChart(element) {
|
|
600
|
+
const props = element.props;
|
|
601
|
+
const kind = {
|
|
602
|
+
type: 'AreaChart',
|
|
603
|
+
series: props.series.map(s => ({ name: s.name, data: s.data, color: s.color })),
|
|
604
|
+
labels: props.labels,
|
|
605
|
+
width: props.width,
|
|
606
|
+
height: props.height,
|
|
607
|
+
show_grid: props.showGrid ?? false,
|
|
608
|
+
};
|
|
609
|
+
if (props.title !== undefined)
|
|
610
|
+
kind.title = props.title;
|
|
611
|
+
return {
|
|
612
|
+
kind,
|
|
613
|
+
style: mapStyle(props.style),
|
|
614
|
+
children: [],
|
|
615
|
+
sourceLocation: extractSourceLocation(element),
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
function serializeDotPlot(element) {
|
|
619
|
+
const props = element.props;
|
|
620
|
+
const kind = {
|
|
621
|
+
type: 'DotPlot',
|
|
622
|
+
groups: props.groups.map(g => ({ name: g.name, color: g.color, data: g.data })),
|
|
623
|
+
width: props.width,
|
|
624
|
+
height: props.height,
|
|
625
|
+
show_legend: props.showLegend ?? false,
|
|
626
|
+
dot_size: props.dotSize ?? 4,
|
|
627
|
+
};
|
|
628
|
+
if (props.xMin !== undefined)
|
|
629
|
+
kind.x_min = props.xMin;
|
|
630
|
+
if (props.xMax !== undefined)
|
|
631
|
+
kind.x_max = props.xMax;
|
|
632
|
+
if (props.yMin !== undefined)
|
|
633
|
+
kind.y_min = props.yMin;
|
|
634
|
+
if (props.yMax !== undefined)
|
|
635
|
+
kind.y_max = props.yMax;
|
|
636
|
+
if (props.xLabel !== undefined)
|
|
637
|
+
kind.x_label = props.xLabel;
|
|
638
|
+
if (props.yLabel !== undefined)
|
|
639
|
+
kind.y_label = props.yLabel;
|
|
640
|
+
return {
|
|
641
|
+
kind,
|
|
642
|
+
style: mapStyle(props.style),
|
|
643
|
+
children: [],
|
|
644
|
+
sourceLocation: extractSourceLocation(element),
|
|
645
|
+
};
|
|
646
|
+
}
|
|
523
647
|
// ─── Children helpers ────────────────────────────────────────────────
|
|
524
648
|
function flattenChildren(children) {
|
|
525
649
|
const result = [];
|
|
@@ -1318,6 +1442,16 @@ function serializeTemplateChild(child, parent = null) {
|
|
|
1318
1442
|
return serializeCanvas(element);
|
|
1319
1443
|
if (element.type === Watermark)
|
|
1320
1444
|
return serializeWatermark(element);
|
|
1445
|
+
if (element.type === BarChart)
|
|
1446
|
+
return serializeBarChart(element);
|
|
1447
|
+
if (element.type === LineChart)
|
|
1448
|
+
return serializeLineChart(element);
|
|
1449
|
+
if (element.type === PieChart)
|
|
1450
|
+
return serializePieChart(element);
|
|
1451
|
+
if (element.type === AreaChart)
|
|
1452
|
+
return serializeAreaChart(element);
|
|
1453
|
+
if (element.type === DotPlot)
|
|
1454
|
+
return serializeDotPlot(element);
|
|
1321
1455
|
if (element.type === PageBreak) {
|
|
1322
1456
|
return { kind: { type: 'PageBreak' }, style: {}, children: [] };
|
|
1323
1457
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -250,57 +250,110 @@ export interface BarcodeProps {
|
|
|
250
250
|
color?: string;
|
|
251
251
|
style?: Style;
|
|
252
252
|
}
|
|
253
|
-
/** Data point for bar and
|
|
253
|
+
/** Data point for bar and pie charts. */
|
|
254
254
|
export interface ChartDataPoint {
|
|
255
255
|
label: string;
|
|
256
256
|
value: number;
|
|
257
|
+
/** Optional per-item color (hex string). */
|
|
258
|
+
color?: string;
|
|
257
259
|
}
|
|
258
|
-
/**
|
|
260
|
+
/** @deprecated Use ChartDataPoint instead (color is now optional on ChartDataPoint). */
|
|
259
261
|
export interface PieDataPoint {
|
|
260
262
|
label: string;
|
|
261
263
|
value: number;
|
|
262
264
|
color: string;
|
|
263
265
|
}
|
|
266
|
+
/** A data series for multi-series line and area charts. */
|
|
267
|
+
export interface ChartSeries {
|
|
268
|
+
name: string;
|
|
269
|
+
data: number[];
|
|
270
|
+
/** Optional series color (hex string). */
|
|
271
|
+
color?: string;
|
|
272
|
+
}
|
|
273
|
+
/** A group of (x, y) data points for dot plots. */
|
|
274
|
+
export interface DotPlotGroup {
|
|
275
|
+
name: string;
|
|
276
|
+
/** Optional group color (hex string). */
|
|
277
|
+
color?: string;
|
|
278
|
+
data: [number, number][];
|
|
279
|
+
}
|
|
264
280
|
export interface BarChartProps {
|
|
265
281
|
width: number;
|
|
266
282
|
height: number;
|
|
267
283
|
data: ChartDataPoint[];
|
|
268
284
|
/** Bar color. Default: "#1a365d". */
|
|
269
285
|
color?: string;
|
|
270
|
-
/**
|
|
271
|
-
|
|
286
|
+
/** Show X-axis labels below bars. Default: true. */
|
|
287
|
+
showLabels?: boolean;
|
|
272
288
|
/** Show horizontal grid lines. Default: false. */
|
|
273
289
|
showGrid?: boolean;
|
|
274
290
|
/** Show value labels above bars. Default: false. */
|
|
275
291
|
showValues?: boolean;
|
|
276
|
-
/**
|
|
277
|
-
|
|
292
|
+
/** Chart title. */
|
|
293
|
+
title?: string;
|
|
278
294
|
style?: Style;
|
|
279
295
|
}
|
|
280
296
|
export interface LineChartProps {
|
|
281
297
|
width: number;
|
|
282
298
|
height: number;
|
|
283
|
-
data
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
strokeWidth?: number;
|
|
299
|
+
/** Multi-series data. */
|
|
300
|
+
series: ChartSeries[];
|
|
301
|
+
/** X-axis labels. */
|
|
302
|
+
labels: string[];
|
|
288
303
|
/** Show dots at data points. Default: false. */
|
|
289
|
-
|
|
304
|
+
showPoints?: boolean;
|
|
290
305
|
/** Show horizontal grid lines. Default: false. */
|
|
291
306
|
showGrid?: boolean;
|
|
292
|
-
/**
|
|
293
|
-
|
|
307
|
+
/** Chart title. */
|
|
308
|
+
title?: string;
|
|
294
309
|
style?: Style;
|
|
295
310
|
}
|
|
296
311
|
export interface PieChartProps {
|
|
297
312
|
width: number;
|
|
298
313
|
height: number;
|
|
299
|
-
data:
|
|
300
|
-
/**
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
|
|
314
|
+
data: ChartDataPoint[];
|
|
315
|
+
/** Render as donut chart. Default: false. */
|
|
316
|
+
donut?: boolean;
|
|
317
|
+
/** Show legend. Default: false. */
|
|
318
|
+
showLegend?: boolean;
|
|
319
|
+
/** Chart title. */
|
|
320
|
+
title?: string;
|
|
321
|
+
style?: Style;
|
|
322
|
+
}
|
|
323
|
+
export interface AreaChartProps {
|
|
324
|
+
width: number;
|
|
325
|
+
height: number;
|
|
326
|
+
/** Multi-series data. */
|
|
327
|
+
series: ChartSeries[];
|
|
328
|
+
/** X-axis labels. */
|
|
329
|
+
labels: string[];
|
|
330
|
+
/** Show horizontal grid lines. Default: false. */
|
|
331
|
+
showGrid?: boolean;
|
|
332
|
+
/** Chart title. */
|
|
333
|
+
title?: string;
|
|
334
|
+
style?: Style;
|
|
335
|
+
}
|
|
336
|
+
export interface DotPlotProps {
|
|
337
|
+
width: number;
|
|
338
|
+
height: number;
|
|
339
|
+
/** Groups of (x, y) data points. */
|
|
340
|
+
groups: DotPlotGroup[];
|
|
341
|
+
/** Minimum X value. Auto-computed if omitted. */
|
|
342
|
+
xMin?: number;
|
|
343
|
+
/** Maximum X value. Auto-computed if omitted. */
|
|
344
|
+
xMax?: number;
|
|
345
|
+
/** Minimum Y value. Auto-computed if omitted. */
|
|
346
|
+
yMin?: number;
|
|
347
|
+
/** Maximum Y value. Auto-computed if omitted. */
|
|
348
|
+
yMax?: number;
|
|
349
|
+
/** X-axis label. */
|
|
350
|
+
xLabel?: string;
|
|
351
|
+
/** Y-axis label. */
|
|
352
|
+
yLabel?: string;
|
|
353
|
+
/** Show legend. Default: false. */
|
|
354
|
+
showLegend?: boolean;
|
|
355
|
+
/** Dot radius in points. Default: 4. */
|
|
356
|
+
dotSize?: number;
|
|
304
357
|
style?: Style;
|
|
305
358
|
}
|
|
306
359
|
export interface WatermarkProps {
|
|
@@ -538,6 +591,54 @@ export type FormeNodeKind = {
|
|
|
538
591
|
width: number;
|
|
539
592
|
height: number;
|
|
540
593
|
operations: CanvasOp[];
|
|
594
|
+
} | {
|
|
595
|
+
type: 'BarChart';
|
|
596
|
+
data: ChartDataPoint[];
|
|
597
|
+
width: number;
|
|
598
|
+
height: number;
|
|
599
|
+
color?: string;
|
|
600
|
+
show_labels: boolean;
|
|
601
|
+
show_values: boolean;
|
|
602
|
+
show_grid: boolean;
|
|
603
|
+
title?: string;
|
|
604
|
+
} | {
|
|
605
|
+
type: 'LineChart';
|
|
606
|
+
series: ChartSeries[];
|
|
607
|
+
labels: string[];
|
|
608
|
+
width: number;
|
|
609
|
+
height: number;
|
|
610
|
+
show_points: boolean;
|
|
611
|
+
show_grid: boolean;
|
|
612
|
+
title?: string;
|
|
613
|
+
} | {
|
|
614
|
+
type: 'PieChart';
|
|
615
|
+
data: ChartDataPoint[];
|
|
616
|
+
width: number;
|
|
617
|
+
height: number;
|
|
618
|
+
donut: boolean;
|
|
619
|
+
show_legend: boolean;
|
|
620
|
+
title?: string;
|
|
621
|
+
} | {
|
|
622
|
+
type: 'AreaChart';
|
|
623
|
+
series: ChartSeries[];
|
|
624
|
+
labels: string[];
|
|
625
|
+
width: number;
|
|
626
|
+
height: number;
|
|
627
|
+
show_grid: boolean;
|
|
628
|
+
title?: string;
|
|
629
|
+
} | {
|
|
630
|
+
type: 'DotPlot';
|
|
631
|
+
groups: DotPlotGroup[];
|
|
632
|
+
width: number;
|
|
633
|
+
height: number;
|
|
634
|
+
x_min?: number;
|
|
635
|
+
x_max?: number;
|
|
636
|
+
y_min?: number;
|
|
637
|
+
y_max?: number;
|
|
638
|
+
x_label?: string;
|
|
639
|
+
y_label?: string;
|
|
640
|
+
show_legend: boolean;
|
|
641
|
+
dot_size: number;
|
|
541
642
|
} | {
|
|
542
643
|
type: 'Watermark';
|
|
543
644
|
text: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formepdf/react",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"description": "JSX-to-JSON serializer for Forme PDF engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|