-
Notifications
You must be signed in to change notification settings - Fork 20
/
about_svg.html
90 lines (88 loc) · 2.96 KB
/
about_svg.html
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
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<a href="index.html">Home</a>
<h3>SVG</h3>
<p>Using SVG to represent/visualize data is usually more reliable, consistent, and faster than using regular HTML elements. SVG is XML based, so open tags need to be matched with a closing tag: <code><element></element></code>. The <code><svg></svg></code> tag is the container object where the shapes will be generated, a lot like the HTML5 <code><canvas></code> tag. You have to also specify the <code>height</code> and <code>width</code> attributes if you don't want it taking up the entire window.</p>
<h3>Basic SVG:</h3>
<p>The basic shapes have their own elements:</p>
<ul>
<li>
Circle:<br>
<svg width="100" height="100">
<circle cx="50" cy="50" r="25"/>
</svg>
<code><pre>
<svg width="100" height="100">
<circle cx="50" cy="50" r="25"/>
</svg>
</pre></code>
</li>
<li>
Ellipse:<br>
<svg width="100" height="100">
<ellipse cx="50" cy="50" rx="40" ry="20"/>
</svg>
<code><pre>
<svg width="100" height="100">
<ellipse cx="50" cy="50" rx="40" ry="20"/>
</svg>
</pre></code>
</li>
<li>
Rectangle:<br>
<svg width="100" height="100">
<rect x="10" y="10" width="80" height="80"/>
</svg>
<code><pre>
<svg width="100" height="100">
<rect x="10" y="10" width="80" height="80"/>
</svg>
</pre></code>
</li>
<li>
Line:<br>
<svg width="100" height="100">
<line x1="0" y1="0" x2="100" y2="100" stroke="black"/>
</svg>
<code><pre>
<svg width="100" height="100">
<line x1="0" y1="0" x2="100" y2="100" stroke="black"/>
</svg>
</pre></code>
</li>
</ul>
<h3>Styling and Rendering</h3>
The <code>fill</code> attribute lets us set the color of the SVG element
<ul>
<li>
Circles:<br>
<svg width="100" height="100">
<circle cx="10" cy="50" r="10" fill="rgba(128, 0, 128, 1.0)"/>
<circle cx="30" cy="50" r="15" fill="rgba(0, 0, 255, 0.75)"/>
<circle cx="50" cy="50" r="20" fill="rgba(0, 255, 0, 0.5)"/>
<circle cx="70" cy="50" r="15" fill="rgba(255, 255, 0, 0.25)"/>
<circle cx="90" cy="50" r="10" fill="rgba(255, 0, 0, 0.1)"/>
</svg>
<code><pre>
<svg width="100" height="100">
<circle cx="10" cy="50" r="10" fill="rgba(128, 0, 128, 1.0)"/>
<circle cx="30" cy="50" r="15" fill="rgba(0, 0, 255, 0.75)"/>
<circle cx="50" cy="50" r="20" fill="rgba(0, 255, 0, 0.5)"/>
<circle cx="70" cy="50" r="15" fill="rgba(255, 255, 0, 0.25)"/>
<circle cx="90" cy="50" r="10" fill="rgba(255, 0, 0, 0.1)"/>
</svg>
</pre></code>
</li>
</ul>
<a href="transitions.html">Transitions</a> - <a href="d3-svg.html">D3 SVG</a>
<script>
function applyD3Selectors(){
}
</script>
</body>
</html>