Created on October 21, 2014 00:25 | Updated almost 5 years ago

**Link:** https://gist.github.com/jywarren/10c2637e4a9f690b238c

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 console.log(v[0]) 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 }