-
Notifications
You must be signed in to change notification settings - Fork 33
/
hexjson.html
513 lines (497 loc) · 28.7 KB
/
hexjson.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<!DOCTYPE html>
<html lang="en">
<head>
<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" />
<title>HexJSON format v1.1</title>
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@ODILeeds">
<meta name="twitter:url" property="og:url" content="https://open-innovations.org/projects/hexmaps/hexjson">
<meta name="twitter:title" property="og:title" content="HexJSON format">
<meta name="twitter:description" property="og:description" content="Defining a format for sharing hex-based maps.">
<meta name="twitter:image" property="og:image" content="https://open-innovations.org/projects/hexmaps/hexmap.png">
<script type="text/javascript" src="resources/oi.hexmap.0.8.3.min.js"></script>
<style>
/*! minireset.css v0.0.6 | MIT License | github.com/jgthms/minireset.css */html,body,p,ol,ul,li,dl,dt,dd,blockquote,figure,fieldset,legend,textarea,pre,iframe,hr,h1,h2,h3,h4,h5,h6{margin:0;padding:0}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}ul{list-style:none}button,input,select{margin:0}html{box-sizing:border-box}*,*::before,*::after{box-sizing:inherit}img,video{height:auto;max-width:100%}iframe{border:0}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}
@font-face {
font-family: 'Poppins';
font-style: italic;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiDyp8kv8JHgFVrJJLmr19VFteOcEg.woff2) format('woff2');
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
}
@font-face {
font-family: 'Poppins';
font-style: italic;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiDyp8kv8JHgFVrJJLmr19VGdeOcEg.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: 'Poppins';
font-style: italic;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiDyp8kv8JHgFVrJJLmr19VF9eO.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiByp8kv8JHgFVrLEj6Z11lFc-K.woff2) format('woff2');
unicode-range: U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB;
}
@font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiByp8kv8JHgFVrLEj6Z1JlFc-K.woff2) format('woff2');
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 600;
font-display: swap;
src: url(https://open-innovations.org/resources/fonts/Poppins/pxiByp8kv8JHgFVrLEj6Z1xlFQ.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
h1,h2,h3,h4 { font-family: Poppins; line-height: 1em; }
html, body {
padding: 0px;
margin: 0px;
min-height: 100%!important;
height: 100%!important;
background-color: #efefef;
font-family: "Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
font-size: 16px;
color: #333;
line-height: 1.44em;
}
.leaflet-container { font-size: inherit; }
h1 { font-size: 2em; line-height: 1em; }
h2 { font-size: 1.7rem; padding-top: 3rem; margin-bottom: 16px; }
h1 { margin-top: 0em; }
strong { font-weight: 700; }
em { font-style: italic; }
ol { margin-left: 2rem; }
header, footer, #main {
width: 100%;
transition: margin-left 0.3s ease-in;
}
footer {
width: 100%;
padding: 1em;
padding-bottom: 3em;
}
footer a {
color: white;
}
.line {
text-decoration: underline;
}
.holder {
position: relative;
width: 1080px;
max-width: 100%;
margin: auto;
}
.padded { padding: 1em; }
.tallpadded { padding: 2em 0; }
code,pre {
font-family: monospace;
color: #555555;
background-color: white;
}
code {
padding: 0.125em 0.25em;
}
pre {
max-width: 100%;
overflow-x: auto;
padding: 16px;
margin-bottom: 16px;
}
html,body { background: white; }
header,footer { background: black; color: white; padding: 1em; }
header { margin-bottom: 1em; }
p, iframe, h2, h3, figcaption, ul, ol, .block, .padded-bottom { margin-bottom: 16px; }
p:last-child, figure iframe { margin-bottom: 0; }
pre,code { background: #efefef; }
.boundaries, .layouts { display:grid; grid-gap: 1em; margin-left: 0!important; margin-bottom: 1em; }
.boundaries { grid-template-columns: repeat(4,1fr); }
.layouts { grid-template-columns: repeat(4,1fr); }
.boundaries li, .layouts li { list-style: none; text-align: center; }
.hexlayout { height: 250px; font-size: 1em; }
.hexlayout .hex-cell { fill: #efefef; stroke: #bbb; }
.warning {
color: #9F6000;
background-color: #FEEFB3;
padding: 1em;
margin-bottom: 1em;
}
.warning:before {
content:'\26a0';
margin-right: 0.5em;
}
.hex-label, .hexagon { font-family: Poppins; }
.q { fill: #0DBC37; color: #0DBC37; }
.r { fill: #178CFF; color: #178CFF; }
.e { fill: #722EA5; color: #722EA5; }
code.q, code.r, code.e { font-weight: bold; }
.q-axis-same .hex-cell { fill: hsl( 90, 20%, 87%); }
.r-axis-same .hex-cell { fill: hsl(200, 15%, 90%); }
.q-axis-same.r-axis-same .hex-cell { fill: hsl(60, 100%, 85%); }
.q-axis-same.r-axis-same .hex-label { font-weight: bold; }
.hex-cell.select {
fill: red;
}
@media screen and (max-width: 1080px) {
.layouts { grid-template-columns: repeat(2,1fr); }
}
@media screen and (max-width: 600px) {
.layouts { grid-template-columns: 100%; }
}
</style>
<script>
OI.ready(function(){
hexjsonr = {
'layout':'odd-r',
'hexes':{
'00':{'n':'0,0','q':0,'r':0},
'01':{'n':'0,1','q':0,'r':1},
'02':{'n':'0,2','q':0,'r':2},
'03':{'n':'0,3','q':0,'r':3},
'04':{'n':'0,4','q':0,'r':4},
'10':{'n':'1,0','q':1,'r':0},
'11':{'n':'1,1','q':1,'r':1},
'12':{'n':'1,2','q':1,'r':2},
'13':{'n':'1,3','q':1,'r':3},
'14':{'n':'1,4','q':1,'r':4},
'20':{'n':'2,0','q':2,'r':0},
'21':{'n':'2,1','q':2,'r':1},
'22':{'n':'2,2','q':2,'r':2},
'23':{'n':'2,3','q':2,'r':3},
'24':{'n':'2,4','q':2,'r':4},
'30':{'n':'3,0','q':3,'r':0},
'31':{'n':'3,1','q':3,'r':1},
'32':{'n':'3,2','q':3,'r':2},
'33':{'n':'3,3','q':3,'r':3},
'34':{'n':'3,4','q':3,'r':4},
'40':{'n':'4,0','q':4,'r':0},
'41':{'n':'4,1','q':4,'r':1},
'42':{'n':'4,2','q':4,'r':2},
'43':{'n':'4,3','q':4,'r':3},
'44':{'n':'4,4','q':4,'r':4}
}
};
hexjsonq = {
'layout':'odd-q',
'hexes':{
'00':{'n':'0,0','q':0,'r':0},
'01':{'n':'0,1','q':0,'r':1},
'02':{'n':'0,2','q':0,'r':2},
'03':{'n':'0,3','q':0,'r':3},
'10':{'n':'1,0','q':1,'r':0},
'11':{'n':'1,1','q':1,'r':1},
'12':{'n':'1,2','q':1,'r':2},
'13':{'n':'1,3','q':1,'r':3},
'20':{'n':'2,0','q':2,'r':0},
'21':{'n':'2,1','q':2,'r':1},
'22':{'n':'2,2','q':2,'r':2},
'23':{'n':'2,3','q':2,'r':3},
'30':{'n':'3,0','q':3,'r':0},
'31':{'n':'3,1','q':3,'r':1},
'32':{'n':'3,2','q':3,'r':2},
'33':{'n':'3,3','q':3,'r':3},
'40':{'n':'4,0','q':4,'r':0},
'41':{'n':'4,1','q':4,'r':1},
'42':{'n':'4,2','q':4,'r':2},
'43':{'n':'4,3','q':4,'r':3},
'50':{'n':'5,0','q':5,'r':0},
'51':{'n':'5,1','q':5,'r':1},
'52':{'n':'5,2','q':5,'r':2},
'53':{'n':'5,3','q':5,'r':3}
}
};
function label(txt,attr){
tspans = '';
tspans += '<tspan class="on q" y="'+(attr.y + (-0.5)*attr['font-size'])+'" x="'+attr.x+'">q:'+attr.hex.q+'</tspan>';
tspans += '<tspan class="on r" y="'+(attr.y + (0.5)*attr['font-size'])+'" x="'+attr.x+'">r:'+attr.hex.r+'</tspan>';
return tspans;
}
function highlight(e){
hex = e.data.data;
hexes = e.data.hexmap.areas;
for(r in hexes){
matchq = (hexes[r].data.q==hex.q);
matchr = (hexes[r].data.r==hex.r);
if(matchq) hexes[r].g.classList.add('q-axis-same');
else hexes[r].g.classList.remove('q-axis-same');
if(matchr) hexes[r].g.classList.add('r-axis-same');
else hexes[r].g.classList.remove('r-axis-same');
}
}
function dehighlight(e){
hexes = e.data.hexmap.areas;
for(r in hexes){
hexes[r].g.classList.remove('q-axis-same');
hexes[r].g.classList.remove('r-axis-same');
}
}
oddr = new OI.hexmap(document.getElementById('odd-r'),{
'label':{'show': true,'format':label,'clip':true},
'hexjson':hexjsonr
});
oddr.on('mouseover',highlight).on('mouseout',dehighlight);
hexjsonr.layout = "even-r";
evenr = new OI.hexmap(document.getElementById('even-r'),{
'label':{'show': true,'format':label,'clip':true},
'hexjson':hexjsonr
});
evenr.on('mouseover',highlight).on('mouseout',dehighlight);
oddq = new OI.hexmap(document.getElementById('odd-q'),{
'label':{'show': true,'format':label,'clip':true},
'hexjson':hexjsonq
});
oddq.on('mouseover',highlight).on('mouseout',dehighlight);
hexjsonq.layout = "even-q";
evenq = new OI.hexmap(document.getElementById('even-q'),{
'label':{'show': true,'format':label,'clip':true},
'hexjson':hexjsonq
});
evenq.on('mouseover',highlight).on('mouseout',dehighlight);
});
</script>
</head>
<body>
<div id="main">
<header>
<div class="b1-bg">
<div class="holder" style="text-align:center;">
<a href="https://open-innovations.org/"><svg width="80" height="80" overflow="auto" viewBox="-32 -32 64 64" xmlns="http://www.w3.org/2000/svg"><mask id="oi-person"><path d="m-32-32h64v64h-12v-24a4 4 0 0 0 -4 -4h-8a4 4 0 0 0 -4 4v24h-36zm44 27m-8 0a8 8 0 1 0 16 0 8 8 0 1 0-16 0" fill="#fff"></path></mask><g id="oi-logo" fill="#E6007C"><circle r="32" mask="url(#oi-person)"></circle></g></svg></a>
<h1>HexJSON format v1.1</h1>
</div>
</div>
</header>
<div class="holder tallpadded padded">
<p>We want to make sharing <a href="https://open-innovations.org/blog/2017-05-08-mapping-election-with-hexes">hexagon-based maps</a> - such as our <a href="constituencies/index.html">UK constituency hex map</a> - easy. We've defined a simple <a href="http://jsonlint.com/">JSON format</a> to achieve that. The format requires <code>layout</code> and <code>hexes</code>:</p>
<pre><code>{
"layout": "odd-r",
"hexes": {
"E14000530": {"q":-3,"r":-11},
"E14000531": {"q":-3,"r":-1}
}
}</code></pre>
<p>The <code>layout</code> property should be one of the following <a href="http://www.redblobgames.com/grids/hexagons/#coordinates">coordinate systems</a>:</p>
<ul class="layouts">
<li><div id="odd-r" class="hexlayout"></div><code>odd-r</code> (pointy-topped)<br />odd numbered rows shift right</li>
<li><div id="even-r" class="hexlayout"></div><code>even-r</code> (pointy-topped)<br />even numbered rows shift right</li>
<li><div id="odd-q" class="hexlayout"></div><code>odd-q</code> (flat-topped)<br />odd numbered columns shift up</li>
<li><div id="even-q" class="hexlayout"></div><code>even-q</code> (flat-topped)<br />even numbered columns shift up</li>
</ul>
<p>Unlike Red Blob Games, the row number, <code class="r">r</code>, increases vertically. This is to match with conventions used in most cartography (the HexJSON format is inspired by GeoJSON which has -90° at the geometric south pole and +90° at the geometric north pole) and most x-y graphs but differs from conventions in computer graphics.</p>
<div class="warning">Note: the shifts in each coordinate system are based on the absolute column/row numbers as specified in the HexJSON file, not on their relative position in a layout. Using absolute numbers ensures that a layout still renders correctly if a column or row is added later.</div>
<h2 id="hexes">Adding hexes</h2>
<p>The <code>hexes</code> are then defined using unique keys for each. Every hex is positioned by providing column (<code class="q">q</code>) and row (<code class="r">r</code>) coordinates. You don't have to start at 0,0.</p>
<p>You can add your own custom data fields to each hex if you want to. Just make sure you don't use the keys <code class="q">q</code> and <code class="r">r</code> as they will be the coordinates e.g.</p>
<pre><code>{
"layout": "odd-r",
"hexes": {
"E14000530":{
"name": "Aldershot",
"q": -3,
"r": -11,
"area": "SE",
"NUTS1": "UKJ",
"electorate": 72430
},
"E14000531":{
"name": "Aldridge-Brownhills",
"q": -3,
"r": -1,
"area": "WM",
"NUTS1": "UKG",
"electorate": 60215
}
...
}
}</code></pre>
<h2 id="boundaries">Adding boundaries</h2>
<p>In version 1.1 (28th February 2024) we have added the concept of boundaries around hexagons. This lets us define, say, a border between two groups of hexagons. You can provide multiple named boundaries using the additional property <code>boundaries</code>. Each boundary should contain an <code class="e">edges</code> array that defines an ordered series of edges to create a line (the line does not have to be continuous). Each item in the array should provide the <code class="q">q</code> and <code class="r">r</code> coordinates of a particular hexagon along with the edge number <code class="e">e</code>. For example:</p>
<pre><code>{
"layout": "odd-r",
"hexes": { ... },
"boundaries": {
"name-1": {
"edges": [
{"q":-3,"r":-11,"e":2},
{"q":-3,"r":-12,"e":4}
]
}
}
}</code></pre>
<p>Edges, <code class="e">e</code>, are numbered from 1 to 6 moving clockwise from the top of the hexagon. Positive numbered edges are drawn in a clockwise sense and negative numbered edges are drawn in an anti-clockwise sense. This should allow continuous lines to be created. </p>
<ul class="boundaries">
<li>
<svg class="hexagon" xmlns="http://www.w3.org/2000/svg" version="1.1" overflow="visible" viewBox="0 0 70 58" style="max-width:100%;" preserveAspectRatio="xMinYMin meet" vector-effect="non-scaling-stroke">
<g transform-origin="35px 29px" transform="translate(35 29) translate(0 -25)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(30)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(21.65 -12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(90)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(21.65 12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(150)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(0 25)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(210)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-21.65 12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(270)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-21.65 -12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(330)" />
</g>
<text x="35px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="q">q</tspan>,<tspan class="r">r</tspan></text>
<text x="50px" y="6px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:1</tspan></text>
<text x="63px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:2</tspan></text>
<text x="50px" y="52px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:3</tspan></text>
<text x="20px" y="52px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:4</tspan></text>
<text x="7px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:5</tspan></text>
<text x="20px" y="6px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:6</tspan></text>
</svg>
pointy-topped<br />positive edge numbers
</li>
<li>
<svg class="hexagon" xmlns="http://www.w3.org/2000/svg" version="1.1" overflow="visible" viewBox="0 0 70 58" style="max-width:100%;" preserveAspectRatio="xMinYMin meet" vector-effect="non-scaling-stroke">
<g transform-origin="35px 29px" transform="translate(35 29) translate(0 -25)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(150)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(21.65 -12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(210)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(21.65 12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(270)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(0 25)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(330)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-21.65 12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(30)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-21.65 -12.5)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(90)" />
</g>
<text x="35px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="q">q</tspan>,<tspan class="r">r</tspan></text>
<text x="50px" y="6px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-1</tspan></text>
<text x="63px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-2</tspan></text>
<text x="50px" y="52px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-3</tspan></text>
<text x="20px" y="52px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-4</tspan></text>
<text x="7px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-5</tspan></text>
<text x="20px" y="6px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:-6</tspan></text>
</svg>
pointy-topped<br />negative edge numbers
</li>
<li>
<svg class="hexagon" xmlns="http://www.w3.org/2000/svg" version="1.1" overflow="visible" viewBox="0 0 70 58" style="max-width:100%;" preserveAspectRatio="xMinYMin meet" vector-effect="non-scaling-stroke">
<g transform-origin="35px 29px" transform="translate(35 29) translate(-12.5 -21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(0)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(12.5 -21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(60)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(25 0)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(120)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(12.5 21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(180)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-12.5 21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(240)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-25 0)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(300)" />
</g>
<text x="35px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="q">q</tspan>,<tspan class="r">r</tspan></text>
<text x="35px" y="2px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:1</tspan></text>
<text x="60px" y="16px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:2</tspan></text>
<text x="60px" y="42px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:3</tspan></text>
<text x="35px" y="56px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:4</tspan></text>
<text x="10px" y="42px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:5</tspan></text>
<text x="10px" y="16px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:6</tspan></text>
</svg>
flat-topped<br />positive edge numbers
</li>
<li>
<svg class="hexagon" xmlns="http://www.w3.org/2000/svg" version="1.1" overflow="visible" viewBox="0 0 70 58" style="max-width:100%;" preserveAspectRatio="xMinYMin meet" vector-effect="non-scaling-stroke">
<g transform-origin="35px 29px" transform="translate(35 29) translate(-12.5 -21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(120)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(12.5 -21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(180)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(25 0)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(240)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(12.5 21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(300)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-12.5 21.65)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(0)" />
</g>
<g transform-origin="35px 29px" transform="translate(35 29) translate(-25 0)">
<path d="m 0 0 l 24 0 m 0 0 l -2 1.5 m 2 -1.5 l -2 -1.5" stroke="black" fill="transparent" stroke-linecap="round" transform="rotate(60)" />
</g>
<text x="35px" y="29px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="q">q</tspan>,<tspan class="r">r</tspan></text>
<text x="35px" y="2px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:1</tspan></text>
<text x="60px" y="16px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:2</tspan></text>
<text x="60px" y="42px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:3</tspan></text>
<text x="35px" y="56px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:4</tspan></text>
<text x="10px" y="42px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:5</tspan></text>
<text x="10px" y="16px" dominant-baseline="central" text-anchor="middle" font-size="4px"><tspan class="e">e</tspan><tspan>:6</tspan></text>
</svg>
flat-topped<br />negative edge numbers
</li>
</ul>
<p>This means that there are two ways to define the same edge moving in the same direction; using one hexagon's coordinates with a clockwise sense or the neighbouring hexagon in the anti-clockwise sense. Although this adds redundancy, it gives the following advantages:</p>
<ol>
<li>Allows you to use the "best" hexagon as the base. For instance, if you want to draw a border for Scotland you could make sure that all your edges were based on Scottish hexagons.</li>
<li>Drawing multiple anti-clockwise edges around the same hexagon is more straightforward.</li>
<li>Allowing anti-clockwise edges needs fewer edges to change if you were to switch between even and odd layouts.</li>
</ol>
<div class="warning">Note: The <code class="e">edges</code> are not required to continue on from each other. That means that a line may contain gaps. So a renderer should check where the end of the last edge finished and the current edge begins to work out if a gap should be left. A renderer may also wish to give users the option to style a specific boundary using its name or any other properties of the boundary.</div>
<p>See <a href="https://open-innovations.github.io/oi.hexmap.js/#ex3">edges being drawn in this example</a>.</p>
<h2>Changelog</h2>
<ul>
<li><strong>v1.1</strong> (28 February 2024): added definition of optional <code>boundaries</code>.</li>
<li><strong>v1.0</strong> (8 May 2017): initial definition of format including <code>layout</code> and <code>hexes</code>.</li>
</ul>
<h2>Using HexJSON</h2>
<p>The format is JSON so should be easy to ingest by your favourite programming language. We'll add examples that people have created below.</p>
<ul>
<li><strong>Building a layout:</strong> Stuart Lowe created a <a href="builder.html">HexJSON builder</a> that reads a CSV file, allows you to reposition hexes, and save the output.</li>
<li><strong>JS:</strong> Stuart Lowe has created a <a href="https://open-innovations.github.io/oi.hexmap.js/">small standalone JS library</a>.</li>
<li><strong>D3:</strong> Oli Hawkins has created <a href="https://github.com/olihawkins/d3-hexjson">a plugin to read HexJSON files with D3.js</a>.</li>
<li><strong>R:</strong> Tony Hirst wrote a series of blog posts (<a href="https://blog.ouseful.info/2017/06/28/hexjson-htmlwidget-for-r-part-1/">part 1</a>, <a href="https://blog.ouseful.info/2017/06/29/hexjson-htmlwidget-for-r-part-2/">part 2</a>, <a href="https://blog.ouseful.info/2017/06/30/hexjson-htmlwidget-for-r-part-3/">part 3</a>) which describe a HTMLWidget that renders HexJSON for R.</li>
<li><strong>R:</strong> Joseph Bailey has a great <a href="https://github.com/sassalley/hexmapr/">tool for generating hex maps from geospatial polygons</a>.</li>
</ul>
</div>
</div>
<footer class="b1-bg">
<div class="holder tallpadded padded">
© 2017-2024 <a href="https://open-innovations.org/">Open Innovations</a>. Released under an MIT license. <a href="https://github.com/odileeds/hexmaps">Source on Github</a>.
</div>
</footer>
<script src="https://open-innovations.org/resources/oi.log.js"></script>
<script>
OI.log.setup({'id':'odileeds','target':['open-innovations.org','odileeds.github.io']}).add('action=view');
</script>
</body>
</html>