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.
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
// 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