]>
git.proxmox.com Git - sencha-touch.git/blob - src/examples/stockapp/app/store/MovingAverage.js
1 Ext
.define("StockApp.store.MovingAverage", {
3 requires
: ['StockApp.model.Stock', 'Ext.data.reader.Array'],
4 extend
: "Ext.data.ArrayStore",
6 model
: "StockApp.model.Stock",
11 applySource: function (source
) {
12 return Ext
.StoreManager
.lookup(source
);
15 updateSource: function (source
, oldSource
) {
17 source
.on('refresh', 'onRefreshSource', this);
18 this.setOriginalData(source
.getData());
21 oldSource
.on('refresh', 'onRefreshSource', this);
25 onRefreshSource: function () {
26 if (this.getSource()) {
27 this.setOriginalData(this.getSource().getData());
31 setOriginalData: function (data
) {
32 var length
= data
.length
,
35 window
= this.getWindow(),
45 for (i
= 0; i
< window
; i
++) {
51 cntClose
+= item
.close
;
52 cntVolume
+= item
.volume
;
53 cntAdjClose
+= item
.adjClose
;
64 for (i
= 0, j
= window
; j
< length
; i
++, j
++) {
66 item2
= items
[j
].data
;
67 cntDate
+= item2
.date
- item
.date
;
68 cntOpen
+= item2
.open
- item
.open
;
69 cntHigh
+= item2
.high
- item
.high
;
70 cntLow
+= item2
.low
- item
.low
;
71 cntClose
+= item2
.close
- item
.close
;
72 cntVolume
+= item2
.volume
- item
.volume
;
73 cntAdjClose
+= item2
.adjClose
- item
.adjClose
;
84 for (; i
< length
- 1; i
++) {
90 cntClose
-= item
.close
;
91 cntVolume
-= item
.volume
;
92 cntAdjClose
-= item
.adjClose
;
94 cntDate
/ (length
- i
- 1),
95 cntOpen
/ (length
- i
- 1),
96 cntHigh
/ (length
- i
- 1),
97 cntLow
/ (length
- i
- 1),
98 cntClose
/ (length
- i
- 1),
99 cntVolume
/ (length
- i
- 1),
100 cntAdjClose
/ (length
- i
- 1)
103 item
= items
[i
].data
;