blah2/html/js/plot_spectrum.js

138 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-12-12 14:40:52 +00:00
var timestamp = -1;
var nRows = 3;
var host = window.location.hostname;
var isLocalHost = is_localhost(host);
2023-12-12 14:40:52 +00:00
var range_x = [];
var range_y = [];
// setup API
2023-12-19 09:37:42 +00:00
var urlTimestamp;
var urlMap;
2023-12-12 14:40:52 +00:00
if (isLocalHost) {
2023-12-17 06:16:36 +00:00
urlTimestamp = '//' + host + ':3000/api/timestamp';
2023-12-12 14:40:52 +00:00
} else {
2023-12-17 06:16:36 +00:00
urlTimestamp = '//' + host + '/api/timestamp';
}
if (isLocalHost) {
urlMap = '//' + host + ':3000' + '/stash/iqdata';
} else {
urlMap = '//' + host + '/stash/iqdata';
2023-12-12 14:40:52 +00:00
}
// setup plotly
var layout = {
autosize: true,
margin: {
l: 50,
r: 50,
b: 50,
t: 10,
pad: 0
},
hoverlabel: {
namelength: 0
},
plot_bgcolor: "rgba(0,0,0,0)",
paper_bgcolor: "rgba(0,0,0,0)",
annotations: [],
displayModeBar: false,
xaxis: {
title: {
text: 'Frequency (MHz)',
font: {
size: 24
}
},
ticks: '',
side: 'bottom'
},
yaxis: {
title: {
text: 'Timestamp',
font: {
size: 24
}
},
ticks: '',
ticksuffix: ' ',
autosize: false,
categoryorder: "total descending"
}
};
var config = {
responsive: true,
displayModeBar: false
}
// setup plotly data
var data = [
{
z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
colorscale: 'Jet',
type: 'heatmap'
}
];
var detection = [];
Plotly.newPlot('data', data, layout, config);
// callback function
var intervalId = window.setInterval(function () {
// check if timestamp is updated
$.get(urlTimestamp, function () { })
2023-12-12 14:40:52 +00:00
.done(function (data) {
if (timestamp != data) {
timestamp = data;
// get new map data
$.getJSON(urlMap, function () { })
2023-12-12 14:40:52 +00:00
.done(function (data) {
// case draw new plot
if (data.nRows != nRows) {
nRows = data.nRows;
// timestamp posix to js
for (i = 0; i < data.timestamp.length; i++)
{
data.timestamp[i] = new Date(data.timestamp[i]);
}
2023-12-12 14:40:52 +00:00
var trace1 = {
y: data.timestamp,
2023-12-12 14:40:52 +00:00
z: data.spectrum,
colorscale: 'Jet',
zauto: false,
type: 'heatmap'
};
var data_trace = [trace1];
Plotly.newPlot('data', data_trace, layout, config);
}
// case update plot
else {
// timestamp posix to js
for (i = 0; i < data.timestamp.length; i++)
{
data.timestamp[i] = new Date(data.timestamp[i]);
}
2023-12-12 14:40:52 +00:00
var trace_update = {
y: [data.timestamp],
2023-12-12 14:40:52 +00:00
z: [data.spectrum]
};
Plotly.update('data', trace_update);
}
})
.fail(function () {
})
.always(function () {
});
}
})
.fail(function () {
})
.always(function () {
});
}, 100);