@@ -57,6 +57,7 @@ GraphSpectrumPlot.initialize = function (canvas, sysConfig) {
5757 this . _logRateWarning = undefined ;
5858 this . _zoomX = 1 ;
5959 this . _zoomY = 1 ;
60+ this . _importedSpectrumData = null ;
6061} ;
6162
6263GraphSpectrumPlot . setZoom = function ( zoomX , zoomY ) {
@@ -89,6 +90,12 @@ GraphSpectrumPlot.setData = function (fftData, spectrumType) {
8990 this . _invalidateDataCache ( ) ;
9091} ;
9192
93+ GraphSpectrumPlot . setImportedSpectrumData = function ( curvesData ) {
94+ this . _importedSpectrumData = curvesData ;
95+ this . _invalidateCache ( ) ;
96+ this . _invalidateDataCache ( ) ;
97+ GraphSpectrumPlot . draw ( ) ;
98+ } ;
9299GraphSpectrumPlot . setOverdraw = function ( overdrawType ) {
93100 this . _overdrawType = overdrawType ;
94101 this . _invalidateCache ( ) ;
@@ -187,7 +194,7 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
187194 "rgba(255,128,128,1.0)"
188195 ) ;
189196
190- canvasCtx . fillStyle = barGradient ; //'rgba(0,255,0,0.3)'; //green
197+ canvasCtx . fillStyle = barGradient ;
191198
192199 const fftScale = HEIGHT / ( this . _zoomY * 100 ) ;
193200 for ( let i = 0 ; i < PLOTTED_BUFFER_LENGTH ; i += 10 ) {
@@ -196,6 +203,41 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
196203 x += barWidth + 1 ;
197204 }
198205
206+
207+ //Draw imported spectrum
208+ if ( this . _importedSpectrumData ) {
209+ const curvesPonts = this . _importedSpectrumData ;
210+ const pointsCount = curvesPonts . length ;
211+ const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this . _zoomX ;
212+
213+ canvasCtx . beginPath ( ) ;
214+ canvasCtx . strokeStyle = "cyan" ;
215+ canvasCtx . moveTo ( 0 , HEIGHT ) ;
216+ const filterPointsCount = 20 ;
217+ for ( let i = 0 ; i < pointsCount ; i ++ ) {
218+ // Apply moving average filter at spectrum points to get visible line
219+ let filterStartPoint = i - filterPointsCount / 2 ;
220+ if ( filterStartPoint < 0 ) {
221+ filterStartPoint = 0 ;
222+ }
223+ let filterStopPoint = filterStartPoint + filterPointsCount ;
224+ if ( filterStopPoint > pointsCount ) {
225+ filterStopPoint = pointsCount ;
226+ filterStartPoint = filterStopPoint - filterPointsCount ;
227+ if ( filterStartPoint < 0 ) {
228+ filterStartPoint = 0 ;
229+ }
230+ }
231+ let middleValue = 0 ;
232+ for ( let j = filterStartPoint ; j < filterStopPoint ; j ++ ) {
233+ middleValue += curvesPonts [ j ] . value ;
234+ }
235+ middleValue /= filterPointsCount ;
236+
237+ canvasCtx . lineTo ( curvesPonts [ i ] . freq * scaleX , HEIGHT - middleValue * fftScale ) ;
238+ }
239+ canvasCtx . stroke ( ) ;
240+ }
199241 this . _drawAxisLabel (
200242 canvasCtx ,
201243 this . _fftData . fieldName ,
0 commit comments