-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvg-markers.html
More file actions
228 lines (216 loc) · 11.6 KB
/
svg-markers.html
File metadata and controls
228 lines (216 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo: SVG Markers</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; padding: 20px; }
h2 { margin-bottom: 10px; font-size: 18px; }
h3 { margin: 16px 0 8px; font-size: 14px; color: #555; }
.section { margin-bottom: 24px; }
.row { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.item { display: flex; flex-direction: column; align-items: center; }
.label { font-size: 11px; color: #888; margin-top: 4px; }
</style>
</head>
<body>
<div id="root">
<h2>SVG Markers Demo</h2>
<!-- 1. Basic inline SVG with arrow markers on a path -->
<div class="section">
<h3>1. Inline SVG – Arrow markers on path</h3>
<svg width="300" height="80" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-start" viewBox="0 -5 10 10" refX="0" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M10,-5L0,0L10,5" fill="steelblue" />
</marker>
<marker id="arrow-end" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="steelblue" />
</marker>
</defs>
<line x1="30" y1="40" x2="270" y2="40" stroke="steelblue" stroke-width="2"
marker-start="url(#arrow-start)" marker-end="url(#arrow-end)" />
</svg>
</div>
<!-- 2. Markers on polyline (start, mid, end) -->
<div class="section">
<h3>2. Inline SVG – Markers on polyline (start + mid + end)</h3>
<svg width="300" height="100" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="dot" viewBox="0 0 10 10" refX="5" refY="5"
markerWidth="5" markerHeight="5">
<circle cx="5" cy="5" r="5" fill="crimson" />
</marker>
<marker id="arrow2" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="crimson" />
</marker>
</defs>
<polyline points="20,80 80,20 150,60 220,20 280,80"
fill="none" stroke="crimson" stroke-width="2"
marker-start="url(#dot)" marker-mid="url(#dot)" marker-end="url(#arrow2)" />
</svg>
</div>
<!-- 3. Marker on polygon -->
<div class="section">
<h3>3. Inline SVG – Marker on polygon vertices</h3>
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="square-marker" viewBox="0 0 10 10" refX="5" refY="5"
markerWidth="6" markerHeight="6">
<polygon points="0,0 10,0 10,10 0,10" fill="darkorange" />
</marker>
</defs>
<polygon points="100,20 180,80 150,170 50,170 20,80"
fill="none" stroke="darkorange" stroke-width="2"
marker-start="url(#square-marker)" marker-mid="url(#square-marker)" />
</svg>
</div>
<!-- 4. viewBox scaling: large viewBox, small viewport (triggers "too huge" bug) -->
<div class="section">
<h3>4. ViewBox scaling – large viewBox in small viewport</h3>
<svg width="200" height="100" viewBox="0 0 1000 500" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-scaled" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="green" />
</marker>
</defs>
<line x1="100" y1="250" x2="900" y2="250" stroke="green" stroke-width="10"
marker-end="url(#arrow-scaled)" />
</svg>
</div>
<!-- 5. viewBox scaling: small viewBox, large viewport -->
<div class="section">
<h3>5. ViewBox scaling – small viewBox in large viewport</h3>
<svg width="400" height="200" viewBox="0 0 100 50" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-upscale" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="purple" />
</marker>
</defs>
<line x1="10" y1="25" x2="90" y2="25" stroke="purple" stroke-width="2"
marker-end="url(#arrow-upscale)" />
</svg>
</div>
<!-- 6. Group transform affecting markers -->
<div class="section">
<h3>6. Group transform (scale 2x)</h3>
<svg width="300" height="120" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-group" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="teal" />
</marker>
</defs>
<g transform="scale(2) translate(10, 10)">
<line x1="10" y1="20" x2="120" y2="20" stroke="teal" stroke-width="1"
marker-end="url(#arrow-group)" />
</g>
</svg>
</div>
<!-- 7. Different stroke widths -->
<div class="section">
<h3>7. Varying stroke widths with same marker</h3>
<svg width="300" height="120" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-sw" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="black" />
</marker>
</defs>
<line x1="20" y1="20" x2="280" y2="20" stroke="black" stroke-width="1"
marker-end="url(#arrow-sw)" />
<line x1="20" y1="50" x2="280" y2="50" stroke="black" stroke-width="3"
marker-end="url(#arrow-sw)" />
<line x1="20" y1="90" x2="280" y2="90" stroke="black" stroke-width="6"
marker-end="url(#arrow-sw)" />
</svg>
</div>
<!-- 8. markerUnits="userSpaceOnUse" -->
<div class="section">
<h3>8. markerUnits="userSpaceOnUse"</h3>
<svg width="300" height="80" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-usu" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="15" markerHeight="15" markerUnits="userSpaceOnUse" orient="auto">
<path d="M0,-5L10,0L0,5" fill="navy" />
</marker>
</defs>
<line x1="30" y1="40" x2="270" y2="40" stroke="navy" stroke-width="2"
marker-end="url(#arrow-usu)" />
</svg>
</div>
<!-- 9. SVG with markers as <img> tag -->
<div class="section">
<h3>9. SVG with markers as <img> tag</h3>
<div class="row">
<div class="item">
<img width="200" height="80" style="border:1px solid #ccc;"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22200%22%20height%3D%2280%22%3E%3Cdefs%3E%3Cmarker%20id%3D%22a%22%20viewBox%3D%220%20-5%2010%2010%22%20refX%3D%2210%22%20refY%3D%220%22%20markerWidth%3D%226%22%20markerHeight%3D%226%22%20orient%3D%22auto%22%3E%3Cpath%20d%3D%22M0%2C-5L10%2C0L0%2C5%22%20fill%3D%22%23e53935%22%2F%3E%3C%2Fmarker%3E%3C%2Fdefs%3E%3Cline%20x1%3D%2220%22%20y1%3D%2240%22%20x2%3D%22180%22%20y2%3D%2240%22%20stroke%3D%22%23e53935%22%20stroke-width%3D%222%22%20marker-end%3D%22url(%23a)%22%2F%3E%3C%2Fsvg%3E">
<span class="label">img tag (no viewBox scaling)</span>
</div>
<div class="item">
<img width="200" height="80" style="border:1px solid #ccc;"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20400%20160%22%20width%3D%22200%22%20height%3D%2280%22%3E%3Cdefs%3E%3Cmarker%20id%3D%22a%22%20viewBox%3D%220%20-5%2010%2010%22%20refX%3D%2210%22%20refY%3D%220%22%20markerWidth%3D%226%22%20markerHeight%3D%226%22%20orient%3D%22auto%22%3E%3Cpath%20d%3D%22M0%2C-5L10%2C0L0%2C5%22%20fill%3D%22%231e88e5%22%2F%3E%3C%2Fmarker%3E%3C%2Fdefs%3E%3Cline%20x1%3D%2240%22%20y1%3D%2280%22%20x2%3D%22360%22%20y2%3D%2280%22%20stroke%3D%22%231e88e5%22%20stroke-width%3D%224%22%20marker-end%3D%22url(%23a)%22%2F%3E%3C%2Fsvg%3E">
<span class="label">img tag (viewBox 400x160 → 200x80)</span>
</div>
</div>
</div>
<!-- 10. SVG with markers as CSS background-image -->
<div class="section">
<h3>10. SVG with markers as CSS background-image</h3>
<div class="row">
<div class="item">
<div style="width:200px; height:80px; border:1px solid #ccc;
background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22200%22%20height%3D%2280%22%3E%3Cdefs%3E%3Cmarker%20id%3D%22a%22%20viewBox%3D%220%20-5%2010%2010%22%20refX%3D%2210%22%20refY%3D%220%22%20markerWidth%3D%226%22%20markerHeight%3D%226%22%20orient%3D%22auto%22%3E%3Cpath%20d%3D%22M0%2C-5L10%2C0L0%2C5%22%20fill%3D%22%2343a047%22%2F%3E%3C%2Fmarker%3E%3C%2Fdefs%3E%3Cline%20x1%3D%2220%22%20y1%3D%2240%22%20x2%3D%22180%22%20y2%3D%2240%22%20stroke%3D%22%2343a047%22%20stroke-width%3D%222%22%20marker-end%3D%22url(%23a)%22%2F%3E%3C%2Fsvg%3E');
background-size: contain; background-repeat: no-repeat;">
</div>
<span class="label">background-image (no viewBox scaling)</span>
</div>
</div>
</div>
<!-- 11. Curved path with markers -->
<div class="section">
<h3>11. Curved path with marker-start and marker-end</h3>
<svg width="300" height="120" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-curve-s" viewBox="0 -5 10 10" refX="0" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M10,-5L0,0L10,5" fill="#e91e63" />
</marker>
<marker id="arrow-curve-e" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="#e91e63" />
</marker>
</defs>
<path d="M 20 100 Q 150 -20 280 100" fill="none" stroke="#e91e63" stroke-width="2"
marker-start="url(#arrow-curve-s)" marker-end="url(#arrow-curve-e)" />
</svg>
</div>
<!-- 12. Multiple paths sharing markers, with viewBox scaling -->
<div class="section">
<h3>12. Multiple paths sharing markers in scaled viewBox</h3>
<svg width="300" height="150" viewBox="0 0 600 300" xmlns="http://www.w3.org/2000/svg" style="border:1px solid #ccc;">
<defs>
<marker id="arrow-shared" viewBox="0 -5 10 10" refX="10" refY="0"
markerWidth="6" markerHeight="6" orient="auto">
<path d="M0,-5L10,0L0,5" fill="#ff5722" />
</marker>
</defs>
<line x1="50" y1="75" x2="550" y2="75" stroke="#ff5722" stroke-width="4"
marker-end="url(#arrow-shared)" />
<line x1="50" y1="150" x2="550" y2="150" stroke="#ff5722" stroke-width="8"
marker-end="url(#arrow-shared)" />
<line x1="50" y1="225" x2="550" y2="225" stroke="#ff5722" stroke-width="16"
marker-end="url(#arrow-shared)" />
</svg>
</div>
</div>
</body>
</html>