-
Notifications
You must be signed in to change notification settings - Fork 8
/
d3.html
210 lines (200 loc) · 5.39 KB
/
d3.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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CoffeeBeans for d3.js</title>
<script src="lib/jquery.js"></script>
<script src="lib/coffee-script.js"></script>
<script src="lib/underscore.js"></script>
<script src="lib/underscore.math/underscore.math.js"></script>
<script src="lib/backbone.js"></script>
<script src="lib/backbone-localstorage.js"></script>
<script src="lib/js2coffee.min.js"></script>
<script src="lib/d3.v2.js"></script>
<script src="lib/require.js"></script>
<script src=lib/codemirror2/lib/codemirror.js></script>
<script src=lib/codemirror2/lib/util/runmode.js></script>
<script src=lib/codemirror2/mode/javascript/javascript.js></script>
<script src=coffeescript-mode.js></script>
<script src=lib/codemirror2/lib/util/simple-hint.js></script>
<script src=lib/codemirror2/lib/util/javascript-hint.js></script>
<link rel=stylesheet href=lib/codemirror2/lib/util/simple-hint.css>
<link rel=stylesheet href=lib/codemirror2/lib/codemirror.css>
<link rel=stylesheet href=css/coffeescript.css>
<link rel=stylesheet href=css/style-old.css>
<style>
body {
background: #ddd;
}
#chart {
position: fixed;
top: 0;
left: 0;
margin: 0 0 0 ;
height: 100%;
width: 40%;
background: #fff;
box-shadow: 0 0 4px #d0d0d0;
}
#beans-docs {
position: fixed;
top: 0;
right: 0;
width: 30%;
height: 100%;
z-index: 5;
border-left: 1px solid #bbb;
box-shadow: 0 0 6px #ccc;
background: #f6f6f6 url('img/background.png');
overflow: auto;
}
#beans-docs .inner {
padding: 20px;
}
#console.beans-side-console {
position: fixed;
left: 40%;
width: 30%;
height: 100%;
background: none;
}
#console.beans-side-console #puts {
top: 0;
height: 70%;
padding: 0 10px;
margin: 0;
}
#console.beans-side-console #puts * {
resize: none;
}
#console.beans-side-console #coffee-error {
right: 10px;
height: 14px;
top: 70%;
}
#console.beans-side-console #input-wrap{
height: 26%;
bottom: 0;
}
</style>
</head>
<body class="fullscreen">
<div id="console" class="beans-side-console">
<div id="puts">
</div>
<div id="coffee-error">
<span id="compile-error">
</span>
</div>
<div class="buttons">
<button id="store-code">Store</button>
<button id="bloh">!</button>
<button id="blah">!</button>
<button id="bleh">!</button>
</div>
<div id="input-wrap"><textarea id="input" class="input" wrap="off" rows="1"></textarea></div>
</div>
<div id="beans-docs">
<div class="inner">
<div>
<p>A <a href="http://coffeescript.org/">CoffeeScript</a> console for <a href="http://mbostock.github.com/d3/">d3.js</a> visualization</p>
<p>Find more tutorials on the <a href="https://github.com/mbostock/d3/wiki">wiki</a></p>
<p>Study the <a href="https://github.com/mbostock/d3/wiki/API-Reference">reference</a> to discover what's possible</p>
<div class="half">
<h2>Keyboard Shortcuts</h2>
<p><a href="http://fleetinbeing.net/beans/">CoffeeBeans</a> uses a <a href="http://codemirror.net/">CodeMirror</a> editor with the following shortcuts</p>
<table class="shortcuts">
<tr>
<td>Shift-Enter</td>
<td>Run code</td>
</tr>
<tr>
<td>Tab</td>
<td>Autocomplete</td>
</tr>
<tr>
<td>Enter</td>
<td>New Line</td>
</tr>
</table>
</div>
<div class="half">
<h2>History</h2>
<p>Commands are stored in the browser's local storage using <a href="http://documentcloud.github.com/backbone/">Backbone.js</a>.</p>
<table class="shortcuts">
<tr>
<td>Up</td>
<td>Previous command</td>
</tr>
<tr>
<td>Down</td>
<td>Next command</td>
</tr>
</table>
</div>
<div class="clear"></div>
</div>
<h2>Tutorial</h2>
<p>Try copying these code blocks into the console to the right, and run them.</p>
<p>Create an SVG canvas</p>
<pre class="highlight">
svg = d3.select('#chart')
.append('svg')</pre>
<p>Append a circle</p>
<pre class="highlight">
circle = svg.append('circle')</pre>
<p>Give the circle a position and radius</p>
<pre class="highlight">
circle
.attr('cx', 100)
.attr('cy', 100)
.attr('r', 40)
</pre>
<p>Transition to a new position, radius, and fill color</p>
<pre class="highlight">
circle
.transition()
.duration(800)
.attr('cx', 200)
.attr('cy', 200)
.attr('fill', 'orange')
.attr('r', 200)
</pre>
<p>Create some data</p>
<pre class="highlight">
some_data = [1,2,3,4,5,4,3,2,1]</pre>
<p>Bind the data to the circles</p>
<pre class="highlight">
svg.selectAll('circle')
.data(some_data)
.enter().append('circle')
circles = svg.selectAll('circle')</pre>
<p>Make a simple visualization</p>
<pre class="highlight">
circles
.transition()
.duration(800)
.attr('stroke', '#666')
.attr('fill', '#444')
.attr('cx', (d,i) -> 40+40*i)
.attr('cy', (d,i) -> 40+40*i)
.attr('r', (d,i) -> 4*d)</pre>
<p>Transition representation</p>
<pre class="highlight">
circles
.transition()
.duration(800)
.attr('fill', (d) ->
d3.hsl(40*d,0.6,0.6)
)
.attr('cx', 210)
.attr('stroke', '#fff')</pre>
</div>
</div>
<div id="chart"></div>
<script src=commands.js></script>
<script src=beans.js></script>
<script>
var beans = CoffeeBeans();
</script>
</html>