ef4fbbf7ae327fecceb41708fe900ef1aa7ccfda
[dygraphs.git] / experimental / palette / samples.js
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 Source samples.
23 *
24 * @author konigsberg@google.com (Robert Konigsberg)
25 */
26
27 "use strict";
28
29 var Samples = {};
30 Samples.data = [
31 {
32 id: "interestingShapes",
33 title: "Interesting Shapes",
34 data: function() {
35 var zp = function(x) { if (x < 10) return "0"+x; else return x; };
36 var r = "date,parabola,line,another line,sine wave\n";
37 for (var i=1; i<=31; i++) {
38 r += "201110" + zp(i);
39 r += "," + 10*(i*(31-i));
40 r += "," + 10*(8*i);
41 r += "," + 10*(250 - 8*i);
42 r += "," + 10*(125 + 125 * Math.sin(0.3*i));
43 r += "\n";
44 }
45 return r;
46 },
47 options: {
48 colors: [
49 "rgb(51,204,204)",
50 "rgb(255,100,100)",
51 "#00DD55",
52 "rgba(50,50,200,0.4)"
53 ],
54 labelsSeparateLines: true,
55 labelsKMB: true,
56 legend: 'always',
57 width: 640,
58 height: 480,
59 title: 'Interesting Shapes',
60 xlabel: 'Date',
61 ylabel: 'Count',
62 axisLineColor: 'white',
63 drawXGrid: false,
64 pointClickCallback: function() {
65 alert("p-click!");
66 },
67 }
68 },
69
70 {
71 id: "sparse",
72 title: "Sparse Data",
73 data: [
74 [ new Date("2009/12/01"), 10, 10, 10],
75 [ new Date("2009/12/02"), 15, 11, 12],
76 [ new Date("2009/12/03"), null, null, 12],
77 [ new Date("2009/12/04"), 20, 14, null],
78 [ new Date("2009/12/05"), 15, null, 17],
79 [ new Date("2009/12/06"), 18, null, null],
80 [ new Date("2009/12/07"), 12, 14, null]
81 ],
82 options: {
83 labels: ["Date", "Series1", "Series2", "Series3"]
84 }
85 },
86
87 {
88 id: "manyPoints",
89 title: "Dense Data",
90 data: function() {
91 var numPoints = 1000;
92 var numSeries = 100;
93
94 var data = [];
95 var xmin = 0.0;
96 var xmax = 2.0 * Math.PI;
97 var adj = .5;
98 var delta = (xmax - xmin) / (numPoints - 1);
99
100 for (var i = 0; i < numPoints; ++i) {
101 var x = xmin + delta * i;
102 var elem = [ x ];
103 for (var j = 0; j < numSeries; j++) {
104 var y = Math.pow(Math.random() - Math.random(), 7);
105 elem.push(y);
106 }
107 data[i] = elem;
108 }
109 return data;
110 },
111 options: {
112 labelsSeparateLines: true,
113 width: 640,
114 height: 480,
115 title: 'Many Points',
116 axisLineColor: 'white',
117 }
118 },
119
120 {
121 id: "errorBars",
122 title: "Error Bars",
123 data: [
124 [1, [10, 10, 100]],
125 [2, [15, 20, 110]],
126 [3, [10, 30, 100]],
127 [4, [15, 40, 110]],
128 [5, [10, 120, 100]],
129 [6, [15, 50, 110]],
130 [7, [10, 70, 100]],
131 [8, [15, 90, 110]],
132 [9, [10, 50, 100]]
133 ],
134 options: {
135 customBars: true,
136 errorBars: true
137 }
138 }
139 ];
140
141 Samples.indexOf = function(id) {
142 for (var idx in Samples.data) {
143 if (Samples.data[idx].id == id) {
144 return idx;
145 }
146 }
147 return null;
148 }