@@ -375,9 +375,7 @@ const fitData = new FitData()
375375
376376class Smoother {
377377 constructor ( ) {
378- this . res = null ;
379378 this . isActive = false ;
380- this . shown3D = false
381379 this . shown = false
382380 this . inpElem = document . getElementById ( 'smoothInp' )
383381 this . allColElem = document . getElementById ( 'smAllCol' )
@@ -395,44 +393,25 @@ class Smoother {
395393 }
396394 }
397395
398- colChangedProxy = ( ) => {
399- if ( ! this . allColElem . checked ) this . smoothApprox ( ) ;
400- }
401-
402- sliderChangeProxy = ( ) => {
403- if ( ! this . allBlockElem . checked ) this . smoothApprox ( ) ;
404- }
405-
406396 open = ( ) => {
407397 this . isActive = true
408398 Plotly . addTraces ( figurecontainer , iniPointsSm ) ;
409- fullData . push ( [ ] )
410- fullDataCols . push ( col )
411- legendNames . push ( 'Approximated' )
412399 this . smoothApprox ( )
413400 analytics . add ( 'smoother' )
414- if ( ! this . shown3D && is3D ) {
415- showStatus ( 'Press Ctrl+Tab to view the approximated data in 3D viewer.' )
416- this . shown3D = true
417- }
418401
419- window . addEventListener ( 'columnChanged' , this . colChangedProxy )
420- window . addEventListener ( 'sliderChanged' , this . sliderChangeProxy )
402+ window . addEventListener ( 'columnChanged' , this . smoothApprox )
403+ window . addEventListener ( 'sliderChanged' , this . smoothApprox )
421404 window . addEventListener ( 'keydown' , this . saveProxy )
422405 }
423406
424407 close = ( ) => {
425- currentEditable = 0 ;
426408 this . isActive = false
427- this . res = null
428409 try {
429410 Plotly . deleteTraces ( figurecontainer , 1 ) ;
430411 } catch ( error ) {
431412 console . log ( 'AutoSmoother Error: No trace found while trying to delete the approximated trace.' )
432413 }
433- fullData . splice ( 1 , 1 )
434- fullDataCols . splice ( 1 , 1 )
435- legendNames . splice ( 1 , 1 )
414+
436415 window . removeEventListener ( 'columnChanged' , this . colChangedProxy )
437416 window . removeEventListener ( 'sliderChanged' , this . sliderChangeProxy )
438417 window . removeEventListener ( 'keydown' , this . saveProxy )
@@ -441,39 +420,22 @@ class Smoother {
441420 smoothApprox = ( ) => {
442421 if ( ! this . isActive ) return
443422 const smtFactor = parseFloat ( this . inpElem . value )
444- const notAllCol = ! this . allColElem . checked
445- const notAllX = ! this . allBlockElem . checked
446- const cz = col . z
447423 if ( smtFactor > 1 || smtFactor < 0 ) alertElec ( "Smoothing factor must be in between 0 and 1" )
448-
449- var cx = col . x , cy = col . y ;
450- // smooth in one direction
451- this . res = data . map ( ( dat , ii ) => ( notAllX && ii != th_in ) ? dat : dat . map ( ( y , ind ) => ( ind == cx || ind == cy || ( notAllCol && ind != cz ) ) ? y : splineSmoother ( dat [ cy ] , y , smtFactor ) ) )
452- // for 2D case, we have to smooth it in two direction...
453- //NOTE: here just ignoring the other side smoothing, this is simpler and the other side can be simply done with rotating the axis
454- // if(data.length!=1) {
455- // var [cx, cy] = [cy, cx];
456- // res = expRotate(res, cx, cy)
457- // res = res.map(dat=> dat.map((y,ind)=> (ind ==cx || ind == cy|| (notAllCol && ind!=cz)) ? y : this.#smoothOut(dat[cy],y,smtFactor)))
458- // var [cx, cy] = [cy, cx]
459- // this.res= expRotate(res,cx,cy)
460- // } else{
461- // this.res = res
462- // }
463- // this.res = res
464- // if (!this.initialDone) this.initalSetup()
465- fullData [ 1 ] = this . res
466- updatePlot ( )
424+ Plotly . restyle ( figurecontainer , { x : [ dpsx ] , y : [ splineSmoother ( dpsx , dpsy , smtFactor ) ] , 'name' : [ 'Approximated' ] } , 1 )
467425 }
468426
469427 saveProxy = ( ev ) => {
470428 if ( ev . altKey && ev . key == 's' ) this . saveApprox ( )
471429 }
472430
473431 saveApprox = ( ) => {
474- // modify the data with the approximation
475- if ( this . res == null ) return
476- data = this . res
432+
433+ const smtFactor = parseFloat ( this . inpElem . value )
434+ const notAllCol = ! this . allColElem . checked
435+ const notAllX = ! this . allBlockElem . checked
436+ const cz = col . z
437+ var cx = col . x , cy = col . y ;
438+ data = data . map ( ( dat , ii ) => ( notAllX && ii != th_in ) ? dat : dat . map ( ( y , ind ) => ( ind == cx || ind == cy || ( notAllCol && ind != cz ) ) ? y : splineSmoother ( dat [ cy ] , y , smtFactor ) ) )
477439 fullData [ 0 ] = data
478440 updatePlot ( )
479441 viewer3D . update ( )
@@ -506,7 +468,7 @@ class AutoFixer {
506468 Plotly . addTraces ( figurecontainer , iniPointsSm ) ;
507469 this . runFixer ( )
508470 window . addEventListener ( 'sliderChanged' , this . runFixer )
509- window . addEventListener ( 'colChanged ' , this . runFixer )
471+ window . addEventListener ( 'columnChanged ' , this . runFixer )
510472 window . addEventListener ( 'keydown' , this . saveProxy )
511473 }
512474
@@ -520,7 +482,7 @@ class AutoFixer {
520482 console . log ( 'AutoFixer Error: No trace found while trying to delete the approximated trace.' )
521483 }
522484 window . removeEventListener ( 'sliderChanged' , this . runFixer )
523- window . removeEventListener ( 'colChanged ' , this . runFixer )
485+ window . removeEventListener ( 'columnChanged ' , this . runFixer )
524486 window . removeEventListener ( 'keydown' , this . saveProxy )
525487 }
526488
0 commit comments