Clip off the top and bottom 2% by area from each end of the data (averaging for multiple graphs) for a better use of graph real-estate on SpectralWorkbench.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clip off the top and bottom 2% by area from each end of the data (averaging for multiple graphs) for a better use of graph real-estate on SpectralWorkbench.org | |
setup: function() { | |
// code to run on startup | |
var area = 0, end = 0, start = 0 | |
// go through each spectrum | |
$.each($W.data,function(index,spectrum){ | |
// calculate total area: | |
$.each(spectrum.data,function(i,v){ | |
area += v[1] | |
}) | |
}) | |
// average area: | |
area /= $W.data.length | |
// start at beginning | |
$.each($W.data,function(index,spectrum){ | |
// now find the halfway point | |
var count = 0 | |
$.each(spectrum.data,function(i,v){ | |
// continue if still under 2% of area: | |
if (count < area/50) { count += v[1] } | |
else { | |
start += v[0] | |
return false | |
} | |
}) | |
// start at end | |
var count = 0 | |
$.each(spectrum.data.reverse(),function(i,v){ | |
// continue if still under 2% of area: | |
if (count < area/50) { count += v[1] } | |
else { | |
end += v[0] | |
return false | |
} | |
}) | |
}) | |
end /= $W.data.length | |
start /= $W.data.length | |
flotoptions.xaxis.min = start | |
flotoptions.xaxis.max = end | |
$W.plot = $.plot($("#graph"),$W.data,flotoptions); | |
}, | |
draw: function() { | |
// code to run every frame | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment