Commit | Line | Data |
---|---|---|
20590000 RK |
1 | // Copyright (c) 2012 Google, Inc. |
2 | // | |
3 | // Permission is hereby granted, free of charge, to any person obtaining a copy | |
4 | // of this software and associated documentation files (the "Software"), to deal | |
5 | // in the Software without restriction, including without limitation the rights | |
6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
7 | // copies of the Software, and to permit persons to whom the Software is | |
8 | // furnished to do so, subject to the following conditions: | |
9 | // | |
10 | // The above copyright notice and this permission notice shall be included in | |
11 | // all copies or substantial portions of the Software. | |
12 | // | |
13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
19 | // THE SOFTWARE. | |
20 | ||
21 | /** | |
22 | * @fileoverview Javascript to run index.html. | |
23 | * | |
24 | * @author konigsberg@google.com (Robert Konigsberg) | |
25 | */ | |
26 | ||
27 | "use strict"; | |
28 | ||
29 | function draw(element, options) { | |
30 | try { | |
31 | element.innerHTML = ""; | |
32 | element.removeAttribute("style"); | |
33 | var g = new Dygraph( | |
34 | element, | |
35 | function() { | |
36 | var zp = function(x) { if (x < 10) return "0"+x; else return x; }; | |
37 | var r = "date,parabola,line,another line,sine wave\n"; | |
38 | for (var i=1; i<=31; i++) { | |
39 | r += "201110" + zp(i); | |
40 | r += "," + 10*(i*(31-i)); | |
41 | r += "," + 10*(8*i); | |
42 | r += "," + 10*(250 - 8*i); | |
43 | r += "," + 10*(125 + 125 * Math.sin(0.3*i)); | |
44 | r += "\n"; | |
45 | } | |
46 | return r; | |
47 | }, options | |
48 | ); | |
49 | ||
50 | // These don't work yet. | |
51 | g.updateOptions({ | |
52 | labelsDiv: 'status', | |
53 | }); | |
54 | } catch(err) { | |
55 | addMessage(err); | |
56 | throw(err); | |
57 | } finally { | |
58 | } | |
59 | } | |
60 | ||
61 | function addMessage(text) { | |
62 | var messages = document.getElementById("messages"); | |
63 | messages.innerText = messages.innerText + text + "\n"; | |
64 | } | |
65 | ||
66 | function start() { | |
67 | var options = { | |
68 | colors: [ | |
69 | "rgb(51,204,204)", | |
70 | "rgb(255,100,100)", | |
71 | "#00DD55", | |
72 | "rgba(50,50,200,0.4)" | |
73 | ], | |
74 | labelsSeparateLines: true, | |
75 | labelsKMB: true, | |
76 | legend: 'always', | |
77 | width: 640, | |
78 | height: 480, | |
79 | title: 'Interesting Shapes', | |
80 | xlabel: 'Date', | |
81 | ylabel: 'Count', | |
82 | axisLineColor: 'white', | |
83 | drawXGrid: false, | |
84 | pointClickCallback: function() { alert("p-click!"); }, | |
85 | }; | |
86 | ||
87 | var redraw = function() { | |
88 | draw(document.getElementById("graph"), palette.read()); | |
89 | } | |
90 | ||
91 | var palette = new Palette(); | |
92 | palette.create(document, document.getElementById("optionsPalette")); | |
93 | palette.write(options); | |
94 | palette.onchange = redraw; | |
95 | palette.filterBar.focus(); | |
96 | redraw(); | |
97 | ||
98 | for (var opt in Dygraph.OPTIONS_REFERENCE) { | |
99 | if (!(opt in opts)) { | |
100 | var entry = Dygraph.OPTIONS_REFERENCE[opt]; | |
101 | console.warn("missing option: " + opt + " of type " + entry.type); | |
102 | } | |
103 | } | |
104 | } |