@@ -94,8 +94,12 @@ GraphSpectrumPlot.getImportedSpectrumCount = function () {
9494 return this . _importedSpectrumsData . length ;
9595} ;
9696
97- GraphSpectrumPlot . addImportedSpectrumData = function ( curvesData ) {
98- this . _importedSpectrumsData . push ( curvesData ) ;
97+ GraphSpectrumPlot . addImportedSpectrumData = function ( curvesData , name ) {
98+ const curve = {
99+ points : curvesData ,
100+ name : name ,
101+ } ;
102+ this . _importedSpectrumsData . push ( curve ) ;
99103 this . _invalidateCache ( ) ;
100104 this . _invalidateDataCache ( ) ;
101105 GraphSpectrumPlot . draw ( ) ;
@@ -171,8 +175,6 @@ GraphSpectrumPlot._drawGraph = function (canvasCtx) {
171175} ;
172176
173177GraphSpectrumPlot . _drawFrequencyGraph = function ( canvasCtx ) {
174- canvasCtx . lineWidth = 1 ;
175-
176178 const HEIGHT = canvasCtx . canvas . height - MARGIN ;
177179 const WIDTH = canvasCtx . canvas . width ;
178180 const LEFT = canvasCtx . canvas . left ;
@@ -181,6 +183,7 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
181183 const PLOTTED_BUFFER_LENGTH = this . _fftData . fftLength / this . _zoomX ;
182184 const PLOTTED_BLACKBOX_RATE = this . _fftData . blackBoxRate / this . _zoomX ;
183185
186+ canvasCtx . save ( ) ;
184187 canvasCtx . translate ( LEFT , TOP ) ;
185188
186189 this . _drawGradientBackground ( canvasCtx , WIDTH , HEIGHT ) ;
@@ -225,12 +228,14 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
225228 "Chocolate" ,
226229 ] ;
227230
228- for ( let spectrumNum = 0 ; spectrumNum < this . _importedSpectrumsData . length ; spectrumNum ++ ) {
229- const curvesPonts = this . _importedSpectrumsData [ spectrumNum ] ;
231+ const spectrumCount = this . _importedSpectrumsData . length ;
232+ for ( let spectrumNum = 0 ; spectrumNum < spectrumCount ; spectrumNum ++ ) {
233+ const curvesPonts = this . _importedSpectrumsData [ spectrumNum ] . points ;
230234 const pointsCount = curvesPonts . length ;
231235 const scaleX = 2 * WIDTH / PLOTTED_BLACKBOX_RATE * this . _zoomX ;
232236
233237 canvasCtx . beginPath ( ) ;
238+ canvasCtx . lineWidth = 1 ;
234239 canvasCtx . strokeStyle = curvesColors [ spectrumNum ] ;
235240 canvasCtx . moveTo ( 0 , HEIGHT ) ;
236241 const filterPointsCount = 50 ;
@@ -259,6 +264,31 @@ GraphSpectrumPlot._drawFrequencyGraph = function (canvasCtx) {
259264 canvasCtx . stroke ( ) ;
260265 }
261266
267+ //Legend draw
268+ if ( this . _isFullScreen ) {
269+ const legendPosX = 0.84 * WIDTH ,
270+ legendPosY = 0.6 * HEIGHT ,
271+ rowHeight = 16 ,
272+ padding = 4 ,
273+ legendWidth = 0.13 * WIDTH + padding ,
274+ legendHeight = spectrumCount * rowHeight + 3 * padding ;
275+
276+ const legendArea = new Path2D ( ) ;
277+ legendArea . rect ( legendPosX , legendPosY , legendWidth , legendHeight ) ;
278+ canvasCtx . clip ( legendArea ) ;
279+ canvasCtx . strokeStyle = "gray" ;
280+ canvasCtx . strokeRect ( legendPosX , legendPosY , legendWidth , legendHeight ) ;
281+ canvasCtx . font = `${ this . _drawingParams . fontSizeFrameLabelFullscreen } pt ${ DEFAULT_FONT_FACE } ` ;
282+ canvasCtx . textAlign = "left" ;
283+ for ( let row = 0 ; row < spectrumCount ; row ++ ) {
284+ const curvesName = this . _importedSpectrumsData [ row ] . name . split ( '.' ) [ 0 ] ;
285+ const Y = legendPosY + padding + rowHeight * ( row + 1 ) ;
286+ canvasCtx . strokeStyle = curvesColors [ row ] ;
287+ canvasCtx . strokeText ( curvesName , legendPosX + padding , Y ) ;
288+ }
289+ }
290+ canvasCtx . restore ( ) ;
291+
262292 this . _drawAxisLabel (
263293 canvasCtx ,
264294 this . _fftData . fieldName ,
0 commit comments