damonblack/rcv-sim

Make graph segments consistent.

Closed this issue · 6 comments

The segments returned from the voteCounter aren't ordered consistently between rounds. The votes added in later rounds should appear to the right of previous votes.

A half-assed way to handle this would be to always show the candidates "own" votes as the leftmost segment of the candidate bar. This isn't a proper solution but it would fix the most confusing looking case, and wouldn't require a lot of rewriting.

I'm guessing a correct solution involves reworking the segment data entirely. My first thought was turning it into an array (which we'd then have control over the insert order). Another option would be adding more properties to the segment data which could be used for sorting the segments. later.

I also see ES2015 has the Map object which maintains key order and could maybe be used here. I suspect this isn't actually a good approach for a couple of reasons, but mentioning anyway for completeness.

I'd forgotten about Map! That might be what we need. I tried to work it into the existing algo, but it's just too much of mess. Needs to be rewritten. Soberly. ;)

My reservations about Map are

  • might make transpiling and/or polyfilling more complicated.
  • keys are stored in create order, and it might not be easy to manage the order like we want. this seems less concerning today than it did yesterday--keys.reverse() or wawa seems like it would match up OK.

I tried to work it into the existing algo, but it's just too much of mess. Needs to be rewritten. Soberly. ;)

Earlier you invited me to rewrite this. Right now I'm still in explore mode, but I might take a swing at it later. If I do rewrite it, I might change some things in the presentation. Or might not. Your way isn't the way I had originally imagined, but it works.

I'd be fine with that. I'm moving rather slowly here is the only caveat.

Resolved with PR #11