Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG marker-mid on specific point on path

I got some code that generates pathes on canvas. the path objects looks similar to this :

<path class="link" d="M450,215.L265,236L225,236" style="stroke-width: 1;"></path>

and on view (a,b,c letters are just for explaining the problem):

enter image description here

My problem is that I want to draw some arrow (marker) on the middle of the line, between "a" to "b", but when I create a marker and do a marker-mid attribute, its generates on b point.

I've tried to do some point between a and b, but then marker-mid did the arrows both there and both on b point.

from WEB API documentation :

The marker-mid defines the arrowhead or polymarker that shall be drawn at every vertex other than the first and last vertex of the given element or basic shape.

How can I disable the marker on point b? Or how can I make something like arrow between a-b ? Thanks !

like image 953
Chenko47 Avatar asked Dec 12 '16 16:12

Chenko47


2 Answers

sometimes its not so easy to split the path at any point you like. Then you can use text on a path with startOffset to position an "arrow" at any point on a path...

path {
  fill: none;
  stroke: red;
  stroke-width: 3
}
text {
  font-size: 35px;
  fill: red;
  dominant-baseline: central
}
<svg viewBox="0 0 500 500" width="300px" height="300px">
  <path class="link" id="path1" d="M0 0 L200 400A300 300 0 0 1 490 150"></path>
  <text >
    <textPath xlink:href="#path1" startOffset="10%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="20%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="30%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="40%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="50%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="60%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="70%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="80%">➤</textPath>
    <textPath xlink:href="#path1" startOffset="90%">➤</textPath>
  </text>
</svg>
like image 191
Holger Will Avatar answered Nov 05 '22 08:11

Holger Will


The marker-mid defines the arrowhead or polymarker that shall be drawn at every vertex other than the first and last vertex of the given element or basic shape.

You are drawing a line with vertices A, B, and C, so by definition the marker will be drawn at B.

If you want a marker to be drawn between A and B you will need to draw a path from A to the midpoint AB to B.

<svg width="200" height="150">
  <defs>
    <marker id="markerArrow" markerWidth="13" markerHeight="13" refX="2" refY="6" orient="auto">
      <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000;" />
    </marker>
  </defs>
  <path d='M0,0 L50,50 L100, 100' style='marker-mid:url(#markerArrow); stroke: #000'/>
  <path d='M100,100 L125, 100 L150, 100' style='marker-mid:url(#markerArrow); stroke: #000' />
</svg>
like image 43
Paul S Avatar answered Nov 05 '22 08:11

Paul S