-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: gh-pages
Are you sure you want to change the base?
Hexagons! #31
Commits on Mar 28, 2019
-
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/
Configuration menu - View commit details
-
Copy full SHA for 21726d9 - Browse repository at this point
Copy the full SHA 21726d9View commit details -
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/
Configuration menu - View commit details
-
Copy full SHA for acc4b5d - Browse repository at this point
Copy the full SHA acc4b5dView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 5748e30 - Browse repository at this point
Copy the full SHA 5748e30View commit details -
Introduce
PetitionMap.mapMode
and draw some hexagonsIf 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/
Configuration menu - View commit details
-
Copy full SHA for 921bf37 - Browse repository at this point
Copy the full SHA 921bf37View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6947ef9 - Browse repository at this point
Copy the full SHA 6947ef9View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 7c537c6 - Browse repository at this point
Copy the full SHA 7c537c6View commit details -
Give credit for hex maps in about page
Also for the d3-hexjson library.
Configuration menu - View commit details
-
Copy full SHA for 722ba23 - Browse repository at this point
Copy the full SHA 722ba23View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for eec5fa4 - Browse repository at this point
Copy the full SHA eec5fa4View commit details