| 1 |
Rickshaw.namespace('Rickshaw.Fixtures.RandomData'); |
| 2 |
|
| 3 |
Rickshaw.Fixtures.RandomData = function(timeInterval) { |
| 4 |
|
| 5 |
var addData; |
| 6 |
timeInterval = timeInterval || 1; |
| 7 |
|
| 8 |
var lastRandomValue = 200; |
| 9 |
|
| 10 |
var timeBase = Math.floor(new Date().getTime() / 1000); |
| 11 |
|
| 12 |
this.addData = function(data) { |
| 13 |
|
| 14 |
var randomValue = Math.random() * 100 + 15 + lastRandomValue; |
| 15 |
var index = data[0].length; |
| 16 |
|
| 17 |
var counter = 1; |
| 18 |
|
| 19 |
data.forEach( function(series) { |
| 20 |
var randomVariance = Math.random() * 20; |
| 21 |
var v = randomValue / 25 + counter++ + |
| 22 |
(Math.cos((index * counter * 11) / 960) + 2) * 15 + |
| 23 |
(Math.cos(index / 7) + 2) * 7 + |
| 24 |
(Math.cos(index / 17) + 2) * 1; |
| 25 |
|
| 26 |
series.push( { x: (index * timeInterval) + timeBase, y: v + randomVariance } ); |
| 27 |
} ); |
| 28 |
|
| 29 |
lastRandomValue = randomValue * 0.85; |
| 30 |
}; |
| 31 |
|
| 32 |
this.removeData = function(data) { |
| 33 |
data.forEach( function(series) { |
| 34 |
series.shift(); |
| 35 |
} ); |
| 36 |
timeBase += timeInterval; |
| 37 |
}; |
| 38 |
}; |
| 39 |
|