Last active
August 29, 2015 14:07
-
-
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
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 | |
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