Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hexagons! #31

Open
wants to merge 8 commits into
base: gh-pages
Choose a base branch
from
Open

Hexagons! #31

wants to merge 8 commits into from

Commits on Mar 28, 2019

  1. Add HexJSON representation of constituencies

    This file represents every UK parliamentary constituency as a hexagon
    arranged on a grid that maintains a semblance of geography.  This will let
    us show a different view of the UK that won't be overwhelmed by all the
    sparsely populated rural constituencies and hide all the densely populated
    urban constituencies.  The data was created by the [ODI Leeds][odi-leeds]
    as part of their [Hexmaps project][odi-hexmaps], thanks to them for making
    the data open; it makes things better!
    
    [odi-leeds]: https://odileeds.org
    [odi-leeds-hexmaps]: https://odileeds.org/projects/hexmaps/constituencies/
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    21726d9 View commit details
    Browse the repository at this point in the history
  2. Add D3 plugin for rendering HexJSON files

    [This plugin][d3-hexjson], by [Oli Hawkins][oli-hawkins], lets us render
    the hexjson file via D3.
    
    [d3-hexjson]: https://github.com/olihawkins/d3-hexjson
    [oli-hawkins]: https://olihawkins.com/
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    acc4b5d View commit details
    Browse the repository at this point in the history
  3. Pass constituency id, not constituency object in event

    The object we send to the events is the constituency representation from
    the topo json file.  The structure of this object will be different when
    we introduce the hex json version.  As it happens we only use the id of
    the constituency in any of our handlers, and this will be present on the
    hex json objects, so we can just pass that instead.
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    5748e30 View commit details
    Browse the repository at this point in the history
  4. Introduce PetitionMap.mapMode and draw some hexagons

    If the mapMode is set to `topo` (the default) we draw the geographic maps
    we always used to.  If we set it to `hex` though, we'll draw the hexagon
    map based on the hexJSON file from the ODI.  We don't need the projection
    and path stuff from the topo json maps because those are to do with
    translating spherical maps onto a flat plane.  Other than that though, it
    is pretty straightforward.  Our hex rendering is based pretty strongly on
    the examples from the [d3-hexjson project][d3-hexjson].
    
    [d3-hexjson]: https://github.com/olihawkins/d3-hexjson/
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    921bf37 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    6947ef9 View commit details
    Browse the repository at this point in the history
  6. Remove arbitrary zoom limit

    I'm not sure why we have it and I can't see any downsides to letting
    people zoom in or out as much as they want.
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    7c537c6 View commit details
    Browse the repository at this point in the history
  7. Give credit for hex maps in about page

    Also for the d3-hexjson library.
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    722ba23 View commit details
    Browse the repository at this point in the history
  8. Add hexjson files for map subdivisions

    Originally I hoped to just filter the uk map to only include the relevant
    constituencies, but for some reason the d3-hexjson library would render
    some of the files incorrectly.  The problem seems to be that the reduced
    number of hexagons in each file means we have to translate the `q` and `r`
    attributes of each hexagon into an absolute grid reference, and sometimes
    this means we move a hexagon from an odd or even `q` or `r` onto an even
    or odd one.  As [rendering hexagons by grid reference][hex-coords] is
    dependent on the odd and even state of the `q` and `r` attributes, this
    meant that for some of the smaller maps some rows were drawn incorrectly,
    making the whole map wrong.
    
    I tried detecting when the absolute `q` and `r` had a different odd or
    even state compared to the original, but this meant that the rendering of
    the map was offset by a row or column, and so the arrangement was good,
    but it wasn't centered on the screen.
    
    The solution I ended up with was to manually translate the `q` and `r`
    attributes of each map to an absolute space that preserved the correct
    odd and even states and didn't cause a problem.
    
    This was painful, but perhaps could be automated later if we need to
    regenerate the subdivisions for any future constituency changes.
    
    [hex-coords]: https://www.redblobgames.com/grids/hexagons/#coordinates
    h-lame committed Mar 28, 2019
    Configuration menu
    Copy the full SHA
    eec5fa4 View commit details
    Browse the repository at this point in the history