Skip to content

Commit 835c47d

Browse files
authored
Merge pull request #474 from xi/svg-style
Avoid inline style in SVG
2 parents 6b7622c + 230c0a1 commit 835c47d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/renderers/svg.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SVGRenderer{
4545

4646
if(this.options.background){
4747
this.drawRect(0, 0, width, maxHeight, this.svg).setAttribute(
48-
"style", "fill:" + this.options.background + ";"
48+
"fill", this.options.background
4949
);
5050
}
5151
}
@@ -89,9 +89,14 @@ class SVGRenderer{
8989
if(options.displayValue){
9090
var x, y;
9191

92-
textElem.setAttribute("style",
93-
"font:" + options.fontOptions + " " + options.fontSize + "px " + options.font
94-
);
92+
textElem.setAttribute("font-family", options.font);
93+
textElem.setAttribute("font-size", options.fontSize);
94+
if (options.fontOptions.includes("bold")) {
95+
textElem.setAttribute("font-weight", "bold");
96+
}
97+
if (options.fontOptions.includes("italic")) {
98+
textElem.setAttribute("font-style", "italic");
99+
}
95100

96101
if(options.textPosition == "top"){
97102
y = options.fontSize - options.textMargin;
@@ -135,8 +140,6 @@ class SVGRenderer{
135140

136141
svg.setAttribute("xmlns", svgns);
137142
svg.setAttribute("version", "1.1");
138-
139-
svg.setAttribute("style", "transform: translate(0,0)");
140143
}
141144

142145
createGroup(x, y, parent){
@@ -149,9 +152,7 @@ class SVGRenderer{
149152
}
150153

151154
setGroupOptions(group, options){
152-
group.setAttribute("style",
153-
"fill:" + options.lineColor + ";"
154-
);
155+
group.setAttribute("fill", options.lineColor);
155156
}
156157

157158
drawRect(x, y, width, height, parent){

0 commit comments

Comments
 (0)