getRowForX method
[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
65 // This indentation is intentional; do not fix.
66 pointClickCallback: function() {
67 alert("p-click!");
68 }
69 }
70 },
71
72 {
73 id: "sparse",
74 title: "Sparse Data",
75 data: [
76 [ new Date("2009/12/01"), 10, 10, 10],
77 [ new Date("2009/12/02"), 15, 11, 12],
78 [ new Date("2009/12/03"), null, null, 12],
79 [ new Date("2009/12/04"), 20, 14, null],
80 [ new Date("2009/12/05"), 15, null, 17],
81 [ new Date("2009/12/06"), 18, null, null],
82 [ new Date("2009/12/07"), 12, 14, null]
83 ],
84 options: {
85 labels: ["Date", "Series1", "Series2", "Series3"]
86 }
87 },
88
89 {
90 id: "manyPoints",
91 title: "Dense Data",
92 data: function() {
93 var numPoints = 1000;
94 var numSeries = 100;
95
96 var data = [];
97 var xmin = 0.0;
98 var xmax = 2.0 * Math.PI;
99 var adj = .5;
100 var delta = (xmax - xmin) / (numPoints - 1);
101
102 for (var i = 0; i < numPoints; ++i) {
103 var x = xmin + delta * i;
104 var elem = [ x ];
105 for (var j = 0; j < numSeries; j++) {
106 var y = Math.pow(Math.random() - Math.random(), 7);
107 elem.push(y);
108 }
109 data[i] = elem;
110 }
111 return data;
112 },
113 options: {
114 labelsSeparateLines: true,
115 width: 640,
116 height: 480,
117 title: 'Many Points',
118 axisLineColor: 'white',
119 }
120 },
121
122 {
123 id: "errorBars",
124 title: "Error Bars",
125 data: [
126 [1, [10, 10, 100]],
127 [2, [15, 20, 110]],
128 [3, [10, 30, 100]],
129 [4, [15, 40, 110]],
130 [5, [10, 120, 100]],
131 [6, [15, 50, 110]],
132 [7, [10, 70, 100]],
133 [8, [15, 90, 110]],
134 [9, [10, 50, 100]]
135 ],
136 options: {
137 customBars: true,
138 errorBars: true
139 }
140 },
141
142 {
143 id: "perSeries",
144 title: "Per Series Options",
145 data: function() {
146 var zp = function(x) { if (x < 10) return "0"+x; else return x; };
147 var r = "date,parabola,line,another line,sine wave,sine wave2\n";
148 for (var i=1; i<=31; i++) {
149 r += "200610" + zp(i);
150 r += "," + 10*(i*(31-i));
151 r += "," + 10*(8*i);
152 r += "," + 10*(250 - 8*i);
153 r += "," + 10*(125 + 125 * Math.sin(0.3*i));
154 r += "," + 10*(125 + 125 * Math.sin(0.3*i+Math.PI));
155 r += "\n";
156 }
157 return r;
158 },
159 options: {
160 strokeWidth: 2,
161 series : {
162 'parabola': {
163 strokeWidth: 0.0,
164 drawPoints: true,
165 pointSize: 4,
166 highlightCircleSize: 6
167 },
168 'line': {
169 strokeWidth: 1.0,
170 drawPoints: true,
171 pointSize: 1.5
172 },
173 'sine wave': {
174 strokeWidth: 3,
175 highlightCircleSize: 10
176 },
177 'sine wave2': {
178 strokePattern: [10, 2, 5, 2],
179 strokeWidth: 2,
180 highlightCircleSize: 3
181 }
182 }
183 }
184 }
185 ];
186
187 Samples.indexOf = function(id) {
188 for (var idx in Samples.data) {
189 if (Samples.data[idx].id == id) {
190 return idx;
191 }
192 }
193 return null;
194 }