function Spectrum(el, msec) { this.el = el; this.msec = msec; this.ctx = null; this.min = 0; this.max = 0; this.timer = 0; this.data = []; // Make sure canvas fills the container el.style.width = '100%'; el.style.height = '100%'; // Start with hidden spectrum display this.close(); }; Spectrum.prototype.update = function(data) { // Do not update if no redraw timer or no canvas if (!this.timer || (this.el.clientHeight == 0)) return; var i = this.data.length < data.length? this.data.length : data.length; // Truncate stored data length, add and fill missing data if (this.data.length > i) { this.data.length = i; } else if(this.data.length < data.length) { this.data.length = data.length; for(var j=i; jthis.data[j]? data[j] : this.data[j] + (data[j] - this.data[j]) / 10.0; } // this.min = Math.min(...data); // this.max = Math.max(...data); var wf_range = Waterfall.getRange(); this.min = wf_range.min - 5; this.max = wf_range.max + 5; }; Spectrum.prototype.draw = function() { // Do not draw if no redraw timer or no canvas if (!this.timer || (this.el.clientHeight == 0)) return; var vis_freq = get_visible_freq_range(); var vis_center = vis_freq.center; var vis_start = 0.5 - (center_freq - vis_freq.start) / bandwidth; var vis_end = 0.5 - (center_freq - vis_freq.end) / bandwidth; var data_start = Math.round(fft_size * vis_start); var data_end = Math.round(fft_size * vis_end); var data_width = data_end - data_start; var data_height = Math.abs(this.max - this.min); var spec_width = this.el.offsetWidth; var spec_height = this.el.offsetHeight; // If canvas got resized, or no context yet... if (!this.ctx || spec_width!=this.el.width || spec_height!=this.el.height) { this.el.width = spec_width; this.el.height = spec_height; this.ctx = this.el.getContext("2d"); this.ctx.fillStyle = "rgba(255, 255, 255, 0.4)"; this.ctx.strokeStyle = "rgba(255, 255, 0, 1.0)"; this.ctx.lineWidth = 1; } // Clear canvas to transparency this.ctx.clearRect(0, 0, spec_width, spec_height); // Mark currently tuned frequences // var demodulators = getDemodulators(); // for (var i=0; i