-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsvg.html
111 lines (102 loc) · 2.69 KB
/
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vg.js SVG notebook</title>
<style>
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 12px;
}
.header {
position: relative;
height: 40px;
left: 0;
right: 0;
background: #81be97;
color: #d9ebe0;
border-bottom: 1px solid #4d9567;
}
.header h2 {
display: inline-block;
margin: 0;
padding: 10px;
}
.btn {
background: #c2dfcd;
color: #888;
margin: 0;
padding: 6px;
line-height: 1.8em;
}
.btn div {
position: relative;
display: inline-block;
padding: 5px;
line-height: 1em;
color: #519c6c;
}
.btn button {
position: relative;
margin-left: 48%;
display: inline-block;
padding: 5px;
background: #81be97;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 3px;
line-height: 1em;
color: #d9ebe0;
}
#ta {
position: absolute;
width: 48%;
height: 85%;
border: none;
padding: 10px;
font-family: monospace;
font-size: 14px;
color: purple;
}
#canvasarea {
width: 50%;
height: 87%;
position: absolute;
left: 50%;
border-left: 1px solid lightgray;
}
#canvasarea canvas {
width: 100%;
height: 100%;
}
</style>
<script src="build/vg.js"></script>
<script type="text/javascript">
function render() {
var s = document.getElementById('ta').value;
var result = vg.svg.parseString(s);
var bounds = vg.bounds(result);
var canvas = document.getElementById('c');
var width = canvas.width = document.getElementById('canvasarea').clientWidth;
var height = canvas.height = document.getElementById('canvasarea').clientHeight;
ctx = canvas.getContext('2d');
ctx.translate((width - bounds.width) / 2, (height - bounds.height) / 2);
vg.draw(ctx, result);
}
</script>
</head>
<body>
<div class="header">
<h2>vg.js SVG notebook</h2>
</div>
<div class="btn">
<div>SVG</div>
<button onClick="render()">Render</button>
</div>
<textarea id="ta"></textarea>
<div id="canvasarea">
<canvas id="c" />
</div>
</body>
</html>