Fix slider gradient bug when loading components from a previous sim run. (#514)
This commit is contained in:
parent
724ac19281
commit
d0331720b4
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user