Accepted answer

what you already have looks like a good start to me. the basic pattern is this.

  • render a default selection when the csv is loaded.
  • when the selection changes, filter the data to display like you already do. you might want to keep a reference to the currently selected data somewhere. remember that your filter function can be something arbitrarily complex, i.e. you can check all the conditions you like.
  • select all the train paths and pass in the new data. you will need to provide a key function (second argument to .data(), see here) to make sure that data and lines are matched correctly.
  • handle the enter/update/exit selections. start without transitions first and then add them.

how exactly you want to do the transitions depends on you, but you could have for example enter and exit selection fading in and out like so.

selection.enter().append("path").attr("opacity", 0).transition().attr("opacity", 1);
selection.exit().transition().attr("opacity", 0).remove();

Related Query

More Query from same tag