Skip to content

Commit e98a3ba

Browse files
committed
Have spectrum JS allow for small y-values, when largest visible value is 1.0 or less
1 parent 3418455 commit e98a3ba

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

d3_resources/SpectrumChartD3.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7001,7 +7001,7 @@ SpectrumChartD3.prototype.drawPeaks = function() {
70017001
//console.log( 'minypx=' + minypx + ', maxypx=' + maxypx + ' height=' + self.size.height );
70027002

70037003
//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)
70057005
//peakamplitudes.reverse().forEach( function(peakamps,xindex){ makePathForPeak(peakamps,xindex,false); } );
70067006
// But if we use this next loop instead, things are fine:
70077007
peakamplitudes.reverse().forEach( function(peakamps,xindex){
@@ -10763,14 +10763,14 @@ SpectrumChartD3.prototype.getCountsForEnergy = function(spectrum, energy) {
1076310763

1076410764

1076510765

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 */
1076710767
SpectrumChartD3.prototype.getYAxisDataDomain = function(){
1076810768
var self = this;
1076910769

1077010770
if( !self.rawData || !self.rawData.spectra || !self.rawData.spectra.length )
10771-
return [0, 3000];
10771+
return [0, 3000, self.options.logYAxisMin];
1077210772

10773-
var y0, y1;
10773+
var y0, y1, minNonZeroY0 = self.options.logYAxisMin;
1077410774
var minx = self.xScale.domain()[0], maxx = self.xScale.domain()[1];
1077510775
var foreground = self.rawData.spectra[0];
1077610776
var firstData = self.displayed_start(foreground);
@@ -10780,6 +10780,7 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
1078010780
if( firstData >= 0 ){
1078110781
const forkey = self.options.backgroundSubtract && ('bgsubtractpoints' in foreground) ? 'bgsubtractpoints' : 'points';
1078210782
y0 = y1 = foreground[forkey][firstData].y;
10783+
if( y0 > 0 ) minNonZeroY0 = y0;
1078310784

1078410785
self.rawData.spectra.forEach(function(spectrum) {
1078510786
// Don't consider background spectrum if we're viewing the Background Subtract
@@ -10790,8 +10791,10 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
1079010791

1079110792
for (var i = firstData; i < lastData; i++) {
1079210793
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 );
1079510798
}
1079610799
}
1079710800
});
@@ -10803,7 +10806,7 @@ SpectrumChartD3.prototype.getYAxisDataDomain = function(){
1080310806
if( y0 > y1 ) { y1 = [y0, y0 = y1][0]; }
1080410807
if( y0 == y1 ){ y0 -=1; y1 += 1; }
1080510808

10806-
return [y0, y1];
10809+
return [y0, y1, minNonZeroY0];
1080710810
}
1080810811

1080910812
/**
@@ -10822,11 +10825,15 @@ SpectrumChartD3.prototype.getYAxisDomain = function(){
1082210825

1082310826

1082410827
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
1082710829
var yfractop = self.options.logYFracTop, yfracbottom = self.options.logYFracBottom;
1082810830

1082910831
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+
1083010837
var y1Intitial = ((y1<=0.0) ? 1.0 : y1);
1083110838
y1Intitial = ((y1Intitial<=y0Intitial) ? 1.1*y0Intitial : y1Intitial);
1083210839

0 commit comments

Comments
 (0)