Friday, April 19, 2013

SVG - Draw Arrow

SVG 

Sample 1


<svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 -100 200 200">
<defs>
  <marker id='mid' orient="auto"
    markerWidth='2' markerHeight='4'
    refX='0.1' refY='1'>
    <!-- triangle pointing right (+x) -->
    <path d='M0,0 V2 L1,1 Z' fill="orange"/>
  </marker>
  <marker id='head' orient="auto"
    markerWidth='2' markerHeight='4'
    refX='0.1' refY='2'>
    <!-- triangle pointing right (+x) -->
    <path d='M0,0 V4 L2,2 Z' fill="red"/>
  </marker>
</defs>

<path
  id='arrow-line'
  marker-mid='url(#mid)'
  marker-end='url(#head)'
  stroke-width='5'
  fill='none' stroke='black'  
  d='M0,0 L20,20 C40,40 40,40 60,20 L80,0'
  />
</svg>
 

Result

enter image description here 









Sample 2

<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%">
 <defs>
  <marker id="Triangle" viewBox="0 0 20 20" refX="0" refY="10" markerUnits="strokeWidth" markerWidth="8" markerHeight="6" orient="auto">
   <path d="M 0 0 L 20 10 L 0 20 z"/>
  </marker>
  <marker id="Circle" viewBox="0 0 10 10" refX="4" refY="10" markerUnits="strokeWidth" markerWidth="6" markerHeight="6" orient="auto">
   <circle cx="5" cy="5"  r="3" fill="black"/>
  </marker>
  <marker id="Rect" viewBox="0 0 20 20" refX="0" refY="10" markerUnits="strokeWidth" markerWidth="10" markerHeight="10" orient="auto">
   <rect width="10" height="10" fill="grey"/>
  </marker>
 </defs>
 
 <line x1="10" y1="10" x2="100" y2="10" stroke="black" stroke-width="1" marker-end="url(#Triangle)" marker-start="url(#Circle)"/>
 <path d="M 10 20 100 20 A 20 30 0 0 1 120 50 L 120 110" marker-end="url(#Triangle)" marker-mid="url(#Rect)" fill="none" stroke="black"/>
 </svg> 
 

Result


 
Reference: http://stackoverflow.com/questions/11808860/arrow-triangles-on-my-svg-line

Related Posts:

  • SVG - Fixed the white dot/pixel in corner between lines/ rectangle or path Change values of the stroke-linecap property <line x1="10" y1="15" x2="50" y2="15" style="stroke-linecap: butt; stroke-width: 15;"/> <line x1="10" y1="45" x2="50" y2="45" style="stroke-linecap: roun… Read More
  • SVG - Gradient in XSL with FOP graidient.svg <svg xmlns="http://www.w3.org/2000/svg" version="1.1">  <defs>    <linearGradient id="linearGradient" x1="0%" y1="0%" x2="100%" y2="0%">      <… Read More
  • SVG - Coordinate SystemsMost ProjectedCRS (Map Projection) have the north direction represented by positive values of the second axis and conversely SVG has a y-down coordinate system That's why, in order to follow the usual way to represent… Read More
  • SVG - Draw Arrow SVG  Sample 1 <svg xmlns="http://www.w3.org/2000/svg" viewBox="-50 -100 200 200"> <defs> <marker id='mid' orient="auto" markerWidth='2' markerHeight='4' refX='0.1' refY='1'> <!-- tr… Read More
  • SVG Hints         Reverse/mirror translated text <svg:text x="10" y="20" transform="scale(-1 1)">Reverse</svg:text>  <svg:g xmlns="http://www.w3.org/2000/svg" transform="tr… Read More

0 comments:

Post a Comment