Change SVG polygon color based upon page - svg

I have an SVG that represents a flower (for lack of a better description using Polygons), each leaf is linked to a webpage. When hovering over the leaf it changes colour from green to yellow. This flower is shown on every page, it is functioning as a navigation menu.
What I can't get to work is that when a page is visited the color of the leaf to stay yellow, of the visited page.
Scenario:
User hovers over Communities (leaf).
Communities (leaf) color changes from green to yellow.
User clicks on Communities (leaf).
The communities page opens.
What I am trying to achieve.
The Communities leaf stays yellow when the visitor is on the communities page.
The code I have so far:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 1112 1033.2" style="enable-background:new 0 0 1112 1033.2;" xml:space="preserve">
<style type="text/css">
.st0{fill:#104741;} /*The green color*/
.st0:hover{fill:#F0CB3F;} /*when hover over go yellow*/
.st1{fill:#FFFFFF;} /*standard color for the text*/
.st2{font-family:'Roboto-Bold', sans-serif;} /*Text type*/
.st3{font-size:45px;} /*Text size*/
.st4{fill:#F0CB3F;}
</style>
<a id="Teaching" xlink:href="https://tradeshack.au/teaching-online/" >
<polygon id="Teaching_00000051348337870285784970000016147037851407144324_" class="st0" points="547,303.2 368,403.2 189,303.2
189,103.3 368,3.3 547,103.3 "/>
<text transform="matrix(1 0 0 1 278.9999 223.2402)" class="st1 st2 st3">Teaching</text>
</a>
<a id="Learning" xlink:href="https://tradeshack.au/local-online-courses/" >
<polygon id="Learning_00000173841655452649517230000006122666773149035708_" class="st0" points="927,307.2 748,407.2 569,307.2
569,107.2 748,7.2 927,107.2 "/>
<text transform="matrix(1 0 0 1 658.3733 232.2399)" class="st1 st2 st3">Learning</text>
</a>
<a id="Home" xlink:href="https://tradeshack.au" >
<polygon id="Home_00000093143914122244361730000008396680916595534749_" class="st4" points="736,618.3 557,718.2 378,618.3
378,418.3 557,318.3 736,418.3 "/>
<image style="overflow:visible;" width="214" height="184" id="house_xA0_Image_00000048475658377819784140000012594620538900893574_" xlink:href="https://tradeshack.au/wp-content/uploads/2022/08/C6FE9EEE.png" transform="matrix(1.6822 0 0 1.7609 378 358.24)">
</image>
</a>
<a id="Growing" xlink:href="https://tradeshack.au/backyard-growers/" >
<polygon id="Growing_00000175323106510374922210000005630539508612177844_" class="st0" points="1112,621.4 933,721.4 754,621.4
754,421.4 933,321.5 1112,421.4 "/>
<text transform="matrix(1 0 0 1 851.8009 538.2402)" class="st1 st2 st3">Growing</text>
</a>
<a id="News" xlink:href="https://tradeshack.au/local-news/" >
<polygon id="News_00000098220304566128214590000010493917784746845323_" class="st0" points="360,621.2 181,721.2 2,621.2 2,421.3
181,321.3 360,421.3 "/>
<text transform="matrix(1 0 0 1 123.8486 538.24)" class="st1 st2 st3">News</text>
</a>
<a id="Local_Exchange" xlink:href="https://tradeshack.au/local-edible-exchange/" >
<polygon id="Local_Exchange_00000052093847367928459750000017120200193115507858_" class="st0" points="547,937.2 368,1037.2
189,937.2 189,737.2 368,637.2 547,737.2 "/>
<text transform="matrix(1 0 0 1 210.6318 853.24)" class="st1 st2 st3">Local Exchange</text>
</a>
<a id="Communities" xlink:href="https://tradeshack.au/local-communities/" >
<polygon id="Communities_00000128464967429771677690000007271752719640598663_" class="st0" points="927,937.2 748,1037.2
569,937.2 569,737.2 748,637.2 927,737.2 "/>
<text transform="matrix(1 0 0 1 612.1426 853.24)" class="st1 st2 st3">Communities</text>
</a>
</svg>
So how do I go about getting that done ;-)>
You can see a working example, without the bit that I cannot figure out, on my website Tradeshack website where the example is.

This is resolved now by putting a page specific SVG on each page.

Related

How to get the name of a xlink:href/svg id with scrapy?

I am totally new to scrapy and just started yesterday to use it.
There is a page with ratings for products I want to get. Unfortunately the ratings are not texts but stars.
Let's say a product got two stars, it looks like this:
<div class="index-classRating">
<div class="index-classIcon index-red">
<svg viewBox="0 0 32 32">
<use xlink:href="/static/media/icons.f88ec073.svg#wci-starrating-full">
#shadow-root (closed)
<svg id="wci-starrating-full" viewBox="0 0 512 512" width="100%" height="100%">
<path d="1 2 3"></path>
</svg>
</use>
</svg>
</div>
<div class="index-classIcon index-red">
<svg viewBox="0 0 32 32">
<use xlink:href="/static/media/icons.f88ec073.svg#wci-starrating-full">
#shadow-root (closed)
<svg id="wci-starrating-full" viewBox="0 0 512 512" width="100%" height="100%">
<path d="1 2 3"></path>
</svg>
</use>
</svg>
</div>
So I want to count how many stars aka "/static/media/icons.f88ec073.svg#wci-starrating-full" or "wci-starrating-full" are there.
So I tried
stars = response.xpath('//div[#class="index-classIcon index_red"]/svg[#viewBox="0 0 32 32"]/use[#xlink:href="/static/media/icons.f88ec073.svg#wci-starrating-full"]/svg/#id').extract()
and got an empty list.
But I want to have something like
stars = ["wci-starrating-full","wci-starrating-full"]
viewbox must be written lowercase, "index_red" has dash not hyphen
try
stars=response.xpath('//div[#class="index-classIcon index-red"]/svg[#viewbox="0 0 32 32"]/use/svg/#id').extract()
Total example: (please copy-paste into python)
import scrapy
response=scrapy.http.HtmlResponse(url='just_a_string',encoding='utf-8',body=u'''
<div class="index-classRating">
<div class="index-classIcon index-red">
<svg viewBox="0 0 32 32">
<use xlink:href="/static/media/icons.f88ec073.svg#wci-starrating-full">
#shadow-root (closed)
<svg id="wci-starrating-full" viewBox="0 0 512 512" width="100%" height="100%">
<path d="1 2 3"></path>
</svg>
</use>
</svg>
</div>
<div class="index-classIcon index-red">
<svg viewBox="0 0 32 32">
<use xlink:href="/static/media/icons.f88ec073.svg#wci-starrating-full">
#shadow-root (closed)
<svg id="wci-starrating-full" viewBox="0 0 512 512" width="100%" height="100%">
<path d="1 2 3"></path>
</svg>
</use>
</svg>
</div>
''')
stars=response.xpath('//div[#class="index-classIcon index-red"]/svg[#viewbox="0 0 32 32"]/use/svg/#id').extract()
print(repr(stars))

SVG xlink:href not working in Chrome

I'm new to SVG. I'm trying to put a SVG file with linkable regions (like an image map) on my page and make it responsive. The SVG displays, but the linkable areas aren't working in Chrome. Works fine in FF, IE11, and Edge.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 880 371" style="enable-background:new 0 0 880 371;" xml:space="preserve">
<g id="Background_xA0_Image_1_">
<image style="overflow:visible;" width="880" height="371" id="Background_xA0_Image" xlink:href="data:image/jpeg;... />
</image>
</g>
<g id="Layer_2_xA0_Image_1_">
<a id="Layer_2_xA0_Image" xlink:href="http://www.example.com" transform="matrix(1 0 0 1 572 215)">
<image style="overflow:visible;" width="195" height="42" xlink:href="data:image/png;...>
</image>
</a>
</g>
<g id="Layer_1_xA0_Image_1_">
<a id="Layer_1_xA0_Image" xlink:href="http://www.anotherexample.com" transform="matrix(1 0 0 1 308 164)">
<image style="overflow:visible;" width="137" height="46" xlink:href="data:image/png;...>
</image>
</a>
</g>
</svg>
I'm working with a JPG file that I sliced up in Photoshop and then exported to a SVG from Illustrator. This is the code it produced.
Just realized elements within the svg are clickabel - the problem was actually the cursor not changing styles so I thought it wasn't working.
I added cursor:pointer; to the links and it looks good now.

SVG rendering in Safari and IE

I have a lot of trouble with an svg that is made from an Illustrator. Here is the code that the Illustrator gave me.
<svg version="1.1" class="svg active" id="vertical_lines_svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 216.4 64.4" style="enable-background:new 0 0 216.4 64.4;" xml:space="preserve">
<use xlink:href="#I" id="svgCanvas"/>
<pattern x="92.6" y="18.1" width="28.3" height="28.3" patternUnits="userSpaceOnUse" id="New_Pattern" viewBox="0 -28.3 28.3 28.3" style="overflow:visible;">
<g id="XMLID_484_">
<polygon id="XMLID_507_" class="st0" points="0,-28.3 28.3,-28.3 28.3,0 0,0 "/>
<polygon id="XMLID_506_" class="st4" points="7.1,0 0,0 0,-28.3 7.1,-28.3 "/>
<polygon id="XMLID_505_" class="st1" points="14.2,0 7.1,0 7.1,-28.3 14.2,-28.3 "/>
<polygon id="XMLID_504_" class="st4" points="21.3,0 14.2,0 14.2,-28.3 21.3,-28.3 "/>
<polygon id="XMLID_503_" class="st1" points="28.3,0 21.3,0 21.3,-28.3 28.3,-28.3 "/>
</g>
</pattern>
<g id="XMLID_131_">
<pattern id="XMLID_28" xlink:href="#New_Pattern" patternTransform="matrix(1 0 0 1 -40.8688 -2.6535)">
</pattern>
<path id="XMLID_132_" class="st2" fill="url(#XMLID_28_)" d="M74.2,39.6c8.1,3.2,20.8,4.9,33.8,4.8c13,0.1,25.8-1.6,33.8-4.8c8.1,3.2,20.8,4.9,33.8,4.8
c13,0.1,25.8-1.6,33.9-4.9c-0.1-1-0.5-3.4-1-6.5c-1.1-6.8-2.8-16.9-4.1-21.7l-0.1-0.2c-2-7.6-2.9-11.1-7.5-11.1h-40.4
c-6.3,0-7.2,2.6-8.8,8.9l-0.5,2.1c-1.3,5.1-3.1,12.3-4.6,21.9c-0.3,1.9-0.6,4-0.8,6.1c-0.2-1.2-0.5-3.4-1-6
c-1.1-6.8-2.8-16.9-4.1-21.7l-0.1-0.2c-2-7.6-2.9-11.1-7.5-11.1H88.8c-6.3,0-7.2,2.6-8.8,8.9l-0.5,2.1c-1.3,5.1-3.1,12.3-4.6,21.9
c-0.3,1.9-0.6,4-0.8,6.1c-0.2-1.2-0.5-3.4-1-6c-1.1-6.8-2.8-16.9-4.1-21.7l-0.1-0.2C67,3.5,66.1,0,61.5,0H21.2
C14.9,0,14,2.6,12.4,9l-0.5,2.1c-1.3,5.1-3.1,12.3-4.6,21.9C7,35,6.7,37.2,6.5,39.5c8.1,3.3,20.9,4.9,33.9,4.9
C53.4,44.5,66.1,42.8,74.2,39.6z"/>
<pattern id="XMLID_29" xlink:href="#New_Pattern" patternTransform="matrix(1 0 0 1 -40.8688 -2.6535)">
</pattern>
<path id="XMLID_322_" class="st3" fill="url(#XMLID_29_)" d="M211,45.6c-0.3,0-0.6-0.1-0.8-0.1c-10.6,4.9-39.7,7.1-63.5,1.5c-1.6-0.4-3.2-0.8-4.7-1.2
c-1.6,0.7-3.5,1.3-5.7,1.8C122.9,50.9,99.1,51.7,79,47c-1.6-0.4-3.2-0.8-4.7-1.2c-1.6,0.7-3.5,1.3-5.7,1.8
C54,51.2,26.9,51.9,5.9,45.5c-0.3,0-0.6,0-0.8,0.1c-2.7,0.4-6.2,3.2-4.6,4.3c3.4,2.2,8.7,3.9,15,5.1v9.3h49.9v-9.3
c3.3-0.6,6.3-1.4,8.9-2.3c2.6,0.9,5.6,1.7,8.9,2.3v9.3H133v-9.3c3.3-0.6,6.3-1.4,8.9-2.3c2.6,0.9,5.6,1.7,8.9,2.3v9.3h49.9v-9.3
c6.3-1.2,11.6-2.9,15-5.1C217.2,48.8,213.8,46,211,45.6z"/>
</g>
</svg><!--end vertical_lines_svg-->
I have to change the colors of the patterns .st4 and .st1 with jQuery, everything is great in FF and Chrome, but nothing renders on IE and Safari. I tried everything and did not manage to fix it. Any ideas why this is happening and how can I fix it?
Ok, I found the problem you can't have negative values to the viewBox attribute in tag. This will make the svg to disappear in IE

With Jekyll, links inside SVG graphics aren't working

I have an SVG graphic in a Jekyll project with code like this:
```
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 451.5 100" enable-background="new 0 0 451.5 100" xml:space="preserve">
<a xlink:href="http://google.com">
<g id="step1_1_">
<rect x="19" y="15.7" fill="whitesmoke" stroke="orange" stroke-miterlimit="10" width="110.6" height="69.1"/>
<text id="step1" transform="matrix(1 0 0 1 36.1851 39.8042)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">Configure the </tspan><tspan x="0" y="14.4" font-family="'MyriadPro-Regular'" font-size="12">widget</tspan></text>
</g>
</a>
<a xlink:href="http://nytimes.com">
<g id="step2_1_">
<rect x="170.2" y="15.7" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" width="110.6" height="69.1"/>
<text id="step2" transform="matrix(1 0 0 1 190.2962 39.8042)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">Configure the </tspan><tspan x="0" y="14.4" font-family="'MyriadPro-Regular'" font-size="12">gizmo</tspan></text>
</g>
</a>
<a xlink:href="http://yahoo.com">
<g id="step3_1_">
<rect x="321.2" y="15.7" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" width="110.6" height="69.1"/>
<text id="step3" transform="matrix(1 0 0 1 342.4126 38.7301)"><tspan x="0" y="0" font-family="'MyriadPro-Regular'" font-size="12">Copy the scripts</tspan></text>
</g>
</a>
<g id="arrows">
<g>
<g>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="134" y1="46.5" x2="156" y2="46.5"/>
<g>
<path d="M162,46.5c-2.8,1.1-6.4,2.9-8.5,4.8l1.7-4.8l-1.7-4.8C155.6,43.6,159.2,45.4,162,46.5z"/>
</g>
</g>
</g>
<g>
<g>
<line fill="none" stroke="#000000" stroke-miterlimit="10" x1="287" y1="48.5" x2="309" y2="48.5"/>
<g>
<path d="M315,48.5c-2.8,1.1-6.4,2.9-8.5,4.8l1.7-4.8l-1.7-4.8C308.6,45.6,312.2,47.4,315,48.5z"/>
</g>
</g>
</g>
</g>
</svg>
```
This image is just three rectangular shapes that are formatted with links using the a tag.
When I view the image in the browser by itself, the links work. However, when I view the image inside a Jekyll site, the links no longer work. Any ideas why?
If you embed your svg as an image (img) you have no control over it (external css and js) and links are not clickable. Options are :
inline svg
{% include_relative workflow.svg %}
using the object tag
<object data="/workflow.svg" type="image/svg+xml" class="mailicon" />
</object>
More info on https://css-tricks.com/using-svg/

SVG Object displaying SVG Code instead of SVG Graphic?

on my website I have an SVG Object which is meant to display a vector image, whilst testing this offline, everything worked fine, but when I uploaded it onto my website, the object displays the code of the SVG in question. viewable here: link to site with svg
Object Code:
<object type="image/svg+xml" data="ppvisual.svg" width="702px" height="259.37px">
<param name="colour" value="<?php echo $colour; ?>" />
<param name="textcolour" value="<?php echo $textcolour; ?>" />
<param name="lanyardtext" value="<?php echo $lanyardtext; ?>" />
</object>
Doctype: (incase that has anything to do with it?)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
SVG code:
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="702px" height="259.37px" viewBox="0 0 702 259.37" enable-background="new 0 0 702 259.37" xml:space="preserve">
<g>
<g>
<polygon fill="none" points="0,80.811 0.053,113.105 48.17,112.998 48.117,80.705 "/>
<image overflow="visible" width="109" height="188" xlink:href="fitment1.png" transform="matrix(4.854395e-04 0.2963 -0.2559 5.628683e-04 48.1172 80.7046)">
</image>
</g>
</g>
<g>
<path fill-rule="evenodd" clip-rule="evenodd" fill="param(colour) white" d="M43.807,108.613c-0.241,0-0.476-0.086-0.659-0.248
c-0.217-0.189-0.341-0.463-0.341-0.752v-22.26c0-0.502,0.372-0.926,0.87-0.991l633.935-83.34c0.043-0.005,0.086-0.008,0.129-0.008
c0.264,0,0.52,0.104,0.707,0.293l22.26,22.26c0.188,0.188,0.293,0.442,0.293,0.707v61.08c0,0.553-0.447,1-1,1h-22.26
c-0.553,0-1-0.447-1-1v-59.94L43.938,108.605C43.894,108.611,43.851,108.613,43.807,108.613z"/>
<path fill="#636466" d="M677.74,2.013L700,24.273v61.08h-22.26v-61.08l-633.933,83.34v-22.26L677.74,2.013 M677.74,0.013
c-0.086,0-0.174,0.005-0.26,0.017L43.546,83.371c-0.995,0.13-1.739,0.979-1.739,1.982v22.26c0,0.576,0.248,1.125,0.681,1.504
c0.367,0.322,0.836,0.496,1.319,0.496c0.086,0,0.174-0.006,0.261-0.016L675.74,26.553v58.8c0,1.104,0.896,2,2,2H700
c1.105,0,2-0.896,2-2v-61.08c0-0.53-0.211-1.039-0.586-1.414l-22.26-22.26C678.777,0.222,678.268,0.013,677.74,0.013L677.74,0.013z
"/>
</g>
<g>
<path fill-rule="evenodd" clip-rule="evenodd" fill="param(colour) white" d="M43.807,108.613c-0.552,0-1-0.447-1-1v-22.26c0-0.552,0.448-1,1-1
H700c0.404,0,0.77,0.244,0.924,0.617c0.155,0.374,0.069,0.804-0.217,1.09l-22.26,22.26c-0.188,0.188-0.441,0.293-0.707,0.293
H43.807z"/>
<path fill="#636466" d="M700,85.353l-22.26,22.26H43.807v-22.26H677.74H700 M700,83.353h-22.26H43.807c-1.104,0-2,0.896-2,2v22.26
c0,1.104,0.896,2,2,2H677.74c0.53,0,1.039-0.211,1.414-0.586l22.26-22.26c0.572-0.572,0.743-1.432,0.434-2.18
C701.538,83.84,700.809,83.353,700,83.353L700,83.353z"/>
</g>
<rect x="0" y="186.505" fill-rule="evenodd" clip-rule="evenodd" fill="param(colour) white" width="702" height="70.865"/>
<path fill="#636466" d="M702,257.37H0v2h702V257.37z M702,186.505v-2l0,0H0v2H702"/>
<g>
<defs>
<polygon id="SVGID_1_" points="677.74,107.613 43.807,107.613 43.807,85.353 677.74,85.353 700,85.353 "/>
</defs>
<clipPath id="SVGID_2_">
<use xlink:href="#SVGID_1_" overflow="visible"/>
</clipPath>
<g clip-path="url(#SVGID_2_)">
<text transform="matrix(1 0 0 1 372 102.272)" fill="param(textcolour) white" font-family="'Verdana-Bold'" font-size="16" text-anchor="middle" content-value="param(lanyardtext)">Enter Your Text Enter Your Text Enter Your Text Enter Your Text</text>
</g>
</g>
<g>
<defs>
<rect id="SVGID_3_" x="0" y="186.505" width="702" height="70.865"/>
</defs>
<clipPath id="SVGID_4_">
<use xlink:href="#SVGID_3_" overflow="visible"/>
</clipPath>
<g clip-path="url(#SVGID_4_)">
<text transform="matrix(1 0 0 1 350 240.0977)" fill="param(textcolour) white" font-family="'Verdana-Bold'" font-size="50.9319" text-anchor="middle" content-value="param(lanyardtext) white">Enter Your Text Enter Your Text Enter Your Text Enter Your Text</text>
</g>
</g>
<script type="text/ecmascript" xlink:href="param.js" />
</svg>
I'm thinking this might be something about server setting? anybody have any idea how I would fix it?
Thanks in advance.
You are sending the SVG data with a mime type of text/plain. You need to reconfigure your web server to send it with a mime type of image/svg+xml. How you do that depends on what web server you are using.

Resources