Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't update scan chart data until there's actual data #869

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

argilo
Copy link
Contributor

@argilo argilo commented Mar 29, 2024

If the scan chart is open prior to the first scan being completed, an uncaught error occurs:

Uncaught Error: Source data is missing a component at (0,1)!
    convertColumnsToData http://localhost:5000/static/js/c3.min.js:2
    loadFromArgs http://localhost:5000/static/js/c3.min.js:2
    load http://localhost:5000/static/js/c3.min.js:2
    redraw_scan_chart http://localhost:5000/static/js/scan_chart.js:80
    <anonymous> http://localhost:5000/:213
    jQuery 8
    <anonymous> http://localhost:5000/:199
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    onreadystatechange http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    n http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    onreadystatechange http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    n http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    emit http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    value http://localhost:5000/static/js/socket.io.min.js:6
    onreadystatechange http://localhost:5000/static/js/socket.io.min.js:6
    jQuery 2
    <anonymous> http://localhost:5000/:106
    jQuery 13
c3.min.js:2:122014

This occurs because the scan_chart_* variables are overwritten, even though get_scan_data has not provided any data:

$.getJSON("get_scan_data", function(data){
// Load the data into our data stores.
scan_chart_spectra.columns[0] = ['x_spectra'].concat(data.freq);
scan_chart_spectra.columns[1] = ['Spectra'].concat(data.power);
scan_chart_peaks.columns[0] = ['x_peaks'].concat(data.peak_freq);
scan_chart_peaks.columns[1] = ['Peaks'].concat(data.peak_lvl);
scan_chart_threshold.columns[0] = ['x_thresh'].concat([data.freq[0],data.freq[data.freq.length-1]]);
scan_chart_threshold.columns[1] = ['Threshold'].concat([data.threshold+autorx_config.snr_threshold,data.threshold+autorx_config.snr_threshold]);
scan_chart_latest_timestamp = data.timestamp;

The get_scan_data response looks like so:

{
    "freq": [],
    "power": [],
    "peak_freq": [],
    "peak_lvl": [],
    "timestamp":
    "No data yet.",
    "threshold": 0
}

Line 205 accesses non-existent array indices in data.freq, thereby setting the x coordinates of the threshold line to undefined.

To avoid this, we can skip processing if data.freq is empty, which leaves the placeholder data displayed instead.

@darksidelemm darksidelemm merged commit 2e04da0 into projecthorus:testing Mar 29, 2024
1 check passed
@argilo argilo deleted the scan-chart-threshold-fix branch March 30, 2024 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants