Switching svg filter in Angular -


i have angular app in rect element within template based svg image can have 1 of several different colors of glow. approach has been define several glow filters , several rects, each 1 of glows. use switch statment change between them

<g [ngswitch]="glowtype()">      <rect *ngswitchcase="1" [attr.x]="padding/2" [attr.y]="padding/2" fill="white" [attr.width]="x()" [attr.height]="y()"        filter="url(#selectglow)" />      <rect *ngswitchcase="2" [attr.x]="padding/2" [attr.y]="padding/2" fill="white" [attr.width]="x()" [attr.height]="y()"        filter="url(#attackglow)" />      <rect *ngswitchcase="3" [attr.x]="padding/2" [attr.y]="padding/2" fill="white" [attr.width]="x()" [attr.height]="y()"        filter="url(#defenseglow)" />        <rect *ngswitchcase="4" [attr.x]="padding/2" [attr.y]="padding/2" fill="white" [attr.width]="x()" [attr.height]="y()"        filter="url(#targetglow)" />    </g>

in chrome, works 95% of time. fails (the glows don't show) without clear cause. have confirmed glowtype() function returning right value (which should cause glow) , there no errors in console. when inspect html, correct glow rect there, no glow visible.

i attempted use different method, have single rect uses different glow filter depending on output of function

public glow() {      switch (this.glowtype()) {        case glowtype.select:          return 'selectglow';        case glowtype.targeted:          return 'targetglow';        case glowtype.attack:          return 'attackglow';        case glowtype.defense:          return 'defenseglow';        default:          return 'blank';      }    }
<rect class="image-border" [attr.x]="padding/2" [attr.y]="padding/2" fill="white" [attr.width]="x()" [attr.height]="y()" attr.filter="url(#{{glow()}})" />

in case, function returns right thing glows don't work. half rect glows, fails stop glowing when functions result changes. seems more sluggish first method.

so, looking way of dynamically switching glow filter in svg works consistently , without graphical artifacts.

for reference, here 1 of filters. others same, except different colors

<filter id="selectglow" height="300%" width="300%" x="-75%" y="-75%">        <!-- thicken out original shape -->        <femorphology operator="dilate" radius="2" in="sourcealpha" result="thicken" />          <!-- use gaussian blur create soft blurriness of glow -->        <fegaussianblur in="thicken" stddeviation="4" result="blurred" />          <!-- change colour -->        <feflood flood-color="rgb(255,215,0)" result="selectcolor" />          <!-- color in glows -->        <fecomposite in="selectcolor" in2="blurred" operator="in" result="softglow_colored" />          <!--	layer effects -->        <femerge>          <femergenode in="softglow_colored" />          <femergenode in="sourcegraphic" />        </femerge>      </filter>


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -