Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / examples / pivotgrid / faker.js
1 /*!
2  * Ext JS Library 3.3.1
3  * Copyright(c) 2006-2010 Sencha Inc.
4  * licensing@sencha.com
5  * http://www.sencha.com/license
6  */
7 //script used to generate data.json
8 (function() {
9     function buildData(count) {
10         count = count || 1000;
11         
12         var products = ['Ladder', 'Spanner', 'Chair', 'Hammer'],
13             states   = ['CA', 'NY', 'UK', 'AZ', 'TX'],
14             cities   = ['San Francisco', 'Palo Alto', 'London', 'Austin'],
15             people   = ['Tommy Maintz', 'Abe Elias', 'Ed Spencer', 'Jamie Avins'],
16             records  = [],
17             i;
18         
19         for (i = 0; i < count; i++) {
20             records.push({
21                 id      : i + 1,
22                 product : products[Math.floor(Math.random() * products.length)],
23                 city    : cities[Math.floor(Math.random() * cities.length)],
24                 state   : states[Math.floor(Math.random() * states.length)],
25                 quantity: Math.floor(Math.random() * 10000),
26                 value   : Math.floor(Math.random() * 50),
27                 month   : Math.ceil(Math.random() * 12),
28                 quarter : Math.ceil(Math.random() * 4),
29                 year    : 2010 - Math.floor(Math.random() * 2),
30                 person  : people[Math.floor(Math.random() * people.length)]
31             });
32         }
33         
34         return records;
35     };
36     
37     function buildPeople(count) {
38         count = count || 800;
39         
40         var colors  = ['Brown', 'Blue', 'Green'],
41             decades = ['1960s', '1970s', '1980s', '1990s'],
42             hands   = ['Left', 'Right'],
43             genders = ['Male', 'Female'],
44             records = [],
45             i;
46         
47         for (i = 0; i < count; i++) {
48             var iq = Math.round(Math.random() * 100);
49             
50             if (iq < 25 && Math.random() > 0.5) {
51                 iq += Math.random() * 30;
52             } else if (iq > 75 && Math.random() < 0.9) {
53                 iq -= Math.random() * 20;
54             }
55             
56             records.push({
57                 eyeColor   : colors[Math.floor(Math.random() * colors.length)],
58                 gender     : genders[Math.floor(Math.random() * genders.length)],
59                 handedness : hands[Math.floor(Math.random() * hands.length)],
60                 birthDecade: decades[Math.floor(Math.random() * decades.length)],
61                 height     : 5 + parseFloat((Math.random() * 2).toFixed(1)),
62                 iq         : 50 + Math.round(iq)
63             });
64         }
65         
66         return Ext.encode({rows: records});
67     };
68 });