├── pig.png
├── bird.png
├── style.css
├── data.php
├── create.mysql
├── README.md
├── client.php
├── csv2time.py
├── index.php
├── record.php
├── client.js
├── lib.php
└── protovis-r3.2.js
/pig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stamen/Productive-Birds/HEAD/pig.png
--------------------------------------------------------------------------------
/bird.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/stamen/Productive-Birds/HEAD/bird.png
--------------------------------------------------------------------------------
/style.css:
--------------------------------------------------------------------------------
1 | h1, h2 { font: 25px Georgia; }
2 | h3, body, input, select, select option { font: 18px Georgia; }
3 |
--------------------------------------------------------------------------------
/data.php:
--------------------------------------------------------------------------------
1 | 0
11 | ORDER BY week, person, client";
12 |
13 | $res = mysql_query($q, $dbh);
14 | $rows = array();
15 |
16 | header('Content-Type: text/plain');
17 | echo join("\t", array('week', 'person', 'days', 'client'))."\n";
18 |
19 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
20 | echo join("\t", $row)."\n";
21 |
22 | mysql_close($dbh);
23 |
24 | ?>
25 |
--------------------------------------------------------------------------------
/create.mysql:
--------------------------------------------------------------------------------
1 | CREATE TABLE utilization
2 | (
3 | `week` VARCHAR(8) NOT NULL,
4 | `client` VARCHAR(32) NOT NULL,
5 | `person` VARCHAR(16) NOT NULL,
6 | `days` FLOAT,
7 | `count` TINYINT DEFAULT 1,
8 | `order` INT AUTO_INCREMENT,
9 |
10 | PRIMARY KEY (`week`, `client`, `person`),
11 | INDEX `order` (`order`)
12 | );
13 |
14 | CREATE TABLE same_clients
15 | (
16 | `client1` VARCHAR(32) NOT NULL,
17 | `client2` VARCHAR(32) NOT NULL,
18 |
19 | PRIMARY KEY (`client1`, `client2`)
20 | );
21 |
22 | CREATE TABLE client_info
23 | (
24 | `client` VARCHAR(32) NOT NULL,
25 | `ends` VARCHAR(10) NOT NULL,
26 | `days` FLOAT NOT NULL,
27 | `budget` INT NOT NULL,
28 |
29 | PRIMARY KEY (`client`)
30 | );
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Productive Birds
2 | ================
3 |
4 | A very bare-bones project time tracking application for small teams described in
5 | [a detailed blog post](http://mike.teczno.com/notes/angry-productive-birds.html).
6 | There’s not a lot of tooling here, and the goal isn’t so much a web application
7 | as an information display that can be tacked to the wall for high visibility.
8 |
9 | 
10 |
11 | Install
12 | -------
13 |
14 | 1. Make a new MySQL database using `create.mysql`.
15 | 2. Set your database parameters in `connect_mysql()` at the top of `lib.php`.
16 | 3. Add a client to the `client_info` table (sorry, I haven’t made a form for any of this):
17 | * `client` column is their name.
18 | * `ends` is a date for when the project ends, formatted like `"YYYY-MM-DD"`.
19 | * `days` is the number of days your team can spend on the project based on the budget.
20 | * `budget` is an amount of money, used only for display and sorting.
21 | 4. Ignore the `same_clients` tables unless you’re like us and used to use lots of different names for the same things.
22 | 5. Modify the `PEOPLE` list at the top of `lib.php` with initials for your group.
23 | 6. Go to `record.php` and type in some times!
24 | 7. Get data out for use in other systems at `data.php`.
25 |
--------------------------------------------------------------------------------
/client.php:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | = $client_name ?> Client Info
20 |
21 |
22 |
23 |
24 |
25 |
26 | = $client_name ?> ($= nice_int($client_info['budget']) ?>)
27 |
28 |
29 |
38 |
39 |
40 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/csv2time.py:
--------------------------------------------------------------------------------
1 | from sys import argv, stderr, stdout
2 | from csv import reader
3 | from re import compile, I
4 | from datetime import date
5 |
6 | week_pat = compile(r'^week of (\d+)/(\d+) *- *(\d+)/(\d+)$', I)
7 | person_pat = compile(r'^(\w+)( act(ual)?)?$', I)
8 |
9 | today = date.today()
10 |
11 | def esc(str):
12 | return str.replace("'", "''")
13 |
14 | if __name__ == '__main__':
15 |
16 | data = open(argv[1], 'r')
17 | rows = reader(data)
18 |
19 | week_name, people = None, None
20 |
21 | for row in rows:
22 |
23 | if not row:
24 | continue
25 |
26 | is_date_row = bool(week_pat.match(row[0]))
27 |
28 | if is_date_row:
29 | week_match = week_pat.match(row[0])
30 |
31 | start_month, start_day, end_month, end_day \
32 | = [int(week_match.group(i), 10) for i in (1, 2, 3, 4)]
33 |
34 | start_date = date(today.year, start_month, start_day)
35 | start_week = start_date.strftime('%Y-W%U')
36 |
37 | end_date = date(today.year, end_month, end_day)
38 | end_week = end_date.strftime('%Y-W%U')
39 |
40 | assert start_week == end_week, 'Weeks in "%s" do not match.' % row[0]
41 |
42 | week_name = start_week
43 | continue
44 |
45 | if len(row) <= 3:
46 | continue
47 |
48 | is_people_row = min([bool(person_pat.match(val)) for val in row[1:-1]])
49 |
50 | if is_people_row:
51 | people = [person_pat.match(val).group(1) for val in row[1:-1]]
52 | continue
53 |
54 | if not row[0]:
55 | continue
56 |
57 | if week_name and people:
58 |
59 | client_name = row[0]
60 |
61 | for (person, days) in zip(people, row[1:]):
62 |
63 | if not days:
64 | print >> stdout, "DELETE FROM utilization WHERE week='%s' AND client='%s' AND person='%s';" \
65 | % (esc(week_name), esc(client_name), esc(person))
66 |
67 | continue
68 |
69 | if days == '*':
70 | days = 0.0
71 | elif days in ('1/2', '*1/2', '1/2 *'):
72 | days = 0.5
73 | elif days in ('1*', '1 *'):
74 | days = 1.0
75 | else:
76 | days = float(days)
77 |
78 | assert days <= 7, 'Too many days on %s for %s: %.1f' % (client_name, person, days)
79 |
80 | print >> stderr, week_name, client_name, person, days
81 | print >> stdout, "REPLACE INTO utilization SET week='%s', client='%s', person='%s', days=%.3f;" \
82 | % (esc(week_name), esc(client_name), esc(person), days)
83 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
22 | Stamen Clients
23 |
24 |
25 |
26 |
27 |
38 |
39 |
40 | Current Projects
41 |
42 |
43 |
By Name:
44 |
45 | foreach($current_byname as $info) { ?>
46 |
47 | = $info['name'] ?>
48 |
49 | } ?>
50 |
51 |
52 |
53 |
54 |
By End Date:
55 |
56 | foreach($current_bydate as $info) { ?>
57 |
58 | = $info['name'] ?>
59 |
60 | = nice_relative_date($info['time']) ?>.
61 |
62 | } ?>
63 |
64 |
65 |
66 |
67 |
By Size:
68 |
69 | foreach($current_bysize as $info) { ?>
70 |
71 | = $info['name'] ?>
72 |
73 | $= nice_int($info['budget']) ?>,
74 | = nice_days($info['days']) ?> days.
75 |
76 | } ?>
77 |
78 |
79 |
80 | Past Projects
81 |
82 |
92 |
93 |
94 |
By End Date:
95 |
96 | foreach($past_bydate as $info) { ?>
97 |
98 | = $info['name'] ?>
99 |
100 | = nice_relative_date($info['time']) ?>.
101 |
102 | } ?>
103 |
104 |
105 |
106 |
107 |
By Size:
108 |
109 | foreach($past_bysize as $info) { ?>
110 |
111 | = $info['name'] ?>
112 |
113 | $= nice_int($info['budget']) ?>,
114 | = nice_days($info['days']) ?> days.
115 |
116 | } ?>
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/record.php:
--------------------------------------------------------------------------------
1 | $person_days)
22 | {
23 | if(empty($clients[$client]))
24 | continue;
25 |
26 | foreach($person_days as $person => $days)
27 | {
28 | if(empty($people[$person]))
29 | continue;
30 |
31 | if(empty($days) && $days != '0') {
32 | continue;
33 |
34 | } elseif(preg_match('#^\d*\.?\d*$#', trim($days))) {
35 | // integer or floating point number
36 | $days = floatval($days);
37 |
38 | } elseif(preg_match('#^(\d+)\s*/\s*(\d+)$#', trim($days), $m)) {
39 | // fraction such as "1/2"
40 | $days = floatval($m[1]) / floatval($m[2]);
41 |
42 | } elseif(trim($days) == '*') {
43 | // splat means checkmark means meeting
44 | $days = 0;
45 |
46 | } else {
47 | continue;
48 | }
49 |
50 | $q = sprintf("INSERT INTO utilization
51 | (`week`, `client`, `person`, `days`)
52 | VALUES('%s', '%s', '%s', %f)",
53 |
54 | mysql_real_escape_string($_POST['week'], $dbh),
55 | mysql_real_escape_string($clients[$client], $dbh),
56 | mysql_real_escape_string($people[$person], $dbh),
57 | $days);
58 |
59 | //echo "{$q}\n\n";
60 | $res = mysql_query($q, $dbh);
61 | }
62 | }
63 |
64 | header('HTTP/1.1 303 See Other');
65 | header("Location: {$_SERVER['SCRIPT_NAME']}?week={$_POST['week']}");
66 | exit();
67 | }
68 |
69 | $current_clients = week_clients(&$dbh, $_GET['week']);
70 |
71 | $recent_clients = recent_clients($dbh);
72 | $recent_clients = array_merge($current_clients, $recent_clients);
73 | $recent_clients = array_values(array_unique($recent_clients));
74 |
75 | if(isset($_GET['week'])) {
76 | $explicit_week = true;
77 |
78 | $t = strtotime($_GET['week']);
79 | $this_week = nice_week($t);
80 | $prev_week = nice_week($t - 604800);
81 | $next_week = nice_week($t + 604800);
82 |
83 | $people = week_people($dbh, $this_week);
84 | $days = week_utilization(&$dbh, $this_week, $current_clients, $people);
85 |
86 | } else {
87 | $explicit_week = false;
88 |
89 | $this_week = nice_week(time());
90 | $prev_week = nice_week(time() - 604800);
91 |
92 | $people = recent_people($dbh);
93 | $days = array();
94 |
95 | header('HTTP/1.1 303 See Other');
96 | header("Location: {$_SERVER['SCRIPT_NAME']}?week={$this_week}");
97 | exit();
98 | }
99 |
100 | $week_text = sprintf('Week ending %s', date('M j', strtotime("{$this_week}-5")));
101 |
102 | // pad some
103 | $people[] = '';
104 | $people[] = '';
105 | $people[] = '';
106 |
107 | $rows = 25;
108 |
109 | mysql_close($dbh);
110 |
111 | ?>
112 |
113 |
114 |
115 | Record Week
116 |
117 |
118 |
119 |
120 |
149 |
150 |
151 |
152 |
153 |
190 |
191 |
216 |
217 |
218 |
219 |
--------------------------------------------------------------------------------
/client.js:
--------------------------------------------------------------------------------
1 | function nice_days(days)
2 | {
3 | return days.toFixed(1)
4 | .replace(/\.0$/, '')
5 | .replace(/\.5$/, '½')
6 | .replace(/^0/, '');
7 | }
8 |
9 | function render_client(data, info)
10 | {
11 | var total = 0,
12 | last = null;
13 |
14 | var start = {'days': 0, 'time': data[0].time - 7*86400, 'week': ''};
15 | data.unshift(start);
16 |
17 | for(var i = 0; i < data.length; i++)
18 | {
19 | total += data[i].days;
20 | data[i].total = total;
21 | last = data[i];
22 | }
23 |
24 | var w = 960,
25 | h = 390,
26 | end_time = Math.max(last.time, info ? info.time : 0),
27 | total_days = (end_time - data[0].time) / 86400,
28 | x = pv.Scale.linear(start.time, end_time).range(0, w),
29 | y = pv.Scale.linear(0, Math.max(total, info ? info.days : 0)).range(0, h),
30 | small = '13px Georgia',
31 | large = '18px Georgia',
32 | giant = '25px Georgia';
33 |
34 | var vis = new pv.Panel()
35 | .width(w)
36 | .height(h)
37 | .left(40)
38 | .right(25)
39 | .bottom(info ? 30 : 60)
40 | .top(info ? 40 : 80);
41 |
42 | //
43 | // area of profitability
44 | //
45 | if(info)
46 | {
47 | vis.add(pv.Area)
48 | .data([{time: start.time, total: 0}, {time: info.time, total: info.days}])
49 | .left(function(d) { return x(d.time) })
50 | .height(function(d) { return y(d.total) })
51 | .bottom(0)
52 | .fillStyle('#f4f4f4');
53 | }
54 |
55 | //
56 | // weekly vertical rules
57 | //
58 | vis.add(pv.Rule)
59 | .data(data)
60 | .strokeStyle('#ccc')
61 | .left(function(d) { return x(d.time) })
62 | .height(function(d) { return y(d.total) })
63 | .bottom(y(0));
64 |
65 | //
66 | // bottom rule
67 | //
68 | vis.add(pv.Rule)
69 | .bottom(y(0))
70 | .strokeStyle('#ccc')
71 | .left(0)
72 | .right(0);
73 |
74 | //
75 | // top rule
76 | //
77 | if(info)
78 | {
79 | vis.add(pv.Rule)
80 | .bottom(y((info.days)))
81 | .strokeStyle('#f90')
82 | .lineWidth(2)
83 | .left(0)
84 | .right(x(Math.max(info.time, last.time)) - x(info.time));
85 | }
86 |
87 | //
88 | // left-hand rule
89 | //
90 | var lr = vis.add(pv.Rule)
91 | .left(x(start.time))
92 | .strokeStyle('#ccc')
93 | .bottom(0)
94 | .top(0);
95 |
96 | if(info)
97 | {
98 | lr.add(pv.Label)
99 | .left(4)
100 | .top(h - y(info.days) + 24)
101 | .text(nice_days(info.days) + ' days')
102 | .textAlign('left')
103 | .font(large);
104 | }
105 |
106 | //
107 | // left hand ticks
108 | //
109 | vis.add(pv.Rule)
110 | .data(y.ticks(8))
111 | .visible(function() { return this.index > 0 })
112 | .strokeStyle('#ccc')
113 | .bottom(y)
114 | .left(-5)
115 | .width(5)
116 | .anchor('left').add(pv.Label)
117 | .text(y.tickFormat)
118 | .font(small);
119 |
120 | //
121 | // right-hand rule and label
122 | //
123 | if(info)
124 | {
125 | vis.add(pv.Rule)
126 | .left(x(info.time))
127 | .strokeStyle('#f90')
128 | .lineWidth(2)
129 | .bottom(0)
130 | .height(y(info.days))
131 | .add(pv.Label)
132 | .top(h - 8)
133 | .left(x(info.time) - 4)
134 | .text('Ends ' + info.date)
135 | .textAlign('right')
136 | .font(giant);
137 | }
138 |
139 | //
140 | // weekly time
141 | //
142 | vis.add(pv.Line)
143 | .data(data)
144 | .left(function(d) { return x(d.time) })
145 | .bottom(function(d) { return y(d.total) })
146 | .strokeStyle('#fafafa')
147 | .lineWidth(10)
148 | .add(pv.Line)
149 | .data(data)
150 | .left(function(d) { return x(d.time) })
151 | .bottom(function(d) { return y(d.total) })
152 | .strokeStyle('#666')
153 | .lineWidth(4)
154 | .add(pv.Dot)
155 | .size(function(d) { return (this.index > 0) ? 40 : 20 })
156 | .strokeStyle(function(d) { return (this.index > 0) ? '#fafafa' : '#fff' })
157 | .fillStyle('#666')
158 | .anchor('top').add(pv.Label)
159 | .text(function(d) { return nice_days(d.total); })
160 | .visible(function() { return this.index > 0 })
161 | .textAlign('right')
162 | .textAngle(total_days > 160 ? (total_days > 240 ? 0.983 : 0.393) : 0.000)
163 | .font(large);
164 |
165 | //
166 | // weekly dates
167 | //
168 | vis.add(pv.Label)
169 | .data(data)
170 | .left(function(d) { return x(d.time) + 8 })
171 | .bottom(total_days > 160 ? -15 : -20)
172 | .text(function(d) { return d.date })
173 | .textAlign('right')
174 | .textAngle(total_days > 160 ? (total_days > 240 ? -0.983 : -0.393) : 0.000)
175 | .font(small);
176 |
177 | //
178 | // pig
179 | //
180 | if(info)
181 | {
182 | vis.add(pv.Panel)
183 | .width(46)
184 | .height(46)
185 | .left(x(info.time) - 23)
186 | .bottom(y(info.days) - 23)
187 | .add(pv.Image)
188 | .url('pig.png');
189 | }
190 |
191 | //
192 | // bird
193 | //
194 | vis.add(pv.Panel)
195 | .width(41)
196 | .height(35)
197 | .left(x(last.time) - 20)
198 | .bottom(y(last.total) - 20)
199 | .add(pv.Image)
200 | .url('bird.png')
201 |
202 | vis.render();
203 | }
204 |
205 | function render_people(data, info)
206 | {
207 | var initials = ['JE', 'GS', 'SC', 'RB', 'NK', 'SA', 'MM', 'ER'],
208 | target = 0,
209 | maximum = 0,
210 | layers = [],
211 | people = {},
212 | weeks = {};
213 |
214 | for(var i = 0; i < data.length; i++)
215 | {
216 | var w = data[i].week,
217 | p = data[i].person,
218 | d = data[i].days || 0;
219 |
220 | if(!(p in people))
221 | {
222 | people[p] = {'index': layers.length, 'total': 0};
223 |
224 | // put in the very first one twice
225 | var layer = [{'person': p, 'week': '', 'time': data[i].time - 7*86400, 'days': data[i].days}];
226 | layer.person = data[i].person;
227 | layers.push(layer);
228 | }
229 |
230 | if(!(w in weeks))
231 | {
232 | weeks[w] = 0;
233 | }
234 |
235 | weeks[w] += d;
236 | people[p].total += d;
237 | maximum = Math.max(maximum, weeks[w]);
238 |
239 | // duplicate the friday data to monday to improve the visual appearance of the area chart.
240 | var monday = {'person': p, 'week': w, 'time': data[i].time - 5 * 86400, 'days': data[i].days};
241 |
242 | layers[people[p].index].push(monday);
243 | layers[people[p].index].push(data[i]);
244 | }
245 |
246 | // sort with the busiest people at the front
247 | layers.sort(function(a, b) { return people[b[1].person].total - people[a[1].person].total });
248 |
249 | var start = layers[0][0],
250 | last = layers[0][layers[0].length - 1];
251 |
252 | target = info.days * (7 * 86400) / (info.time - layers[0][0].time);
253 | maximum = Math.max(maximum, target);
254 |
255 | var w = 960,
256 | h = 120,
257 | end_time = Math.max(last.time, info.time),
258 | total_days = (end_time - layers[0][0].time) / 86400,
259 | x = pv.Scale.linear(start.time, end_time).range(0, w),
260 | y = pv.Scale.linear(0, maximum).range(0, h),
261 | tiny = '9px Georgia',
262 | small = '13px Georgia',
263 | large = '18px Georgia';
264 |
265 | var vis = new pv.Panel()
266 | .width(w)
267 | .height(h)
268 | .left(40)
269 | .right(25)
270 | .bottom(30)
271 | .top(40);
272 |
273 | var fills = pv.colors('#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#17becf',
274 | '#9edae5', '#bcbd22', '#dbdb8d', '#9c9ede', '#7375b5')
275 | .by(function(d) { return d.person });
276 |
277 | for(var i in initials)
278 | {
279 | fills({person: initials[i]});
280 | }
281 |
282 | //
283 | // area of profitability
284 | //
285 | vis.add(pv.Area)
286 | .data([{time: start.time, total: 0}, {time: info.time, total: info.days}])
287 | .left(function(d) { return x(d.time) })
288 | .height(y(target))
289 | .right(x(last.time))
290 | .bottom(0)
291 | .fillStyle('#f4f4f4');
292 |
293 | //
294 | // area chart
295 | //
296 | vis.add(pv.Layout.Stack)
297 | .layers(layers)
298 | .x(function(d) { return x(d.time) })
299 | .y(function(d) { return y(d.days) })
300 | .layer.add(pv.Area)
301 | .fillStyle(fills);
302 |
303 | //
304 | // bottom rule
305 | //
306 | vis.add(pv.Rule)
307 | .bottom(y(0))
308 | .strokeStyle('#ccc')
309 | .left(0)
310 | .right(0);
311 |
312 | //
313 | // left-hand rule
314 | //
315 | vis.add(pv.Rule)
316 | .left(x(start.time))
317 | .strokeStyle('#ccc')
318 | .bottom(0)
319 | .top(0);
320 |
321 | //
322 | // left hand ticks
323 | //
324 | vis.add(pv.Rule)
325 | .data(y.ticks(4))
326 | .visible(function() { return this.index > 0 })
327 | .strokeStyle('#ccc')
328 | .bottom(y)
329 | .left(-5)
330 | .width(5)
331 | .anchor('left').add(pv.Label)
332 | .text(y.tickFormat)
333 | .font(small);
334 |
335 | //
336 | // weekly dates
337 | //
338 | vis.add(pv.Label)
339 | .data(layers[0])
340 | .left(function(d) { return x(d.time) + 8 })
341 | .bottom(total_days > 160 ? -15 : -20)
342 | .text(function(d) { return d.date })
343 | .textAlign('right')
344 | .textAngle(total_days > 160 ? -0.393 : 0.000)
345 | .font(small);
346 |
347 | //
348 | // key to people colors
349 | //
350 | vis.add(pv.Bar)
351 | .data(layers)
352 | .left(function() { return 15 + this.index * 30 })
353 | .fillStyle(fills)
354 | .top(-10)
355 | .width(25)
356 | .height(15)
357 | .add(pv.Label)
358 | .text(function(d) { return d.person })
359 | .font(small)
360 | .left(function() { return 15 + this.index * 30 - 3 })
361 | .top(-13)
362 | .add(pv.Label)
363 | .text(function(d) { return people[d.person].total })
364 | .font(small)
365 | .left(function() { return 15 + this.index * 30 - 3 })
366 | .top(22);
367 |
368 | vis.render();
369 | }
370 |
--------------------------------------------------------------------------------
/lib.php:
--------------------------------------------------------------------------------
1 | $name)
51 | $names[$i] = sprintf("'%s'", mysql_real_escape_string($name, $dbh));
52 |
53 | return join(', ', $names);
54 | }
55 |
56 | function client_days(&$dbh, $name)
57 | {
58 | $names = client_synonyms_literal($dbh, $name);
59 |
60 | $q = sprintf("SELECT week, SUM(days) AS days
61 | FROM utilization
62 | WHERE client IN (%s)
63 | AND `count` = 1
64 | GROUP BY week
65 | ORDER BY week",
66 | $names);
67 |
68 | $res = mysql_query($q, $dbh);
69 | $rows = array();
70 |
71 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
72 | {
73 | $row['days'] = floatval($row['days']);
74 | $row['time'] = strtotime("{$row['week']}-5 12:00:00");
75 | $row['date'] = date('M j', $row['time']);
76 | $rows[] = $row;
77 | }
78 |
79 | return $rows;
80 | }
81 |
82 | function client_people(&$dbh, $name)
83 | {
84 | $names = client_synonyms_literal($dbh, $name);
85 |
86 | $q = sprintf("SELECT w.week, p.person, u.days
87 | FROM (
88 | SELECT DISTINCT week
89 | FROM utilization
90 | WHERE client IN (%s)
91 | AND `count` = 1
92 | ) AS w
93 | CROSS JOIN (
94 | SELECT DISTINCT person
95 | FROM utilization
96 | WHERE client IN (%s)
97 | AND `count` = 1
98 | ) AS p
99 | LEFT JOIN utilization AS u
100 | ON u.week = w.week
101 | AND u.person = p.person
102 | AND u.client IN (%s)
103 | AND u.count = 1
104 | ORDER BY w.week, p.person",
105 | $names,
106 | $names,
107 | $names);
108 |
109 | $res = mysql_query($q, $dbh);
110 | $rows = array();
111 |
112 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
113 | {
114 | $row['days'] = is_null($row['days']) ? null : floatval($row['days']);
115 | $row['time'] = strtotime("{$row['week']}-5 12:00:00");
116 | $row['date'] = date('M j', $row['time']);
117 | $rows[] = $row;
118 | }
119 |
120 | return $rows;
121 | }
122 |
123 | function client_list(&$dbh, $order, $ended)
124 | {
125 | if($order == 'by-date') {
126 | $order = ($ended == 'no') ? 'ends ASC' : 'ends DESC';
127 |
128 | } else if($order == 'by-size') {
129 | $order = 'days DESC';
130 |
131 | } else {
132 | $order = 'client ASC';
133 | }
134 |
135 | $q = sprintf("SELECT client AS name, ends, days, budget
136 | FROM client_info
137 | WHERE ended = '{$ended}'
138 | ORDER BY {$order}");
139 |
140 | $res = mysql_query($q, $dbh);
141 | $rows = array();
142 |
143 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
144 | {
145 | $row['days']= floatval($row['days']);
146 | $row['time'] = strtotime("{$row['ends']} 12:00:00");
147 | $row['date'] = date('F jS', $row['time']);
148 | $rows[] = $row;
149 | }
150 |
151 | return $rows;
152 | }
153 |
154 | function client_info(&$dbh, $name)
155 | {
156 | $q = sprintf("SELECT client AS name, ends, days, budget
157 | FROM client_info
158 | WHERE client = '%s'",
159 | mysql_real_escape_string($name, $dbh));
160 |
161 | $res = mysql_query($q, $dbh);
162 |
163 | if($row = mysql_fetch_array($res, MYSQL_ASSOC))
164 | {
165 | $row['days']= floatval($row['days']);
166 | $row['time'] = strtotime("{$row['ends']} 12:00:00");
167 | $row['date'] = date('F jS', $row['time']);
168 | return $row;
169 | }
170 |
171 | return null;
172 | }
173 |
174 | function week_clients(&$dbh, $week)
175 | {
176 | $q = sprintf("SELECT DISTINCT `client`
177 | FROM utilization
178 | WHERE week = '%s'
179 | ORDER BY `order`",
180 | mysql_real_escape_string($week, $dbh));
181 |
182 | $res = mysql_query($q, $dbh);
183 | $clients = array();
184 |
185 | while($row = mysql_fetch_array($res, MYSQL_NUM))
186 | $clients[] = $row[0];
187 |
188 | return $clients;
189 | }
190 |
191 | function week_people(&$dbh, $week)
192 | {
193 | $people = explode(' ', PEOPLE);
194 |
195 | $q = sprintf("SELECT DISTINCT `person`
196 | FROM utilization
197 | WHERE week = '%s'",
198 | mysql_real_escape_string($week, $dbh));
199 |
200 | $res = mysql_query($q, $dbh);
201 |
202 | while($row = mysql_fetch_array($res, MYSQL_NUM))
203 | if(!in_array($row[0], $people))
204 | $people[] = $row[0];
205 |
206 | return $people;
207 | }
208 |
209 | /**
210 | * Return a nested array of clients and people, using numeric indexes.
211 | */
212 | function week_utilization(&$dbh, $week, $clients, $people)
213 | {
214 | $q = sprintf("SELECT DISTINCT `client`
215 | FROM utilization
216 | WHERE week = '%s'",
217 | mysql_real_escape_string($week, $dbh));
218 |
219 | $res = mysql_query($q, $dbh);
220 |
221 | $client_days = array();
222 |
223 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
224 | {
225 | $client = array_search($row['client'], $clients);
226 | $client_days[$client] = array();
227 | }
228 |
229 | $q = sprintf("SELECT `client`, `person`, `days`
230 | FROM utilization
231 | WHERE week = '%s'",
232 | mysql_real_escape_string($week, $dbh));
233 |
234 | $res = mysql_query($q, $dbh);
235 |
236 | while($row = mysql_fetch_array($res, MYSQL_ASSOC))
237 | {
238 | $client = array_search($row['client'], $clients);
239 | $person = array_search($row['person'], $people);
240 | $client_days[$client][$person] = $row['days'];
241 | }
242 |
243 | return $client_days;
244 | }
245 |
246 | function recent_clients(&$dbh)
247 | {
248 | $q = "SELECT client
249 | FROM client_info
250 | ORDER BY ends DESC";
251 |
252 | $res = mysql_query($q, $dbh);
253 | $names = array();
254 | $seen = array();
255 |
256 | while($row = mysql_fetch_array($res, MYSQL_NUM))
257 | {
258 | $names[] = $row[0];
259 | $seen[] = strtolower($row[0]);
260 | }
261 |
262 | $q = "SELECT DISTINCT client
263 | FROM utilization
264 | ORDER BY week DESC
265 | LIMIT 50";
266 |
267 | $res = mysql_query($q, $dbh);
268 |
269 | while($row = mysql_fetch_array($res, MYSQL_NUM))
270 | if(!in_array(strtolower($row[0]), $seen))
271 | $names[] = $row[0];
272 |
273 | return $names;
274 | }
275 |
276 | function recent_people(&$dbh)
277 | {
278 | $people = explode(' ', PEOPLE);
279 | $time = time() - 6 * 7 * 86400;
280 | $week = date('Y-', $time).'W'.date('W', $time);
281 |
282 | $q = "SELECT DISTINCT person
283 | FROM utilization
284 | WHERE week >= '{$week}'";
285 |
286 | $res = mysql_query($q, $dbh);
287 |
288 | while($row = mysql_fetch_array($res, MYSQL_NUM))
289 | if(!in_array($row[0], $people))
290 | $people[] = $row[0];
291 |
292 | return $people;
293 | }
294 |
295 | function nice_int($int)
296 | {
297 | if(is_null($int))
298 | return '?';
299 |
300 | $str = sprintf('%d', $int);
301 |
302 | while(preg_match('/\B(\d\d\d)\b/', $str))
303 | $str = preg_replace('/\B(\d\d\d)\b/', ',\1', $str);
304 |
305 | return $str;
306 | }
307 |
308 | function nice_week($time)
309 | {
310 | return sprintf('%s-W%s', date('Y', $time), date('W', $time));
311 | }
312 |
313 | function nice_days($val)
314 | {
315 | $str = sprintf('%.1f', $val);
316 | $str = preg_replace('/\.0$/', '', $str);
317 | $str = preg_replace('/\.5$/', '½', $str);
318 | $str = preg_replace('/^0/', '', $str);
319 |
320 | return $str;
321 | }
322 |
323 | function nice_relative_date($time)
324 | {
325 | $diff = abs($time - time());
326 |
327 | if($diff > 45 * 86400) {
328 | $val = round($diff / (30 * 86400));
329 | $unit = 'month';
330 |
331 | } elseif($diff > 12 * 86400) {
332 | $val = round($diff / (7 * 86400));
333 | $unit = 'week';
334 |
335 | } elseif($diff > 36 * 3600) {
336 | $val = round($diff / 86400);
337 | $unit = 'day';
338 |
339 | } else {
340 | return 'Now';
341 | }
342 |
343 | $str = sprintf('%d %s%s %s',
344 | $val, $unit,
345 | ($val > 1 ? 's' : ''),
346 | ($time < time() ? 'ago' : 'from now'));
347 |
348 | return $str;
349 | }
350 |
351 | ?>
352 |
--------------------------------------------------------------------------------
/protovis-r3.2.js:
--------------------------------------------------------------------------------
1 | // fba9dc2
2 | var a;if(!Array.prototype.map)Array.prototype.map=function(b,c){for(var d=this.length,f=new Array(d),g=0;g>>0,f=0;f=d)throw new Error("reduce: no values, no initial value");}for(;f=0&&d=69&&m<100?1900:0)});return"([0-9]+)";case "%Y":q.push(function(m){g=m});return"([0-9]+)";case "%%":q.push(function(){});
14 | return"%"}return n});(f=f.match(o))&&f.forEach(function(n,m){q[m](n)});return new Date(g,h,i,j,l,k)};return c};
15 | pv.Format.time=function(b){function c(f){f=Number(f);switch(b){case "short":if(f>=31536E6)return(f/31536E6).toFixed(1)+" years";else if(f>=6048E5)return(f/6048E5).toFixed(1)+" weeks";else if(f>=864E5)return(f/864E5).toFixed(1)+" days";else if(f>=36E5)return(f/36E5).toFixed(1)+" hours";else if(f>=6E4)return(f/6E4).toFixed(1)+" minutes";return(f/1E3).toFixed(1)+" seconds";case "long":var g=[],h=f%36E5/6E4>>0;g.push(d("0",2,f%6E4/1E3>>0));if(f>=36E5){var i=f%864E5/36E5>>0;g.push(d("0",2,h));if(f>=864E5){g.push(d("0",
16 | 2,i));g.push(Math.floor(f/864E5).toFixed())}else g.push(i.toFixed())}else g.push(h.toFixed());return g.reverse().join(":")}}var d=pv.Format.pad;c.format=c;c.parse=function(f){switch(b){case "short":for(var g=/([0-9,.]+)\s*([a-z]+)/g,h,i=0;h=g.exec(f);){var j=parseFloat(h[0].replace(",","")),l=0;switch(h[2].toLowerCase()){case "year":case "years":l=31536E6;break;case "week":case "weeks":l=6048E5;break;case "day":case "days":l=864E5;break;case "hour":case "hours":l=36E5;break;case "minute":case "minutes":l=
17 | 6E4;break;case "second":case "seconds":l=1E3;break}i+=j*l}return i;case "long":h=f.replace(",","").split(":").reverse();i=0;if(h.length)i+=parseFloat(h[0])*1E3;if(h.length>1)i+=parseFloat(h[1])*6E4;if(h.length>2)i+=parseFloat(h[2])*36E5;if(h.length>3)i+=parseFloat(h[3])*864E5;return i}};return c};
18 | pv.Format.number=function(){function b(n){if(Infinity>h)n=Math.round(n*i)/i;var m=String(Math.abs(n)).split("."),r=m[0];n=n<0?"-":"";if(r.length>d)r=r.substring(r.length-d);if(k&&r.length3)r=r.replace(/\B(?=(?:\d{3})+(?!\d))/g,o);if(!k&&r.lengthd)m=m.substring(m.length-d);n=n[1]?Number("0."+n[1]):0;if(Infinity>h)n=Math.round(n*i)/i;return Math.round(m)+n};b.integerDigits=function(n,m){if(arguments.length){c=Number(n);d=arguments.length>1?Number(m):c;f=c+Math.floor(c/3)*o.length;return this}return[c,d]};b.fractionDigits=function(n,m){if(arguments.length){g=
20 | Number(n);h=arguments.length>1?Number(m):g;i=Math.pow(10,h);return this}return[g,h]};b.integerPad=function(n){if(arguments.length){j=String(n);k=/\d/.test(j);return this}return j};b.fractionPad=function(n){if(arguments.length){l=String(n);return this}return l};b.decimal=function(n){if(arguments.length){q=String(n);return this}return q};b.group=function(n){if(arguments.length){o=n?String(n):"";f=c+Math.floor(c/3)*o.length;return this}return o};return b};
21 | pv.map=function(b,c){var d={};return c?b.map(function(f,g){d.index=g;return c.call(d,f)}):b.slice()};pv.repeat=function(b,c){if(arguments.length==1)c=2;return pv.blend(pv.range(c).map(function(){return b}))};pv.cross=function(b,c){for(var d=[],f=0,g=b.length,h=c.length;fc){b.length=d;for(var f=c;fc?1:0};
24 | pv.reverseOrder=function(b,c){return cb?1:0};pv.search=function(b,c,d){if(!d)d=pv.identity;for(var f=0,g=b.length-1;f<=g;){var h=f+g>>1,i=d(b[h]);if(ic)g=h-1;else return h}return-f-1};pv.search.index=function(b,c,d){b=pv.search(b,c,d);return b<0?-b-1:b};
25 | pv.range=function(b,c,d){if(arguments.length==1){c=b;b=0}if(d==undefined)d=1;if((c-b)/d==Infinity)throw new Error("range must be finite");var f=[],g=0,h;if(d<0)for(;(h=b+d*g++)>c;)f.push(h);else for(;(h=b+d*g++)f){f=i;d=h}}return d};
27 | pv.min=function(b,c){if(c==pv.index)return 0;return Math.min.apply(null,c?pv.map(b,c):b)};pv.min.index=function(b,c){if(!b.length)return-1;if(c==pv.index)return 0;if(!c)c=pv.identity;for(var d=0,f=Infinity,g={},h=0;h0?Math.pow(c,Math.floor(pv.log(b,c))):-Math.pow(c,-Math.floor(-pv.log(-b,c)))};pv.logCeil=function(b,c){return b>0?Math.pow(c,Math.ceil(pv.log(b,c))):-Math.pow(c,-Math.ceil(-pv.log(-b,c)))};
30 | (function(){var b=Math.PI/180,c=180/Math.PI;pv.radians=function(d){return b*d};pv.degrees=function(d){return c*d}})();pv.keys=function(b){var c=[];for(var d in b)c.push(d);return c};pv.entries=function(b){var c=[];for(var d in b)c.push({key:d,value:b[d]});return c};pv.values=function(b){var c=[];for(var d in b)c.push(b[d]);return c};pv.dict=function(b,c){for(var d={},f={},g=0;g=94608E6){n=31536E6;t="%Y";p=function(w){w.setFullYear(w.getFullYear()+v)}}else if(u>=7776E6){n=2592E6;t="%m/%Y";p=function(w){w.setMonth(w.getMonth()+v)}}else if(u>=18144E5){n=6048E5;t="%m/%d";p=function(w){w.setDate(w.getDate()+7*v)}}else if(u>=2592E5){n=864E5;t="%m/%d";p=function(w){w.setDate(w.getDate()+v)}}else if(u>=108E5){n=36E5;t="%I:%M %p";p=function(w){w.setHours(w.getHours()+
53 | v)}}else if(u>=18E4){n=6E4;t="%I:%M %p";p=function(w){w.setMinutes(w.getMinutes()+v)}}else if(u>=3E3){n=1E3;t="%I:%M:%S";p=function(w){w.setSeconds(w.getSeconds()+v)}}else{n=1;t="%S.%Qs";p=function(w){w.setTime(w.getTime()+v)}}q=pv.Format.date(t);s=new Date(s);t=[];x(s,n);u=u/n;if(u>10)switch(n){case 36E5:v=u>20?6:3;s.setHours(Math.floor(s.getHours()/v)*v);break;case 2592E6:v=3;s.setMonth(Math.floor(s.getMonth()/v)*v);break;case 6E4:v=u>30?15:u>15?10:5;s.setMinutes(Math.floor(s.getMinutes()/v)*v);
54 | break;case 1E3:v=u>90?15:u>60?10:5;s.setSeconds(Math.floor(s.getSeconds()/v)*v);break;case 1:v=u>1E3?250:u>200?100:u>100?50:u>50?25:5;s.setMilliseconds(Math.floor(s.getMilliseconds()/v)*v);break;default:v=pv.logCeil(u/15,10);if(u/v<2)v/=5;else if(u/v<5)v/=2;s.setFullYear(Math.floor(s.getFullYear()/v)*v);break}for(;;){p(s);if(s>m)break;t.push(new Date(s))}return r?t.reverse():t}arguments.length||(o=10);v=pv.logFloor(u/o,10);n=o/(u/v);if(n<=0.15)v*=10;else if(n<=0.35)v*=5;else if(n<=0.75)v*=2;n=Math.ceil(s/
55 | v)*v;m=Math.floor(m/v)*v;q=pv.Format.number().fractionDigits(Math.max(0,-Math.floor(pv.log(v,10)+0.01)));m=pv.range(n,m+v,v);return r?m.reverse():m};c.tickFormat=function(o){return q(o)};c.nice=function(){if(d.length!=2)return this;var o=d[0],n=d[d.length-1],m=n0;i--)k.push(-g(-j)*i);else{for(;jh[1];l--);return k.slice(j,l)};b.tickFormat=function(h){return h.toPrecision(1)};
58 | b.nice=function(){var h=b.domain();return b.domain(pv.logFloor(h[0],c),pv.logCeil(h[1],c))};b.base=function(h){if(arguments.length){c=Number(h);d=Math.log(c);b.transform(f,g);return this}return c};b.domain.apply(b,arguments);return b.base(10)};pv.Scale.root=function(){var b=pv.Scale.quantitative();b.power=function(c){if(arguments.length){var d=Number(c),f=1/d;b.transform(function(g){return Math.pow(g,f)},function(g){return Math.pow(g,d)});return this}return d};b.domain.apply(b,arguments);return b.power(2)};
59 | pv.Scale.ordinal=function(){function b(g){g in d||(d[g]=c.push(g)-1);return f[d[g]%f.length]}var c=[],d={},f=[];b.domain=function(g,h){if(arguments.length){g=g instanceof Array?arguments.length>1?pv.map(g,h):g:Array.prototype.slice.call(arguments);c=[];for(var i={},j=0;j1?pv.map(g,h):g:Array.prototype.slice.call(arguments);
60 | if(typeof f[0]=="string")f=f.map(pv.color);return this}return f};b.split=function(g,h){var i=(h-g)/this.domain().length;f=pv.range(g+i/2,h,i);return this};b.splitFlush=function(g,h){var i=this.domain().length,j=(h-g)/(i-1);f=i==1?[(g+h)/2]:pv.range(g,h+j/2,j);return this};b.splitBanded=function(g,h,i){if(arguments.length<3)i=1;if(i<0){var j=this.domain().length;j=(h-g- -i*j)/(j+1);f=pv.range(g+j,h,j-i);f.band=-i}else{j=(h-g)/(this.domain().length+(1-i));f=pv.range(g+j*(1-i),h,j);f.band=j*i}return this};
61 | b.by=function(g){function h(){return b(g.apply(this,arguments))}for(var i in b)h[i]=b[i];return h};b.domain.apply(b,arguments);return b};
62 | pv.Scale.quantile=function(){function b(i){return h(Math.max(0,Math.min(d,pv.search.index(f,i)-1))/d)}var c=-1,d=-1,f=[],g=[],h=pv.Scale.linear();b.quantiles=function(i){if(arguments.length){c=Number(i);if(c<0){f=[g[0]].concat(g);d=g.length-1}else{f=[];f[0]=g[0];for(var j=1;j<=c;j++)f[j]=g[~~(j*(g.length-1)/c)];d=c-1}return this}return f};b.domain=function(i,j){if(arguments.length){g=i instanceof Array?pv.map(i,j):Array.prototype.slice.call(arguments);g.sort(pv.naturalOrder);b.quantiles(c);return this}return g};
63 | b.range=function(){if(arguments.length){h.range.apply(h,arguments);return this}return h.range()};b.by=function(i){function j(){return b(i.apply(this,arguments))}for(var l in b)j[l]=b[l];return j};b.domain.apply(b,arguments);return b};
64 | pv.histogram=function(b,c){var d=true;return{bins:function(f){var g=pv.map(b,c),h=[];arguments.length||(f=pv.Scale.linear(g).ticks());for(var i=0;i360)j-=360;else if(j<0)j+=360;if(j<60)return i+(h-i)*j/60;if(j<180)return h;if(j<240)return i+(h-i)*(240-j)/60;return i}function c(j){return Math.round(b(j)*255)}var d=this.h,f=this.s,g=this.l;d%=360;if(d<0)d+=360;f=Math.max(0,Math.min(f,1));g=Math.max(0,Math.min(g,1));var h=g<=0.5?g*(1+f):g+f-g*f,i=2*g-h;return pv.rgb(c(d+120),c(d),c(d-120),this.a)};
72 | pv.Color.names={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",
73 | darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",
74 | ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",
75 | lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",
76 | moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",
77 | seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32",transparent:pv.Color.transparent=pv.rgb(0,0,0,0)};(function(){var b=pv.Color.names;for(var c in b)b[c]=pv.color(b[c])})();
78 | pv.colors=function(){var b=pv.Scale.ordinal();b.range.apply(b,arguments);return b};pv.Colors={};pv.Colors.category10=function(){var b=pv.colors("#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf");b.domain.apply(b,arguments);return b};
79 | pv.Colors.category20=function(){var b=pv.colors("#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5");b.domain.apply(b,arguments);return b};
80 | pv.Colors.category19=function(){var b=pv.colors("#9c9ede","#7375b5","#4a5584","#cedb9c","#b5cf6b","#8ca252","#637939","#e7cb94","#e7ba52","#bd9e39","#8c6d31","#e7969c","#d6616b","#ad494a","#843c39","#de9ed6","#ce6dbd","#a55194","#7b4173");b.domain.apply(b,arguments);return b};pv.ramp=function(){var b=pv.Scale.linear();b.range.apply(b,arguments);return b};
81 | pv.Scene=pv.SvgScene={svg:"http://www.w3.org/2000/svg",xmlns:"http://www.w3.org/2000/xmlns",xlink:"http://www.w3.org/1999/xlink",xhtml:"http://www.w3.org/1999/xhtml",scale:1,events:["DOMMouseScroll","mousewheel","mousedown","mouseup","mouseover","mouseout","mousemove","click","dblclick"],implicit:{svg:{"shape-rendering":"auto","pointer-events":"painted",x:0,y:0,dy:0,"text-anchor":"start",transform:"translate(0,0)",fill:"none","fill-opacity":1,stroke:"none","stroke-opacity":1,"stroke-width":1.5,"stroke-linejoin":"miter"},
82 | css:{font:"10px sans-serif"}}};pv.SvgScene.updateAll=function(b){if(b.length&&b[0].reverse&&b.type!="line"&&b.type!="area"){for(var c=pv.extend(b),d=0,f=b.length-1;f>=0;d++,f--)c[d]=b[f];b=c}this.removeSiblings(this[b.type](b))};pv.SvgScene.create=function(b){return document.createElementNS(this.svg,b)};
83 | pv.SvgScene.expect=function(b,c,d,f){if(b){if(b.tagName=="a")b=b.firstChild;if(b.tagName!=c){c=this.create(c);b.parentNode.replaceChild(c,b);b=c}}else b=this.create(c);for(var g in d){c=d[g];if(c==this.implicit.svg[g])c=null;c==null?b.removeAttribute(g):b.setAttribute(g,c)}for(g in f){c=f[g];if(c==this.implicit.css[g])c=null;if(c==null)b.style.removeProperty(g);else b.style[g]=c}return b};
84 | pv.SvgScene.append=function(b,c,d){b.$scene={scenes:c,index:d};b=this.title(b,c[d]);b.parentNode||c.$g.appendChild(b);return b.nextSibling};pv.SvgScene.title=function(b,c){var d=b.parentNode;if(d&&d.tagName!="a")d=null;if(c.title){if(!d){d=this.create("a");b.parentNode&&b.parentNode.replaceChild(d,b);d.appendChild(b)}d.setAttributeNS(this.xlink,"title",c.title);return d}d&&d.parentNode.replaceChild(b,d);return b};
85 | pv.SvgScene.dispatch=pv.listener(function(b){var c=b.target.$scene;if(c){var d=b.type;switch(d){case "DOMMouseScroll":d="mousewheel";b.wheel=-480*b.detail;break;case "mousewheel":b.wheel=(window.opera?12:1)*b.wheelDelta;break}pv.Mark.dispatch(d,c.scenes,c.index)&&b.preventDefault()}});pv.SvgScene.removeSiblings=function(b){for(;b;){var c=b.nextSibling;b.parentNode.removeChild(b);b=c}};pv.SvgScene.undefined=function(){};
86 | pv.SvgScene.pathBasis=function(){function b(f,g,h,i,j){return{x:f[0]*g.left+f[1]*h.left+f[2]*i.left+f[3]*j.left,y:f[0]*g.top+f[1]*h.top+f[2]*i.top+f[3]*j.top}}var c=[[1/6,2/3,1/6,0],[0,2/3,1/3,0],[0,1/3,2/3,0],[0,1/6,2/3,1/6]],d=function(f,g,h,i){var j=b(c[1],f,g,h,i),l=b(c[2],f,g,h,i);f=b(c[3],f,g,h,i);return"C"+j.x+","+j.y+","+l.x+","+l.y+","+f.x+","+f.y};d.segment=function(f,g,h,i){var j=b(c[0],f,g,h,i),l=b(c[1],f,g,h,i),k=b(c[2],f,g,h,i);f=b(c[3],f,g,h,i);return"M"+j.x+","+j.y+"C"+l.x+","+l.y+
87 | ","+k.x+","+k.y+","+f.x+","+f.y};return d}();pv.SvgScene.curveBasis=function(b){if(b.length<=2)return"";var c="",d=b[0],f=d,g=d,h=b[1];c+=this.pathBasis(d,f,g,h);for(var i=2;i1){j=c[1];h=b[l];l++;f+="C"+(g.left+i.x)+","+(g.top+i.y)+","+(h.left-j.x)+","+(h.top-j.y)+","+h.left+","+h.top;for(g=2;g9){l=3/Math.sqrt(l);f[h]=
95 | l*i*d[h];f[h+1]=l*j*d[h]}}for(h=0;h2&&(g.interpolate=="basis"||g.interpolate=="cardinal"||g.interpolate=="monotone")?d:c)(k,q-1));k=q-1}}if(!j.length)return f;f=this.expect(f,"path",{"shape-rendering":g.antialias?null:"crispEdges","pointer-events":g.events,cursor:g.cursor,d:"M"+j.join("ZM")+"Z",fill:h.color,"fill-opacity":h.opacity||
99 | null,stroke:i.color,"stroke-opacity":i.opacity||null,"stroke-width":i.opacity?g.lineWidth/this.scale:null});return this.append(f,b,0)};
100 | pv.SvgScene.areaSegment=function(b){var c=b.$g.firstChild,d=b[0],f,g;if(d.interpolate=="basis"||d.interpolate=="cardinal"||d.interpolate=="monotone"){f=[];g=[];for(var h=0,i=b.length;h2&&(d.interpolate=="basis"||d.interpolate=="cardinal"||d.interpolate=="monotone"))switch(d.interpolate){case "basis":h+=this.curveBasis(b);break;case "cardinal":h+=this.curveCardinal(b,d.tension);break;case "monotone":h+=this.curveMonotone(b);
113 | break}else for(var i=1;i1)break;return"A"+f+","+f+" 0 0,"+d+" "+c.left+","+c.top;case "step-before":return"V"+c.top+"H"+c.left;case "step-after":return"H"+c.left+"V"+c.top}return"L"+c.left+","+c.top};pv.SvgScene.lineIntersect=function(b,c,d,f){return b.plus(c.times(d.minus(b).dot(f.perp())/c.dot(f.perp())))};
117 | pv.SvgScene.pathJoin=function(b,c,d,f){var g=pv.vector(c.left,c.top);d=pv.vector(d.left,d.top);var h=d.minus(g),i=h.perp().norm(),j=i.times(c.lineWidth/(2*this.scale));c=g.plus(j);var l=d.plus(j),k=d.minus(j);j=g.minus(j);if(b&&b.visible){b=g.minus(b.left,b.top).perp().norm().plus(i);j=this.lineIntersect(g,b,j,h);c=this.lineIntersect(g,b,c,h)}if(f&&f.visible){f=pv.vector(f.left,f.top).minus(d).perp().norm().plus(i);k=this.lineIntersect(d,f,k,h);l=this.lineIntersect(d,f,l,h)}return"M"+c.x+","+c.y+
118 | "L"+l.x+","+l.y+" "+k.x+","+k.y+" "+j.x+","+j.y};
119 | pv.SvgScene.panel=function(b){for(var c=b.$g,d=c&&c.firstChild,f=0;f=2*Math.PI)i=i?"M0,"+j+"A"+j+","+j+" 0 1,1 0,"+-j+"A"+j+","+j+" 0 1,1 0,"+j+"M0,"+i+"A"+i+","+i+" 0 1,1 0,"+-i+"A"+i+","+i+" 0 1,1 0,"+i+"Z":"M0,"+j+"A"+j+","+j+" 0 1,1 0,"+-j+"A"+j+","+j+" 0 1,1 0,"+j+"Z";else{var k=Math.min(f.startAngle,f.endAngle),q=Math.max(f.startAngle,f.endAngle),
126 | o=Math.cos(k),n=Math.cos(q);k=Math.sin(k);q=Math.sin(q);i=i?"M"+j*o+","+j*k+"A"+j+","+j+" 0 "+(l1?c:null)};
131 | a.anchor=function(b){function c(g){for(var h=d,i=[];!(f=h.scene);){g=g.parent;i.push({index:g.index,childIndex:h.childIndex});h=h.parent}for(;i.length;){g=i.pop();f=f[g.index].children[g.childIndex]}if(d.hasOwnProperty("index")){i=pv.extend(f[d.index]);i.right=i.top=i.left=i.bottom=0;return[i]}return f}var d=this,f;b||(b="center");return(new pv.Anchor(this)).name(b).def("$mark.anchor",function(){f=this.scene.target=c(this)}).data(function(){return f.map(function(g){return g.data})}).visible(function(){return f[this.index].visible}).left(function(){var g=
132 | f[this.index],h=g.width||0;switch(this.name()){case "bottom":case "top":case "center":return g.left+h/2;case "left":return null}return g.left+h}).top(function(){var g=f[this.index],h=g.height||0;switch(this.name()){case "left":case "right":case "center":return g.top+h/2;case "top":return null}return g.top+h}).right(function(){var g=f[this.index];return this.name()=="left"?g.right+(g.width||0):null}).bottom(function(){var g=f[this.index];return this.name()=="top"?g.bottom+(g.height||0):null}).textAlign(function(){switch(this.name()){case "bottom":case "top":case "center":return"center";
133 | case "right":return"right"}return"left"}).textBaseline(function(){switch(this.name()){case "right":case "left":case "center":return"middle";case "top":return"top"}return"bottom"})};a.anchorTarget=function(){return this.proto.anchorTarget()};a.margin=function(b){return this.left(b).right(b).top(b).bottom(b)};a.instance=function(b){var c=this.scene||this.parent.instance(-1).children[this.childIndex],d=!arguments.length||this.hasOwnProperty("index")?this.index:b;return c[d<0?c.length-1:d]};a.first=function(){return this.scene[0]};
134 | a.last=function(){return this.scene[this.scene.length-1]};a.sibling=function(){return this.index==0?null:this.scene[this.index-1]};a.cousin=function(){var b=this.parent;return(b=b&&b.sibling())&&b.children?b.children[this.childIndex][this.index]:null};
135 | a.render=function(){function b(i,j,l){i.scale=l;if(j=0;k--){var q=l[k];if(!(q.name in c)){c[q.name]=q;switch(q.name){case "data":f=q;break;case "visible":g=q;break;default:d[q.type].push(q);break}}}while(j=j.proto)}var c={},d=[[],[],[],[]],f,g;b(this);b(this.defaults);d[1].reverse();d[3].reverse();var h=this;do for(var i in h.properties)i in c||d[2].push(c[i]={name:i,type:2,value:null});while(h=h.proto);h=d[0].concat(d[1]);for(i=0;ih.id)d[g.name]={id:0,value:g.type&1?g.value.apply(this,c):g.value}}}d=this.binds.data;d=d.type&1?d.value.apply(this,c):d.value;c.unshift(null);
140 | b.length=d.length;for(f=0;f0;k--){n=m[k];n.scale=q;q*=n.scene[n.index].transform.k}if(o.children){k=0;for(m=o.children.length;k=3*Math.PI/2};pv.Wedge.prototype.buildImplied=function(b){if(b.angle==null)b.angle=b.endAngle-b.startAngle;else if(b.endAngle==null)b.endAngle=b.startAngle+b.angle;pv.Mark.prototype.buildImplied.call(this,b)};pv.simulation=function(b){return new pv.Simulation(b)};pv.Simulation=function(b){for(var c=0;c=s,t=q.y>=u;k.leaf=false;switch((t<<1)+x){case 0:k=k.c1||(k.c1=new pv.Quadtree.Node);break;case 1:k=k.c2||(k.c2=new pv.Quadtree.Node);break;case 2:k=k.c3||(k.c3=new pv.Quadtree.Node);break;case 3:k=k.c4||(k.c4=new pv.Quadtree.Node);
179 | break}if(x)o=s;else m=s;if(t)n=u;else r=u;c(k,q,o,n,m,r)}var f,g=Number.POSITIVE_INFINITY,h=g,i=Number.NEGATIVE_INFINITY,j=i;for(f=b;f;f=f.next){if(f.xi)i=f.x;if(f.y>j)j=f.y}f=i-g;var l=j-h;if(f>l)j=h+f;else i=g+l;this.xMin=g;this.yMin=h;this.xMax=i;this.yMax=j;this.root=new pv.Quadtree.Node;for(f=b;f;f=f.next)c(this.root,f,g,h,i,j)};pv.Quadtree.Node=function(){this.leaf=true;this.p=this.c4=this.c3=this.c2=this.c1=null};pv.Force={};
180 | pv.Force.charge=function(b){function c(k){function q(m){c(m);k.cn+=m.cn;o+=m.cn*m.cx;n+=m.cn*m.cy}var o=0,n=0;k.cn=0;if(!k.leaf){k.c1&&q(k.c1);k.c2&&q(k.c2);k.c3&&q(k.c3);k.c4&&q(k.c4)}if(k.p){k.cn+=b;o+=b*k.p.x;n+=b*k.p.y}k.cx=o/k.cn;k.cy=n/k.cn}function d(k,q,o,n,m,r){var s=k.cx-q.x,u=k.cy-q.y,x=1/Math.sqrt(s*s+u*u);if(k.leaf&&k.p!=q||(m-o)*xg)x=g;k=k.cn*x*x*x;s=s*k;u=u*k;q.fx+=s;q.fy+=u}}else if(!k.leaf){var t=(o+m)*0.5,p=(n+r)*0.5;k.c1&&d(k.c1,q,o,n,t,p);k.c2&&d(k.c2,q,t,n,
181 | m,p);k.c3&&d(k.c3,q,o,p,t,r);k.c4&&d(k.c4,q,t,p,m,r);if(!(xg)x=g;if(k.p&&k.p!=q){k=b*x*x*x;s=s*k;u=u*k;q.fx+=s;q.fy+=u}}}}var f=2,g=1/f,h=500,i=1/h,j=0.9,l={};arguments.length||(b=-40);l.constant=function(k){if(arguments.length){b=Number(k);return l}return b};l.domain=function(k,q){if(arguments.length){f=Number(k);g=1/f;h=Number(q);i=1/h;return l}return[f,h]};l.theta=function(k){if(arguments.length){j=Number(k);return l}return j};l.apply=function(k,q){c(q.root);for(k=k;k;k=k.next)d(q.root,
182 | k,q.xMin,q.yMin,q.xMax,q.yMax)};return l};pv.Force.drag=function(b){var c={};arguments.length||(b=0.1);c.constant=function(d){if(arguments.length){b=d;return c}return b};c.apply=function(d){if(b)for(d=d;d;d=d.next){d.fx-=b*d.vx;d.fy-=b*d.vy}};return c};
183 | pv.Force.spring=function(b){var c=0.1,d=20,f,g,h={};arguments.length||(b=0.1);h.links=function(i){if(arguments.length){f=i;g=i.map(function(j){return 1/Math.sqrt(Math.max(j.sourceNode.linkDegree,j.targetNode.linkDegree))});return h}return f};h.constant=function(i){if(arguments.length){b=Number(i);return h}return b};h.damping=function(i){if(arguments.length){c=Number(i);return h}return c};h.length=function(i){if(arguments.length){d=Number(i);return h}return d};h.apply=function(){for(var i=0;ig,p=sh){k.c1&&t&&c(k.c1,q,o,n,s,u);k.c2&&p&&c(k.c2,q,s,n,m,u)}if(x){k.c3&&t&&c(k.c3,q,o,u,s,r);k.c4&&p&&c(k.c4,q,s,u,m,r)}}if(k.p&&k.p!=q){o=q.x-k.p.x;n=q.y-k.p.y;m=Math.sqrt(o*o+n*n);r=f+b(k.p);if(mm)m=n}for(var r=0;rc.max?c.max:g.x;if(d)for(g=f;g;g=g.next)g.y=g.yd.max?d.max:g.y};return b};pv.Layout=function(){pv.Panel.call(this)};pv.Layout.prototype=pv.extend(pv.Panel);
188 | pv.Layout.prototype.property=function(b,c){if(!this.hasOwnProperty("properties"))this.properties=pv.extend(this.properties);this.properties[b]=true;this.propertyMethod(b,false,pv.Mark.cast[b]=c);return this};
189 | pv.Layout.Network=function(){pv.Layout.call(this);var b=this;this.$id=pv.id();(this.node=(new pv.Mark).data(function(){return b.nodes()}).strokeStyle("#1f77b4").fillStyle("#fff").left(function(c){return c.x}).top(function(c){return c.y})).parent=this;this.link=(new pv.Mark).extend(this.node).data(function(c){return[c.sourceNode,c.targetNode]}).fillStyle(null).lineWidth(function(c,d){return d.linkValue*1.5}).strokeStyle("rgba(0,0,0,.2)");this.link.add=function(c){return b.add(pv.Panel).data(function(){return b.links()}).add(c).extend(this)};
190 | (this.label=(new pv.Mark).extend(this.node).textMargin(7).textBaseline("middle").text(function(c){return c.nodeName||c.nodeValue}).textAngle(function(c){c=c.midAngle;return pv.Wedge.upright(c)?c:c+Math.PI}).textAlign(function(c){return pv.Wedge.upright(c.midAngle)?"left":"right"})).parent=this};
191 | pv.Layout.Network.prototype=pv.extend(pv.Layout).property("nodes",function(b){return b.map(function(c,d){if(typeof c!="object")c={nodeValue:c};c.index=d;c.linkDegree=0;return c})}).property("links",function(b){return b.map(function(c){if(isNaN(c.linkValue))c.linkValue=isNaN(c.value)?1:c.value;return c})});pv.Layout.Network.prototype.reset=function(){this.$id=pv.id();return this};
192 | pv.Layout.Network.prototype.buildProperties=function(b,c){if((b.$id||0)=this.$id)return true;b.$id=this.$id;b.links.forEach(function(c){var d=c.linkValue;(c.sourceNode||(c.sourceNode=b.nodes[c.source])).linkDegree+=d;(c.targetNode||(c.targetNode=b.nodes[c.target])).linkDegree+=d})};
193 | pv.Layout.Hierarchy=function(){pv.Layout.Network.call(this);this.link.strokeStyle("#ccc")};pv.Layout.Hierarchy.prototype=pv.extend(pv.Layout.Network);pv.Layout.Hierarchy.prototype.buildImplied=function(b){if(!b.links)b.links=pv.Layout.Hierarchy.links.call(this);pv.Layout.Network.prototype.buildImplied.call(this,b)};pv.Layout.Hierarchy.links=function(){return this.nodes().filter(function(b){return b.parentNode}).map(function(b){return{sourceNode:b,targetNode:b.parentNode,linkValue:1}})};
194 | pv.Layout.Hierarchy.NodeLink={buildImplied:function(b){function c(m){return m.parentNode?m.depth*(o-q)+q:0}function d(m){return m.parentNode?(m.breadth-0.25)*2*Math.PI:0}function f(m){switch(i){case "left":return m.depth*l;case "right":return l-m.depth*l;case "top":return m.breadth*l;case "bottom":return l-m.breadth*l;case "radial":return l/2+c(m)*Math.cos(m.midAngle)}}function g(m){switch(i){case "left":return m.breadth*k;case "right":return k-m.breadth*k;case "top":return m.depth*k;case "bottom":return k-
195 | m.depth*k;case "radial":return k/2+c(m)*Math.sin(m.midAngle)}}var h=b.nodes,i=b.orient,j=/^(top|bottom)$/.test(i),l=b.width,k=b.height;if(i=="radial"){var q=b.innerRadius,o=b.outerRadius;if(q==null)q=0;if(o==null)o=Math.min(l,k)/2}for(b=0;bb.dy?0:-Math.PI/2});(this.leaf=(new pv.Mark).extend(this.node).fillStyle(null).strokeStyle(null).visible(function(b){return!b.firstChild})).parent=
209 | this;delete this.link};pv.Layout.Treemap.prototype=pv.extend(pv.Layout.Hierarchy).property("round",Boolean).property("paddingLeft",Number).property("paddingRight",Number).property("paddingTop",Number).property("paddingBottom",Number).property("mode",String).property("order",String);a=pv.Layout.Treemap.prototype;a.defaults=(new pv.Layout.Treemap).extend(pv.Layout.Hierarchy.prototype.defaults).mode("squarify").order("ascending");a.padding=function(b){return this.paddingLeft(b).paddingRight(b).paddingTop(b).paddingBottom(b)};
210 | a.$size=function(b){return Number(b.nodeValue)};a.size=function(b){this.$size=pv.functor(b);return this};
211 | a.buildImplied=function(b){function c(r,s,u,x,t,p,v){for(var w=0,y=0;wu)u=v;t+=v}t*=t;s*=s;return Math.max(s*u/t,t/(s*x))}function f(r,s){function u(A){var D=p==y,G=pv.sum(A,o),E=y?n(G/y):0;c(A,G,D,x,t,D?p:E,D?E:v);if(D){t+=E;v-=E}else{x+=
212 | E;p-=E}y=Math.min(p,v);return D}var x=r.x+j,t=r.y+k,p=r.dx-j-l,v=r.dy-k-q;if(m!="squarify")c(r.childNodes,r.size,m=="slice"?true:m=="dice"?false:s&1,x,t,p,v);else{var w=[];s=Infinity;var y=Math.min(p,v),z=p*v/r.size;if(!(r.size<=0)){r.visitBefore(function(A){A.size*=z});for(r=r.childNodes.slice();r.length;){var C=r[r.length-1];if(C.size){w.push(C);z=d(w,y);if(z<=s){r.pop();s=z}else{w.pop();u(w);w.length=0;s=Infinity}}else r.pop()}if(u(w))for(s=0;s0){i(l(C,p,v),p,B);A+=B;D+=B}G+=C.mod;A+=y.mod;E+=w.mod;D+=z.mod;C=h(C);y=g(y)}if(C&&!h(z)){z.thread=C;z.mod+=G-D}if(y&&!g(w)){w.thread=y;w.mod+=A-E;v=p}}return v}function g(p){return p.firstChild||p.thread}function h(p){return p.lastChild||p.thread}function i(p,v,w){var y=v.number-p.number;v.change-=w/y;v.shift+=w;p.change+=
217 | w/y;v.prelim+=w;v.mod+=w}function j(p){var v=0,w=0;for(p=p.lastChild;p;p=p.previousSibling){p.prelim+=v;p.mod+=v;w+=p.change;v+=p.shift+w}}function l(p,v,w){return p.ancestor.parentNode==v.parentNode?p.ancestor:w}function k(p,v){return(v?1:u+1)/(m=="radial"?p:1)}function q(p){return m=="radial"?p.breadth/r:0}function o(p){switch(m){case "left":return p.depth;case "right":return x-p.depth;case "top":case "bottom":return p.breadth+x/2;case "radial":return x/2+p.depth*Math.cos(q(p))}}function n(p){switch(m){case "left":case "right":return p.breadth+
218 | t/2;case "top":return p.depth;case "bottom":return t-p.depth;case "radial":return t/2+p.depth*Math.sin(q(p))}}if(!pv.Layout.Hierarchy.prototype.buildImplied.call(this,b)){var m=b.orient,r=b.depth,s=b.breadth,u=b.group,x=b.width,t=b.height;b=b.nodes[0];b.visitAfter(function(p,v){p.ancestor=p;p.prelim=0;p.mod=0;p.change=0;p.shift=0;p.number=p.previousSibling?p.previousSibling.number+1:0;p.depth=v});c(b);d(b,-b.prelim,0);b.visitAfter(function(p){p.breadth*=s;p.depth*=r;p.midAngle=q(p);p.x=o(p);p.y=n(p);
219 | if(p.firstChild)p.midAngle+=Math.PI;delete p.breadth;delete p.depth;delete p.ancestor;delete p.prelim;delete p.mod;delete p.change;delete p.shift;delete p.number;delete p.thread})}};pv.Layout.Indent=function(){pv.Layout.Hierarchy.call(this);this.link.interpolate("step-after")};pv.Layout.Indent.prototype=pv.extend(pv.Layout.Hierarchy).property("depth",Number).property("breadth",Number);pv.Layout.Indent.prototype.defaults=(new pv.Layout.Indent).extend(pv.Layout.Hierarchy.prototype.defaults).depth(15).breadth(15);
220 | pv.Layout.Indent.prototype.buildImplied=function(b){function c(i,j,l){i.x=g+l++*f;i.y=h+j++*d;i.midAngle=0;for(i=i.firstChild;i;i=i.nextSibling)j=c(i,j,l);return j}if(!pv.Layout.Hierarchy.prototype.buildImplied.call(this,b)){var d=b.breadth,f=b.depth,g=0,h=0;c(b.nodes[0],1,1)}};pv.Layout.Pack=function(){pv.Layout.Hierarchy.call(this);this.node.radius(function(b){return b.radius}).strokeStyle("rgb(31, 119, 180)").fillStyle("rgba(31, 119, 180, .25)");this.label.textAlign("center");delete this.link};
221 | pv.Layout.Pack.prototype=pv.extend(pv.Layout.Hierarchy).property("spacing",Number).property("order",String);pv.Layout.Pack.prototype.defaults=(new pv.Layout.Pack).extend(pv.Layout.Hierarchy.prototype.defaults).spacing(1).order("ascending");pv.Layout.Pack.prototype.$radius=function(){return 1};pv.Layout.Pack.prototype.size=function(b){this.$radius=typeof b=="function"?function(){return Math.sqrt(b.apply(this,arguments))}:(b=Math.sqrt(b),function(){return b});return this};
222 | pv.Layout.Pack.prototype.buildImplied=function(b){function c(o){var n=pv.Mark.stack;n.unshift(null);for(var m=0,r=o.length;m0.0010}var u=Infinity,x=-Infinity,t=Infinity,p=-Infinity,v,w,y,z,C;v=o[0];v.x=-v.radius;v.y=0;n(v);if(o.length>1){w=o[1];w.x=w.radius;w.y=0;n(w);if(o.length>2){y=o[2];g(v,w,y);n(y);m(v,y);v.p=
224 | y;m(y,w);w=v.n;for(var A=3;A0){r(v,z);w=z;A--}else if(D<0){r(z,w);v=z;A--}}}}v=(u+x)/2;w=(t+p)/2;for(A=y=0;Ao.min){o.sim.step();
230 | q=true}q&&d.render()},42)}else for(l=0;lg)g=j;i.size=i.firstChild?pv.sum(i.childNodes,function(l){return l.size}):c.$size.apply(c,(f[0]=i,f))});f.shift();switch(b.order){case "ascending":d.sort(function(i,j){return i.size-j.size});break;case "descending":d.sort(function(i,j){return j.size-i.size});break}var h=1/g;d.minBreadth=0;d.breadth=
237 | 0.5;d.maxBreadth=1;d.visitBefore(function(i){for(var j=i.minBreadth,l=i.maxBreadth-j,k=i.firstChild;k;k=k.nextSibling){k.minBreadth=j;k.maxBreadth=j+=k.size/i.size*l;k.breadth=(j+k.minBreadth)/2}});d.visitAfter(function(i,j){i.minDepth=(j-1)*h;i.maxDepth=i.depth=j*h});pv.Layout.Hierarchy.NodeLink.buildImplied.call(this,b)}};pv.Layout.Partition.Fill=function(){pv.Layout.Partition.call(this);pv.Layout.Hierarchy.Fill.constructor.call(this)};pv.Layout.Partition.Fill.prototype=pv.extend(pv.Layout.Partition);
238 | pv.Layout.Partition.Fill.prototype.buildImplied=function(b){pv.Layout.Partition.prototype.buildImplied.call(this,b)||pv.Layout.Hierarchy.Fill.buildImplied.call(this,b)};pv.Layout.Arc=function(){pv.Layout.Network.call(this);var b,c,d,f=this.buildImplied;this.buildImplied=function(g){f.call(this,g);c=g.directed;b=g.orient=="radial"?"linear":"polar";d=g.orient=="right"||g.orient=="top"};this.link.data(function(g){var h=g.sourceNode;g=g.targetNode;return d!=(c||h.breadth>1)*f:null}).bottom(function(l,k){return d=="mirror"?k&1?null:(k+1>>1)*-f:(k&1||-1)*(k+1>>1)*f}).fillStyle(function(l,k){return(k&1?h:i)((k>>1)+1)});this.band.add=function(l){return b.add(pv.Panel).extend(c).add(l).extend(this)}};pv.Layout.Horizon.prototype=pv.extend(pv.Layout).property("bands",Number).property("mode",String).property("backgroundStyle",pv.color).property("positiveStyle",pv.color).property("negativeStyle",pv.color);
244 | pv.Layout.Horizon.prototype.defaults=(new pv.Layout.Horizon).extend(pv.Layout.prototype.defaults).bands(2).mode("offset").backgroundStyle("white").positiveStyle("#1f77b4").negativeStyle("#d62728");
245 | pv.Layout.Rollup=function(){pv.Layout.Network.call(this);var b=this,c,d,f=b.buildImplied;this.buildImplied=function(g){f.call(this,g);c=g.$rollup.nodes;d=g.$rollup.links};this.node.data(function(){return c}).size(function(g){return g.nodes.length*20});this.link.interpolate("polar").eccentricity(0.8);this.link.add=function(g){return b.add(pv.Panel).data(function(){return d}).add(g).extend(this)}};pv.Layout.Rollup.prototype=pv.extend(pv.Layout.Network).property("directed",Boolean);
246 | pv.Layout.Rollup.prototype.x=function(b){this.$x=pv.functor(b);return this};pv.Layout.Rollup.prototype.y=function(b){this.$y=pv.functor(b);return this};
247 | pv.Layout.Rollup.prototype.buildImplied=function(b){function c(r){return i[r]+","+j[r]}if(!pv.Layout.Network.prototype.buildImplied.call(this,b)){var d=b.nodes,f=b.links,g=b.directed,h=d.length,i=[],j=[],l=0,k={},q={},o=pv.Mark.stack,n={parent:this};o.unshift(null);for(var m=0;ml.index?l.index+","+d.index:d.index+","+l.index;(o=q[h])||(o=q[h]={sourceNode:d,targetNode:l,linkValue:0,links:[]});o.links.push(f[m]);o.linkValue+=f[m].linkValue}b.$rollup={nodes:pv.values(k),links:pv.values(q)}}};
249 | pv.Layout.Matrix=function(){pv.Layout.Network.call(this);var b,c,d,f,g,h=this.buildImplied;this.buildImplied=function(i){h.call(this,i);b=i.nodes.length;c=i.width/b;d=i.height/b;f=i.$matrix.labels;g=i.$matrix.pairs};this.link.data(function(){return g}).left(function(){return c*(this.index%b)}).top(function(){return d*Math.floor(this.index/b)}).width(function(){return c}).height(function(){return d}).lineWidth(1.5).strokeStyle("#fff").fillStyle(function(i){return i.linkValue?"#555":"#eee"}).parent=
250 | this;delete this.link.add;this.label.data(function(){return f}).left(function(){return this.index&1?c*((this.index>>1)+0.5):null}).top(function(){return this.index&1?null:d*((this.index>>1)+0.5)}).textMargin(4).textAlign(function(){return this.index&1?"left":"right"}).textAngle(function(){return this.index&1?-Math.PI/2:0});delete this.node};pv.Layout.Matrix.prototype=pv.extend(pv.Layout.Network).property("directed",Boolean);pv.Layout.Matrix.prototype.sort=function(b){this.$sort=b;return this};
251 | pv.Layout.Matrix.prototype.buildImplied=function(b){if(!pv.Layout.Network.prototype.buildImplied.call(this,b)){var c=b.nodes,d=b.links,f=this.$sort,g=c.length,h=pv.range(g),i=[],j=[],l={};b.$matrix={labels:i,pairs:j};f&&h.sort(function(m,r){return f(c[m],c[r])});for(var k=0;kl)k=null;if(g){if(k&&g.scene==k.scene&&g.index==k.index)return;pv.Mark.dispatch("unpoint",g.scene,g.index)}if(g=k){pv.Mark.dispatch("point",k.scene,k.index);pv.listen(this.root.canvas(),"mouseout",f)}}function f(k){if(g&&!pv.ancestor(this,k.relatedTarget)){pv.Mark.dispatch("unpoint",g.scene,g.index);g=null}}var g,h=null,i=1,j=1,l=arguments.length?b*b:900;d.collapse=function(k){if(arguments.length){h=String(k);switch(h){case "y":i=
262 | 1;j=0;break;case "x":i=0;j=1;break;default:j=i=1;break}return d}return h};return d};
263 | pv.Behavior.select=function(){function b(j){g=this.index;f=this.scene;i=this.mouse();h=j;h.x=i.x;h.y=i.y;h.dx=h.dy=0;pv.Mark.dispatch("selectstart",f,g)}function c(){if(f){f.mark.context(f,g,function(){var j=this.mouse();h.x=Math.max(0,Math.min(i.x,j.x));h.y=Math.max(0,Math.min(i.y,j.y));h.dx=Math.min(this.width(),Math.max(j.x,i.x))-h.x;h.dy=Math.min(this.height(),Math.max(j.y,i.y))-h.y;this.render()});pv.Mark.dispatch("select",f,g)}}function d(){if(f){pv.Mark.dispatch("selectend",f,g);f=null}}var f,
264 | g,h,i;pv.listen(window,"mousemove",c);pv.listen(window,"mouseup",d);return b};
265 | pv.Behavior.resize=function(b){function c(l){h=this.index;g=this.scene;j=this.mouse();i=l;switch(b){case "left":j.x=i.x+i.dx;break;case "right":j.x=i.x;break;case "top":j.y=i.y+i.dy;break;case "bottom":j.y=i.y;break}pv.Mark.dispatch("resizestart",g,h)}function d(){if(g){g.mark.context(g,h,function(){var l=this.mouse();i.x=Math.max(0,Math.min(j.x,l.x));i.y=Math.max(0,Math.min(j.y,l.y));i.dx=Math.min(this.parent.width(),Math.max(l.x,j.x))-i.x;i.dy=Math.min(this.parent.height(),Math.max(l.y,j.y))-i.y;
266 | this.render()});pv.Mark.dispatch("resize",g,h)}}function f(){if(g){pv.Mark.dispatch("resizeend",g,h);g=null}}var g,h,i,j;pv.listen(window,"mousemove",d);pv.listen(window,"mouseup",f);return c};
267 | pv.Behavior.pan=function(){function b(){g=this.index;f=this.scene;i=pv.vector(pv.event.pageX,pv.event.pageY);h=this.transform();j=1/(h.k*this.scale);if(l)l={x:(1-h.k)*this.width(),y:(1-h.k)*this.height()}}function c(){if(f){f.mark.context(f,g,function(){var k=h.translate((pv.event.pageX-i.x)*j,(pv.event.pageY-i.y)*j);if(l){k.x=Math.max(l.x,Math.min(0,k.x));k.y=Math.max(l.y,Math.min(0,k.y))}this.transform(k).render()});pv.Mark.dispatch("pan",f,g)}}function d(){f=null}var f,g,h,i,j,l;b.bound=function(k){if(arguments.length){l=
268 | Boolean(k);return this}return Boolean(l)};pv.listen(window,"mousemove",c);pv.listen(window,"mouseup",d);return b};
269 | pv.Behavior.zoom=function(b){function c(){var f=this.mouse(),g=pv.event.wheel*b;f=this.transform().translate(f.x,f.y).scale(g<0?1E3/(1E3-g):(1E3+g)/1E3).translate(-f.x,-f.y);if(d){f.k=Math.max(1,f.k);f.x=Math.max((1-f.k)*this.width(),Math.min(0,f.x));f.y=Math.max((1-f.k)*this.height(),Math.min(0,f.y))}this.transform(f).render();pv.Mark.dispatch("zoom",this.scene,this.index)}var d;arguments.length||(b=1/48);c.bound=function(f){if(arguments.length){d=Boolean(f);return this}return Boolean(d)};return c};
270 | pv.Geo=function(){};
271 | pv.Geo.projections={mercator:{project:function(b){return{x:b.lng/180,y:b.lat>85?1:b.lat<-85?-1:Math.log(Math.tan(Math.PI/4+pv.radians(b.lat)/2))/Math.PI}},invert:function(b){return{lng:b.x*180,lat:pv.degrees(2*Math.atan(Math.exp(b.y*Math.PI))-Math.PI/2)}}},"gall-peters":{project:function(b){return{x:b.lng/180,y:Math.sin(pv.radians(b.lat))}},invert:function(b){return{lng:b.x*180,lat:pv.degrees(Math.asin(b.y))}}},sinusoidal:{project:function(b){return{x:pv.radians(b.lng)*Math.cos(pv.radians(b.lat))/Math.PI,
272 | y:b.lat/90}},invert:function(b){return{lng:pv.degrees(b.x*Math.PI/Math.cos(b.y*Math.PI/2)),lat:b.y*90}}},aitoff:{project:function(b){var c=pv.radians(b.lng);b=pv.radians(b.lat);var d=Math.acos(Math.cos(b)*Math.cos(c/2));return{x:2*(d?Math.cos(b)*Math.sin(c/2)*d/Math.sin(d):0)/Math.PI,y:2*(d?Math.sin(b)*d/Math.sin(d):0)/Math.PI}},invert:function(b){var c=b.y*Math.PI/2;return{lng:pv.degrees(b.x*Math.PI/2/Math.cos(c)),lat:pv.degrees(c)}}},hammer:{project:function(b){var c=pv.radians(b.lng);b=pv.radians(b.lat);
273 | var d=Math.sqrt(1+Math.cos(b)*Math.cos(c/2));return{x:2*Math.SQRT2*Math.cos(b)*Math.sin(c/2)/d/3,y:Math.SQRT2*Math.sin(b)/d/1.5}},invert:function(b){var c=b.x*3;b=b.y*1.5;var d=Math.sqrt(1-c*c/16-b*b/4);return{lng:pv.degrees(2*Math.atan2(d*c,2*(2*d*d-1))),lat:pv.degrees(Math.asin(d*b))}}},identity:{project:function(b){return{x:b.lng/180,y:b.lat/90}},invert:function(b){return{lng:b.x*180,lat:b.y*90}}}};
274 | pv.Geo.scale=function(b){function c(m){if(!o||m.lng!=o.lng||m.lat!=o.lat){o=m;m=d(m);n={x:l(m.x),y:k(m.y)}}return n}function d(m){return j.project({lng:m.lng-q.lng,lat:m.lat})}function f(m){m=j.invert(m);m.lng+=q.lng;return m}var g={x:0,y:0},h={x:1,y:1},i=[],j=pv.Geo.projections.identity,l=pv.Scale.linear(-1,1).range(0,1),k=pv.Scale.linear(-1,1).range(1,0),q={lng:0,lat:0},o,n;c.x=function(m){return c(m).x};c.y=function(m){return c(m).y};c.ticks={lng:function(m){var r;if(i.length>1){var s=pv.Scale.linear();
275 | if(m==undefined)m=10;r=s.domain(i,function(u){return u.lat}).ticks(m);m=s.domain(i,function(u){return u.lng}).ticks(m)}else{r=pv.range(-80,81,10);m=pv.range(-180,181,10)}return m.map(function(u){return r.map(function(x){return{lat:x,lng:u}})})},lat:function(m){return pv.transpose(c.ticks.lng(m))}};c.invert=function(m){return f({x:l.invert(m.x),y:k.invert(m.y)})};c.domain=function(m,r){if(arguments.length){i=m instanceof Array?arguments.length>1?pv.map(m,r):m:Array.prototype.slice.call(arguments);
276 | if(i.length>1){var s=i.map(function(x){return x.lng}),u=i.map(function(x){return x.lat});q={lng:(pv.max(s)+pv.min(s))/2,lat:(pv.max(u)+pv.min(u))/2};s=i.map(d);l.domain(s,function(x){return x.x});k.domain(s,function(x){return x.y})}else{q={lng:0,lat:0};l.domain(-1,1);k.domain(-1,1)}o=null;return this}return i};c.range=function(m,r){if(arguments.length){if(typeof m=="object"){g={x:Number(m.x),y:Number(m.y)};h={x:Number(r.x),y:Number(r.y)}}else{g={x:0,y:0};h={x:Number(m),y:Number(r)}}l.range(g.x,h.x);
277 | k.range(h.y,g.y);o=null;return this}return[g,h]};c.projection=function(m){if(arguments.length){j=typeof m=="string"?pv.Geo.projections[m]||pv.Geo.projections.identity:m;return this.domain(i)}return m};c.by=function(m){function r(){return c(m.apply(this,arguments))}for(var s in c)r[s]=c[s];return r};arguments.length&&c.projection(b);return c};
278 |
--------------------------------------------------------------------------------