Skip to content

Instantly share code, notes, and snippets.

@jywarren jywarren/subset.js
Created Sep 23, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.