Skip to content

Commit c128b2a

Browse files
committed
Added PSD values label on the mouse position cursor by Shift key at the power specral density chart
1 parent 7a59f8a commit c128b2a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/graph_spectrum_plot.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
405405
canvasCtx.restore();
406406
};
407407

408+
GraphSpectrumPlot.getPSDbyFreq = function(frequency) {
409+
const freqIndex = Math.round(2 * frequency / this._fftData.blackBoxRate * (this._fftData.psdOutput.length - 1) );
410+
return this._fftData.psdOutput[freqIndex];
411+
};
412+
408413
GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx, drawPSD = false) {
409414
const PLOTTED_BLACKBOX_RATE = this._fftData.blackBoxRate / this._zoomX;
410415

@@ -1504,6 +1509,17 @@ GraphSpectrumPlot._drawMousePosition = function (
15041509
);
15051510
}
15061511

1512+
if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) {
1513+
const psdLabel = Math.round(this.getPSDbyFreq(mouseFrequency)).toString() + "dBm/Hz";
1514+
this._drawAxisLabel(
1515+
canvasCtx,
1516+
psdLabel,
1517+
mouseX - 30,
1518+
mouseY - 4,
1519+
"left",
1520+
);
1521+
}
1522+
15071523
// Y axis
15081524
let unitLabel;
15091525
switch (this._spectrumType) {
@@ -1547,7 +1563,7 @@ GraphSpectrumPlot._drawMousePosition = function (
15471563
this._drawAxisLabel(
15481564
canvasCtx,
15491565
label,
1550-
mouseX - 25,
1566+
mouseX - 30,
15511567
mouseY - 4,
15521568
"left",
15531569
);

0 commit comments

Comments
 (0)