]>
Commit | Line | Data |
---|---|---|
947f0963 TL |
1 | Ext.define('KitchenSink.store.StockPrice', { |
2 | extend: 'Ext.data.Store', | |
3 | model: 'KitchenSink.model.StockPrice', | |
4 | alias: 'store.stock-price', | |
5 | ||
6 | generateData: function(count) { | |
7 | var first = { | |
8 | time: Ext.Date.now(), | |
9 | close: 100 | |
10 | }, | |
11 | records = [], | |
12 | previous, i; | |
13 | ||
14 | for (i = 0; i < count; i++) { | |
15 | previous = records[i - 1] || first; | |
16 | records.push(Ext.apply({ | |
17 | time: previous.time + 24 * 60 * 60 * 1000 // day interval | |
18 | }, this.getNextPrice(previous.close))); | |
19 | } | |
20 | ||
21 | return records; | |
22 | }, | |
23 | ||
24 | getNextPrice: function(previousClose) { | |
25 | var open = previousClose - 2 + Math.random() * 8, | |
26 | high = open + Math.random() * 2, | |
27 | close = open - Math.random() * 4, | |
28 | low = close - Math.random() * 2, | |
29 | min = Math.min(open, high, low, close); | |
30 | ||
31 | if (min < 0) { | |
32 | open -= min; | |
33 | high -= min; | |
34 | low -= min; | |
35 | close -= min; | |
36 | } | |
37 | ||
38 | return { | |
39 | open: open, | |
40 | high: high, | |
41 | low: low, | |
42 | close: close | |
43 | }; | |
44 | }, | |
45 | ||
46 | refreshData: function() { | |
47 | this.setData(this.generateData(2 * 365)); | |
48 | }, | |
49 | ||
50 | constructor: function(config) { | |
51 | ||
52 | config = Ext.apply({ | |
53 | data: this.generateData(2 * 365) | |
54 | }, config); | |
55 | ||
56 | this.callParent([config]); | |
57 | ||
58 | } | |
59 | }); |