开发者

pySVG css links

开发者 https://www.devze.com 2023-03-29 11:02 出处:网络
开发者_Python百科I\'m trying to figure out pySVG, having trouble understanding how to link to an external CSS file, does pySVG handle this?Looking over the documentation, the style seems to be hard co

开发者_Python百科I'm trying to figure out pySVG, having trouble understanding how to link to an external CSS file, does pySVG handle this? Looking over the documentation, the style seems to be hard coded in most of the examples.

Further, I'd love to add an 'onclick' to change the CSS reference, so, a heat map (for example) could link to a default CSS which styles elements for one set of data, but then the css can be changed to style the elements for a different set of data. I'm not sure whether this requires javascript, or if svg can handle it in the xml.

thoughts?


I'm not quite sure how pySVG does things, but you can add an external CSS to an SVG you've created by adding:

<?xml-stylesheet type="text/css" href="CSS_filename.css" ?>

It should be the very first line of the file, i.e. before the DOCTYPE declaration.

As for the onclick changes, you can have an element like this:

<circle class="class1"
        cx="10" cy="10" r="4"
        onclick="evt.target.setAttributeNS(null, 'class', 'class2')"/>

This will change the class of the circle from class1 to class2 when you click on it (changing it back would be more complicate and probably require javascript or EMCAScript within the SVG itself). I'm not sure how pySVG handles these things, but if you can add arbitrary attributes to elements then you can add the onclick event.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号