-
Notifications
You must be signed in to change notification settings - Fork 33
/
viewer.html
275 lines (250 loc) · 15.4 KB
/
viewer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hexviz - a hex cartogram data viewer</title>
<link rel="icon" href="https://open-innovations.org/resources/images/logos/oi-square-10.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@OpenInnovates">
<meta name="twitter:url" property="og:url" content="https://open-innovations.org/projects/hexmaps/viewer">
<meta name="twitter:title" property="og:title" content="Hex map viewer">
<meta name="twitter:description" property="og:description" content="Display data on hex cartograms.">
<meta name="twitter:image" property="og:image" content="https://open-innovations.org/projects/hexmaps/hexmap.png">
<link rel="StyleSheet" href="resources/style.css" type="text/css" />
<script type="text/javascript" src="resources/oi.hexmap.0.8.2.js"></script>
<!--<script type="text/javascript" src="resources/oi.hexmap-search.js"></script>-->
<script type="text/javascript" src="resources/viewer.js"></script>
<script>
var viewer;
OI.ready(function(){
viewer = new OI.HexViewer(document.getElementById('viewer'),{}).init();
});
</script>
<style>
/* Header styles */
header { display: flex; flex-direction: columns; }
header h1 { padding: 1rem; display: inline-block; position: relative; font-size: 1.4rem; }
header h1 img { margin-right: 0.25em; float:left; width:1em;height:1em; }
header .navigation { flex-grow: 1; font-size: 1.5rem; text-align: right; }
header .navigation button {
height: 100%;
aspect-ratio: 1/1;
justify-content: space-between;
border: none;
padding: 0;
color: inherit;
position: relative;
}
header .navigation button.on:focus { background: #dfdfdf!important; }
header .navigation button.on svg { fill: black; }
header .navigation button svg { position: absolute; width: 1.25em!important; height:1.25em!important; top: 50%; left: 50%; max-height: 75%; transform: translate3d(-50%,-50%,0); }
#menu { position: relative; }
.menu-panel { min-width: 300px; max-width: 100vw; z-index: 1000; position: absolute; right: 0; top: 0; }
.menu-panel .row { margin-bottom: 1em; text-align: left; }
.menu-panel .row label { display: block; }
.menu-panel .row:last-child { margin-bottom: 0; }
.menu-panel code { background: white; }
.menu-panel form { position: relative; }
.menu-panel input, #options select {
width: 100%;
line-height: 2em;
height: 2em;
min-width: 2em;
font-size: 1em;
border-radius: 4px;
border: 1px solid #999;
}
.menu-panel input[type=checkbox] { width: auto; }
.menu-panel input.required, .menu-panel input[required] { outline: 2px solid red; }
.loader { position: relative; text-align: center; }
.loader svg { width: 5em; margin: auto; }
#hexmap {
margin: auto;
width: 100%;
height: 90vh;
max-width: 100vw;
position: relative;
}
#hexmap .hex-cell { stroke: white; stroke-width: 2; transition: fill 0.3s ease-in, stroke 0.3s ease-in, stroke-width 0.3s ease-in; }
/* Set the on and off styles for the text labels */
#hexmap .hex-label tspan.on { display: none; }
#hexmap .hex-label tspan.off { display: block; }
#hexmap .hex-label tspan.big { font-weight: bold; font-size: 1.2em; }
#hexmap .hover .hex-label tspan.on { display: block; }
#hexmap .hover .hex-label tspan.off { display: none; }
#hexmap svg { margin: auto; display: block; }
#messages { max-height: 6em; overflow-y: auto; }
.message { padding: 0.25em 0.5em; font-size: 1em; }
.info { background: #e7f2fa; color: #2980b9; }
.save { text-align: left; }
.save button { margin-right: 0.25rem; font-size: 1.4rem; }
#option_form label { font-weight: bold; font-family: Poppins; }
#option_form p.hint { margin-bottom: 0.25em; }
ul { list-style: disc; }
ul li {
line-height: 2em;
margin-left: 2em;
}
code { background: #444; color: inherit; }
ol { margin-left: 2em; }
#scale-names { line-height: 1em; display: grid; grid-template-columns: repeat(auto-fit, minmax(8em, 1fr)); grid-gap: 0.25em; }
#scale-names code { display: inline-block; line-height: 1em; }
.scale-preview { width: 100%; height: 1em; display: block; }
#scale {width: 300px;max-width: 90vw; margin: auto; margin-top: 1em; margin-bottom: 2em; }
footer > p:first-child { margin-top: 0; }
footer p { margin-bottom: 1em; }
footer h2 { margin-top: 2em; }
.padded { padding: 1em; }
.hex-cell { fill-opacity: 1; }
.oi-map .hex path { stroke: white!important; }
.highlighted .hex-cell { stroke: black!important; stroke-width: 2px!important; }
.not-highlighted .hex-cell { opacity: 0.3!important; }
.hex-cell.hover { stroke: white!important; stroke-width: 5px!important; opacity:1!important; fill-opacity: 1!important; }
.hex-label.hover { fill: white!important; }
.oi-map .overlay, .oi-map .hex .hex-label { pointer-events: none; }
.oi-map .overlay .hex.outline path {stroke: black!important; stroke-width: 5px!important;}
.capture .overlay { display: none; }
#main ul.examples { list-style: none; margin: 0; }
#main ul.examples li { margin-left: 0; }
#main ul.examples li a { display: block; }
#loader { max-width: 600px; margin: auto; }
</style>
</head>
<body class="b1-bg">
<div id="main" class="b6-bg">
<header class="b1-bg">
<h1><a href="https://open-innovations.org/projects/hexmaps/"><img src="https://open-innovations.org/resources/images/logos/oi-square-10.svg" /></a> Hexviz</h1>
<nav id="navigation" class="navigation" role="menubar">
<button aria-label="Share" aria-controls="link" id="menu-link" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-share-fill" viewBox="0 0 16 16">
<path d="M11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.5 2.5 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5"/>
</svg>
</button><button aria-label="Save" aria-controls="saves" id="menu-save" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16">
<path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"/>
<path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"/>
</svg>
</button><button aria-label="Options" aria-controls="options" id="menu-options" role="menuitem">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-gear-fill" viewBox="0 0 16 16">
<path d="M9.405 1.05c-.413-1.4-2.397-1.4-2.81 0l-.1.34a1.464 1.464 0 0 1-2.105.872l-.31-.17c-1.283-.698-2.686.705-1.987 1.987l.169.311c.446.82.023 1.841-.872 2.105l-.34.1c-1.4.413-1.4 2.397 0 2.81l.34.1a1.464 1.464 0 0 1 .872 2.105l-.17.31c-.698 1.283.705 2.686 1.987 1.987l.311-.169a1.464 1.464 0 0 1 2.105.872l.1.34c.413 1.4 2.397 1.4 2.81 0l.1-.34a1.464 1.464 0 0 1 2.105-.872l.31.17c1.283.698 2.686-.705 1.987-1.987l-.169-.311a1.464 1.464 0 0 1 .872-2.105l.34-.1c1.4-.413 1.4-2.397 0-2.81l-.34-.1a1.464 1.464 0 0 1-.872-2.105l.17-.31c.698-1.283-.705-2.686-1.987-1.987l-.311.169a1.464 1.464 0 0 1-2.105-.872zM8 10.93a2.929 2.929 0 1 1 0-5.86 2.929 2.929 0 0 1 0 5.858z"/>
</svg>
</button>
</nav>
</header>
<div id="menu">
<div id="link" class="b5-bg padded menu-panel">
<h2>Link</h2>
<p id="share"></p>
</div>
<div id="saves" class="b5-bg padded menu-panel">
<h2>Save</h2>
<p>Only the HexJSON format can be reloaded in this tool for further editing.</p>
</div>
<div id="options" class="b5-bg padded menu-panel">
<h2>Options</h2>
<form id="option_form" name="option_form" method="GET" enctype="multipart/form-data" accept-charset="UTF-8" action="#">
<div class="row">
<label for="url" aria-describedby="url-hint">CSV URL</label>
<p id="url-hint" class="hint">This can also be a Google Sheet. It must be publicly accessible.</p>
<input id="url" type="text" name="url" class="" placeholder="e.g. https://open-innovations.org/projects/hexmaps/data/wards-leeds.csv" />
</div>
<div class="row">
<label for="hexjson" aria-describedby="hexjson-hint">Layout URL</label>
<p id="hexjson-hint" class="hint">If the CSV doesn't contain <code>q</code> and <code>r</code> columns, provide a <a href="hexjson.html">HexJSON file</a> here.</p>
<input id="hexjson" type="text" name="hexjson" class="" placeholder="e.g. https://open-innovations.org/projects/hexmaps/maps/uk-constituencies-2023.hexjson" />
</div>
<div class="row">
<label for="colourscale">Colour scale</label>
<select id="colourscale" name="colourscale">
<optgroup label="Safe">
<option value="Cividis">Cividis</option>
<option value="Heat">Heat</option>
<option value="Inferno">Inferno</option>
<option value="Magma">Magma</option>
<option value="Mako">Mako</option>
<option value="Plasma">Plasma</option>
<option value="Rocket">Rocket</option>
<option value="Turbo">Turbo</option>
<option value="Viridis" selected="selected">Viridis</option>
<option value="Viridis-light">Viridis-light</option>
</optgroup>
<optgroup label="Diverging">
<option value="PiPG">PiPG</option>
<option value="Planck">Planck</option>
<option value="PRGn">PRGn</option>
<option value="PuOr">PuOr</option>
<option value="Referendum">Referendum</option>
<option value="RdBu">RdBu</option>
</optgroup>
<optgroup label="Other">
<option value="EPC">EPC</option>
<option value="IMD-low-high">IMD-low-high</option>
<option value="IMD-high-low">IMD-high-low</option>
<option value="Leodis">Leodis</option>
<option value="Longside">Longside</option>
</optgroup>
</select>
</div>
<div class="row">
<label for="attribute">Colour by</label><select id="attribute" name="attribute"></select>
</div>
<div class="row">
<label for="labels">Labels</label><select id="labels" name="labels"></select>
</div>
<div class="row">
<label for="tooltips">Tooltips</label><select id="tooltips" name="tooltips"></select>
</div>
<div class="row">
<label for="borders">Hexagon borders?</label><input type="checkbox" id="borders" name="borders"></select>
</div>
<button id="btnSubmit" type="submit" class="button c10-bg">Update</button>
<!--<button id="reset" type="reset" class="c8-bg" style="float:right;">Reset</button>-->
</form>
</div>
</div>
<div id="messages"></div>
<div id="viewer" class="padded">
<div id="loader"></div>
<div id="hexmap"></div>
<div id="scale"></div>
</div>
</div>
<footer class="b1-bg" id="notes">
<div class="holder">
<h2>Notes</h2>
<p>The aim of this tool is to visualise data on a hex cartogram. The data can either be in a CSV file, a simple Google Sheet<a href="#footnote-1" class="footnote">*</a>, or a <a href="hexjson.html">HexJSON</a> file. The URL must be publicly accessible and <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS">CORS will need to be enabled</a> on the remote server (otherwise this page can't access the data).</p>
<h2>Options</h2>
<h3>CSVs</h3>
<p>If you provide a CSV it should contain a column with the heading <code>id</code> that uniquely identifies each hexagon. Other columns will be added as extra properties of each hexagon. Each row will be a specific hex in the final map.</p>
<h3>Hexagon layout</h2>
<p>To show your data we need to know where each hexagon should go. There are three ways you could do this:</p>
<ol>
<li>If your data contains IDs that look like codes for <a href="maps/uk-local-authority-districts-2021.hexjson">UK local authorities</a>, <a href="maps/constituencies.hexjson">UK Parliamentary constituencies</a>, <a href="maps/uk-nuts3.hexjson">UK NUTS3 regions</a>, <a href="maps/uk-upper-tier-local-authorities.hexjson">UK Upper Tier Local Authorities</a>, <a href="https://raw.githubusercontent.com/houseofcommonslibrary/uk-hex-cartograms-noncontiguous/main/hexjson/msoa_hex_coords.hexjson">MSOAs</a>, <a href="maps/nhs-icb-2022.hexjson">NHS Integrated Care Boards</a>, <a href="maps/uk-wards-2022/simple.hexjson">UK wards (2022 - under development)</a>, or <a href="maps/us-states.hexjson">US States</a>, we will try to load a pre-existing <a href="hexjson.html">HexJSON layout</a>. For example, this <a href="https://docs.google.com/spreadsheets/d/1NtcBz6FyfsYwCe6X7_QUCssmhj2wSStSegwc102cH-E/edit#gid=0">Google Sheet contains 2022 ward codes</a> which get detected and an appropriate layout loaded.</li>
<li>You could make your own HexJSON layout with <a href="builder.html">our hex builder tool</a>.</li>
<li>You could add <code>q</code> (column) and <code>r</code> (row) columns to your data to explicitly set your coordinates for each hexagon. These will be interpreted as an <code>odd-r</code> layout; pointy-topped hexes where odd-numbered rows shift to the right.</li>
</ol>
<h3>Colours</h3>
<p>Hexagons can be coloured by any numeric column in your data. For instance, if your CSV file contains a column titled <code>Population</code> you could choose this attribute and set the colour scale to <code>Viridis</code>. The range will be calculated from the data and rounded to "nicer" values. These colour scales are available:</p>
<div id="scale-names"></div>
<h2 id="export">Exporting the map</h2>
<p>Use the <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16"><path d="M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5"></path><path d="M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708z"></path></svg> menu to export the map in one of four ways:</p>
<ol style="margin: 1em 0 1em 2em;">
<li><strong>HexJSON</strong> - This creates a text file representation of your data and hex layout.</li>
<li><strong>SVG</strong> - This will save the image as a scalable vector graphic.</li>
<li><strong>PNG</strong> - This will save the map as an image that you can use elsewhere. It is useful for screenshots.</li>
<li><strong>GeoJSON</strong> - A cartogram is not geographic but some people have requested "geographic formats" so they can use these hex cartograms with specific GIS software. To make it "geographic" we've done a very simple projection at Null Island (0°, 0°) keeping the result to approximately 0.1°×0.1° to try to reduce distortions.</li>
</ol>
<p>If you output as anything other than HexJSON, you won't be able to load it back into this tool.</p>
<hr />
<p id="footnote-1">* The Google Sheet must be public and very straightforward. It must consist of one Sheet with a basic table starting in the first cell. There should be one header row at the top. It shouldn't contain rows that aren't the header or the data.</p>
<hr />
<p>Hex cartogram viewer © 2024 <a href="https://odileeds.org/">Open Innovations</a>. Released under an MIT license. <a href="https://github.com/odileeds/hexmaps">Source on Github</a>.</p>
</div>
</footer>
<script src="https://open-innovations.org/resources/oi.log.js"></script>
<script>
OI.log.setup({'id':'odileeds','target':['open-innovations.org','odileeds.org','odileeds.github.io']}).add('action=view');
</script>
</body>
</html>