Skip to content

Instantly share code, notes, and snippets.

@jywarren
Created October 21, 2014 00:23
  • 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/10c2637e4a9f690b238c to your computer and use it in GitHub Desktop.
Calculate center of area for a graph -- draws a vertical line which bisects the area of the graph equally, on SpectralWorkbench.org. This variant only counts data between 410-700nm.
// calculate center of area for a graph -- draws a vertical line which bisects the area of the graph equally
setup: function() {
// code to run on startup
flotoptions.grid.markings = []
var color_count = 0
// go through each spectrum
$.each($W.data,function(index,spectrum){
// calculate total area:
var area = 0
$.each(spectrum.data,function(i,v){
if (v[0] > 410 && v[0] < 700) area += v[1]
})
// now find the halfway point
var count = 0
$W.colors = flotoptions.colors
$.each(spectrum.data,function(i,v){
if (v[0] > 410 && v[0] < 700) {
if (count < area/2) { count += v[1] }
else {
// draw markers:
color = flotoptions.colors[color_count]
color_count += 1
flotoptions.grid.markings.push({ color: color, lineWidth: 1, xaxis: { from: v[0], to: v[0] } });
return false
}
}
})
})
$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