Properly handle multiple data selections.
[dygraphs.git] / experimental / palette / samples.js
CommitLineData
3dcf1f1f
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 Source samples.
23 *
24 * @author konigsberg@google.com (Robert Konigsberg)
25 */
26
27"use strict";
28
2b3ebdd9
RK
29var Samples = {};
30Samples.data = [
31 {
32 id: "interestingShapes",
33 title: "Interesting Shapes",
3dcf1f1f
RK
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() { alert("p-click!"); },
65 }
66 },
67
2b3ebdd9
RK
68 {
69 id: "sparse",
70 title: "Sparse Data",
71 data: [
72 [ new Date("2009/12/01"), 10, 10, 10],
73 [ new Date("2009/12/02"), 15, 11, 12],
74 [ new Date("2009/12/03"), null, null, 12],
75 [ new Date("2009/12/04"), 20, 14, null],
76 [ new Date("2009/12/05"), 15, null, 17],
77 [ new Date("2009/12/06"), 18, null, null],
78 [ new Date("2009/12/07"), 12, 14, null]
79 ],
80 options: {
81 labels: ["Date", "Series1", "Series2", "Series3"]
82 }
3dcf1f1f
RK
83 },
84
2b3ebdd9
RK
85 {
86 id: "manyPoints",
87 title: "Dense Data",
3dcf1f1f
RK
88 data: function() {
89 var numPoints = 1000;
90 var numSeries = 100;
91
92 var data = [];
93 var xmin = 0.0;
94 var xmax = 2.0 * Math.PI;
95 var adj = .5;
96 var delta = (xmax - xmin) / (numPoints - 1);
97
98 for (var i = 0; i < numPoints; ++i) {
99 var x = xmin + delta * i;
100 var elem = [ x ];
101 for (var j = 0; j < numSeries; j++) {
102 var y = Math.pow(Math.random() - Math.random(), 7);
103 elem.push(y);
104 }
105 data[i] = elem;
106 }
107 return data;
108 },
109 options: {
110 labelsSeparateLines: true,
111 width: 640,
112 height: 480,
113 title: 'Many Points',
114 axisLineColor: 'white',
115 }
2b3ebdd9
RK
116 },
117
118 {
119 id: "errorBars",
120 title: "Error Bars",
121 data: [
122 [1, [10, 10, 100]],
123 [2, [15, 20, 110]],
124 [3, [10, 30, 100]],
125 [4, [15, 40, 110]],
126 [5, [10, 120, 100]],
127 [6, [15, 50, 110]],
128 [7, [10, 70, 100]],
129 [8, [15, 90, 110]],
130 [9, [10, 50, 100]]
131 ],
132 options: {
133 customBars: true,
134 errorBars: true
135 }
136 }
137];
138
139Samples.indexOf = function(id) {
140 for (var idx in Samples.data) {
141 if (Samples.data[idx].id == id) {
142 return idx;
143 }
3dcf1f1f 144 }
2b3ebdd9 145 return null;
3dcf1f1f 146}