Skip to content

Commit 143ef27

Browse files
committed
Add option to change minimum displayed y-axis value, when there is a channel with zero or less counts present.
1 parent 3b38939 commit 143ef27

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

d3_resources/SpectrumChartD3.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ SpectrumChartD3 = function(elem, options) {
127127
// The rotation angle of the labels. A negative value rotates it the direction you probably want.
128128
// A value of 0 is horizontal, a value of -90 is vertical (i.e. up-and-down). Only tested [0,-90]
129129
self.options.peakLabelRotation = (typeof options.peakLabelRotation == 'number') ? options.peakLabelRotation : 0;
130+
self.options.logYAxisMin = ((typeof options.logYAxisMin == 'number') && (options.logYAxisMin > 0)) ? options.logYAxisMin : 0.1;
131+
130132

131133
self.setLocalizations( {}, true );//Set default localization strings
132134

@@ -4697,6 +4699,7 @@ SpectrumChartD3.prototype.setShowLegend = function( show ) {
46974699
* -------------- Y-axis Functions --------------
46984700
*/
46994701
SpectrumChartD3.prototype.yticks = function() {
4702+
const self = this;
47004703
var ticks = [];
47014704
var EPSILON = 1.0E-3;
47024705

@@ -4705,9 +4708,9 @@ SpectrumChartD3.prototype.yticks = function() {
47054708

47064709
var formatYNumber = function(v) {
47074710
/*poorly simulating "%.3g" in snprintf */
4708-
/*SHould get rid of so many regexs, and shorten code (shouldnt there be a builtin function to print to "%.3"?) */
4711+
/*Should get rid of so many regexs, and shorten code (shouldnt there be a builtin function to print to "%.3"?) */
47094712
var t;
4710-
if( v >= 1000 || v < 0.1 )
4713+
if( v >= 1000 || v < self.options.logYAxisMin )
47114714
{
47124715
t = v.toPrecision(3);
47134716
t = t.replace(/\.0+e/g, "e").replace(/\.0+$/g, "");
@@ -4800,9 +4803,11 @@ SpectrumChartD3.prototype.yticks = function() {
48004803

48014804
if( this.options.yscale === "log" )
48024805
{
4806+
const yMinPrefPow = Math.floor( Math.log10(this.options.logYAxisMin) );
4807+
48034808
/*Get the power of 10 just below or equal to rendermin. */
4804-
var minpower = (renderymin > 0.0) ? Math.floor( Math.log10(renderymin) ) : -1;
4805-
4809+
var minpower = (renderymin > 0.0) ? Math.floor( Math.log10(renderymin) ) : yMinPrefPow;
4810+
48064811
/*Get the power of 10 just above or equal to renderymax. If renderymax */
48074812
/* is less than or equal to 0, set power to be 0. */
48084813
var maxpower = (renderymax > 0.0) ? Math.ceil( Math.log10(renderymax) ): 0;
@@ -4813,12 +4818,12 @@ SpectrumChartD3.prototype.yticks = function() {
48134818
/*Happens when renderymin==renderymax which is a power of 10 */
48144819
++maxpower;
48154820
--minpower;
4816-
}else if( maxpower > 2 && minpower < -1)
4821+
}else if( maxpower > 2 && minpower < yMinPrefPow)
48174822
{
48184823
/*We had a tiny value (possibly a fraction of a count), as well as a */
48194824
/* large value (>1000). */
4820-
minpower = -1;
4821-
}else if( maxpower >= 0 && minpower < -1 && (maxpower-minpower) > 6 )
4825+
minpower = yMinPrefPow;
4826+
}else if( maxpower >= 0 && minpower < yMinPrefPow && (maxpower-minpower) > 6 )
48224827
{
48234828
/*we had a tiny power (1.0E-5), as well as one between 1 and 999, */
48244829
/* so we will only show the most significant decades */
@@ -8579,6 +8584,10 @@ SpectrumChartD3.prototype.setPeakLabelRotation = function(d) {
85798584
this.options.peakLabelRotation = (typeof d == 'number') ? d : 0;
85808585
}
85818586

8587+
SpectrumChartD3.prototype.setLogYAxisMin = function(d) {
8588+
this.options.logYAxisMin = (typeof d == 'number') && (d > 0.0) ? d : 0.1;
8589+
}
8590+
85828591
SpectrumChartD3.prototype.setSearchWindows = function(ranges) {
85838592
var self = this;
85848593

@@ -10833,7 +10842,7 @@ SpectrumChartD3.prototype.getYAxisDomain = function(){
1083310842
/* past where the data where hit. */
1083410843
var yfractop = self.options.logYFracTop, yfracbottom = self.options.logYFracBottom;
1083510844

10836-
var y0Intitial = ((y0<=0.0) ? 0.1 : y0);
10845+
var y0Intitial = ((y0<=0.0) ? self.options.logYAxisMin : y0);
1083710846
var y1Intitial = ((y1<=0.0) ? 1.0 : y1);
1083810847
y1Intitial = ((y1Intitial<=y0Intitial) ? 1.1*y0Intitial : y1Intitial);
1083910848

@@ -10846,7 +10855,7 @@ SpectrumChartD3.prototype.getYAxisDomain = function(){
1084610855
var ylower = Math.pow( 10.0, logLowerY );
1084710856
var yupper = Math.pow( 10.0, logUpperY );
1084810857

10849-
y0 = ((y0<=0.0) ? 0.1 : ylower);
10858+
y0 = ((y0<=0.0) ? self.options.logYAxisMin : ylower);
1085010859
y1 = ((y1<=0.0) ? 1.0 : yupper);
1085110860
} else if( self.options.yscale == "lin" ) {
1085210861
y0 = ((y0 <= 0.0) ? (1+self.options.linYFracBottom)*y0 : (1-self.options.linYFracBottom)*y0);

0 commit comments

Comments
 (0)