@@ -7001,7 +7001,7 @@ 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
- // TODO: We should be able to use this next line to make the paths for peaks, but it ends up being a bit wonky
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 (See commit fc790795b24d21431467c32ca189c05e2f9b0f12 for when this issue was introduced)
7005
7005
//peakamplitudes.reverse().forEach( function(peakamps,xindex){ makePathForPeak(peakamps,xindex,false); } );
7006
7006
// But if we use this next loop instead, things are fine:
7007
7007
peakamplitudes . reverse ( ) . forEach ( function ( peakamps , xindex ) {
@@ -10763,14 +10763,14 @@ SpectrumChartD3.prototype.getCountsForEnergy = function(spectrum, energy) {
10763
10763
10764
10764
10765
10765
10766
- /* Returns the data y-range for the currently viewed x-range. */
10766
+ /* Returns the data y-range for the currently viewed x-range. Third element of returned array gives smallest non-zero height in the range */
10767
10767
SpectrumChartD3 . prototype . getYAxisDataDomain = function ( ) {
10768
10768
var self = this ;
10769
10769
10770
10770
if ( ! self . rawData || ! self . rawData . spectra || ! self . rawData . spectra . length )
10771
- return [ 0 , 3000 ] ;
10771
+ return [ 0 , 3000 , self . options . logYAxisMin ] ;
10772
10772
10773
- var y0 , y1 ;
10773
+ var y0 , y1 , minNonZeroY0 = self . options . logYAxisMin ;
10774
10774
var minx = self . xScale . domain ( ) [ 0 ] , maxx = self . xScale . domain ( ) [ 1 ] ;
10775
10775
var foreground = self . rawData . spectra [ 0 ] ;
10776
10776
var firstData = self . displayed_start ( foreground ) ;
@@ -10780,6 +10780,7 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
10780
10780
if ( firstData >= 0 ) {
10781
10781
const forkey = self . options . backgroundSubtract && ( 'bgsubtractpoints' in foreground ) ? 'bgsubtractpoints' : 'points' ;
10782
10782
y0 = y1 = foreground [ forkey ] [ firstData ] . y ;
10783
+ if ( y0 > 0 ) minNonZeroY0 = y0 ;
10783
10784
10784
10785
self . rawData . spectra . forEach ( function ( spectrum ) {
10785
10786
// Don't consider background spectrum if we're viewing the Background Subtract
@@ -10790,8 +10791,10 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
10790
10791
10791
10792
for ( var i = firstData ; i < lastData ; i ++ ) {
10792
10793
if ( spectrum [ speckey ] [ i ] ) {
10793
- y0 = Math . min ( y0 , spectrum [ speckey ] [ i ] . y ) ;
10794
- y1 = Math . max ( y1 , spectrum [ speckey ] [ i ] . y ) ;
10794
+ const y = spectrum [ speckey ] [ i ] . y ;
10795
+ y0 = Math . min ( y0 , y ) ;
10796
+ y1 = Math . max ( y1 , y ) ;
10797
+ if ( y > 0 ) minNonZeroY0 = Math . min ( minNonZeroY0 , y ) ;
10795
10798
}
10796
10799
}
10797
10800
} ) ;
@@ -10803,7 +10806,7 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
10803
10806
if ( y0 > y1 ) { y1 = [ y0 , y0 = y1 ] [ 0 ] ; }
10804
10807
if ( y0 == y1 ) { y0 -= 1 ; y1 += 1 ; }
10805
10808
10806
- return [ y0 , y1 ] ;
10809
+ return [ y0 , y1 , minNonZeroY0 ] ;
10807
10810
}
10808
10811
10809
10812
/**
@@ -10822,11 +10825,15 @@ SpectrumChartD3.prototype.getYAxisDomain = function(){
10822
10825
10823
10826
10824
10827
if ( self . options . yscale == "log" ) {
10825
- /*Specify the (approx) fraction of the chart that the scale should extend */
10826
- /* past where the data where hit. */
10828
+ // Specify the (approx) fraction of the chart that the scale should extend past the data
10827
10829
var yfractop = self . options . logYFracTop , yfracbottom = self . options . logYFracBottom ;
10828
10830
10829
10831
var y0Intitial = ( ( y0 <= 0.0 ) ? self . options . logYAxisMin : y0 ) ;
10832
+
10833
+ // If the y-range doesnt go above 1.0, lets set the y-axis minimum to be based on minimum non-zero counts
10834
+ if ( ( y0 <= 0.0 ) && ( yrange . length > 2 ) && ( yrange [ 2 ] > 0.0 ) && ( yrange [ 2 ] < self . options . logYAxisMin ) && ( yrange [ 1 ] < 1 ) )
10835
+ y0 = y0Intitial = 0.5 * yrange [ 2 ] ;
10836
+
10830
10837
var y1Intitial = ( ( y1 <= 0.0 ) ? 1.0 : y1 ) ;
10831
10838
y1Intitial = ( ( y1Intitial <= y0Intitial ) ? 1.1 * y0Intitial : y1Intitial ) ;
10832
10839
0 commit comments