var rnorm = function(bias, pow) { // using a mu just to avoid the special case of 0 centering return bias + (Math.random() > 0.5 ? 1 : -1) * Math.pow(Math.abs( Math.random() + Math.random() + Math.random() + Math.random() + Math.random() + Math.random() - 3) / 3, pow) } tserLabels = R.always(['Insulin-like growth factor', 'Von Willebrand Factor', 'Voltage-gated 6T & 1P', 'Mechanosensitive ion ch.', 'GABAA receptor positive ', 'Epidermal growth factor', 'Signal recognition particle'].slice(0,7)) var samples = flyd.stream() function sampler(time) { return tserLabels().map(function(d, i) {return {key: time, value: rnorm(15, 0.25 + (2 - 0.25) * i / tserLabels().length)}}) } var historyContextLength = 64 var historyShownLength = 16 var initialLength = 16 var initialHistory = R.map(sampler)(R.range(0, initialLength)) // ensuring 2 data points to give sufficient input to the Y scale function generateSample(time) { samples(sampler(time)) } var time = initialLength var samplesHistoricalContext = flyd.stream([samples], function() { var newHistory = R.concat(samplesHistoricalContext(), [samples()]) samplesHistoricalContext(R.slice(-historyContextLength, newHistory.length, newHistory)) })(initialHistory) var pause = false var timeCadence = 100 window.setInterval(function(){if(!pause) generateSample(time++)}, timeCadence) function tserMaker(history) { var tserLength = history.length var range = R.range(0, tserLength) var tsers = tserLabels().map(function(d, i) { var full = R.map(function(time) { return history[time][i] })(range) return { key: d, contextValue: full, value: R.slice(-historyShownLength, full.length, full) } }) return tsers } var model = flyd.stream([samplesHistoricalContext], function() { var history = samplesHistoricalContext() return tserMaker(history) })