Skip to content

Commit

Permalink
code improvements, fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburnell committed Jan 21, 2024
1 parent 50cc696 commit bdffede
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions svg-sparkline.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class SVGSparkline extends HTMLElement {
}

render() {
if (!this.hasAttribute("values")) {
return
}

this.values = this.getAttribute("values").split(",")
this.width = parseFloat(this.getAttribute("width")) || 160
this.height = parseFloat(this.getAttribute("height")) || 28
Expand Down Expand Up @@ -135,25 +139,27 @@ class SVGSparkline extends HTMLElement {
}

initTemplate() {
let template = document.createElement("template")
template.innerHTML = this.render()
this.shadowRoot.appendChild(template.content.cloneNode(true))
}
if (this.shadowRoot) {
this.shadowRoot.innerHTML = this.render()
return
}

init() {
this.attachShadow({
mode: "open"
});
let shadowroot = this.attachShadow({ mode: "open" });

let sheet = new CSSStyleSheet();
sheet.replace(SVGSparkline.css);
this.shadowRoot.adoptedStyleSheets = [sheet];
sheet.replaceSync(SVGSparkline.css);
shadowroot.adoptedStyleSheets = [sheet];

let template = document.createElement("template")
template.innerHTML = this.render()
shadowroot.appendChild(template.content.cloneNode(true))
}

async init() {
this.initTemplate()
}

attributeChangedCallback(name, oldValue, newValue) {
this.shadowRoot.innerHTML = ``
attributeChangedCallback() {
this.initTemplate()
}

Expand Down

0 comments on commit bdffede

Please sign in to comment.