Add shadow to an SVG element, such as line - html

So I'm pretty new to SVG but I started playing with a graph. The graph is from here. I've been searching for hours and did only find a half solution to my problem. As you see from the code snippet, if you hover on the graph it "glows". But I want that only the circles and the "joints" would glow when I'm hovering on them.
What I tried:
Using regular CSS shadowing
Using the code that makes "glow" the graph, but only on g elements.
Creating a separate SVG both: a) in the main SVG b) separately, and
mixing them with position: absolute. (after this the positioning
worked weirdly)
What should I do to make only the circles and the joints "glow"?
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body{
height: 100%;
width: 100%;
}
#import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap');
body {
font-family: 'Roboto Mono', monospace;
}
.graph .labels.x-labels {
text-anchor: middle;
}
.graph .labels.y-labels {
text-anchor: end;
}
.graph {
height: 500px;
width: 800px;
}
.graph .grid {
stroke: #ccc;
stroke-dasharray: 0;
stroke-width: 3;
}
.labels {
font-size: 17px;
font-weight: 400;
}
.label-title {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
fill: black;
}
.data {
fill: #f86d36;
stroke-width: 1;
}
.graph .dot-joints {
stroke: #f86d36;
stroke-dasharray: 0;
stroke-width: 3;
}
svg:hover {
-webkit-filter: drop-shadow(0px 0px 4px #f86d36e8);
filter: drop-shadow(0px 0px 4px #f86d36e8);
}
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph"
aria-labelledby="title" role="img">
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="90" y1="5" y2="371"></line>
</g>
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="705" y1="370" y2="370"></line>
</g>
<g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392"
y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440"
class="label-title">Year</text></g>
<g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70"
y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g>
<g class="data" data-setname="Our first data set">
<circle cx="95" cy="192" data-value="7.2" r="5"></circle>
<circle cx="240" cy="141" data-value="8.1" r="5"></circle>
<circle cx="388" cy="179" data-value="7.7" r="5"></circle>
<circle cx="531" cy="200" data-value="6.8" r="5"></circle>
<circle cx="677" cy="104" data-value="6.7" r="5"></circle>
</g>
<g class="dot-joints x-grid">
<line x1="95" x2="240" y1="192" y2="141"></line>
<line x1="240" x2="388" y1="141" y2="179"></line>
<line x1="388" x2="531" y1="179" y2="200"></line>
<line x1="531" x2="677" y1="200" y2="104"></line>
</g>
</svg>

I hope this is what you need: I'm using an svg filter for the shadow.
To your code I've added .data circle:hover{filter:url(#f)}for the individual circles and .dot-joints.x-grid:hover{filter:url(#f)} for the group of lines:
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body{
height: 100%;
width: 100%;
}
#import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap');
body {
font-family: 'Roboto Mono', monospace;
}
.graph .labels.x-labels {
text-anchor: middle;
}
.graph .labels.y-labels {
text-anchor: end;
}
.graph {
height: 500px;
width: 800px;
}
.graph .grid {
stroke: #ccc;
stroke-dasharray: 0;
stroke-width: 3;
}
.labels {
font-size: 17px;
font-weight: 400;
}
.label-title {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
fill: black;
}
.data {
fill: #f86d36;
stroke-width: 1;
}
.data circle:hover{filter:url(#f)}
.graph .dot-joints {
stroke: #f86d36;
stroke-dasharray: 0;
stroke-width: 3;
}
.dot-joints.x-grid:hover{filter:url(#f)}
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph"
aria-labelledby="title" role="img">
<defs>
<filter id="f" filterUnits="userSpaceOnUse" id="shadow" x="-10" y="-150" width="120%" height="120%">
<feGaussianBlur in="SourceAlpha" stdDeviation="5" result="blur"></feGaussianBlur>
<feOffset in="blur" dx="3" dy="1" result="shadow"></feOffset>
<feFlood flood-color="rgba(0,0,0,.52)" result="color" />
<feComposite in ="color" in2="shadow" operator="in" />
<feComposite in="SourceGraphic"/>
</filter>
</defs>
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="90" y1="5" y2="371"></line>
</g>
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="705" y1="370" y2="370"></line>
</g>
<g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392"
y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440"
class="label-title">Year</text></g>
<g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70"
y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g>
<g class="data" data-setname="Our first data set">
<circle cx="95" cy="192" data-value="7.2" r="5"></circle>
<circle cx="240" cy="141" data-value="8.1" r="5"></circle>
<circle cx="388" cy="179" data-value="7.7" r="5"></circle>
<circle cx="531" cy="200" data-value="6.8" r="5"></circle>
<circle cx="677" cy="104" data-value="6.7" r="5"></circle>
</g>
<g class="dot-joints x-grid" >
<line x1="95" x2="240" y1="192" y2="141"></line>
<line x1="240" x2="388" y1="141" y2="179"></line>
<line x1="388" x2="531" y1="179" y2="200"></line>
<line x1="531" x2="677" y1="200" y2="104"></line>
</g>
</svg>
Alternatively you may want this instead:
svg:hover .data,
svg:hover .dot-joints.x-grid{filter:url(#f)}
When hovering the svg element apply shadow to the lines and circles.
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body{
height: 100%;
width: 100%;
}
#import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,500&display=swap');
body {
font-family: 'Roboto Mono', monospace;
}
.graph .labels.x-labels {
text-anchor: middle;
}
.graph .labels.y-labels {
text-anchor: end;
}
.graph {
height: 500px;
width: 800px;
}
.graph .grid {
stroke: #ccc;
stroke-dasharray: 0;
stroke-width: 3;
}
.labels {
font-size: 17px;
font-weight: 400;
}
.label-title {
font-weight: 500;
text-transform: uppercase;
font-size: 15px;
fill: black;
}
.data {
fill: #f86d36;
stroke-width: 1;
}
.graph .dot-joints {
stroke: #f86d36;
stroke-dasharray: 0;
stroke-width: 3;
}
svg:hover .data,
svg:hover .dot-joints.x-grid{filter:url(#f)}
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="graph"
aria-labelledby="title" role="img">
<defs>
<filter id="f" filterUnits="userSpaceOnUse" id="shadow" x="-10" y="-150" width="120%" height="120%">
<feGaussianBlur in="SourceAlpha" stdDeviation="5" result="blur"></feGaussianBlur>
<feOffset in="blur" dx="3" dy="1" result="shadow"></feOffset>
<feFlood flood-color="rgba(0,0,0,.52)" result="color" />
<feComposite in ="color" in2="shadow" operator="in" />
<feComposite in="SourceGraphic"/>
</filter>
</defs>
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="90" y1="5" y2="371"></line>
</g>
<g class="grid x-grid" id="xGrid">
<line x1="90" x2="705" y1="370" y2="370"></line>
</g>
<g class="labels x-labels"><text x="100" y="400">2008</text><text x="246" y="400">2009</text><text x="392"
y="400">2010</text><text x="538" y="400">2011</text><text x="694" y="400">2012</text><text x="400" y="440"
class="label-title">Year</text></g>
<g class="labels x-labels"><text x="70" y="15">15</text><text x="70" y="131">10</text><text x="70"
y="248">5</text><text x="70" y="373">0</text><text x="35" y="200" class="label-title">Price</text></g>
<g class="data" data-setname="Our first data set">
<circle cx="95" cy="192" data-value="7.2" r="5"></circle>
<circle cx="240" cy="141" data-value="8.1" r="5"></circle>
<circle cx="388" cy="179" data-value="7.7" r="5"></circle>
<circle cx="531" cy="200" data-value="6.8" r="5"></circle>
<circle cx="677" cy="104" data-value="6.7" r="5"></circle>
</g>
<g class="dot-joints x-grid" >
<line x1="95" x2="240" y1="192" y2="141"></line>
<line x1="240" x2="388" y1="141" y2="179"></line>
<line x1="388" x2="531" y1="179" y2="200"></line>
<line x1="531" x2="677" y1="200" y2="104"></line>
</g>
</svg>
UPDATE
The OP is commenting:
Can you explain it in a little more details
In the <defs> I've added an svg filter. This filter first is creating a blur feGaussianBlur. You may need to change the stdDeviation in order to change the aspect of the shadow.
Next is offsetting the the previously created blur feOffset: You may need to change the dx="3"and dy="1" attributes in order to move the shadow.
Then feFlood and feComposite are used to add a color to the shadow. In this case I'm using a semitransparent black, but you can use the color you want.
I'm using this filter to apply the shadow only to those elements you want: filter:url(#f) - where f is the filter's id

Related

How can I translate an element and at the same time rotate realistically?

It turns out of position and moves incorrectly. It's hard to find the exact point so it looks realistic and the transitions are smooth. the turning is out of cue and can not find a solution to make it turn faster as it moves at its normal rate. I have tried many times to get the exact timing but I cant find a way.
function wid() {
if (window.innerWidth < 960) {
var r = document.querySelector(':root');
r.style.setProperty('--wid', '100%');
}
wid();
}
#car {
background-color: transparent;
width: 10px;
height: 20px;
transform: translate(241.5px, 215px);
position: relative;
animation-name: driving;
animation-duration: 10s;
animation-timing-function: linear;
/*linear ease-in-out*/
}
#map {
background-color: transparent;
width: 400px;
margin: auto;
position: absolute;
transform: translate(5%, 5%);
}
#bod {
background-color: green;
position: absolute;
width: 100%;
height: 100%;
}
html,
body {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
.mainsec {}
#keyframes driving {
0% {
transform: translate(241.5px, 215px);
}
10% {
transform: translate(241.5px, 40px)rotate(-60deg);
}
28% {
transform: translate(41.5px, 86px)rotate(-125deg);
}
38% {
transform: translate(41.5px, 300px)rotate(-180deg);
}
40% {
transform: translate(120px, 360px)rotate(-220deg);
}
50% {
transform: translate(160px, 360px)rotate(-125deg);
}
60% {
transform: translate(200px, 450px)rotate(-230deg);
}
70% {
transform: translate(400px, 460px)rotate(-360deg);
}
80% {
transform: translate(260.5px, 215pxrotate(360deg));
}
90% {
transform: translate(241.5px, 180pxrotate(360deg));
}
100% {
transform: translate(241.5px, 215pxrotate(360deg));
}
}
<div id="bod">
<div id="map">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="415.00774" height="464.03421" viewBox="0,0,415.00774,464.03421">
<g transform="translate(-5.56354,24.30861)">
<g data-paper-data="{"isPaintingLayer":true}" fill-rule="nonzero" stroke-width="0" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal">
<path d="M193.21864,323.70241c2.08101,14.58763 -0.75936,39.6034 -0.75936,39.6034l-76.95053,-59.65507c0,0 27.04231,-21.9967 43.16349,-20.31537c5.01955,0.5235 15.96324,3.86994 22.75063,11.80093c6.7874,7.93099 11.43447,26.03343 11.79578,28.56611z" fill="#e2ea8f" stroke="none"/>
<path d="M5.56688,290.21195c0.51544,-15.25718 8.62251,-39.2653 8.62251,-39.2653l75.02651,85.4148c0,0 -34.79132,12.85441 -52.63063,5.75382c-5.55452,-2.21087 -17.2321,-9.2315 -23.32635,-19.42903c-6.09425,-10.19755 -7.78154,-29.82536 -7.69204,-32.47428z" fill="#e2ea8f" stroke="none"/>
<path d="M219.05583,250.34734v-212.80012c0,0 1.48764,-14.0667 -3.9272,-17.72172c-5.41484,-3.65502 -26.47434,-0.83576 -26.47434,-0.83576l-66.30684,14.95228c0,0 -31.54844,6.49453 -43.16799,13.0135c-11.85598,6.65162 -17.65815,11.05621 -23.81015,25.35199c-6.15201,14.29579 -4.49552,155.45874 -4.49552,155.45874c0,0 0.12847,18.24631 2.32244,26.68213c1.97899,7.60918 18.15757,34.8776 33.34816,40.17712c19.19535,6.69665 43.22077,-3.09306 62.42146,3.17404c13.17719,4.30105 19.38737,8.26387 26.48485,18.94892c8.15443,12.27627 12.12432,31.97154 14.43416,37.56194c3.22503,7.80536 6.42812,17.86233 6.42812,17.86233l3.4807,18.08984c0,0 1.03251,15.13972 8.75099,18.80522c6.38845,3.03387 114.48707,3.64998 151.55195,3.77223c7.71664,0.02545 10.45146,1.27859 12.93151,-2.85614c1.26925,-2.11608 1.73211,-6.23932 -2.62668,-9.76101c-4.15809,-3.35953 -50.05552,-4.44025 -50.05552,-4.44025l8.83274,-34.13795c0,0 28.4294,-1.70463 51.65944,4.28594c23.23005,5.99057 28.02805,8.6783 34.85366,27.38878c4.72033,16.40398 10.64834,45.16217 -7.11765,45.35982c-60.58922,0.67405 -196.5872,1.94573 -217.63794,0.05149c-6.61359,-0.59513 -10.36459,-4.25214 -10.90643,-5.25027c-2.18537,-4.02565 -3.47544,-7.21102 -4.98448,-12.09238c-1.50902,-4.88135 -11.88057,-53.84601 -20.93852,-71.76255c-6.71889,-13.2899 -21.01689,-13.36816 -21.01689,-13.36816l-36.99995,-0.31926c0,0 -24.73763,1.62251 -39.7364,-10.8668c-11.6551,-9.70507 -19.2506,-18.21353 -27.99162,-32.54346c-8.74102,-14.32992 -9.25637,-22.76613 -12.14607,-33.25777c-2.88029,-10.45743 -3.43264,-33.62966 -3.43264,-33.62966c0,0 2.31202,-92.96558 1.9462,-152.4744c-0.07076,-11.51164 3.51657,-14.76709 6.12168,-20.3207c3.4054,-7.25967 10.81182,-13.80213 10.81182,-13.80213c0,0 19.26399,-15.40827 29.93019,-21.31454c10.50848,-5.81894 33.60085,-13.86497 33.60085,-13.86497l94.80812,-23.31008c0,0 15.46605,-4.62962 28.36495,-4.85435c11.96737,-0.2085 21.24293,3.77639 25.88139,8.78947c2.73367,2.95445 8.45832,9.73142 10.28464,14.53415c4.2386,11.14628 2.66852,21.78451 2.66852,21.78451v229.54004c0,0 -1.40764,17.5481 -0.50008,26.82662c0.34086,3.48486 4.70635,31.95634 21.05493,49.25219c15.8564,16.77515 51.49572,35.54486 51.49572,35.54486l-8.29877,33.81234c0,0 -16.52481,-0.78157 -32.88652,-13.95939c-14.69724,-7.65388 -27.17248,-17.57315 -36.41394,-27.55132c-16.40866,-17.71676 -22.39766,-35.61914 -24.07827,-41.35593c-5.39145,-18.40375 -8.51881,-62.56938 -8.51881,-62.56938z" fill="#414141" stroke="#000000"/>
<path d="M219.05583,165.09336v-5.97191h38.14575v5.97191z" fill="#d2d2d2" stroke="#000000"/>
<path d="M224.72917,199.44555v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M240.9985,199.47883v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M224.72915,169.62976v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M240.99849,169.66305v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M224.72915,184.69724v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M240.9985,184.73053v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M224.73546,228.96504v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M241.00479,228.99833v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M224.73546,214.21673v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M241.00479,214.25002v-1.40716h10.52976v1.40716z" fill="#d2d2d2" stroke="#000000"/>
<path d="M203.48125,23.23113l-0.09191,-5.49181c0,0 9.04848,-1.64122 13.01789,1.24562c2.86101,2.08074 4.05979,12.06922 4.05979,12.06922l-6.28979,0.0411c0,0 -0.42661,-5.56759 -3.14675,-7.23476c-2.27102,-1.39192 -7.54922,-0.62936 -7.54922,-0.62936z" fill="#bd0000" stroke="none"/>
<path d="M207.96794,23.16086v-5.85189c0,0 2.70134,0.06002 4.01174,0.21819c1.25881,0.15192 3.70211,0.71279 3.70211,0.71279l-4.38891,5.71888c0,0 -1.13567,-0.40556 -1.69516,-0.53983c-0.5486,-0.13166 -1.62977,-0.25815 -1.62977,-0.25815z" fill="#bdbdbd" stroke="none"/><path d="M214.08583,31.1407l-0.66499,-3.85692l5.98488,-1.59597l0.93098,5.18691z" fill="#bdbdbd" stroke="none"/>
</g>
</g>
</svg>
</div>
<div id="car">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5.69151" height="13.00614" viewBox="0,0,5.69151,13.00614">
<g transform="translate(-237.15425,-173.49693)">
<g data-paper-data="{"isPaintingLayer":true}" fill-rule="nonzero" stroke-width="0" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" style="mix-blend-mode: normal">
<path d="M237.95271,176.91509v-0.36484h1.65836v0.36484z" fill="#7e7e7e" stroke="none"/><path d="M240.4616,177.96722l-0.10174,-0.19425l1.68345,-0.8818l0.10175,0.19425z" data-paper-data="{"index":null}" fill="#7e7e7e" stroke="none"/>
<path d="M240.40631,176.94827v-0.36484h1.65836v0.36484z" data-paper-data="{"index":null}" fill="#7e7e7e" stroke="none"/>
<path d="M237.87231,177.05225l0.10177,-0.19425l1.68345,0.8818l-0.10174,0.19425z" fill="#7e7e7e" stroke="none"/>
<path d="M237.68777,185.93213l0.07908,-4.54285l0.04206,-0.67016l0.26596,-0.28733c0,0 0.87932,-0.26451 1.13707,-0.61548c0.38158,-0.51961 0.30716,-1.61303 0.30716,-1.61303l0.13902,-3.00375l-0.57115,-0.00965l-0.80751,0.2432l-0.79069,-0.00484v-1.58791h2.20561l0.33641,-0.34338l0.34463,0.34338h2.13582v1.58791l-0.66608,0.00627l-0.80156,-0.27803l-0.63165,-0.00276l0.13298,3.04754c0,0 -0.04796,1.08621 0.37004,1.67854c0.27203,0.38548 1.01745,0.57779 1.01745,0.57779c0,0 0.22801,0.19788 0.25867,0.29475c0.03066,0.09686 0.03601,0.63613 0.03601,0.63613l0.08511,4.54371z" fill="#000000" stroke="#000000"/>
<path d="M237.15425,177.61095v-1.79988h0.82698v1.79988z" fill="#353535" stroke="none"/>
<path d="M242.01878,177.65959v-1.79987h0.82697v1.79987z" fill="#353535" stroke="none"/>
<path d="M237.15425,186.26759v-1.79987h1.0923v1.79987z" fill="#353535" stroke="none"/>
<path d="M241.75344,186.31622v-1.79986h1.0923v1.79986z" fill="#353535" stroke="none"/>
<path d="M238.35111,185.93798l0.0268,-1.54014l-0.65122,-0.69631l0.04014,-2.30639l0.04206,-0.67016l0.26596,-0.28734c0,0 0.87933,-0.26451 1.13708,-0.61549c0.38158,-0.51961 0.30716,-1.61302 0.30716,-1.61302l0.13902,-3.00375l0.03627,-1.35921l0.33641,-0.34338l0.34463,0.34338l0.03653,1.31338l0.13297,3.04753c0,0 -0.04796,1.08623 0.37004,1.67854c0.27203,0.38548 1.01745,0.57779 1.01745,0.57779c0,0 0.22801,0.19788 0.25867,0.29475c0.03066,0.09686 0.03602,0.63613 0.03602,0.63613l0.0426,2.27394l-0.64783,0.79572l0.06016,1.47404z" fill="#f30000" stroke="#000000"/>
<path d="M238.82256,186.50307v-0.92868h2.35487v0.92868z" fill="#000000" stroke="none"/>
<path d="M239.43365,180.99989v-1.46517c0,0 0.25408,-0.66824 0.56634,-0.65782c0.34514,0.01152 0.56635,0.65782 0.56635,0.65782v1.46517z" fill="#7e7e7e" stroke="none"/>
<path d="M239.99999,180.68103c-0.17989,0 -0.32574,-0.16918 -0.32574,-0.37787c0,-0.20869 0.14583,-0.37787 0.32574,-0.37787c0.17989,0 0.32575,0.16918 0.32575,0.37787c0,0.20869 -0.14584,0.37787 -0.32575,0.37787z" fill="#f30000" stroke="none"/>
</g>
</g>
</svg>
</div>
</div>

How to center and rotate SVG circle correctly and center polygon in the center of the circle?

I'm trying to let the circles inside rotate. Using 50% in the from and to of the animateTransform didn't work.
The other thing I'm trying is to put the polygon in the center of the circle.
body {
margin: 0;
background: black;
}
#container {
background: rgba(0, 155, 255, 0.3);
padding: 10px;
}
#circle1 {
}
#circle2 {
stroke-dasharray: 20 3 55;
}
#circle3 {
stroke-dasharray: 22;
}
<div id="container">
<svg xmlns="http://www.w3.org/2000/svg" height=207px width=207px stroke="#00bd80" fill="none">
<circle id="circle1" r="100" cx="50%" cy="50%" stroke-width="7px"/>
<circle id="circle2" r="96" cx="50%" cy="50%" stroke-width="5px">
<animateTransform attributeType="xml"
attributeName="transform"
type="rotate"
from="0 98.5 98.5"
to="360 98.5 98.5"
dur="20s"
repeatCount="indefinite"/> <!-- how to center correctly -->
</circle>
<circle id="circle3" r="80" cx="50%" cy="50%" stroke-width="5px"/>
<polygon points="30,15 22.5,28.0 7.5,28.0 0,15 7.5,2.0 22.5,2.0"></polygon>
</svg>
</div>
Your canvas is 207px wide and 207px high. The circles are centred at 50% so at 207/2 = 103.5px so that's where you need to do your rotation around.
The polygon is 30px wide and 26px across so you can just translate that into place too. You could combine the two polygon translate commands, I've left them separate so it's clearer what I've done.
console.log(document.getElementsByTagName("polygon")[0].getBBox())
body {
margin: 0;
background: black;
}
#container {
background: rgba(0, 155, 255, 0.3);
padding: 10px;
}
#circle1 {
}
#circle2 {
stroke-dasharray: 20 3 55;
}
#circle3 {
stroke-dasharray: 22;
}
<div id="container">
<svg xmlns="http://www.w3.org/2000/svg" height=207px width=207px stroke="#00bd80" fill="none">
<circle id="circle1" r="100" cx="50%" cy="50%" stroke-width="7px"/>
<circle id="circle2" r="96" cx="50%" cy="50%" stroke-width="5px">
<animateTransform attributeType="xml"
attributeName="transform"
type="rotate"
from="0 103.5 103.5"
to="360 103.5 103.5"
dur="20s"
repeatCount="indefinite"/> <!-- how to center correctly -->
</circle>
<circle id="circle3" r="80" cx="50%" cy="50%" stroke-width="5px"/>
<polygon transform="translate(103.5, 103.5) translate(-15, -13)" points="30,15 22.5,28.0 7.5,28.0 0,15 7.5,2.0 22.5,2.0"></polygon>
</svg>
</div>

