Add detections to map front end display

This commit is contained in:
30hours 2023-11-27 02:35:42 +00:00
parent 6eddada856
commit 8555f51417
3 changed files with 94 additions and 110 deletions

View file

@ -84,9 +84,9 @@
<body style="background-color:#f78c58;">
<div style="height: 100vh; width: 90vw" class="container-fluid">
<div style="height: 100vh; width: 95vw" class="container-fluid">
<div style="height: 100vh; width: 90vw" class="row d-flex">
<div style="height: 100vh; width: 95vw" class="row d-flex">
<div class="justify-content-center" id="ddmap"></div>

View file

@ -1,98 +1,34 @@
var timestamp = -1;
var nRows = 3;
var nCols = 3;
var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112");
var data = [
{
z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
colorscale: 'Jet',
type: 'heatmap'
}
];
// setup API
var urlTimestamp = '';
if (isLocalHost) {
urlTimestamp = '//' + host + ':3000/timestamp?timestamp=' + Date.now();
} else {
urlTimestamp = '//' + host + '/api/timestamp?timestamp=' + Date.now();
}
var urlDetection = '';
if (isLocalHost) {
urlDetection = '//' + host + ':3000/detection?timestamp=' + Date.now();
} else {
urlDetection = '//' + host + '/api/detection?timestamp=' + Date.now();
}
// setup plotly
var layout = {
autosize: false,
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
t: 10,
pad: 0
},
width: document.getElementById('ddmap').offsetWidth,
height: document.getElementById('ddmap').offsetHeight,
plot_bgcolor: "rgba(0,0,0,0)",
paper_bgcolor: "rgba(0,0,0,0)",
annotations: [],
coloraxis: {
cmin: 0,
cmax: 1
},
displayModeBar: false,
xaxis: {
ticks: '',
side: 'bottom'
},
yaxis: {
ticks: '',
ticksuffix: ' ',
autosize: false
}
};
var config = {
displayModeBar: false,
responsive: true
}
Plotly.newPlot('ddmap', data, layout, config);
var intervalId = window.setInterval(function () {
// check if timestamp is updated
var timestampData = $.get(urlTimestamp, function () { })
.done(function (data) {
if (timestamp != data) {
timestamp = data;
// get new map data
var apiData = $.getJSON(urlMap, function () { })
.done(function (data) {
// case draw new plot
if (data.nRows != nRows || data.nCols != nCols) {
nRows = data.nRows;
nCols = data.nCols;
data = [
{
z: data.data,
x: data.delay,
y: data.doppler,
colorscale: 'Jet',
zauto: false,
zmin: 0,
zmax: Math.max(13, data.maxPower),
type: 'heatmap'
}
];
layout = {
autosize: false,
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
pad: 0
hoverlabel: {
namelength: 0
},
width: document.getElementById('ddmap').offsetWidth,
height: document.getElementById('ddmap').offsetHeight,
@ -122,38 +58,86 @@ var intervalId = window.setInterval(function () {
autosize: false,
categoryorder: "total descending"
}
};
Plotly.newPlot('ddmap', data, layout, { displayModeBar: false });
}
else {
data_update =
};
var config = {
displayModeBar: false,
responsive: true
}
// setup plotly data
var data = [
{
'z': [data.data],
'zmax': Math.max(13, data.maxPower)
z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
colorscale: 'Jet',
type: 'heatmap'
}
];
var detection = [];
Plotly.newPlot('ddmap', data, layout, config);
// callback function
var intervalId = window.setInterval(function () {
// check if timestamp is updated
var timestampData = $.get(urlTimestamp, function () { })
.done(function (data) {
if (timestamp != data) {
timestamp = data;
// get new map data
var apiData = $.getJSON(urlMap, function () { })
.done(function (data) {
// get detection data
var detectionData = $.getJSON(urlDetection, function () { })
.done(function (data_detection) {
detection = data_detection;
});
// case draw new plot
if (data.nRows != nRows) {
nRows = data.nRows;
var trace1 = {
z: data.data,
x: data.delay,
y: data.doppler,
colorscale: 'Jet',
zauto: false,
zmin: 0,
zmax: Math.max(13, data.maxPower),
type: 'heatmap'
};
layout_update = {
var trace2 = {
x: detection.delay,
y: detection.doppler,
mode: 'markers',
type: 'scatter'
};
Plotly.update('ddmap', data_update, layout_update, { displayModeBar: false });
var data_trace = [trace1, trace2];
Plotly.newPlot('ddmap', data_trace, layout, config);
}
// case update plot
else {
var trace_update = {
x: [data.delay, detection.delay],
y: [data.doppler, detection.doppler],
z: [data.data, []],
zmax: [Math.max(13, data.maxPower), []]
};
Plotly.update('ddmap', trace_update);
}
})
.fail(function () {
console.log('API Fail');
})
.always(function () {
});
}
})
.fail(function () {
console.log('API Fail');
})
.always(function () {
});
}, 100);

View file

@ -84,9 +84,9 @@
<body style="background-color:#f78c58;">
<div style="height: 100vh; width: 90vw" class="container-fluid">
<div style="height: 100vh; width: 95vw" class="container-fluid">
<div style="height: 100vh; width: 90vw" class="row d-flex">
<div style="height: 100vh; width: 95vw" class="row d-flex">
<div class="justify-content-center" id="ddmap"></div>