Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsielicki committed May 27, 2016
1 parent 5d71437 commit e654c63
Showing 1 changed file with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,18 @@ define("slycat-timeseries-waveformplot", ["d3", "knob"], function(d3, knob)
var result, current_waveform, p, strokeStyle;
var color_scale_and_color_array = self.options.color_scale != null && self.options.color_array != null;

var waveformsLength = waveform_subset.length;
if(waveformsLength > 0){
this.waveformsLength = waveform_subset.length;
if(this.waveformsLength > 0){
self.waveformPie.trigger(
'configure',
{
"max":waveformsLength,
"max":this.waveformsLength,
}
);
self.waveformSelectorPie.trigger(
'configure',
{
"max":waveformsLength,
"max":this.waveformsLength,
}
);

Expand All @@ -347,33 +347,13 @@ define("slycat-timeseries-waveformplot", ["d3", "knob"], function(d3, knob)

this._calculate_paths();

timedProcessArray(
self._timedProcessArray(
waveform_subset,
processWaveform,
finishedProcessingWaveforms,
self.waveformPie
);
previewWaveforms();
}

function timedProcessArray(items, process, callback, progressControl){
var timeout = 100; //how long to yield control to UI thread
var todo = items.concat(); //create a clone of the original

self.waveformProcessingTimeout = setTimeout(function(){
var start = +new Date();
do {
process(todo.shift());
} while (todo.length > 0 && (+new Date() - start < 50));

if (todo.length > 0){
self.waveformProcessingTimeout = setTimeout(arguments.callee, timeout);
} else {
callback(items);
}

progressControl.val(waveformsLength - todo.length).trigger('change');
}, timeout);
previewWaveforms(self.canvas_offscreen, self.canvas_datum_ctx);
}

function processWaveform(waveform){
Expand Down Expand Up @@ -420,21 +400,20 @@ define("slycat-timeseries-waveformplot", ["d3", "knob"], function(d3, knob)
self.waveformSelectorPieContainer.show(0);
}, 1000);

timedProcessArray(
self._timedProcessArray(
waveform_subset,
processWaveformLookup,
finishedProcessingWaveformsLookup,
self.waveformSelectorPie
);
}

function previewWaveforms(timeout, maxIterations){
function previewWaveforms(sourceCanvas, destinationContext, timeout){
if (timeout == null)
timeout = 500

self.previewWaveformsTimeout = setTimeout( function(){
console.log("inside previewWaveforms deeper timeout");
self.canvas_datum_ctx.drawImage(self.canvas_offscreen, 0, 0);
destinationContext.drawImage(sourceCanvas, 0, 0);
if(self.previewWaveformsTimeout)
{
self.previewWaveformsTimeout = setTimeout(arguments.callee, timeout);
Expand Down Expand Up @@ -571,6 +550,28 @@ define("slycat-timeseries-waveformplot", ["d3", "knob"], function(d3, knob)
self.waveformPieContainer.hide();
},

_timedProcessArray: function(items, process, callback, progressControl)
{
var self = this;
var timeout = 100; //how long to yield control to UI thread
var todo = items.concat(); //create a clone of the original

self.waveformProcessingTimeout = setTimeout(function(){
var start = +new Date();
do {
process(todo.shift());
} while (todo.length > 0 && (+new Date() - start < 50));

if (todo.length > 0){
self.waveformProcessingTimeout = setTimeout(arguments.callee, timeout);
} else {
callback(items);
}

progressControl.val(self.waveformsLength - todo.length).trigger('change');
}, timeout);
},

_set_color: function()
{
var self = this;
Expand Down

0 comments on commit e654c63

Please sign in to comment.