I have the following generated test-SVG (excerpt).
<svg _ngcontent-dhk-c13=""><g _ngcontent-dhk-c13="" hccard="" _nghost-dhk-c12="" ng-reflect-card="[object Object]"><rect _ngcontent-dhk-c12="" id="8261337b-fb4b-4ac9-a213-0d86cc3dc604" width="100" height="100" x="750" y="450"></rect><g _ngcontent-dhk-c12="" hcedge="" _nghost-dhk-c11="" ng-reflect-edge="[object Object]"><path _ngcontent-dhk-c11="" stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path></g><g _ngcontent-dhk-c12="" hcedge="" _nghost-dhk-c11="" ng-reflect-edge="[object Object]"><path _ngcontent-dhk-c11="" stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path></g><!--bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object"
}--></g><!--bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object"
}--></svg>
There should be a <path> element going from 750/450 to 750/600. However nothing is visible. If i move the <path> element outside of its <g> container into the <g> container above that also holds the red <rect>, it is suddenly visible. Any other way to fix this, other than moving the <path> out of the inner <g>?
As #enxaneta said, the rect and path in your SVG are way outside its default viewport. A viewport is the area on your page that the SVG contents are rendered into.
If we use some CSS to make the viewport size visible (light brown area) and make overflow visible, we can see what's happening.
svg {
background-color: linen;
overflow: visible;
transform: scale(0.5);
}
<svg>
<g>
<rect width="100" height="100" x="750" y="450"></rect>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
</g>
</svg>
If you want to fix that, you'll need to do one of two things:
Make the viewport bigger
In the example below, I have made the SVG width and height big enough so that the content is now visible. You may need to scroll down and right to see it.
svg {
background-color: linen;
}
<svg width="850" height="600">
<g>
<rect width="100" height="100" x="750" y="450"></rect>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
</g>
</svg>
Tell the browser where in the SVG your elements are, so that it can draw them inside the viewport. You do this by adding a viewBox.
In the example below, I've chosen viewBox values that define the boundaries of the content. The browser is scaling and moving that content so that it fits in the viewport.
svg {
background-color: linen;
width: 400px;
height: 400px;
}
<svg viewBox="750 450 100 150">
<g>
<rect width="100" height="100" x="750" y="450"></rect>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
<g>
<path stroke="black" stroke-width="2" d="M 750 450 L 750 600 Z"></path>
</g>
</g>
</svg>
Related
Is there any possible way to get/find the border radius of an SVG?
Specifically, the rounded corners.
Example:
<svg width="266" height="185" viewBox="-1.5 0 71 48">
<path fill="currentColor" style="stroke: #0059dd; stroke-width:1px;color:black;" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#000000" ></path><path d="M 45,24 27,14 27,34" fill="#0059dd"></path>
</svg>
Svg source code(car`s Tier)
This is the of a cars Tier and i want to rotate it 360 degree.Please Help me..!
<svg id="octocat" xmlns="http://www.w3.org/2000/svg" width="880px" height="500px" viewBox="200 100 259 785" style="fill:#000000;stroke: #000; stroke-opacity:0.5">
<g i:extraneous="self">
<rect id="_x3C_Slice_x3E_" x="25" y="376" fill="none" width="370" height="179"/>
<g>
<!-- begin snippet: js hide: false -->
<path class="Tiers" fill="#FFFFFF" d="M-104.577,448.995c56.009,0.229,100.2,42.714,101.4,97.454c1.246,56.84-42.531,98.123-91.49,101.636
c-62.914,4.515-103.152-44.328-107.193-88.244c-2.873-31.223,6.157-58.2,27.881-80.679
C-154.761,459.278-130.841,449.813-104.577,448.995z M-103.31,626.189c39.698,0.926,78.677-30.209,78.19-78.934
c-0.411-41.153-32.875-76.105-77.887-76.017c-44.221,0.087-76.996,34.386-77.513,76.561
C-181.075,593.027-144.647,626.601-103.31,626.189z"/>
I need to place text relative to the parent <g>.
Currently, I have a path and a text element wrapped in a <g>. But all the text coordinates are relative to the outer most <g>.
<svg width="1000" height="550">
<g transform="translate(500,275)" stroke-width="2" stroke="black">
<g>
<path d="M1.6838893488276108e-14,-275A275,275 0 0,1 238.15698604072065,137.49999999999994L0,0Z" id="path_0" style="fill: rgb(17, 17, 17);"></path>
<text transform="translate(100, 100)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
<g>
<path d="M238.15698604072065,137.49999999999994A275,275 0 0,1 -238.1569860407206,137.50000000000009L0,0Z" id="path_1" style="fill: rgb(34, 34, 34);"></path>
<text transform="translate(100, 100)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
<g>
<path d="M-238.1569860407206,137.50000000000009A275,275 0 0,1 -5.051668046482832e-14,-275L0,0Z" id="path_2" style="fill: rgb(51, 51, 51);"></path>
<text transform="translate(100, 100)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
</g>
</svg>
It's hard to see which part of this you're having trouble with, but I'll explain as best I can.
Your SVG picture is 1000 pixels wide and 550 pixels tall:
<svg width="1000" height="550">
The top level node inside this SVG is a <g> node that moves the origin of the coordinate system from the top left corner to (500,275) (i.e., the middle of the drawing area; Y coordinates increase from top to bottom in SVGs)
<g transform="translate(500,275)" ... >
All the children of this top-level node will therefore use this transformed coordinate system. You have added additional <g> nodes as children of this top-level node, but they don't really do anything in this instance because they contain no attributes:
<g>
As a result, the <path> nodes will still be using the same transformed coordinate system that was set up by the top-level <g>. These all produce circular sectors with an apex at (0,0). And since (0,0) corresponds to the middle of the drawing area in this transformed coordinate system, that is where they end up:
<path d="M0-275A275 275 0 0 1 238 137.5L0 0Z" style="fill: rgb(17, 17, 17);"></path>
<path d="M238 137.5A275 275 0 0 1-238 137.5L0 0Z" style="fill: rgb(34, 34, 34);"></path>
<path d="M-238 137.5A275 275 0 0 1 0-275L0 0Z" style="fill: rgb(51, 51, 51);"></path>
Your <text> nodes are also drawn in this coordinate system, but offset by (100,100) because you added a transform attribute to shift them 100 pixels down and 100 pixels to the right:
<text transform="translate(100, 100)" ... >text</text>
So the end result is that all three of your text nodes are drawn at coordinates of (600,375) relative to the top left corner of the drawing area. If you want the text to appear somewhere else, you'll have specify a different offset. For example:
<text transform="translate(120,-80)" ... >text</text>
<text transform="translate(0,160)" ... >text</text>
<text transform="translate(-120,-80)" ... >text</text>
<svg width="1000" height="550">
<g transform="translate(500,275)" stroke-width="2" stroke="black">
<g>
<path d="M0-275A275 275 0 0 1 238 137.5L0 0Z" style="fill: rgb(17, 17, 17);"></path>
<text transform="translate(120,-80)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
<g>
<path d="M238 137.5A275 275 0 0 1-238 137.5L0 0Z" style="fill: rgb(34, 34, 34);"></path>
<text transform="translate(0,160)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
<g>
<path d="M-238 137.5A275 275 0 0 1 0-275L0 0Z" style="fill: rgb(51, 51, 51);"></path>
<text transform="translate(-120,-80)" class="tooltipText" stroke-width="0" fill="white" style="text-anchor: middle;">text</text>
</g>
</g>
</svg>
I've tried unsuccessfully to replace the white triangle, the marker-start, with an inverse mask/clip-path in order to cut the end of the arrow in shape of the marker instead of painting it white.
Not sure if marker masks can be defined.
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" id="mySVG" viewBox="-100 0 200 200" height="600" width="700">
<defs>
<marker refY="0.5" refX="0.0" markerHeight="4" markerWidth="2" orient="auto" id="head">
<path fill="#D0D0D0" d="M0,0 L0.5,0.5 L0,1 L-0.5,0.5 Z"/>
</marker>
<marker refY="0.6" refX="0.1" markerHeight="4" markerWidth="2" orient="auto" id="tail">
<clip-Path id="cp1" d="M0 0 V1.3 L0.6 0.6 Z">
<path fill="white" d="M0 0 V1.3 L0.6 0.6 Z" />
<clip-Path>
</marker>
</defs>
<path id="myArrow" marker-start="url(#tail)" marker-end="url(#head)" d="M -66.38265586443396 22.21132594835645 A 70 70 0 0 0 66.38265586443396 22.21132594835645" fill="none" stroke="#D0D0D0" stroke-width="8" clip-path="url(#cp1)"/>
Markers are independent symbols which are positioned and drawn at the various points in the path after the path has been drawn.
It sounds like you are trying to use them to clip out bits of the path. This is futile. That's not how markers work, I'm afraid.
I am in the middle of writing SVG output from MuPDF, and I've run up against what seems to be a limitation in the capabilities of SVG. I thought I'd ask here in case this was a known problem with a known workaround (or in case I'm doing something stupid!)
I have the following SVG:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="21.59cm" height="27.94cm" viewBox="0 0 600 600">
<path stroke-width="12" fill="none" stroke="#0000ff" d="M 150 300 L 80 300 L 80 370 L 150 370 " />
<clipPath id="cp0">
<path stroke-width="12" fill="none" stroke="#000000" d="M 150 300 L 80 300 L 80 370 L 150 370 " />
</clipPath>
<g clip-path="url(#cp0)">
<rect fill="#ff0000" x="0" y="0" width="600" height="600"/>
</g>
</svg>
This draws a stroked path (shaped like '[' in blue). Then it sets the same path to be a clipping path, and fills the clipping path in red.
I was hoping that the clipping path would be set to the stroked version of the path, and hence the red shape would exactly overwrite the blue one. In my tests here however, the "fill or strokedness" of the path is ignored, and the path is "filled" - hence I get a red square drawn within the blue shape.
Is there a way to get the behaviour I was hoping for? Or am I going to have to write code to manually flatten and stroke paths before outputting them to SVG?
Thanks in advance for any replies!
Clip-paths in svg are meant to be just the shape, not the traits of the shape, so in other words you'll not get the stroke included. What you can do is use a mask instead, setting the stroke of the path in the mask to white.
Here's an example:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 600 600">
<defs>
<mask id="m0" maskUnits="userSpaceOnUse" x="0" y="0" width="600" height="600">
<path fill="none" stroke="white" stroke-width="5" d="M 150 300 L 80 300 L 80 370 L 150 370" />
</mask>
</defs>
<path stroke-width="12" fill="none" stroke="#0000ff" d="M 150 300 L 80 300 L 80 370 L 150 370 " />
<g mask="url(#m0)">
<rect fill="yellow" x="0" y="0" width="600" height="600" />
</g>
</svg>