Skip to content

Commit 5a7ef5a

Browse files
authored
add option that allows setting background color (#53)
1 parent 8c29afb commit 5a7ef5a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/getSvgFromGraphicsObject.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ export function getSvgFromGraphicsObject(
8888
graphics: GraphicsObject,
8989
{
9090
includeTextLabels = false,
91+
backgroundColor,
9192
}: {
9293
includeTextLabels?: boolean
94+
backgroundColor?: string
9395
} = {},
9496
): string {
9597
const bounds = getBounds(graphics)
@@ -105,6 +107,20 @@ export function getSvgFromGraphicsObject(
105107
xmlns: "http://www.w3.org/2000/svg",
106108
},
107109
children: [
110+
// Background rectangle (optional)
111+
...(backgroundColor
112+
? [
113+
{
114+
name: "rect",
115+
type: "element",
116+
attributes: {
117+
width: "100%",
118+
height: "100%",
119+
fill: backgroundColor,
120+
},
121+
},
122+
]
123+
: []),
108124
// Points
109125
...(graphics.points || []).map((point) => {
110126
const projected = projectPoint(point, matrix)

0 commit comments

Comments
 (0)