Skip to content

Instantly share code, notes, and snippets.

@dsernst
Created September 13, 2016 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsernst/f5956b4754e7d34f84fedc36c9ae6bac to your computer and use it in GitHub Desktop.
Save dsernst/f5956b4754e7d34f84fedc36c9ae6bac to your computer and use it in GitHub Desktop.
How to arrange a complex linked list? For visualizing Liquid Democracy

How to arrange a complex linked list?

Given a singly linked list like this:

[
  {
    uid: 'a',
    full_name: 'Angela Augustine',
    next: 'c',
  },
  {
    uid: 'b',
    full_name: 'Ben Botticelli',
    next: 'd',
  },
  {
    uid: 'c',
    full_name: 'Carl Campbell',
    next: 'a',
  },
  {
    uid: 'd',
    full_name: 'Dalia Douglass',
    next: 'b',
  },
  {
    uid: 'e',
    full_name: 'Eva Ernst',
    next: 'a',
  },
  {
    uid: 'f',
    full_name: 'Franklin Fishburne',
    next: 'a',
  },
  {
    uid: 'g',
    full_name: 'Grant Gordon',
    next: 'a',
  },
  {
    uid: 'h',
    full_name: 'Heather Highgarden',
    next: 'a',
  },
]

How would you arrange the nodes in two dimensions for clarity?

The Reingold-Tilford algorithm that @mbostock uses in Radial Reingold–Tilford Tree is very nice looking, but breaks down in our use case because it doesn't have any cycles. Ours won't have a single node in the center without a pointer.

Maybe this will work: http://bl.ocks.org/mbostock/1153292

@dsernst
Copy link
Author

dsernst commented Apr 7, 2017

This is now live at https://demo.liquid.vote

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment