This is just an exercise to implement grouping of curves according to the values of one of several possible "factors". In this example the factors are chosen only because they correspond to well-known n-somes, for n ∈ {2, 3, 4, 5}.
I've refactored this code many times, trying to make the code readable, but I think I've failed miserably in this regard, especially with the d3.js stuff. I think I just don't get d3.js... Comments welcome!
https://code.jquery.com/jquery-1.10.2.min.js
https://d3js.org/d3.v3.min.js