@@ -330,33 +330,35 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
330330 const WIDTH = canvasCtx . canvas . width - ACTUAL_MARGIN_LEFT ;
331331 const LEFT = canvasCtx . canvas . offsetLeft + ACTUAL_MARGIN_LEFT ;
332332 const TOP = canvasCtx . canvas . offsetTop ;
333-
334333 const PLOTTED_BLACKBOX_RATE = this . _fftData . blackBoxRate / this . _zoomX ;
335334
336- canvasCtx . save ( ) ;
337- canvasCtx . translate ( LEFT , TOP ) ;
338- this . _drawGradientBackground ( canvasCtx , WIDTH , HEIGHT ) ;
339-
340- const pointsCount = this . _fftData . fftLength ;
341- const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this . _zoomX ;
342- canvasCtx . beginPath ( ) ;
343- canvasCtx . lineWidth = 1 ;
344- canvasCtx . strokeStyle = "white" ;
345-
346335 // Allign y axis range by 10db
336+ const minimum = Math . min ( this . _fftData . minimum , this . _importedPSD . minY ) ,
337+ maximum = Math . max ( this . _fftData . maximum , this . _importedPSD . maxY ) ;
347338 const dbStep = 10 ;
348- const minY = Math . floor ( this . _fftData . minimum / dbStep ) * dbStep ;
349- let maxY = ( Math . floor ( this . _fftData . maximum / dbStep ) + 1 ) * dbStep ;
339+ const minY = Math . floor ( minimum / dbStep ) * dbStep ;
340+ let maxY = ( Math . floor ( maximum / dbStep ) + 1 ) * dbStep ;
350341 if ( minY == maxY ) {
351342 maxY = minY + 1 ; // prevent divide by zero
352343 }
353- const ticksCount = ( maxY - minY ) / dbStep ;
354- const scaleY = HEIGHT / ( maxY - minY ) ;
355344 //Store vsRange for _drawMousePosition
356345 this . _fftData . vsRange = {
357346 min : minY ,
358347 max : maxY ,
359348 } ;
349+
350+ const ticksCount = ( maxY - minY ) / dbStep ;
351+ const pointsCount = this . _fftData . fftLength ;
352+ const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this . _zoomX ;
353+ const scaleY = HEIGHT / ( maxY - minY ) ;
354+
355+ canvasCtx . save ( ) ;
356+ canvasCtx . translate ( LEFT , TOP ) ;
357+ this . _drawGradientBackground ( canvasCtx , WIDTH , HEIGHT ) ;
358+
359+ canvasCtx . beginPath ( ) ;
360+ canvasCtx . lineWidth = 1 ;
361+ canvasCtx . strokeStyle = "white" ;
360362 canvasCtx . moveTo ( 0 , 0 ) ;
361363 for ( let pointNum = 0 ; pointNum < pointsCount ; pointNum ++ ) {
362364 const freq = PLOTTED_BLACKBOX_RATE / 2 * pointNum / pointsCount ;
@@ -365,6 +367,29 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
365367 }
366368 canvasCtx . stroke ( ) ;
367369
370+ const spectrumCount = this . _importedPSD . curvesCount ( ) ;
371+ for ( let spectrumNum = 0 ; spectrumNum < spectrumCount ; spectrumNum ++ ) {
372+ const curvesPonts = this . _importedPSD . _curvesData [ spectrumNum ] . points ;
373+ const pointsCount = curvesPonts . length ;
374+
375+ canvasCtx . beginPath ( ) ;
376+ canvasCtx . lineWidth = 1 ;
377+ canvasCtx . strokeStyle = this . curvesColors [ spectrumNum ] ;
378+ canvasCtx . moveTo ( 0 , HEIGHT ) ;
379+ const filterPointsCount = 100 ;
380+ for ( const point of curvesPonts ) {
381+ canvasCtx . lineTo ( point . x * scaleX , HEIGHT - ( point . y - minY ) * scaleY ) ;
382+ }
383+ canvasCtx . stroke ( ) ;
384+ }
385+
386+ //Legend draw
387+ if ( this . _isFullScreen && spectrumCount > 0 ) {
388+ canvasCtx . save ( ) ;
389+ this . _drawLegend ( canvasCtx , WIDTH , HEIGHT , this . _importedPSD . _curvesData ) ;
390+ canvasCtx . restore ( ) ;
391+ }
392+
368393 this . _drawAxisLabel (
369394 canvasCtx ,
370395 this . _fftData . fieldName ,
@@ -405,8 +430,6 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
405430 "rgba(255,0,0,0.50)" ,
406431 3 ,
407432 ) ;
408-
409- canvasCtx . restore ( ) ;
410433} ;
411434
412435GraphSpectrumPlot . _drawLegend = function ( canvasCtx , WIDTH , HEIGHT , importedCurves ) {
@@ -432,6 +455,7 @@ GraphSpectrumPlot._drawLegend = function (canvasCtx, WIDTH, HEIGHT, importedCurv
432455 canvasCtx . strokeText ( curvesName , legendPosX + padding , Y ) ;
433456 }
434457}
458+
435459GraphSpectrumPlot . getPSDbyFreq = function ( frequency ) {
436460 let freqIndex = Math . round ( 2 * frequency / this . _fftData . blackBoxRate * ( this . _fftData . fftOutput . length - 1 ) ) ;
437461 freqIndex = Math . min ( freqIndex , this . _fftData . fftOutput . length - 1 ) ;
0 commit comments