Fix slider gradient bug when loading components from a previous sim run. (#514)

This commit is contained in:
Sam El-Husseini 2018-04-13 15:52:38 -07:00 committed by GitHub
parent 724ac19281
commit d0331720b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View File

@ -54,7 +54,8 @@ namespace pxsim.visuals {
this.group = svg.elt("g") as SVGGElement;
let gc = "gradient-color-" + this.getPort();
this.colorGradient = svg.linearGradient(globalDefs, gc, false);
const prevColorGradient = globalDefs.querySelector(`#${gc}`) as SVGLinearGradientElement;
this.colorGradient = prevColorGradient ? prevColorGradient : svg.linearGradient(globalDefs, gc, false);
svg.setGradientValue(this.colorGradient, "50%");
svg.setGradientColors(this.colorGradient, "black", "yellow");
@ -99,10 +100,5 @@ namespace pxsim.visuals {
return this.group;
}
public dispose() {
if (this.colorGradient) this.colorGradient.parentElement.removeChild(this.colorGradient);
super.dispose();
}
}
}

View File

@ -15,7 +15,8 @@ namespace pxsim.visuals {
getInnerView(parent: SVGSVGElement, globalDefs: SVGDefsElement) {
let gid = "gradient-slider-" + this.getPort();
this.group = svg.elt("g") as SVGGElement;
this.gradient = createGradient(gid, this.getGradientDefinition());
const prevGradient = globalDefs.querySelector(`#${gid}`) as SVGLinearGradientElement;
this.gradient = prevGradient ? prevGradient : createGradient(gid, this.getGradientDefinition());
this.gradient.setAttribute('x1', '0%');
this.gradient.setAttribute('y1', '0%');
this.gradient.setAttribute('x2', '0%');
@ -74,11 +75,6 @@ namespace pxsim.visuals {
return this.group;
}
public dispose() {
if (this.gradient) this.gradient.parentElement.removeChild(this.gradient);
super.dispose();
}
getInnerHeight() {
return 192;
}