Skip to content

Commit 0b469de

Browse files
committed
Fix peak drawings having glitch in them.
Sometimes ROIs would have weird artifacts in them - this fixes that, but more work needs to be done to properly fix it.
1 parent 60864f4 commit 0b469de

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

d3_resources/SpectrumChartD3.js

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6639,8 +6639,8 @@ SpectrumChartD3.prototype.drawPeaks = function() {
66396639
let roiLB = Math.max(roi.lowerEnergy,minx);
66406640
let roiUB = Math.min(roi.upperEnergy,maxx);
66416641

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 );
66446644

66456645
// Boolean to signify whether to subtract points from background
66466646
const useBackgroundSubtract = self.options.backgroundSubtract && background;
@@ -6651,26 +6651,25 @@ SpectrumChartD3.prototype.drawPeaks = function() {
66516651
if( xendind >= (points.length-2) )
66526652
xendind = points.length - 2;
66536653

6654+
if( xstartind >= xendind )
6655+
return { paths: paths };
6656+
66546657
/*The continuum values used for the first and last bin of the ROI are fudged */
66556658
/* 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;
66576660

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;
66636662

66646663
// Background Subtract - Subtract the initial y-value with the corresponding background point
66656664
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);
66676666
firsty -= background.points[bi] ? background.points[bi].y : 0;
66686667
}
66696668

66706669
//paths[0] = "M" + self.xScale(points[xstartind].x) + "," + self.yScale(firsty) + " L";
66716670
paths[0] = "M" + self.xScale(roiLB) + "," + self.yScale(firsty) + " L";
66726671

6673-
for( var j = 0; j < 2*roi.peaks.length; ++j )
6672+
for( let j = 0; j < 2*roi.peaks.length; ++j )
66746673
paths[j+1] = "";
66756674

66766675
//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() {
67106709
}//if( the centroid of this peak is in this bin )
67116710

67126711
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`
67136713
if( !paths[j+1].length ){
67146714
paths[j+1+roi.peaks.length] = "M" + self.xScale(thisx) + "," + self.yScale(thisy) + " L";
67156715
}else{
@@ -7001,7 +7001,33 @@ 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-
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+
});
70057031

70067032
for( var peaknum = 0; peaknum < roi.peaks.length; ++peaknum ){
70077033
if( leftMostFillValue[peaknum] && paths[peaknum+1].length )
@@ -7049,8 +7075,10 @@ SpectrumChartD3.prototype.drawPeaks = function() {
70497075
/* - The first path will be an underline of entire ROI
70507076
- The next roi.peaks.length entries are the fills for each of the peaks
70517077
- 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.
70527080
*/
7053-
if( num === 0 )
7081+
if( (num === 0) || !p.length )
70547082
return;
70557083

70567084
console.assert( p.startsWith("M"), "Got path not starting with 'M': " + p );

0 commit comments

Comments
 (0)