You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Leo Lim <le...@fedex.com> on 2007/03/08 23:59:57 UTC
setting attributes dynamically
Hello,
Is it possible to set attributes (fill, stroke) dynamically?
The g elements in my svg file have already defined the stroke element as you
can see below,
<g id="Rudder_Trim_Knob">
<path i:knockout="Off" fill="#B2B2B2" stroke="#000000" stroke-width="0.9684"
d="M202.786,159.913
c59.836,0,108.342,48.437,108.342,108.184c0,59.75-48.506,108.189-108.342,108.
189c-59.834,0-108.342-48.439-108.342-108.189
C94.444,208.35,142.952,159.913,202.786,159.913z"/>
<path i:knockout="Off" fill="#F2F2F2" stroke="#000000"
stroke-width="0.9684" d="M175.799,166.63
.
</g>
With this setup, is it possible to call
target.setAttribute(SVGConstants.SVG_STROKE_ATTRIBUTE, "green");
I tried this one and nothing happened. However, when I removed the stroke
definitions above, I was able
to set it successfully using setAttribute.
But I want the stroke definitions to remain in my svg file as the image
would look ugly without them. That said,
is there a way to override the initial definitions of the stroke attribute?
Thanks!
Leo Lim
Re: setting attributes dynamically
Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Leo.
Leo Lim:
> Is it possible to set attributes (fill, stroke) dynamically?
Sure.
> The g elements in my svg file have already defined the stroke element as you
> can see below,
No, the g element doesn’t define a stroke. The two path elements do.
> <g id="Rudder_Trim_Knob">
>
> <path i:knockout="Off" fill="#B2B2B2" stroke="#000000" stroke-width="0.9684"
> d="M202.786,159.913
>
>
> c59.836,0,108.342,48.437,108.342,108.184c0,59.75-48.506,108.189-108.342,108.
> 189c-59.834,0-108.342-48.439-108.342-108.189
>
> C94.444,208.35,142.952,159.913,202.786,159.913z"/>
>
> <path i:knockout="Off" fill="#F2F2F2" stroke="#000000"
> stroke-width="0.9684" d="M175.799,166.63
>
> .
>
> </g>
>
>
>
> With this setup, is it possible to call
> target.setAttribute(SVGConstants.SVG_STROKE_ATTRIBUTE, "green");
>
> I tried this one and nothing happened. However, when I removed the stroke
> definitions above, I was able
>
> to set it successfully using setAttribute.
If target is actually the g element, then that is the expected
behaviour, since the stroke property inherits down the tree. The path
elements then override the stroke with the stroke="#000000" attributes.
So if you want to be able to set both paths’ stroke to green at once,
you should put stroke="#000000" on the g element to begin with, and then
update it from your script.
Cameron
--
Cameron McCormack, http://mcc.id.au/
xmpp:heycam@jabber.org ▪ ICQ 26955922 ▪ MSN cam@mcc.id.au
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org