source: django_apps/running/static/week-total.js@ 307

Last change on this file since 307 was 298, checked in by Rick van der Zwet, 14 years ago
  • Move javascript magic into seperate functions for readability.
  • Implemented form allowing user to alter his data.
File size: 1.2 KB
Line 
1function weekTotalGraph(myData, binder) {
2 Array.prototype.max = function () {
3 return Math.max.apply(Math, this);
4 };
5
6 data = myData.data;
7 itemCount = data.length;
8 var w = 1000,
9 h = 100,
10 x = pv.Scale.ordinal(pv.range(itemCount)).splitBanded(0, w, 4/5),
11 y = pv.Scale.linear(0, myData.data.max()).range(0, h);
12
13 var vis = new pv.Panel().canvas(binder)
14 .width(w)
15 .height(h)
16 .bottom(20)
17 .left(20)
18 .right(5)
19 .top(5);
20
21 var bar = vis.add(pv.Bar)
22 .data(data)
23 .left(function() x(this.index))
24 .width(x.range().band)
25 .bottom(0)
26 .height(y);
27
28 bar.anchor("top").add(pv.Label)
29 .textStyle("white")
30 .text(function(d) d.toFixed(1));
31
32 bar.anchor("bottom").add(pv.Label)
33 .textMargin(5)
34 .textBaseline("top")
35 .text(function() myData.label[this.index]);
36
37 vis.add(pv.Rule)
38 .data(y.ticks())
39 .bottom(function(d) Math.round(y(d)) - .5)
40 .strokeStyle(function(d) d ? "rgba(255,255,255,.3)" : "#000")
41 .add(pv.Rule)
42 .left(0)
43 .width(5)
44 .strokeStyle("#000")
45 .anchor("left").add(pv.Label)
46
47 vis.render();
48}
Note: See TracBrowser for help on using the repository browser.