SVG Animation - How can I reverse the start and end points in this svg path?

So I am creating some kind of small animations for icons. I want to stick svg as they are just some small line animations.
The .svg is in the html document. The css has the styles for the lines and the animation.
https://jsfiddle.net/pd9ux6e7/
So now what I got. I got this drawing line, just like I wanted it. The only thing that bothers me is the way the animation start and ends. Now it goes from bottom right to top left. But I want to have it from top left to bottom right (just like how you read, from left to right feels much more natural)
Any idea how I can fix this? I think it's somewhere in the svg path but idk what these values stand for. This is the blue line in svg <path class="st3" d="M1194.1,777.2H7c-2.8,0-5-2.2-5-5V35.9" />
I've reversed the path and this reversed the animation. Also the path's length is 1932 so in the css i'm using this value instead.
.st0 {
fill: #ffffff;
}
.st1 {
fill: none;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st2 {
fill: #ffffff;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st3 {
fill: none;
stroke: #2646ff;
stroke-width: 7;
stroke-linecap: round;
stroke-linejoin: round;
stroke-miterlimit: 10;
}
#Streep .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: 0;
animation: dash 8s ease-in-out;
animation-direction: reverse;
}
#keyframes dash {
to {
stroke-dashoffset: 1932;
}
}
<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 1200 780" style="enable-background:new 0 0 1200 780;" xml:space="preserve">
<g id="Layer_1"></g>
<g id="Layer_6">
<g>
<g>
<path
class="st0"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
<path
class="st1"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
</g>
<line class="st1" x1="2" y1="688.2" x2="1198" y2="688.2" />
<ellipse class="st2" cx="559.9" cy="732.7" rx="16.9" ry="16.7" />
</g>
</g>
<g id="Layer_5">
<g>
<g>
<path
class="st0"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="626.5" y1="715.5" x2="1127.3" y2="715.5" />
</g>
</g>
<g id="Layer_4">
<g>
<g>
<path
class="st0"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="971.8" y1="732" x2="1198" y2="732" />
</g>
</g>
<g id="Streep">
<g>
<path class="st3" d="M2,35.9L2,772.2 C2,775 4.2,777.2 7,777.2 L1194.1,777.2" />
</g>
</g>
</svg>
There is no need to reverse the path definition. Just reverse the dashoffset animation.
#Streep .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: -1932;
animation: dash 8s ease-in-out;
animation-direction: forwards;
}
#keyframes dash {
to {
stroke-dashoffset: 0;
}
}
This will work in most browsers, but unfortunately not Safari, which has a bug where it doesn't accept negative dashoffsets.
To work around that, just shift your dashoffset values up by (dashlength + dashgap) = 1932 + 1932 = 3864.
#Streep .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: 1932;
animation: dash 8s ease-in-out;
animation-direction: forwards;
}
#keyframes dash {
to {
stroke-dashoffset: 3864;
}
}
The result:
svg { width: 500px; }
.st0 {
fill: #ffffff;
}
.st1 {
fill: none;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st2 {
fill: #ffffff;
stroke: #afafaf;
stroke-width: 4;
stroke-miterlimit: 10;
}
.st3 {
fill: none;
stroke: #2646ff;
stroke-width: 7;
stroke-linecap: round;
stroke-linejoin: round;
stroke-miterlimit: 10;
}
#Streep .st3 {
stroke-dasharray: 1932;
stroke-dashoffset: 1932;
animation: dash 8s ease-in-out;
animation-direction: forwards;
}
#keyframes dash {
to {
stroke-dashoffset: 3864;
}
}
<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 1200 780"
style="enable-background:new 0 0 1200 780;"
xml:space="preserve"
>
<g id="Layer_1"></g>
<g id="Layer_6">
<g>
<g>
<path
class="st0"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
<path
class="st1"
d="M1198,772.2c0,2.8-2.2,5-5,5H7c-2.8,0-5-2.2-5-5V36.6c0-2.8,2.2-5,5-5h1186c2.8,0,5,2.2,5,5V772.2z"
/>
</g>
<line class="st1" x1="2" y1="688.2" x2="1198" y2="688.2" />
<ellipse class="st2" cx="559.9" cy="732.7" rx="16.9" ry="16.7" />
</g>
</g>
<g id="Layer_5">
<g>
<g>
<path
class="st0"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1127.3,771.9c0,2.8-2.2,5-5,5H631.5c-2.8,0-5-2.2-5-5V194.2c0-2.8,2.2-5,5-5h490.8c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="626.5" y1="715.5" x2="1127.3" y2="715.5" />
</g>
</g>
<g id="Layer_4">
<g>
<g>
<path
class="st0"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
<path
class="st1"
d="M1198,771.9c0,2.8-2.2,5-5,5H976.8c-2.8,0-5-2.2-5-5V352.1c0-2.8,2.2-5,5-5H1193c2.8,0,5,2.2,5,5V771.9z"
/>
</g>
<line class="st1" x1="971.8" y1="732" x2="1198" y2="732" />
</g>
</g>
<g id="Streep">
<g>
<path class="st3" d="M1194.1,777.2H7c-2.8,0-5-2.2-5-5V35.9" />
</g>
</g>
</svg>

