@@ -6639,8 +6639,8 @@ SpectrumChartD3.prototype.drawPeaks = function() {
6639
6639
let roiLB = Math . max ( roi . lowerEnergy , minx ) ;
6640
6640
let roiUB = Math . min ( roi . upperEnergy , maxx ) ;
6641
6641
6642
- var xstartind = bisector . left ( points , roiLB ) ;
6643
- var xendind = bisector . right ( points , roiUB ) ;
6642
+ let xstartind = bisector . left ( points , roiLB ) ;
6643
+ let xendind = bisector . right ( points , roiUB ) ;
6644
6644
6645
6645
// Boolean to signify whether to subtract points from background
6646
6646
const useBackgroundSubtract = self . options . backgroundSubtract && background ;
@@ -6651,26 +6651,25 @@ SpectrumChartD3.prototype.drawPeaks = function() {
6651
6651
if ( xendind >= ( points . length - 2 ) )
6652
6652
xendind = points . length - 2 ;
6653
6653
6654
+ if ( xstartind >= xendind )
6655
+ return { paths : paths } ;
6656
+
6654
6657
/*The continuum values used for the first and last bin of the ROI are fudged */
6655
6658
/* for now... To be fixed */
6656
- var thisy = null , thisx = null , m , s , peak_area , cont_area ;
6659
+ let thisy = null , thisx = null , m , s , peak_area , cont_area ;
6657
6660
6658
- //Need to go thorugh and get min/max, in px of each ROI, and save it somehome
6659
- // so we can draw the line in only the ROI's y-domain
6660
- //var minyval_px = self.size.height
6661
- // , maxyval_py = 0;
6662
- var firsty = self . offset_integral ( roi , points [ xstartind - ( xstartind ?1 :0 ) ] . x , points [ xstartind + ( xstartind ?0 :1 ) ] . x ) * scaleFactor ;
6661
+ let firsty = self . offset_integral ( roi , points [ xstartind - ( xstartind ?1 :0 ) ] . x , points [ xstartind + ( xstartind ?0 :1 ) ] . x ) * scaleFactor ;
6663
6662
6664
6663
// Background Subtract - Subtract the initial y-value with the corresponding background point
6665
6664
if ( useBackgroundSubtract ) {
6666
- var bi = bisector . left ( background . points , points [ xstartind - ( xstartind ?1 :0 ) ] . x ) ;
6665
+ const bi = bisector . left ( background . points , points [ xstartind - ( xstartind ?1 :0 ) ] . x ) ;
6667
6666
firsty -= background . points [ bi ] ? background . points [ bi ] . y : 0 ;
6668
6667
}
6669
6668
6670
6669
//paths[0] = "M" + self.xScale(points[xstartind].x) + "," + self.yScale(firsty) + " L";
6671
6670
paths [ 0 ] = "M" + self . xScale ( roiLB ) + "," + self . yScale ( firsty ) + " L" ;
6672
6671
6673
- for ( var j = 0 ; j < 2 * roi . peaks . length ; ++ j )
6672
+ for ( let j = 0 ; j < 2 * roi . peaks . length ; ++ j )
6674
6673
paths [ j + 1 ] = "" ;
6675
6674
6676
6675
//Go from left to right and create lower path for each of the outlines that sit on the continuum
@@ -6710,6 +6709,7 @@ SpectrumChartD3.prototype.drawPeaks = function() {
6710
6709
} //if( the centroid of this peak is in this bin )
6711
6710
6712
6711
if ( roi . peaks . length === 1 || ( ( vr [ 0 ] <= x1 ) && ( vr [ 1 ] >= x0 ) ) || ( ( thisx >= vr [ 0 ] ) && ( thisx < vr [ 1 ] ) ) ) {
6712
+ // This next index looks suspect, should it be `j+1+roi.peaks.length`
6713
6713
if ( ! paths [ j + 1 ] . length ) {
6714
6714
paths [ j + 1 + roi . peaks . length ] = "M" + self . xScale ( thisx ) + "," + self . yScale ( thisy ) + " L" ;
6715
6715
} else {
@@ -7001,7 +7001,33 @@ SpectrumChartD3.prototype.drawPeaks = function() {
7001
7001
//console.log( 'minypx=' + minypx + ', maxypx=' + maxypx + ' height=' + self.size.height );
7002
7002
7003
7003
//go right to left and draw the fill areas top
7004
- peakamplitudes . reverse ( ) . forEach ( function ( peakamps , xindex ) { makePathForPeak ( peakamps , xindex , false ) ; } ) ;
7004
+ // TODO: We should be able to use this next line to make the paths for peaks, but it ends up being a bit wonky
7005
+ //peakamplitudes.reverse().forEach( function(peakamps,xindex){ makePathForPeak(peakamps,xindex,false); } );
7006
+ // But if we use this next loop instead, things are fine:
7007
+ peakamplitudes . reverse ( ) . forEach ( function ( peakamps , xindex ) {
7008
+ var cont = peakamps [ 0 ] ;
7009
+ var thisx = peakamps [ 1 ] ;
7010
+
7011
+ peakamps . forEach ( function ( peakamp , peakindex ) {
7012
+ if ( peakindex < 2 )
7013
+ return ;
7014
+
7015
+ const peaknum = ( peakindex - 2 ) ;
7016
+ const peak = roi . peaks [ peaknum ] ;
7017
+ const m = peak . Centroid [ 0 ] ;
7018
+ const s = peak . Width [ 0 ] ;
7019
+ const vr = peak . visRange ? peak . visRange : [ ( m - 5 * s ) , ( m + 5 * s ) ] ;
7020
+
7021
+ if ( ( roi . peaks . length > 1 ) && ( ( thisx < vr [ 0 ] ) || ( thisx > vr [ 1 ] ) ) )
7022
+ return ;
7023
+
7024
+ var thisy = cont ;
7025
+ for ( var j = 2 ; j <= peakindex ; ++ j )
7026
+ thisy += peakamps [ j ] ;
7027
+
7028
+ paths [ peaknum + 1 ] += " " + self . xScale ( thisx ) + "," + self . yScale ( thisy ) ;
7029
+ } ) ;
7030
+ } ) ;
7005
7031
7006
7032
for ( var peaknum = 0 ; peaknum < roi . peaks . length ; ++ peaknum ) {
7007
7033
if ( leftMostFillValue [ peaknum ] && paths [ peaknum + 1 ] . length )
@@ -7049,8 +7075,10 @@ SpectrumChartD3.prototype.drawPeaks = function() {
7049
7075
/* - The first path will be an underline of entire ROI
7050
7076
- The next roi.peaks.length entries are the fills for each of the peaks
7051
7077
- The next roi.peaks.length entries are the path of the peak, that sits on the ROI
7078
+
7079
+ If a peak in the ROI is not visible (ROI partially off screen), then path will be empty.
7052
7080
*/
7053
- if ( num === 0 )
7081
+ if ( ( num === 0 ) || ! p . length )
7054
7082
return ;
7055
7083
7056
7084
console . assert ( p . startsWith ( "M" ) , "Got path not starting with 'M': " + p ) ;
0 commit comments