svg & stroke & style & class
svg selected style
methods
-
style
-
class, !important
-
fill, stroke, stroke-width, fill-opacity: 0.5;
-
outline, box-shadow
clickSelected(className = `selected-svg`) {
// update select element
const color = this.reverseColor();
this.poly.setAttribute("fill", color);
// this.poly.setAttribute("fill", "#67c23a");
const cssClass = this.poly.getAttribute("class");
// this.poly.setAttribute("class", "selected-svg");
this.poly.setAttribute("class", `${cssClass} ${className}`);
const style = "fill:lime; fill-opacity: 0.5; stroke:purple; stroke-10;";
this.poly.setAttribute("style", style);
}
reverseColor() {
const color = this.poly.getAttribute("fill");
return `#` + color.slice(1).split("").reverse().join("");
}
demo polygon
https://www.w3schools.com/graphics/tryit.asp?filename=trysvg_polygon
<!DOCTYPE html>
<html>
<body>
<svg height="210" width="500">
<polygon points="200,10 250,190 160,210" style="fill:lime; stroke:purple; stroke-5" />
Sorry, your browser does not support inline SVG.
</svg>
</body>
</html>
style="fill:lime; stroke:purple; stroke-5"
style
stroke-width, stroke
<polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00" style="fill:lime; stroke:purple; stroke-5"></polygon>
css class
stroke-width, stroke
.selected-class {
fill: #ccc !important;
stroke- 10px !important;
stroke: #0f0 !important;
}
size not change
poly = document.querySelector(`polygon`);
// <polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00" style="fill:lime; stroke:purple; stroke-5"></polygon>
poly.getBBox();
// SVGRect {x: 249.5, y: 0.5, 425, height: 136}
poly.getBoundingClientRect();
// DOMRect {x: 174.64999389648438, y: 190.35000610351562, 297.5, height: 95.19998168945312, top: 190.35000610351562, …}
poly = document.querySelector(`polygon`);
// <polygon fill="#cccccc" fill-opacity="1" points="249.5 0.5 674.5 0.5 674.5 136.5 249.5 136.5" class="feature selected-class" stroke="#00ff00"></polygon>
poly.getBBox();
// SVGRect {x: 249.5, y: 0.5, 425, height: 136}
poly.getBoundingClientRect();
// DOMRect {x: 174.64999389648438, y: 190.35000610351562, 297.5, height: 95.19998168945312, top: 190.35000610351562, …}