Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
continuous version of https://gist.github.com/jywarren/3791c67384c88d53f155 which draws a vertical line which bisects the area of the graph equally, on SpectralWorkbench.org -- for capture mode
// calculate center of area for a graph -- draws a vertical line which bisects the area of the graph equally
draw: function() {
// code to run every frame
flotoptions.grid.markings = []
// calculate total area:
var area = 0
$.each($W.data[0].data,function(i,v){
area += v[1]
})
// now find the halfway point
var count = 0
$.each($W.data[0].data,function(i,v){
if (count < area/2) { count += v[1] }
else {
// draw markers:
flotoptions.grid.markings.push({ label: "centroid", color: "yellow", lineWidth: 1, xaxis: { from: v[0], to: v[0] } });
return false
}
})
},
setup: function() {
// code to run on startup
}
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.