Adding drop shadows to SVG symbols

I'm building a website that is very heavy on icons, so I'm working with SVG symbols to reduce duplication. In some cases the design calls for the symbols to have a drop shadow, and not in others. I'm struggling to figure out how I can add a drop shadow.
Example of my SVG:
<svg id="icons-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
...
<symbol id="icon-communications" viewBox="1400 0 200 200">
<title>Communications</title>
<rect style="fill: currentColor" x="1447.3" y="95.3" width="105.3" height="5.3"/>
<rect style="fill: currentColor" x="1447.3" y="78" width="105.3" height="5.3"/>
<polygon style="fill: currentColor" points="1463.2,127.9 1468,130.1 1475.7,113.6 1470.9,111.4 "/>
...
</symbol>
...
</svg>
I then include the icon on page using the standard:
<svg class="icon-svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<use xlink:href="#icon-communications"/>
</svg>
I can then set the color of the icon like this:
.icon-svg use {
color: blue;
}
.error .icon-svg use {
color: red;
}
But I can't figure out how to add a drop shadow. I've tried CSS box-shadow, and also filter: drop-shadow(), but neither seem to do anything. e.g.
.someClass .icon-svg use {
color: #fff;
-webkit-filter: drop-shadow( 0 0 20px #000 );
filter: drop-shadow( 0 0 20px #000 );
}
Any help would be appreciated.
Use an SVG Filter:
.icon-svg use {
color: blue;
}
.error .icon-svg use {
color: red;
}
.icon-svg {
-webkit-filter: url(#dropshadowy);
}
<svg id="icons-svg" >
<defs>
<filter id="dropshadowy">
<feGaussianBlur in="SourceAlpha" stdDeviation="4"/>
<feMerge>
<feMergeNode/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
<symbol id="icon-communications" viewBox="1400 0 200 200">
<title>Communications</title>
<rect style="fill: currentColor" x="1447.3" y="95.3" width="105.3" height="5.3"/>
<rect style="fill: currentColor" x="1447.3" y="78" width="105.3" height="5.3"/>
<polygon style="fill: currentColor" points="1463.2,127.9 1468,130.1 1475.7,113.6 1470.9,111.4 "/>
</symbol>
</defs>
</svg>
<svg class="icon-svg" >
<use xlink:href="#icon-communications"/>
</svg>

Flipping textPath direction from anti-clockwise to clockwise?

By default, SVG wraps text around a path in an anti-clockwise manner. The ceiling of the text sticks the path. How to change the direction to clockwise so that the floor of the text sticks to the circumference instead of the ceiling?
.textspace
{
letter-spacing: 5px;
font-family: fantasy;
font-size: 50px;
writing-mode: tb;
}
.curved-text
{
font-family: fantasy;
font-size: 20px;
letter-spacing: 5px;
word-spacing: 10px;
}
<svg height="400" width="400">
<defs>
<path d="M60,60
A50,50
0
1,0
61,60"
stroke="black"
stroke-width="2"
fill="none"
id="tracker-path"/>
</defs>
<text x="50" y="50" class="curved-text">
<textPath xlink:href="#tracker-path">
Tracking succesful.
</textPath>
</text>
</svg>
I managed to solve this. All you need to do is set the value of sweep-flag from 0 to 1. That will flip the direction of path
.textspace
{
letter-spacing: 5px;
font-family: fantasy;
font-size: 50px;
writing-mode: tb;
}
.curved-text
{
font-family: fantasy;
font-size: 20px;
letter-spacing: 5px;
word-spacing: 10px;
}
<svg height="400" width="400">
<defs>
<path d="M80,160
A50,50
0
1,1
81,160"
stroke="black"
stroke-width="2"
fill="none"
id="tracker-path"/>
</defs>
<text x="50" y="50" class="curved-text">
<textPath xlink:href="#tracker-path">
Tracking succesful.
</textPath>
</text>
</svg>