-
Notifications
You must be signed in to change notification settings - Fork 2
/
summarise.html
710 lines (667 loc) · 30.6 KB
/
summarise.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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<!DOCTYPE html>
<html lang="en-GB">
<head>
<title>Summarise</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"/>
<meta charset="UTF-8"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto"/>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<link rel="stylesheet" href="https://www.trafforddatalab.io/assets/leaflet//MarkerCluster.TraffordDataLab.css"/>
<style>
body{
font-family: 'Open Sans', sans-serif;
margin: 0;
padding: 0;
}
a{
color: #e24a90;
text-decoration: none;
}
a:hover{
text-decoration: underline;
}
h2
{
font-family: 'Roboto', sans-serif;
color: #757575;
font-size: 25px;
}
#mainBody{
padding: 0 20px 5em 12px;
margin: 0;
height: 100%;
color: #212121;
clear:both;
}
.header{
padding-top: 5px;
padding-left: 12px;
border-bottom: 1px solid #ccc;
}
#appTitle{
font-family: 'Roboto', sans-serif;
display:inline-block;
vertical-align: bottom;
padding: 0px 10px;
margin: 0px;
color:#757575;
font-size: 15px
}
#appName{
color: #e24a90;
font-size: 25px;
}
#appTitle p{
margin: 0px;
}
#TDLlogo{
color: #e24a90;
}
.double div{
float: left;
}
select{
font-size: 12px;
}
.double{
clear:both;
padding-top: 20px;
}
#map{
width:70%;
height:400px;
}
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div
{
background-color: rgba(226,74,144, 0.8);
}
.leaflet-oldie .marker-cluster-small div, .leaflet-oldie .marker-cluster-medium div, .leaflet-oldie .marker-cluster-large div
{
background-color: rgb(226,74,144);
}
#countPoints{
background-color: white;
opacity: 0.8;
position: relative;
top: 280px;
left:20px;
z-index: 1000;
padding:0 15px;
border-radius: 8px;
box-shadow: 0px 0px 10px 0px #cccccc;
}
#countPoints p{
font-size: 12px;
line-height: 12px;
margin:0;
padding:3px 0px;
}
#timeLine{
width:70%;
}
.comment{
width:25%;
padding-top: 15px;
padding-left: 10px;
margin-left: 3px;
border-style: none none none solid;
border-color: #e24a90;
border-width: 1px;
}
#tableDiv{
width:70%;
padding-bottom: 40px;
}
.circleLegend{
border:1px solid #E24A90;
border-radius: 50%;
height: 10px;
width: 10px;
opacity: 0.8;
margin-right: 5px;
margin-top: 4px;
}
.legendItem{
clear:both;
}
.legendItem:hover .circleLegend{
background-color: #E24A90;
}
.circleActive{
background-color: #E24A90;
}
.legLabelActive{
color: #e24a90
}
.popupServ a{
color: #e24a90;
text-decoration: none;
}
.popupServ a:hover{
text-decoration: underline;
}
.popupServ .leaflet-popup-tip,
.popupServ .leaflet-popup-content-wrapper {
background: white;
border-radius: 0%;
border:1px solid #cccccc;
}
.popupServ .leaflet-popup-tip-container{
display:none;
}
.leaflet-popup-close-button{
text-decoration: none;
}
#downloadCSV{
background-color: grey;
color: white;
width:36px;
cursor:pointer;
margin-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
}
#tableTitle{
font-size: 20px;
}
#BRtable tr td:nth-child(2)
{
text-align: right;
}
.bar{
background-color: #e24a90;
height: 15px;
}
#OGIfooter{
padding-left: 12px;
clear:both;
padding-top: 10px;
border-top: 1px solid #ccc;
}
#OGIfooter p{
margin:0;
font-size: 12px
}
.svg_holder{
float: left;
margin-right: 12px;
}
_:-ms-fullscreen, :root #timeLine{
height:30vw;
}
@media (max-width:800px)
{
#appTitle{
padding: 0px;
}
#map{
width:95%;
}
#timeLine, #tableDiv{
width:100%;
}
.comment{
width:100%;
padding-top: 10px;
padding-left: 0px;
margin-left: 0px;
border-style: none;
}
#countPoints{
top: 240px;
left: 0px;
padding:0 3px;
}
#tableDiv{
font-size: 10px;
}
#tableTitle {
font-size: 14px;
}
}
@media (min-width:1300px) {
.double
{
width: 1240px;
}
}
</style>
</head>
<body>
<div class="header">
<a id="TDLlogo" href="https://www.trafforddatalab.io/index.html" target="_blank"><img src="https://www.trafforddatalab.io/assets/logo/trafforddatalab_logo.svg" alt="Trafford Data Lab" width="93" border="0" class="traffordDataLabLogo"/></a>
<div id="appTitle"><p><span id="appName">Summarise</span> worklessness data at a glance</p></div>
</div>
<div id='mainBody'>
<h2 id='titleName'>Greater Manchester</h2>
<div class="double padd0">
<div id='Local Authority'></div>
<div id='Ward'></div>
</div>
<div class="double">
<div id="map"><div id="countPoints"></div></div>
<div id="statComm" class="comment">Select an area for information related to unemployment.</div>
</div>
<div class="double">
<div id='timeLine'></div>
<div id='chartComm' class="comment"></div>
</div>
<div class="double">
<div id= "tableDiv">
<p id="tableTitle"></p>
<table id='BRtable'></table>
</div>
<div id="bussinessComm" class="comment"></div>
</div>
</div>
<div id="OGIfooter">
<div class="svg_holder">
<svg width="81" height="54">
<desc>European flag</desc>
<g transform="scale(0.1)">
<defs><g id="s"><g id="c"><path id="t" d="M0,0v1h0.5z" transform="translate(0,-1)rotate(18)"/><use xlink:href="#t" transform="scale(-1,1)"/></g><g id="a"><use xlink:href="#c" transform="rotate(72)"/><use xlink:href="#c" transform="rotate(144)"/></g><use xlink:href="#a" transform="scale(-1,1)"/></g></defs>
<rect fill="#039" width="810" height="540"/><g fill="#fc0" transform="scale(30)translate(13.5,9)"><use xlink:href="#s" y="-6"/><use xlink:href="#s" y="6"/><g id="l"><use xlink:href="#s" x="-6"/><use xlink:href="#s" transform="rotate(150)translate(0,6)rotate(66)"/><use xlink:href="#s" transform="rotate(120)translate(0,6)rotate(24)"/><use xlink:href="#s" transform="rotate(60)translate(0,6)rotate(12)"/><use xlink:href="#s" transform="rotate(30)translate(0,6)rotate(42)"/></g><use xlink:href="#l" transform="scale(-1,1)"/></g></g>
</svg>
</div>
<p>This project has received funding from the European Union's Horizon 2020 research and innovation programme under grant agreement No 693849.</p>
<p>Discover more about the <a href="http://www.trafforddatalab.io/opengovintelligence/" target="_blank">Trafford Worklessness Pilot</a>.</p>
</div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://www.trafforddatalab.io/assets/javascript/labError.js"></script>
<script src="https://www.trafforddatalab.io/assets/javascript/labAjax.js"></script>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<script src="http://www.trafforddatalab.io/assets/d3/timeSeries.js"></script>
<script src="https://unpkg.com/leaflet.markercluster@1.3.0/dist/leaflet.markercluster.js"></script>
<script>
if (location.protocol == 'https:')
location.href = location.href.replace(/^https:/, 'http:')
var stringCSV="";
var endpoint = 'http://gmdatastore.org.uk/sparql.json';
var keyObj = '{"area_name":"Greater Manchester", "area_code":"E47000001"}'
var servicesObj={"gps":[],"dentists":[],"foodBanks":[],"probationOffices":[],"jobcentrePlus":[]}
//Start the map
var dateNow = new Date();
var leafletMap = L.map('map')
tiles=L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a> Contains National Statistics & OS data <a href="https://www.ons.gov.uk/methodology/geography/licences">© Crown copyright and database right ' + dateNow.getFullYear() + '</a>',
}).addTo(leafletMap);
clusters = L.markerClusterGroup({
maxClusterRadius: 25,
spiderfyOnMaxZoom: true,
showCoverageOnHover: false,
zoomToBoundsOnClick: true
});
var dataSeries=[]
plotReport(keyObj);// plot report for GM
var query1 = 'SELECT ?area_name ?area_code WHERE { ?metcty <http://www.w3.org/2000/01/rdf-schema#label> "E11000001" . ?district <http://publishmydata.com/def/ontology/spatial/within> ?metcty . ?district <http://statistics.data.gov.uk/def/statistical-geography#officialname> ?area_name . ?district <http://www.w3.org/2000/01/rdf-schema#label> ?area_code }'
postQuery(query1,endpoint,function(d){popSelect(d,"Local Authority","loadWardList")});//populate the first dropdown
function postQuery(query, url, callback){
query="query="+encodeURIComponent(query)
labAjax(url,callback,{ data:query, method: 'POST', header: [{ header: 'Accept', value: 'application/sparql-results+json' }, { header: 'Content-Type', value: 'application/x-www-form-urlencoded'}] });
}
function popSelect(data,container,onChangeFun){
var laNames = data.results.bindings;
var laSelect = '<select name="frmLAnames" onChange="' + onChangeFun + '(this.value)" class="datasetSelect"><option value="{}">Select a ' + container + '</option>';
for (var i = 0; i < laNames.length; i++) {
laSelect += '<option value="{£area_name£:£' + laNames[i]["area_name"]["value"] + '£,£area_code£:£' + laNames[i]["area_code"]["value"] + '£}"';
laSelect += '>' + laNames[i]["area_name"]["value"] + '</option>';
}
laSelect += '</select>';
var divf = document.createElement('div');
divf.innerHTML = laSelect;
document.getElementById(container).innerHTML = "";
document.getElementById(container).appendChild(divf);
}
function loadWardList(LAkey){
if(LAkey=="{}"){
LAkey = '{"area_name":"Greater Manchester", "area_code":"E11000001"}';
document.getElementById('Ward').innerHTML = "";
dataSeries=[]
plotReport(LAkey)
}else{
plotReport(LAkey);
var LAkey=JSON.parse(LAkey.replace(/£/g, '"'));
var area_code = LAkey["area_code"];
var area_name = LAkey["area_name"];
//ward list
var query = 'SELECT ?area_name ?area_code WHERE {?district <http://www.w3.org/2000/01/rdf-schema#label> "'+ area_code +'" . ?indistrict <http://publishmydata.com/def/ontology/spatial/within> ?district . ?indistrict <http://statistics.data.gov.uk/def/statistical-entity#code> <http://statistics.data.gov.uk/id/statistical-entity/E05> . ?indistrict <http://statistics.data.gov.uk/def/statistical-geography#officialname> ?area_name . ?indistrict <http://www.w3.org/2000/01/rdf-schema#label> ?area_code . }'
postQuery(query,endpoint,function(d){popSelect(d,"Ward","plotReport")});
}
}
function plotReport (obj) {
if (obj!= "{}"){
var keyObj=JSON.parse(obj.replace(/£/g, '"'));
var area_code = keyObj["area_code"];
var area_name = keyObj["area_name"];
if (!/^E47/.test(area_code)){
leafletMap.removeLayer(boundary);
clusters.clearLayers();
}
if(/^E11/.test(area_code)){
area_code= "E47000001"
}
document.getElementById('titleName').innerHTML = area_name;
//Map
d3.json("http://gmdatastore.org.uk/boundaries/"+area_code+".json", function(error, geoData) {
boundary = L.geoJSON(geoData,{style:{"color":"#e24a90",fillOpacity: 0.1}})
.addTo(leafletMap);
leafletMap.fitBounds(boundary.getBounds()); // adjust the zoom to fit the boundary to the screen size
//Table for services
//
servicesObj["gps"]=[];servicesObj["dentists"]=[];servicesObj["foodBanks"]=[];servicesObj["probationOffices"]=[];
servicesObj["jobcentrePlus"]=[];
var flag=0;
var stringHtmlArray=[]
if(/^E05/.test(area_code)){
d3.csv("https://www.trafforddatalab.io/open_data/general_practice/gm_general_practices.csv", function(data){
for(i=0;i<data.length;i++){
if (d3.geoContains(geoData, [data[i].lon,data[i].lat]) ){
servicesObj["gps"].push(data[i])
}
}
flag++
stringHtmlArray.push([1,"<div class='legendItem' onclick='showServices(this,\"gps\")'><div class='circleLegend'></div><div class='legLabel' >General Practice: "+servicesObj["gps"].length+"</div></div>"]);
if(flag==5)displayServices(servicesObj,stringHtmlArray)
});
d3.csv("https://www.trafforddatalab.io/open_data/dentists/gm_dentists.csv", function(data){
for(i=0;i<data.length;i++){
if (d3.geoContains(geoData, [data[i].lon,data[i].lat]) ){
servicesObj["dentists"].push(data[i])
}
}
flag++
stringHtmlArray.push([2,"<div class='legendItem' onclick='showServices(this,\"dentists\")'><div class='circleLegend'></div><div class='legLabel' >Dentists: "+servicesObj["dentists"].length+"</div></div>"]);
if(flag==5)displayServices(servicesObj,stringHtmlArray)
});
d3.csv("https://www.trafforddatalab.io/open_data/food_banks/gm_food_banks.csv", function(data){
for(i=0;i<data.length;i++){
if (d3.geoContains(geoData, [data[i].lon,data[i].lat]) ){
servicesObj["foodBanks"].push(data[i])
}
}
flag++
stringHtmlArray.push([3,"<div class='legendItem' onclick='showServices(this,\"foodBanks\")'><div class='circleLegend'></div><div class='legLabel' >Food Banks: "+servicesObj["foodBanks"].length+"</div></div>"]);
if(flag==5)displayServices(servicesObj,stringHtmlArray)
});
d3.csv("https://www.trafforddatalab.io/open_data/jobcentre_plus/gm_jobcentreplus.csv", function(data){
for(i=0;i<data.length;i++){
if (d3.geoContains(geoData, [data[i].lon,data[i].lat]) ){
servicesObj["jobcentrePlus"].push(data[i])
}
}
flag++
stringHtmlArray.push([4,"<div class='legendItem' onclick='showServices(this,\"jobcentrePlus\")'><div class='circleLegend'></div><div class='legLabel' >Jobcentre Plus: "+servicesObj["jobcentrePlus"].length+"</div></div>"]);
if(flag==5)displayServices(servicesObj,stringHtmlArray)
});
d3.csv("https://www.trafforddatalab.io/open_data/probation/gm_probation_offices.csv", function(data){
for(i=0;i<data.length;i++){
if (d3.geoContains(geoData, [data[i].lon,data[i].lat]) ){
servicesObj["probationOffices"].push(data[i])
}
}
flag++
stringHtmlArray.push([5,"<div class='legendItem' onclick='showServices(this,\"probationOffices\")'><div class='circleLegend'></div><div class='legLabel' >Probation Office: "+servicesObj["probationOffices"].length+"</div></div>"]);
if(flag==5)displayServices(servicesObj,stringHtmlArray)
});
}
})
function displayServices(servicesObj,stringHtmlArray){
stringHtmlArray.sort(function(a, b) {
return a[0] - b[0];
});
var htmlString="<p>Click for locations</p>"
for(i=0;i<stringHtmlArray.length;i++){
htmlString+=stringHtmlArray[i][1]
}
document.getElementById('countPoints').innerHTML=htmlString
document.getElementById('countPoints').style.opacity=0.8;
}
//Comment stats
var flag2=0;
var stringHtmlArray2=[]
var cbql1=encodeURIComponent('{cubiql{dataset_working_age_population {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page{observation {count}}}}}}')
var endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql1
labAjax(endpointCubiql,function(d){
var responsesArray=d["data"]["cubiql"]["dataset_working_age_population"]["observations"]["page"]["observation"]
if(responsesArray.length>0){
var numFormat = d3.format(",");
flag2++
stringHtmlArray2.push([1, "Working age population (2017): " + numFormat(responsesArray[0]["count"])]);
if(flag2==4)printStats(stringHtmlArray2)
}
});
var cbql2=encodeURIComponent('{cubiql{dataset_working_age_adults_with_no_qualifications {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page{observation {reference_area {label}count}}}}}}')
endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql2
labAjax(endpointCubiql,function(d){
var responsesArray=d["data"]["cubiql"]["dataset_working_age_adults_with_no_qualifications"]["observations"]["page"]["observation"]
if(responsesArray.length>0){
var numFormat = d3.format(",");
flag2++
stringHtmlArray2.push([2, "</br></br> Working age adults with no qualifications (2011): " + numFormat(responsesArray[0]["count"])]);
if(flag2==4)printStats(stringHtmlArray2)
}
})
var cbql3=encodeURIComponent('{cubiql{dataset_households_with_lone_parent_not_in_employment {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page{observation {reference_area {label}count}}}}}}')
endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql3
labAjax(endpointCubiql,function(d){
var responsesArray=d["data"]["cubiql"]["dataset_households_with_lone_parent_not_in_employment"]["observations"]["page"]["observation"]
if(responsesArray.length>0){
var numFormat = d3.format(",");
flag2++
stringHtmlArray2.push([3, "</br></br> Households with lone parent not in employment (2011): " + numFormat(responsesArray[0]["count"])]);
if(flag2==4)printStats(stringHtmlArray2)
}
})
var cbql4=encodeURIComponent('{cubiql{dataset_social_rented_households {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page{observation {reference_area {label}count}}}}}}')
endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql4
labAjax(endpointCubiql,function(d){
var responsesArray=d["data"]["cubiql"]["dataset_social_rented_households"]["observations"]["page"]["observation"]
if(responsesArray.length>0){
var numFormat = d3.format(",");
flag2++
stringHtmlArray2.push([4, "</br></br> Social rented households (2011): " + numFormat(responsesArray[0]["count"])]);
if(flag2==4)printStats(stringHtmlArray2)
}
})
//Time series of Claimant Count
//var query = 'SELECT ?date ?percent WHERE { ?wardurl <http://www.w3.org/2000/01/rdf-schema#label> "'+ area_code +'" . ?s2 <http://purl.org/linked-data/cube#dataSet> <http://gmdatastore.org.uk/data/claimant-rate> . ?s2 <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?wardurl . ?s2 <http://gmdatastore.org.uk/def/measure-properties/percent> ?percent . ?s2 <http://purl.org/linked-data/sdmx/2009/dimension#refPeriod> ?refDate . ?refDate <http://www.w3.org/2000/01/rdf-schema#label> ?date . } ORDER BY ?date'
var cbql5=encodeURIComponent('{cubiql{dataset_claimant_rate {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page (first:50) {observation {reference_area {label} reference_period {label}percent}}}}}}')
endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql5
labAjax(endpointCubiql,function(d){
document.getElementById('timeLine').innerHTML = "";
var responsesArray=d["data"]["cubiql"]["dataset_claimant_rate"]["observations"]["page"]["observation"]
var data=[];
for (var i = 0; i < responsesArray.length; i++) {
data.push({serie:area_name, areaCode:area_code, date:responsesArray[i]["reference_period"]["label"],value:responsesArray[i]["percent"]})
}
if (dataSeries.length<=1){
dataSeries.push(data);
}else if (dataSeries.length==2){
if (/^E08/.test(area_code)){//LA
dataSeries[1]=data;
}else{
dataSeries[2]=data;
}
}else if (dataSeries.length==3){
if (/^E08/.test(area_code)){//LA
dataSeries.splice(2,1);
dataSeries[1]=data;
}else{
dataSeries[2]=data;
}
}
var formatTime = "%Y-%m";
var plotParams={data:dataSeries,
formatTime:formatTime,
container:"#timeLine",
title:"Proportion of people claiming unemployment related benefits ",
ytitle:"Percent",
source:"Claimant Count, DWP",
palette:['#fbc7d9','#f18db4','#e24a90']//['#f7a9c6','#ee7dab','#e24a90']
}
var svg=timeSeries(plotParams)
//Comment timeseries
var subs = (data[data.length-1].value-data[data.length-13].value).toFixed(2)
var subst= Math.abs(subs)+"%"
if (subs==0.00) subst = ""
document.getElementById('chartComm').innerHTML = "";
var difference ="";
if (subs==0) difference="equal to";
else if (subs>0) difference="more than";
else if (subs<0) difference="less than";
var parseTime = d3.timeParse("%Y-%m");
var formatTime = d3.timeFormat("%B %Y");
document.getElementById('chartComm').innerHTML = "In " + formatTime(parseTime(data[data.length-1].date)) + ", " + data[data.length-1].value+ "% of the population was claiming unemployment related benefits in " + data[data.length-1].serie + ".</br> That was "+ subst +" "+ difference +" the percentage of claimants in " + formatTime(parseTime(data[data.length-13].date)) + ". </br></br>Download <span id='downloadCSV' onclick='createCSV()'> CSV</span>"
stringCSV="area_code,area_name,date,measure,value"
for (var a = 0; a<dataSeries.length; a++){
for (var b = 0;b<dataSeries[a].length; b++){
stringCSV+="\n"+dataSeries[a][b]["areaCode"]+","+dataSeries[a][b]["serie"]+","+dataSeries[a][b]["date"]+",Proportion of residents claiming JSA or Universal Credit,"+dataSeries[a][b]["value"];
}
}
// */
});
//var query2 = 'SELECT DISTINCT ?category ?count WHERE { ?wardurl <http://www.w3.org/2000/01/rdf-schema#label> "'+ area_code +'" . ?s2 <http://purl.org/linked-data/sdmx/2009/dimension#refArea> ?wardurl . ?s2 <http://purl.org/linked-data/cube#dataSet> <http://gmdatastore.org.uk/data/business-register-employment-survey> . ?s2 <http://gmdatastore.org.uk/def/dimension/industry-category> ?urlcategory . ?urlcategory <http://www.w3.org/2000/01/rdf-schema#label> ?category . ?s2 <http://gmdatastore.org.uk/def/measure-properties/count> ?count . }'
//postQuery(query2,endpoint,function(data){
var cbql6=encodeURIComponent('{cubiql{dataset_industry_category {observations(dimensions:{reference_area:"http://statistics.data.gov.uk/id/statistical-geography/'+ area_code +'"}) {page (first:50) {observation {reference_area {label}industry_category percent}}}}}}')
endpointCubiql = 'http://cubiql.gmdatastore.org.uk/graphql?query='+cbql6
labAjax(endpointCubiql,function(d){
document.getElementById("BRtable").innerHTML = "";
document.getElementById("tableTitle").innerHTML = "";
document.getElementById('bussinessComm').innerHTML ="";
var lookup={"A_18_ARTS_ENTERTAINMENT_RECREATION_OTHER_SERVICES_R_S_T_AND_U":"Arts, entertainment, recreation & other services",
"A_4_CONSTRUCTION_F":"Construction",
"A_15_PUBLIC_ADMINISTRATION_DEFENCE_O":"Public administration & defence",
"A_9_ACCOMMODATION_FOOD_SERVICES_I":"Accommodation & food services",
"A_14_BUSINESS_ADMINISTRATION_SUPPORT_SERVICES_N":"Business administration & support services",
"A_16_EDUCATION_P":"Education",
"A_11_FINANCIAL_INSURANCE_K":"Financial & insurance",
"A_1_AGRICULTURE_FORESTRY_FISHING_A":"Agriculture, forestry & fishing",
"A_17_HEALTH_Q":"Health",
"A_7_RETAIL_PART_G":"Retail",
"A_12_PROPERTY_L":"Property",
"A_6_WHOLESALE_PART_G":"Wholesale",
"A_10_INFORMATION_COMMUNICATION_J":"Information & communication",
"A_2_MINING_QUARRYING_UTILITIES_B_D_AND_E":"Mining, quarrying & utilities",
"A_3_MANUFACTURING_C":"Manufacturing",
"A_5_MOTOR_TRADES_PART_G":"Motor trade",
"A_8_TRANSPORT_STORAGE_INC_POSTAL_H":"Transport & storage",
"A_13_PROFESSIONAL_SCIENTIFIC_TECHNICAL_M":"Professional, scientific & technical"}
var responsesArray=d["data"]["cubiql"]["dataset_industry_category"]["observations"]["page"]["observation"]
responsesArray.sort(function(a, b){
return b.percent - a.percent;
})
var tableContent = ""
if (responsesArray.length>0){
document.getElementById('tableTitle').innerHTML = "Percent of the count of employees by broad industry group according to the UK business register and employment survey <a href='https:\//www.ons.gov.uk/employmentandlabourmarket/peopleinwork/employmentandemployeetypes/bulletins/businessregisterandemploymentsurveybresprovisionalresults/provisionalresults2017revisedresults2016' target='_blank'>(BRES)</a> 2017 "
for (var i = 0; i < responsesArray.length; i++) {
tableContent += '<tr><td>' + lookup[responsesArray[i]["industry_category"]] + '</td><td>' + responsesArray[i]["percent"].toFixed(1) + '</td></tr>'
}
document.getElementById('BRtable').innerHTML = tableContent;
var width = document.getElementById('tableDiv').offsetWidth-document.getElementById('BRtable').offsetWidth-20//.getElementsByTagName('tr');
var max = d3.max(responsesArray, function (d) {
return + d["percent"];
})
var barScale = d3.scaleLinear()
.range([0, width])
.domain([0, max]);
var trs = document.getElementById('BRtable').getElementsByTagName('tr')
for (var i = 0; i < responsesArray.length; i++) {
var tdB = document.createElement("td");
tdB.innerHTML = '<td><div class="bar" style="width:' + barScale(responsesArray[i]["percent"])+'px"></div></tr>';
trs[i].appendChild(tdB)
}
//Comment bussiness register employment
for (var i = 0; i < responsesArray.length; i++){
if(responsesArray[i]["percent"]== max){
var industry = lookup[responsesArray[i]["industry_category"]]
break;
}
}
document.getElementById('bussinessComm').innerHTML = "The industry with the largest number of employees working in " + area_name + " is: " + industry +".";
document.getElementById('bussinessComm').style.borderColor = "#e24a90";
}else{
document.getElementById('bussinessComm').style.borderColor = "white";
}
});
}
}
function printStats(array){
var numFormat = d3.format(",");
array.sort(function(a, b) {
return a[0] - b[0];
});
var htmlString=""
for(i=0;i<array.length;i++){
htmlString+=array[i][1]
}
document.getElementById('statComm').innerHTML =htmlString;
}
function showServices(e,filterKey){
var legLabels=document.getElementById("countPoints").getElementsByClassName("legLabel")
var circleLegends=document.getElementById("countPoints").getElementsByClassName("circleLegend")
for (i=0;i<legLabels.length;i++) {
legLabels[i].className="legLabel";
}
for (i=0;i<circleLegends.length;i++) {
circleLegends[i].className="circleLegend";
}
e.getElementsByClassName("legLabel")[0].className="legLabel legLabelActive";
e.getElementsByClassName("circleLegend")[0].className="circleLegend circleActive";
//leafletMap.removeLayer(services);
clusters.clearLayers();
var circles =[]
//show recent month
var geojsonMarkerOptions = {
color: 'white',
opacity: 0.8,
weight: 1,
fillColor: '#E24A90',
fillOpacity: 0.8,
radius: 6
};
servicesObj[filterKey].forEach(function(service) {
var circle=L.circleMarker([service.lat, service.lon], geojsonMarkerOptions)
if ("website" in service){
if (service.website=="NA"){
circle.bindPopup(service.name,{'className' : 'popupServ'});
}else{
circle.bindPopup('<a href="'+service.website+'" target="_blank">'+service.name+'</a>',{'className' : 'popupServ'});
}
}else{
circle.bindPopup(service.name,{'className' : 'popupServ'});
}
circles.push(circle)
})
services = L.layerGroup(circles).addTo(clusters)
leafletMap.addLayer(clusters);
}
function createCSV(){
var download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';
if (navigator.msSaveBlob) { // IE10
navigator.msSaveBlob(new Blob([content], {
type: mimeType
}), fileName);
} else if (URL && 'download' in a) { //html5 A[download]
a.href = URL.createObjectURL(new Blob([content], {
type: mimeType
}));
a.setAttribute('download', fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
location.href = 'data:application/octet-stream,' + encodeURIComponent(content);
}
}
download(stringCSV, 'Claimant-rate.csv', 'text/csv;encoding:utf-8');
}
</script>
</body>
</html>