make this more robust

This commit is contained in:
Jakob Ketterl 2021-01-01 23:37:10 +01:00
parent a1cbc45b88
commit c1245308bd

View File

@ -314,14 +314,16 @@ function scale_px_from_freq(f, range) {
} }
function get_visible_freq_range() { function get_visible_freq_range() {
var out = {}; if (!bandwidth) return false;
var fcalc = function (x) { var fcalc = function (x) {
var canvasWidth = waterfallWidth() * zoom_levels[zoom_level]; var canvasWidth = waterfallWidth() * zoom_levels[zoom_level];
return Math.round(((-zoom_offset_px + x) / canvasWidth) * bandwidth) + (center_freq - bandwidth / 2); return Math.round(((-zoom_offset_px + x) / canvasWidth) * bandwidth) + (center_freq - bandwidth / 2);
}; };
out.start = fcalc(0); var out = {
out.center = fcalc(waterfallWidth() / 2); start: fcalc(0),
out.end = fcalc(waterfallWidth()); center: fcalc(waterfallWidth() / 2),
end: fcalc(waterfallWidth()),
}
out.bw = out.end - out.start; out.bw = out.end - out.start;
out.hps = out.bw / waterfallWidth(); out.hps = out.bw / waterfallWidth();
return out; return out;
@ -426,6 +428,7 @@ var range;
function mkscale() { function mkscale() {
//clear the lower part of the canvas (where frequency scale resides; the upper part is used by filter envelopes): //clear the lower part of the canvas (where frequency scale resides; the upper part is used by filter envelopes):
range = get_visible_freq_range(); range = get_visible_freq_range();
if (!range) return;
mkenvelopes(range); //when scale changes we will always have to redraw filter envelopes, too mkenvelopes(range); //when scale changes we will always have to redraw filter envelopes, too
scale_ctx.clearRect(0, 22, scale_ctx.canvas.width, scale_ctx.canvas.height - 22); scale_ctx.clearRect(0, 22, scale_ctx.canvas.width, scale_ctx.canvas.height - 22);
scale_ctx.strokeStyle = "#fff"; scale_ctx.strokeStyle = "#fff";
@ -442,9 +445,7 @@ function mkscale() {
}; };
var last_large; var last_large;
var x; var x;
for (; ;) { while ((x = scale_px_from_freq(marker_hz, range)) <= window.innerWidth) {
x = scale_px_from_freq(marker_hz, range);
if (x > window.innerWidth) break;
scale_ctx.beginPath(); scale_ctx.beginPath();
scale_ctx.moveTo(x, 22); scale_ctx.moveTo(x, 22);
if (marker_hz % spacing.params.large_marker_per_hz === 0) { //large marker if (marker_hz % spacing.params.large_marker_per_hz === 0) { //large marker
@ -736,8 +737,7 @@ function on_ws_recv(evt) {
if ('max_clients' in config) if ('max_clients' in config)
$('#openwebrx-bar-clients').progressbar().setMaxClients(config['max_clients']); $('#openwebrx-bar-clients').progressbar().setMaxClients(config['max_clients']);
if (typeof(bandwidth) != 'undefined') waterfall_init();
waterfall_init();
var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel(); var demodulatorPanel = $('#openwebrx-panel-receiver').demodulatorPanel();
demodulatorPanel.setCenterFrequency(center_freq); demodulatorPanel.setCenterFrequency(center_freq);
@ -751,8 +751,7 @@ function on_ws_recv(evt) {
$('#openwebrx-sdr-profiles-listbox').val(currentprofile); $('#openwebrx-sdr-profiles-listbox').val(currentprofile);
} }
if (typeof(bandwidth) != 'undefined') waterfall_clear();
waterfall_clear();
if ('frequency_display_precision' in config) if ('frequency_display_precision' in config)
$('#openwebrx-panel-receiver').demodulatorPanel().setFrequencyPrecision(config['frequency_display_precision']); $('#openwebrx-panel-receiver').demodulatorPanel().setFrequencyPrecision(config['frequency_display_precision']);