mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 08:49:27 +00:00
Complete (?) bands display. Closes #48
This commit is contained in:
@@ -14,6 +14,8 @@ Supported data sources include DX Clusters, the Reverse Beacon Network (RBN), th
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
### Accessing the public version
|
### Accessing the public version
|
||||||
|
|
||||||
You can access the public version's web interface at [https://spothole.app](https://spothole.app), and see [https://spothole.app/apidocs](https://spothole.app/apidocs) for the API details.
|
You can access the public version's web interface at [https://spothole.app](https://spothole.app), and see [https://spothole.app/apidocs](https://spothole.app/apidocs) for the API details.
|
||||||
|
|||||||
BIN
images/screenshot3.png
Normal file
BIN
images/screenshot3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 173 KiB |
@@ -5,6 +5,7 @@ BAND_COLUMN_CANVAS_WIDTH_EM = 4;
|
|||||||
BAND_COLUMN_FONT_SIZE = 16;
|
BAND_COLUMN_FONT_SIZE = 16;
|
||||||
BAND_COLUMN_HEIGHT_PX = BAND_COLUMN_HEIGHT_EM * BAND_COLUMN_FONT_SIZE;
|
BAND_COLUMN_HEIGHT_PX = BAND_COLUMN_HEIGHT_EM * BAND_COLUMN_FONT_SIZE;
|
||||||
BAND_COLUMN_CANVAS_WIDTH_PX = BAND_COLUMN_CANVAS_WIDTH_EM * BAND_COLUMN_FONT_SIZE;
|
BAND_COLUMN_CANVAS_WIDTH_PX = BAND_COLUMN_CANVAS_WIDTH_EM * BAND_COLUMN_FONT_SIZE;
|
||||||
|
BAND_COLUMN_SPOT_DIV_HEIGHT_PX = BAND_COLUMN_FONT_SIZE * 1.6;
|
||||||
|
|
||||||
// Load spots and populate the bands display.
|
// Load spots and populate the bands display.
|
||||||
function loadSpots() {
|
function loadSpots() {
|
||||||
@@ -87,35 +88,67 @@ function updateBands() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the spots on the band. Each one is a div with the details, shifted down if necessary to prevent
|
// Prepare the spots list
|
||||||
// overlap
|
var bandSpotsDiv = $("<div class='band-spots'>");
|
||||||
bandSpotsDiv = $("<div class='band-spots'>");
|
var lastSpotPxDownBand = -999;
|
||||||
// Sort by frequency so we print higher frequencies later, and can bump them further down the track to prevent
|
// Sort by frequency so have a consistent order in which to plan where they will appear on the band div.
|
||||||
// overlaps
|
|
||||||
spotList.sort(function(a, b) { return a.freq - b.freq; });
|
spotList.sort(function(a, b) { return a.freq - b.freq; });
|
||||||
var lastSpotEmDownBand = -999;
|
// First calculate how we should be displaying the spots. There are three "modes" to try to place them in a
|
||||||
// Iterate through the spots list
|
// visually appealing way:
|
||||||
spotList.forEach(s => {
|
// 1) Spaced normally, not going over the end of the band, so we populate them forwards.
|
||||||
// Work out how far down the div to draw it
|
// 2) Would go over the end, but the spots don't fill the band, so we populate them backwards.
|
||||||
var percentDownBand = (s.freq - band.start_freq) / (band.end_freq - band.start_freq) * 0.97; // not 100% due to fudge, the first and last dashes are not exactly at the top and bottom of the div as some space is needed for text
|
// 3) Spots totally fill the band (or more), so we space them evenly starting at the top.
|
||||||
var emDownBand = percentDownBand * BAND_COLUMN_HEIGHT_EM;
|
// In each case, we don't add anything to the DOM yet, we just calculate "pxDownBandLabel" (how far the *top* of
|
||||||
if (emDownBand < lastSpotEmDownBand + 1.6) {
|
// the label is from the top of the div) and add that as a property to the spot for later use.
|
||||||
emDownBand = lastSpotEmDownBand + 1.6; // Prevent overlap
|
if (spotList.length >= BAND_COLUMN_HEIGHT_PX / BAND_COLUMN_SPOT_DIV_HEIGHT_PX) {
|
||||||
}
|
// Mode 3.
|
||||||
lastSpotEmDownBand = emDownBand;
|
// Just lay out all spots simply, starting at 0px offset and working down with each one touching.
|
||||||
// Calculate how many px down the band div the label appears, and store it with the spot, so we can use it
|
lastSpotPxDownBand = 0 - BAND_COLUMN_SPOT_DIV_HEIGHT_PX;
|
||||||
// later for drawing the lines.
|
spotList.forEach(s => {
|
||||||
var pxDownBandLabel = (emDownBand * BAND_COLUMN_FONT_SIZE) + (0.015 * BAND_COLUMN_HEIGHT_PX);
|
lastSpotPxDownBand = lastSpotPxDownBand + BAND_COLUMN_SPOT_DIV_HEIGHT_PX;
|
||||||
s["pxDownBandLabel"] = pxDownBandLabel;
|
s["pxDownBandLabel"] = lastSpotPxDownBand;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Mode 1 or 2. Run through adding things to the list forwards as a test.
|
||||||
|
spotList.forEach(s => {
|
||||||
|
// Work out how far down the div to draw it
|
||||||
|
var percentDownBand = (s.freq - band.start_freq) / (band.end_freq - band.start_freq) * 0.97; // not 100% due to fudge, the first and last dashes are not exactly at the top and bottom of the div as some space is needed for text
|
||||||
|
var pxDownBand = percentDownBand * BAND_COLUMN_HEIGHT_PX;
|
||||||
|
if (pxDownBand < lastSpotPxDownBand + BAND_COLUMN_SPOT_DIV_HEIGHT_PX) {
|
||||||
|
pxDownBand = lastSpotPxDownBand + BAND_COLUMN_SPOT_DIV_HEIGHT_PX; // Prevent overlap
|
||||||
|
}
|
||||||
|
s["pxDownBandLabel"] = pxDownBand;
|
||||||
|
lastSpotPxDownBand = pxDownBand;
|
||||||
|
});
|
||||||
|
|
||||||
// Add spot div to DOM
|
// Work out if we overflowed the end.
|
||||||
bandSpotsDiv.append(`<div class="band-spot" style="top: ${emDownBand}em; border-top: 1px solid ${s.band_color}; border-left: 5px solid ${s.band_color}; border-bottom: 1px solid ${s.band_color}; border-right: 1px solid ${s.band_color};"><span class="band-spot-call">${s.dx_call}</span><span class="band-spot-info">${s.dx_call} ${(s.freq/1000000).toFixed(3)} ${s.mode}</span></div>`);
|
if (lastSpotPxDownBand <= BAND_COLUMN_HEIGHT_PX) {
|
||||||
|
// Mode 1. Current positions are fine and there's nothing to do.
|
||||||
|
} else {
|
||||||
|
// Mode 2. Repeat the process but backwards, starting at the end and working upwards.
|
||||||
|
lastSpotPxDownBand = 999999;
|
||||||
|
spotList.reverse().forEach(s => {
|
||||||
|
// Work out how far down the div to draw it
|
||||||
|
var percentDownBand = (s.freq - band.start_freq) / (band.end_freq - band.start_freq) * 0.97; // not 100% due to fudge, the first and last dashes are not exactly at the top and bottom of the div as some space is needed for text
|
||||||
|
var pxDownBand = percentDownBand * BAND_COLUMN_HEIGHT_PX;
|
||||||
|
if (pxDownBand > lastSpotPxDownBand - BAND_COLUMN_SPOT_DIV_HEIGHT_PX) {
|
||||||
|
pxDownBand = lastSpotPxDownBand - BAND_COLUMN_SPOT_DIV_HEIGHT_PX; // Prevent overlap
|
||||||
|
}
|
||||||
|
s["pxDownBandLabel"] = pxDownBand;
|
||||||
|
lastSpotPxDownBand = pxDownBand;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now each spot is tagged with how far down the div it should go, add them to the DOM.
|
||||||
|
spotList.forEach(s => {
|
||||||
|
bandSpotsDiv.append(`<div class="band-spot" style="top: ${s['pxDownBandLabel']}px; border-top: 1px solid ${s.band_color}; border-left: 5px solid ${s.band_color}; border-bottom: 1px solid ${s.band_color}; border-right: 1px solid ${s.band_color};"><span class="band-spot-call">${s.dx_call}</span><span class="band-spot-info">${s.dx_call} ${(s.freq/1000000).toFixed(3)} ${s.mode}</span></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Work out how tall the canvas should be. Normally this is matching the normal band column height, but if some
|
// Work out how tall the canvas should be. Normally this is matching the normal band column height, but if some
|
||||||
// spots have gone off the end of the band markers and stretched their div, we need to resize the canvas to
|
// spots have gone off the end of the band markers and stretched their div, we need to resize the canvas to
|
||||||
// match, otherwise we have nowhere to draw their connecting lines.
|
// match, otherwise we have nowhere to draw their connecting lines.
|
||||||
var canvasHeight = Math.max(BAND_COLUMN_HEIGHT_PX, (lastSpotEmDownBand+1.6) * BAND_COLUMN_FONT_SIZE);
|
var canvasHeight = Math.max(BAND_COLUMN_HEIGHT_PX, lastSpotPxDownBand + BAND_COLUMN_SPOT_DIV_HEIGHT_PX);
|
||||||
maxHeightBand = Math.max(maxHeightBand, canvasHeight);
|
maxHeightBand = Math.max(maxHeightBand, canvasHeight);
|
||||||
|
|
||||||
// Draw horizontal or diagonal lines to join up the "real" frequency with where the spot div ended up
|
// Draw horizontal or diagonal lines to join up the "real" frequency with where the spot div ended up
|
||||||
@@ -124,7 +157,7 @@ function updateBands() {
|
|||||||
// Work out how far down the div to draw it
|
// Work out how far down the div to draw it
|
||||||
var percentDownBand = (s.freq - band.start_freq) / (band.end_freq - band.start_freq) * 0.97; // not 100% due to fudge, the first and last dashes are not exactly at the top and bottom of the div as some space is needed for text
|
var percentDownBand = (s.freq - band.start_freq) / (band.end_freq - band.start_freq) * 0.97; // not 100% due to fudge, the first and last dashes are not exactly at the top and bottom of the div as some space is needed for text
|
||||||
var pxDownBandFreq = (percentDownBand + 0.015) * BAND_COLUMN_HEIGHT_PX; // same fudge but add half to put the left end of the line in the right place
|
var pxDownBandFreq = (percentDownBand + 0.015) * BAND_COLUMN_HEIGHT_PX; // same fudge but add half to put the left end of the line in the right place
|
||||||
var pxDownBandLabel = s["pxDownBandLabel"];
|
var pxDownBandLabel = s["pxDownBandLabel"] + (BAND_COLUMN_SPOT_DIV_HEIGHT_PX / 1.75); // line should be to the vertical text-centre spot, not to the top corner
|
||||||
|
|
||||||
// Draw the line on the canvas
|
// Draw the line on the canvas
|
||||||
var ctx = bandLinesCanvas[0].getContext('2d');
|
var ctx = bandLinesCanvas[0].getContext('2d');
|
||||||
|
|||||||
Reference in New Issue
Block a user