Skip to content

Commit 2a7b13e

Browse files
committed
Added one log PSD curves into import list by press Insert key to spectrum comparison
1 parent 2c90daa commit 2a7b13e

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/graph_imported_curves.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function ImportedCurves(curvesChanged) {
66
this.maxX = -Number.MAX_VALUE;
77
this.minY = Number.MAX_VALUE;
88
this.maxY = -Number.MAX_VALUE;
9-
9+
1010
this.curvesCount = function() {
1111
return this._curvesData.length;
1212
};
@@ -64,6 +64,29 @@ export function ImportedCurves(curvesChanged) {
6464
}
6565
};
6666

67+
this.addCurve = function(points, name) {
68+
this._curvesData.push({
69+
name: name,
70+
points: points,
71+
});
72+
for (const point of points) {
73+
this.minX = Math.min(point.x, _that.minX);
74+
this.maxX = Math.max(point.x, _that.maxX);
75+
this.minY = Math.min(point.y, _that.minY);
76+
this.maxY = Math.max(point.y, _that.maxY);
77+
}
78+
curvesChanged();
79+
}
80+
81+
this.isNewCurve = function(name) {
82+
for (const curve of this._curvesData) {
83+
if (curve.name == name) {
84+
return false;
85+
}
86+
}
87+
return true;
88+
}
89+
6790
this.removeCurves = function() {
6891
this._curvesData.length = 0;
6992
this.minX = Number.MAX_VALUE;

src/graph_spectrum_plot.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,8 +1801,19 @@ GraphSpectrumPlot.removeImportedCurves = function() {
18011801
};
18021802

18031803
GraphSpectrumPlot.addCurrentSpectrumIntoImport = function() {
1804-
if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) {
1805-
alert("The PSD curve is added into import");
1804+
if (this._spectrumType === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY &&
1805+
this._importedPSD.isNewCurve(this._fftData.fieldName)) {
1806+
const fftLength = this._fftData.fftLength;
1807+
const frequencyStep = 0.5 * this._fftData.blackBoxRate / fftLength;
1808+
const points = [];
1809+
for (let index = 0; index < fftLength; index++) {
1810+
const frequency = frequencyStep * index;
1811+
points.push({
1812+
x: frequency,
1813+
y: this._fftData.fftOutput[index],
1814+
});
1815+
}
1816+
this._importedPSD.addCurve(points, this._fftData.fieldName);
18061817
}
18071818
};
18081819

0 commit comments

Comments
 (0)