I have a simple SVG code, which is a circle progress bar with an image, and I used it to change the value of progress as below, I want to have this SVG with this feature in react native,
things I tried :
react-native-SVG package, but didn't work and I get some weird behavior with it
the code in React js , the props is changed from outside so I can change any props to change progress value , and image inside , as well as the width too ,
function CircularBar({ imgSrc, progress, width }) {
return (
<svg viewBox="0 0 200 210" width={width}>
<defs>
<mask id="m1">
<circle cx="100" cy="105" r="55" fill="white" />
</mask>
<linearGradient
id="lg1"
gradientTransform="rotate(0) skewX(-20) skewY(-40)"
>
<stop offset="0" stop-color="red" />
<stop offset="75%" stop-color="orange" />
</linearGradient>
</defs>
<image mask="url(#m1)" href={imgSrc} width="200" />
<path
pathLength="360"
d="M100 175 a 75 75 0 1 1 1 0"
stroke="LightSlateGray"
fill="none"
stroke-width="30"
stroke-linecap="round"
stroke-dasharray="270 360"
stroke-dashoffset="-45"
/>
<path
pathLength="360"
d="M100 175 a 75 75 0 1 1 1 0"
stroke="url(#lg1)"
fill="none"
stroke-width="15"
stroke-linecap="round"
stroke-dasharray={`${progress * 270} 360`}
stroke-dashoffset="-45"
/>
<g
transform="translate(100 180)"
font-size="16"
font-family="sans-serif"
font-weight="bold"
text-anchor="middle"
>
<text>Overall</text>
<text transform="translate(0 20)">Wellbeing</text>
</g>
</svg>
);
}
export default CircularBar;
this is where I'm stuck, this is the code for react native side
import React from 'react';
import Svg, {
Circle,
Defs,
G,
Image,
LinearGradient,
Mask,
Path,
Stop,
Text,
} from 'react-native-svg';
function CircularBar({imgSrc, progress, width}) {
return (
<Svg width="200" height="400">
<Defs>
<Mask id="m1">
<Circle cx="100" cy="105" r="500" fill="white" />
</Mask>
<LinearGradient
id="lg1"
gradientTransform="rotate(0) skewX(-20) skewY(-40)">
<Stop offset="0" stop-color="red" />
<Stop offset="75%" stop-color="orange" />
</LinearGradient>
</Defs>
<Image mask="url(#m1)" href={imgSrc} width="200" />
<Path
pathLength="360"
d="M100 175 a 75 75 0 1 1 1 0"
stroke="#778899"
fill="none"
stroke-width="30"
stroke-linecap="round"
stroke-dasharray="270 360"
stroke-dashoffset="-45"
/>
<Path
pathLength="360"
d="M100 175 a 75 75 0 1 1 1 0"
stroke="url(#lg1)"
fill="none"
stroke-width="15"
stroke-linecap="round"
stroke-dasharray={`200 360`}
stroke-dashoffset="-45"
/>
<G
transform="translate(100 180)"
font-size="16"
font-family="sans-serif"
font-weight="bold"
text-anchor="middle">
<Text>Overall</Text>
<Text transform="translate(0 20)">Wellbeing</Text>
</G>
</Svg>
);
}
so I hope you could help me with it
I normally use https://react-svgr.com/playground/?native=true to convert my svg to a react native component.
Make sure you check react-native on the left tab.
Example raw svg
<svg width="40" height="40" viewBox="0 0 40 40" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path opacity="0.1" d="M40 20C40 31.0457 31.0457 40 20 40C8.9543 40 0 31.0457 0
20C0 8.9543 8.9543 0 20 0C31.0457 0 40 8.9543 40 20ZM4 20C4 28.8366 11.1634 36
20 36C28.8366 36 36 28.8366 36 20C36 11.1634 28.8366 4 20 4C11.1634 4 4 11.1634
4 20Z" fill="#2B86C3"/>
<path d="M20 40C16.0979 40 12.281 38.8585 9.01954 36.7161C5.75811 34.5738
3.19463 31.5242 1.64491 27.943C0.0951845 24.3618 -0.373076 20.4054 0.297814
16.5614C0.968704 12.7174 2.74944 9.15359 5.42063 6.30906C8.09182 3.46453
11.5368 1.46353 15.3311 0.552601C19.1254 -0.358333 23.1033 -0.139414 26.7748
1.18239C30.4462 2.50419 33.6508 4.87112 35.9937 7.9916C38.3366 11.1121 39.7155
14.8498 39.9605 18.7442L35.9684 18.9954C35.7724 15.8798 34.6693 12.8897 32.795
10.3933C30.9206 7.8969 28.357 6.00335 25.4198 4.94591C22.4827 3.88847 19.3003
3.71333 16.2649 4.44208C13.2294 5.17083 10.4735 6.77162 8.3365 9.04725C6.19955
11.3229 4.77496 14.1739 4.23825 17.2491C3.70154 20.3244 4.07615 23.4894 5.31593
26.3544C6.5557 29.2193 8.60649 31.659 11.2156 33.3729C13.8248 35.0868 16.8783
36 20 36V40Z" fill="#2B86C3"/>
<path d="M12.6744 14.8182H11.1779L8.63743 16.4787V17.9503L11.0735
16.3594H11.1332V25H12.6744V14.8182ZM18.7894 25.1392C20.8377 25.1392 22.2994
23.6925 22.2944 21.7088C22.2994 19.7401 20.9272 18.3082 19.0728
18.3082C18.3171 18.3082 17.6161 18.5966 17.2184 18.9844H17.1587L17.4819
16.1357H21.8022V14.8182H16.2042L15.6325 19.9489L17.0394 20.1577C17.4222
19.8146 18.1083 19.581 18.7248 19.581C19.9329 19.5909 20.8079 20.4957 20.8079
21.7386C20.8079 22.9616 19.9577 23.8466 18.7894 23.8466C17.805 23.8466 17.0245
23.2202 16.945 22.3452H15.4535C15.5131 23.9659 16.9201 25.1392 18.7894
25.1392ZM27.655 25.169C30.0066 25.169 31.3837 23.25 31.3837 19.9141C31.3837
16.603 29.9867 14.679 27.655 14.679C25.3184 14.679 23.9263 16.598 23.9213
19.9141C23.9213 23.245 25.2985 25.1641 27.655 25.169ZM27.655 23.8416C26.2779
23.8416 25.4476 22.4595 25.4476 19.9141C25.4526 17.3786 26.2828 15.9815 27.655
15.9815C29.0222 15.9815 29.8574 17.3786 29.8574 19.9141C29.8574 22.4595
29.0272 23.8416 27.655 23.8416Z" fill="#2B86C3"/>
</svg>
after converting :
import * as React from "react"
import Svg, { Path } from "react-native-svg"
function SvgComponent(props) {
return (
<Svg
width={props.width}
height={40}
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<Path
opacity={0.1}
d="M40 20c0 11.046-8.954 20-20 20S0 31.046 0 20 8.954 0 20 0s20 8.954 20 20zM4 20c0 8.837 7.163 16 16 16s16-7.163 16-16S28.837 4 20 4 4 11.163 4 20z"
fill="#2B86C3"
/>
<Path
d="M20 40a20 20 0 1119.96-21.256l-3.992.251A16 16 0 1020 36v4z"
fill="#2B86C3"
/>
<Path
d="M12.674 14.818h-1.496l-2.54 1.66v1.472l2.435-1.59h.06V25h1.541V14.818zM18.79 25.14c2.049 0 3.51-1.447 3.505-3.43.005-1.969-1.367-3.4-3.221-3.4-.756 0-1.457.288-1.855.675h-.06l.324-2.848h4.32v-1.318h-5.598l-.572 5.13 1.407.21c.383-.343 1.07-.577 1.686-.577 1.208.01 2.083.915 2.083 2.158 0 1.223-.85 2.108-2.019 2.108-.984 0-1.765-.627-1.844-1.502h-1.492c.06 1.62 1.467 2.794 3.336 2.794zm8.866.03c2.352 0 3.729-1.919 3.729-5.255 0-3.311-1.397-5.235-3.729-5.235-2.337 0-3.729 1.919-3.734 5.235 0 3.331 1.378 5.25 3.734 5.255zm0-1.327c-1.377 0-2.207-1.383-2.207-3.928.005-2.535.835-3.933 2.207-3.933 1.367 0 2.202 1.398 2.202 3.933 0 2.545-.83 3.928-2.202 3.928z"
fill="#2B86C3"
/>
</Svg>
)
}
export default SvgComponent
and use in your component like:
import SvgComponent from '...path.../SvgComponent'
.
.
.
<View>
<SvgComponent width={40} />
<Text>your number</Text>
</View>
make your number over progress with absolute position
I specify width since I have value of width in my svg component is {props.width}
Similarly for numbers and use your own logic.
I found the solution you will have to take a raw SVG , and then used it in SVGXML from react_native_svg
let xml = `
<svg viewBox="0 0 200 210" width="100%"
>
<defs>
<linearGradient id="b" gradientTransform="matrix(1.3054 -.8391 -.36397 1 0 0)">
<stop offset="0" stop-color="red"/>
<stop offset="75%" stop-color="orange"/>
</linearGradient>
<mask id="a">
<circle cx="100" cy="100" r="55" fill="#fff"/>
</mask>
</defs>
<image mask="url(#a)" height="250" width="200" href="https://djelfa.cc/man.png" />
<path pathLength="360" d="M100 175a75 75 0 1 1 1 0" stroke="#789" fill="none" stroke-width="30" stroke-linecap="round" stroke-dasharray="270 360" stroke-dashoffset="-45"/>
<path pathLength="360" d="M100 175a75 75 0 1 1 1 0" stroke="url(#b)" fill="none" stroke-width="15" stroke-linecap="round" stroke-dasharray="${
counter ? counter * 270 : 0
} 360" stroke-dashoffset="-45"/>
<g font-size="16" font-family="sans-serif" font-weight="bold" text-anchor="middle">
<text transform="translate(100 180)">Overall</text>
<text transform="translate(100 200)">Wellbeing</text>
</g>
</svg>
`;
return <SvgXml xml={xml} width="100%" height="100%" />;
the only problem here is how to make the image fit inside the mask, I mean how to make the image contained inside it, that's the difference between my react code and this code even they are the same
I'm making a website where you can create your own character in order to learn more about SVGs. I want the user to be able to select different poses.
I was wondering how I could toggle the visibility of an SVG on the website to make one disappear and another appear.
Here is my SVG code:
<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 720 720" style="enable-background:new 0 0 720 720;" xml:space="preserve">
<g id="skin">
<circle class="skin" cx="364.42" cy="383" r="278" />
</g>
<g id="mouth">
<path class="mouth" d="M172.92,383c127.67,0,255.33,0,383,0c0,105.05-86.45,191.5-191.5,191.5S172.92,488.05,172.92,383z"/>
</g>
<g id="hair">
<path class = "hair" d="M107.4,276.86c-2.76-50.59,10.76-81.24,24.2-100.13C189.57,95.31,331.92,112,341.92,57.91
c2.04-11.03-2.07-21.46-6.93-29.61c18.47-6.31,81.92-25.39,151.28,3.28c94.59,39.09,121.88,137.21,127.56,160.84
c7.93,32.98,7.18,61.32,5.46,79.42c-38.79-64.73-78.17-85.57-107.42-92.42c-43.32-10.15-60.72,11.26-139.64,11.71
c-67.77,0.39-78.13-15.27-119.49-10.14C216.75,185.45,165.19,204.69,107.4,276.86z"/>
</g>
<g id="eyes">
<g>
<circle class = "eyes" cx="251.17" cy="271.25" r="52.4"/>
<circle class = "eyes" cx="477.67" cy="271.25" r="52.4"/>
</g>
</g>
<g id="clothing">
<rect x="236.92" y="644.4" width="255" height="180"/>
</g>
<g id="tie">
<rect class="tie" x="341.82" y="653.68" transform="matrix(0.7071 0.7071 -0.7071 0.7071 584.9371 -59.6038)" class="st0" width="45.2" height="45.2"/>
<path class="tie" d="M364.95,927.93c-6.29-12.71-12.59-25.42-18.88-38.13c3.44-63.19,6.89-126.39,10.33-189.58
c5.1,0.25,10.2,0.49,15.29,0.74c4.13,62.75,8.25,125.49,12.38,188.24C377.7,902.11,371.32,915.02,364.95,927.93z"/>
</g>
</svg>
The SVG is just a sample right now before I make the actual assets.
I have an SVG that had to have text centred both horizontally and vertically.
I would have pasted an image but don't have enough rep points. You can see the graphic at
https://www.dropbox.com/s/tt9ayqr0xugr4m9/link_example.png?dl=0
I need the white around the text to go grey (#eeeeee) when you hover over it. I got that with some simple CSS. I even got it with jQuery and some SVG but the issue is that when you hover over the word about (which needs to stay black all the time), the grey goes back to white as the text is over the circle and cancels the hover. I have been trying for hours and hours to fix this.
My code is:
<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 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<!-- gradient information -->
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="50" y1="0" x2="50" y2="100">
<stop offset="0" style="stop-color:#ED7625"/>
<stop offset="1" style="stop-color:#CF202F"/>
</linearGradient>
<a xlink:href="about.php">
<!-- gradient -->
<circle class="gradient-outer" fill="url(#SVGID_1_)" cx="50" cy="50" r="50"/>
<g class="svg-button_1">
<!-- white overlay -->
<circle id="#svg-text_1" class="white-inner" cx="50" cy="50" r="46" stroke="black" stroke-width="0" fill="white" />
<!-- text element -->
<text x="50%" y="50%" dy=".3em" text-anchor="middle">About</text>
</g>
</a>
Any help would be appreciated and I have tried many numerous ways with HTML/CSS/jquery to do it but it also have to be a link, scalable, ratio locked and responsive. (GROAN!!!)
JSBin
The jsbin has your required code. The issue you are facing is because
Text is not inside circle. Create a svg group and make that effect on
the svg group
2>One more point is dont give your id as # i.e <circle
id="#svg-text_1" should be <circle id="svg-text_1"
.svg-button_1:hover #svg-text_1{
fill: grey;
}
SVG is as below
<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 100 100" enable-background="new 0 0 100 100" xml:space="preserve">
<!-- gradient information -->
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="50" y1="0" x2="50" y2="100">
<stop offset="0" style="stop-color:#ED7625"/>
<stop offset="1" style="stop-color:#CF202F"/>
</linearGradient>
<a xlink:href="about.php">
<!-- gradient -->
<circle class="gradient-outer" fill="url(#SVGID_1_)" cx="50" cy="50" r="50"/>
<g class="svg-button_1">
<!-- white overlay -->
<circle id="svg-text_1" class="white-inner" cx="50" cy="50" r="46" stroke="black" stroke-width="0" fill="white" />
<!-- text element -->
<text x="50%" y="50%" dy=".3em" text-anchor="middle">About</text>
</g>
</a>
I'm currently testing different options to animate SVG Files directly in the .svg File. RIght now I'm testing animation with includet javascript. The Problem is, i don't get a proper rotation around the origin working.
My Code is currently looking like that:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
<g>
<g>
<path class="bag" fill="#016D49" d="M42.1,45.6c-6.7,0-13.5,0-20.2,0c-0.2,0-0.3-0.1-0.3-0.3c0.4-6.9,0.9-13.8,1.3-20.7c0-0.2,0.2-0.3,0.3-0.3
c5.9,0,11.7,0,17.6,0c0.2,0,0.3,0.1,0.3,0.3c0.4,6.9,0.9,13.8,1.3,20.7C42.4,45.5,42.3,45.6,42.1,45.6z"/>
</g>
<g>
<path fill="#016D49" d="M27.8,23.1c0-0.2,0.1-0.5,0.1-0.8c0.9-5.3,4.1-5,4.2-5c0,0,3-0.3,4,5c0,0.3,0.1,0.6,0.2,0.8H38
c0-0.2-0.1-0.5-0.2-0.8c-0.2-0.7-0.4-1.3-0.6-2.1c-1.2-3.1-3-4.7-5.4-4.6c-3.6,0.2-5.1,3.8-5.6,6.6c0,0.3-0.1,0.6-0.1,0.8
L27.8,23.1L27.8,23.1z"/>
</g>
</g>
<g id="loadingRing">
<circle fill="none" stroke="#016D49" stroke-width="0.75" stroke-miterlimit="10" stroke-dasharray="7.0201,7.0201" cx="32" cy="32" r="26.8">
</circle>
<script language="JavaScript" type="text/javascript">
var zpos=0;
function turnAround(){
zpos++;
if(zpos>359)zpos=0;
var dz=document.getElementById("loadingRing");
dz.style.transform = "rotate("+zpos+"deg) translate(1%,1%)";
window.setTimeout("turnAround()", 14);
}
turnAround();
</script>
</g>
</svg>
So what am I missing, or does there a better solution exist? Maybe it is possible to include jquery in the svg File?
Thanks in advance
Maybe you should stick to normal SVG tools and not over complicate things for something as trivial as a rotation.
It wasn't clear to me what you want to spin, so I made them both spin:
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
<g>
<g>
<path class="bag" fill="#016D49" d="M42.1,45.6c-6.7,0-13.5,0-20.2,0c-0.2,0-0.3-0.1-0.3-0.3c0.4-6.9,0.9-13.8,1.3-20.7c0-0.2,0.2-0.3,0.3-0.3
c5.9,0,11.7,0,17.6,0c0.2,0,0.3,0.1,0.3,0.3c0.4,6.9,0.9,13.8,1.3,20.7C42.4,45.5,42.3,45.6,42.1,45.6z"/>
</g>
<g>
<path fill="#016D49" d="M27.8,23.1c0-0.2,0.1-0.5,0.1-0.8c0.9-5.3,4.1-5,4.2-5c0,0,3-0.3,4,5c0,0.3,0.1,0.6,0.2,0.8H38
c0-0.2-0.1-0.5-0.2-0.8c-0.2-0.7-0.4-1.3-0.6-2.1c-1.2-3.1-3-4.7-5.4-4.6c-3.6,0.2-5.1,3.8-5.6,6.6c0,0.3-0.1,0.6-0.1,0.8
L27.8,23.1L27.8,23.1z"/>
</g>
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="360 32 32"
to="0 32 32"
dur="10s"
repeatCount="indefinite"/>
</g>
<g id="loadingRing">
<circle fill="none" stroke="#016D49" stroke-width="0.75" stroke-miterlimit="10" stroke-dasharray="7.0201,7.0201" cx="32" cy="32" r="26.8">
</circle>
<animateTransform attributeName="transform"
attributeType="XML"
type="rotate"
from="0 32 32"
to="360 32 32"
dur="5s"
repeatCount="indefinite"/>
</g>
</svg>
Here you go, a version with scripting, impractical, but since you wanted it...
dz.setAttribute("transform", "rotate(" + zpos + " 32 32)");
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 18.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Ebene_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
<g>
<g>
<path class="bag" fill="#016D49" d="M42.1,45.6c-6.7,0-13.5,0-20.2,0c-0.2,0-0.3-0.1-0.3-0.3c0.4-6.9,0.9-13.8,1.3-20.7c0-0.2,0.2-0.3,0.3-0.3
c5.9,0,11.7,0,17.6,0c0.2,0,0.3,0.1,0.3,0.3c0.4,6.9,0.9,13.8,1.3,20.7C42.4,45.5,42.3,45.6,42.1,45.6z"/>
</g>
<g>
<path fill="#016D49" d="M27.8,23.1c0-0.2,0.1-0.5,0.1-0.8c0.9-5.3,4.1-5,4.2-5c0,0,3-0.3,4,5c0,0.3,0.1,0.6,0.2,0.8H38
c0-0.2-0.1-0.5-0.2-0.8c-0.2-0.7-0.4-1.3-0.6-2.1c-1.2-3.1-3-4.7-5.4-4.6c-3.6,0.2-5.1,3.8-5.6,6.6c0,0.3-0.1,0.6-0.1,0.8
L27.8,23.1L27.8,23.1z"/>
</g>
</g>
<g id="loadingRing">
<circle fill="none" stroke="#016D49" stroke-width="0.75" stroke-miterlimit="10" stroke-dasharray="7.0201,7.0201" cx="32" cy="32" r="26.8">
</circle>
<script language="JavaScript" type="text/javascript">
var zpos=0;
function turnAround(){
zpos++;
//if(zpos>359)zpos=0;
var dz=document.getElementById("loadingRing");
//dz.style.transform = "rotate("+zpos+"deg 32 32)";
dz.setAttribute("transform", "rotate(" + zpos + " 32 32)");
window.setTimeout("turnAround()", 14);
}
turnAround();
</script>
</g>
</svg>
Notes:
I couldn't make it work with changing the style property. Not sure why.
You don't need to reset from 359 to 0. Degrees are anyway computed mod 360.