Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active August 29, 2015 14:07
  • 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/0d7433ccb5f8219671dc to your computer and use it in GitHub Desktop.
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