Skip to content

Instantly share code, notes, and snippets.

@jywarren
Created September 23, 2014 03:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jywarren/b2d8138f34c9b587cffe to your computer and use it in GitHub Desktop.
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
// 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