Back to FrogFind! | Browsing URL:


Custom report - Nomis - Official Labour Market Statistics

official labour market statistics

', geogNameInTableAmbiguous: '$label in $parent', geogNameInCompleteList: '$label $typename' }; var p = null; var compared = []; var complookups = 0; // During initialisation, number of area lookups ongoing. var initialSearch = null; function createRemoveFunction(item) { var itm = item; return function() { compared = compared.filter(function(el) { return el.value !== itm.value; }); go(); }; } function createMoveComparsionFunc(index, direction) { var _i = index; var _d = direction; return function() { var tmp = compared[_i]; compared[_i] = compared[_i + _d]; compared[_i + _d] = tmp; updatecomparedlist(); updateGeogConfig(); p.redraw(); }; }; function getGeogType(tp) { if(tp > 10000) tp = tp >> 22; for(var i = 0; i 0) { var added = []; for(var i = 0; i 5) window.alert('Maximum of 5 comparison areas allowed, please remove some before adding parent areas of ' + a.label + '.'); else if(added.length > 0) { added.map(function(par) { addComparison(par, true); }); updatecomparedlist(); go(); } else window.alert('Parent areas of ' + a.label + ' are not available in this report.'); } } } function updatecomparedlist() { var div = document.getElementById('comparisonareas'); if(modes[mode].alpha) div.innerHTML = 'Please note, area selection is in early stages of development and may change significantly in the future.'; else div.innerHTML = ''; var c = ''; for(var i = 0; i 0) { var par = lookup(ca.parents[0]); if(par) { lbl += ' (' + par.label + ')'; } } n.appendChild(document.createTextNode(lbl)); var btnCf = ui.button({ label: '+Parents', classname: 'positive', onclick: createParentCompareFunction(ca) }); btnCf.innerHTML = '⑂'; btnCf.title = 'Compare with parent areas'; var btnUp = ui.button( { label: 'Move Up', classname: 'positive', onclick: createMoveComparsionFunc(i, -1) } ); var btnDn = ui.button( { label: 'Move Down', classname: 'positive', onclick: createMoveComparsionFunc(i, 1) } ); btnUp.innerHTML = '⇧'; btnUp.title = 'Move this area up the list'; btnDn.innerHTML = '⇩'; btnDn.title = 'Move this area down the list'; if(i == 0) btnUp.disabled = true; if(i == compared.length - 1) btnDn.disabled = true; var ctrl = document.createElement('div'); if(!ca.parents || (ca.parents.length == 0)) { btnCf.disabled = true; } else { var hasall = true; var cft = []; for(var j = 0; j 1 && k == cft.length - 1) btnCflbl += ' and '; else if(k > 0) btnCflbl += ', '; btnCflbl += lookup(cft[k]).label; } btnCf.title = btnCflbl; } } var btnRm = ui.button( { label: 'Remove', classname: 'negative', onclick: createRemoveFunction(ca) } ) btnRm.innerHTML = '✕ Remove'; btnRm.title = 'Remove ' + ca.label; // Shuffle button if(modes[mode].showShuffleButtonsForSelectedAreas) { ctrl.appendChild(btnDn); ctrl.appendChild(btnUp); } // Comparison with parents button if(modes[mode].showAddParentsButtonForSelectedAreas) ctrl.appendChild(btnCf); ctrl.appendChild(btnRm); n.appendChild(ctrl); div.appendChild(n); if(c.length > 0) c += ','; c += compared[i].gss; } // Delete all button if(compared.length > 1) { var btnDa = ui.button( { label: 'Remove all areas', classname: 'negative', onclick: function() { compared = []; go(); } }); div.appendChild(btnDa); } // URL update if (history.pushState) { if(c.length > 0) { var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?compare=' + c; if(mode > 0) newurl += '&mode=' + mode; if(document.location.href != newurl) window.history.pushState({path:newurl},'',newurl); } } } function updateGeogConfig() { params.config.geography = []; params.config.geognames = ''; params.config.geognamelist = []; params.config.substitute = { geography: [ ] }; for(var i = 0; i > 22 == 267) ambig = true; // Force Built-up area names through to data else { // Check ambiguous name? for(var j = 0; j 0) par = lookup(compared[i].parents[0]); params.config.geography.push(compared[i].value); var gnlname = patterns.geogNameInReport; gnlname = gnlname.replace('$label', entry.label); gnlname = gnlname.replace('$typename', gt.singular); gnlname = gnlname.replace('$parent', (par)? par.label : 'unknown'); gnlname = gnlname.replace('$gss', (compared[i].gss)? compared[i].gss : 'unknown'); params.config.geognamelist.push(gnlname); // Make the data display the names the way we refer to them in the application. var gntname = (ambig)? patterns.geogNameInTableAmbiguous : patterns.geogNameInTable; gntname = gntname.replace('$label', entry.label); gntname = gntname.replace('$typename', gt.singular); gntname = gntname.replace('$parent', (par)? par.label : 'unknown'); gntname = gntname.replace('$gss', (compared[i].gss)? compared[i].gss : 'unknown'); params.config.substitute.geography.push({ value: entry.value, label: gntname }); // Complete list of geography names in play var gnname = patterns.geogNameInCompleteList; gnname = gnname.replace('$label', entry.label); gnname = gnname.replace('$typename', gt.singular); gnname = gnname.replace('$parent', (par)? par.label : 'unknown'); gnname = gnname.replace('$gss', (compared[i].gss)? compared[i].gss : 'unknown'); if(params.config.geognames.length > 0) params.config.geognames += (i == compared.length-1)? ' and ' : ', '; params.config.geognames += gnname; } } function go() { updatecomparedlist(); updateGeogConfig(); document.getElementById('template-wrapper').innerHTML = ''; if(params.config.geography.length > 0) { if (p == null) p = NomisProfile.create(params); else p.refresh(); ga('send', 'event', 'Report localarea', 'View', params.config.geography[0]); ga('send', 'event', 'Report localarea', 'View (area type)', getGeogType(params.config.geography[0]).singular); $('#template-wrapper').show(); } else { if(p != null) p.remove(); $('#template-wrapper').hide(); } } function setSearchingEnabled(enabled) { if(enabled) refreshSearchResults(); document.getElementById('searchtxt').disabled = !enabled; document.getElementById('searchbtn').disabled = !enabled; } var areatypelist = { }; function setAreaType(typenum, callback) { if(!areatypelist['type' + typenum]) { loadingMsg('Loading areas'); $.getJSON("/json/geography/type" + typenum + ".json?3", function (data) { areatypelist['type' + typenum] = data; data.map(function(area) { // Fix gss code not present in object, but given in label. var s = area.label.split(' : '); if((s.length) > 1 && !area.gss) { area.gss = s[0]; area.label = s[1]; } }); if(callback) callback(data); }); } else { if(callback) callback(areatypelist['type' + typenum]); } } function getAreas(tp) { return areatypelist['type' + tp]; } function hasComparison(kv) { for(var i = 0; i 0) { for(var i = 0; i No matching areas found.'; } function clearResults() { var matchbox = document.getElementById('matches'); matchbox.innerHTML = ''; hits = []; } function findHitIn(value, o) { var hit = o[value]; if(!hit) { // Look through everything in o for (var property in o) { if (o.hasOwnProperty(property)) { var op = o[property]; if(op) { if(op.hit.value == value) { hit = op; break; } else { hit = findHitIn(value, op.children); if(hit) break; } } } } } return hit; } function addChildrenToHitEntry(entry) { validgeogtypes.map(function(t) { if(t.type != (entry.value >> 22)) { getAreas(t.type).map(function(a) { if(a.parents && a.parents.length > 0) { var fc = a.parents[0]; if(fc == entry.hit.value) { entry.children.push({ hit: a, children: [] }); } } }); } }); } function organiseHits(h) { var o = {}; h.map(function(a) { var entry = findHitIn(a.value, o); if(!entry) { // create entry entry = { hit: a, children: [] }; addChildrenToHitEntry(entry); o[a.value] = entry; } entry.autoExpand = false; entry.realHit = true; if(a.parents) { var lastp = null; for(var i = a.parents.length - 1; i >= 0; i--) { var p = a.parents[i]; var pentry = findHitIn(p, o); if(!pentry) { // create entry var par = lookup(p); if(par) { // valid parent pentry = { hit: par, children: [] }; o[p] = pentry; } } if(pentry) { if(lastp != null) { o[p] = null; // This is now a child if(lastp.children.indexOf(pentry) == -1) lastp.children.push(pentry); } lastp = pentry; } } if(lastp != null) { o[a.value] = null; if(lastp.children.indexOf(entry) == -1) lastp.children.push(entry); //o[lastp.hit.value] = lastp; } } }); return o; } function addSearchNodeProperties(node) { var m = node.hit; var div = ui.element({ tagname: 'span', classname: 'search-result' }); div.appendChild(ui.button({ label: m.label, classname: node.realHit? 'actual-search-hit' : '', onclick: function() { if(hasComparison(m.value)) window.alert('You have already selected ' + m.label + '.'); else if(compared.length == maxcomparisons) window.alert('Maximum of ' + maxcomparisons + ' areas can be compared, please remove one before trying to add more.'); else { addComparison(m); clearResults(); } } })); div.appendChild(ui.element({ tagname: 'span', classname: 'areatype-name', content: getGeogType(node.hit.value).name })); node.content = div; if(node.children && node.children.length > 0) { // Sort children node.children.sort(function (a, b) { if (a.hit.label b.hit.label) return 1; return 0; }); node.children.map(function(c) { addSearchNodeProperties(c); }); } else node.children = null; } function createSearchTreeNodes(h) { var t = []; for (var property in h) { if (h.hasOwnProperty(property)) { var op = h[property]; if(op) { addSearchNodeProperties(op); t.push(op); } } } return t; } function createSearchTree(nodes) { return ui.tree({ classname: 'tree', children: nodes }) } function refreshSearchResults() { if(hits.length > 0) { var matchbox = document.getElementById('matches'); if(modes[mode].searchResultViewStyle == 'tree') { // Hierarchical tree view of results var h = organiseHits(hits); var nodes = createSearchTreeNodes(h); var tree = createSearchTree(nodes); matchbox.appendChild(tree); } else { // List view hits.map(function(h) { addListSearchResults(h.matches, h.geogtype, matchbox); }); var opts = document.createElement('aside'); opts.appendChild(ui.element({ tagname: 'h1', content: 'Options' })); opts.appendChild(ui.checkbox({ id: 'chkpar', value: 'yes', label: 'When I choose an area, include its parent areas (for example the local authority and country that it is within).', checked: modes[mode].autoAddParentsOnSelectArea, onclick: function() { modes[mode].autoAddParentsOnSelectArea = document.getElementById('chkpar').checked; return true; } })); matchbox.appendChild(opts); } } } function setSearchResults(matches, geogtype) { if(modes[mode].searchResultViewStyle == 'tree') { matches.map(function(m) { hits.push(m); }); } else { // List view hits.push({ matches: matches, geogtype: geogtype }); } } function addListSearchResults(matches, geogtype, matchbox) { matchbox.appendChild(ui.element({ tagname: 'h3', content: ((matches.length 0) { matches.sort(function (a, b) { if (a.label b.label) return 1; return 0; }); matches.map(function(m) { var lbl = m.label; var lbl2 = 'Compare ' + m.label; var others = []; if(geogtype.labelWithGSS && m.gss && (m.label.indexOf(m.gss) == -1)) { lbl = m.gss + ' - ' + lbl; } if((lbl.indexOf('(') == -1 || lbl.indexOf('(no data)') != -1) && m.parents && m.parents.length > 0) { for(var i = 0; i > 22 }); lbl += ' (in ' + par.label; if(tmpptp) lbl += ' ' + tmpptp.singular; lbl += ')'; } if(i == 0 || i == m.parents.length - 1) { if(others.length == 0) lbl2 += ' with '; else if(i == m.parents.length - 1) lbl2 += ' and '; else lbl2 += ','; lbl2 += par.label; others.push(par); } } } } var nodata = (lbl.indexOf('(no data)') != -1); var div = document.createElement('div'); div.className = 'search-result'; var btn = ui.button({ label: lbl, classname: 'actual-search-hit', onclick: function() { if(hasComparison(m.value)) window.alert('You have already selected ' + lbl + '.'); else if(compared.length == maxcomparisons) window.alert('Maximum of ' + maxcomparisons + ' areas can be compared, please remove one before trying to add more.'); else { ga('send', 'event', 'Report localarea', 'Select area', 'Result list'); addComparison(m); if(!modes[mode].keepResults) clearResults(); } } }); var maplink = document.createElement('a'); maplink.onclick = function() { modalMap(m.value, lbl, false, event.shiftKey); } maplink.setAttribute('class', 'maplink'); maplink.setAttribute('title', 'Preview a map of ' + lbl); var mapicon = document.createElement('img'); mapicon.setAttribute('src', '/images/map.gif'); maplink.appendChild(mapicon); div.appendChild(btn); div.appendChild(maplink); if(nodata) { btn.disabled = nodata; div.appendChild(ui.alink({ href: '#', classname: 'whynodata', label: 'Why no data?', onclick: function() { window.alert('2011 Census data are not available for this Parish.'); ga('send', 'event', 'Report localarea', 'Select area', 'Why no data'); return false; } })); } matchbox.appendChild(div); }); } else { matchbox.appendChild(ui.element({ tagname: 'span', content: (geogtype.noMatchMessage)? geogtype.noMatchMessage : 'No matches found' }));; } } function isInCoverage(a) { if(countryCoverage == null || (!a.cov)) return true; for(var i = 0; i 0) return true; else return false;l } function search(pattern) { var suppliedpattern = pattern; pattern = pattern.toLowerCase(); pattern = pattern.replace(/ /g, ''); pattern = pattern.replace(/-/g, ''); pattern = pattern.replace(/[\W_]+/g," "); // Strip out funny characters if(pattern.length 0) { setSearchResults(matches, gssgeogtypes[t]); // Stop after first hit break; } } if(matchcount == 0) { ga('send', 'event', 'Report localarea', 'Search area - no hits', suppliedpattern); nomatch(); setSearchingEnabled(true); } else { ga('send', 'event', 'Report localarea', 'Search area - hits', suppliedpattern); setSearchingEnabled(true); } } else { // Name search for(var t = 0; t 0) setSearchResults(matches, namegeogtypes[t]); matchcount += matches.length; } // If no area matches then try a postcode search if(matchcount == 0) { if(pattern.length >= 5) { containsnum = /\d/.test(pattern); if(containsnum) { // No number then it can't be a postcode. var queue = FuncQueue.create({ ignoreErrors: false, timeout: 30000, onError: function(message) { console.log(message); }, onTimeout: function() { console.log('failed'); } }); // Add some function calls to the queue pcgeogtypes.map(function(t) { queue.add(createPCfunc(pattern, t)); }); queue.run(function(data) { data.map(function(d) { // Process results to try and resolve parents for areas that don't have their own list if(d.geogtype.resolveParents = true && d.matches.length == 1) { data.map(function(d2) { if(d2.geogtype.type == d.geogtype.resolveParent && d2.matches.length == 1) { var a = d2.matches[0]; // Take this area and its last parent too. d.matches[0].parents.push(a.value); d.matches[0].parents.push(a.parents[a.parents.length - 1]); } }); } setSearchResults(d.matches, d.geogtype); matchcount += d.matches.length; }); if(matchcount == 0) ga('send', 'event', 'Report localarea', 'Search postcode - no hits', suppliedpattern); else ga('send', 'event', 'Report localarea', 'Search postcode', suppliedpattern); setSearchingEnabled(true); }); } else { ga('send', 'event', 'Report localarea', 'Search area - no hits', suppliedpattern); nomatch(); setSearchingEnabled(true); } } else { ga('send', 'event', 'Report localarea', 'Search area - no hits', suppliedpattern); nomatch(); setSearchingEnabled(true); } } else { ga('send', 'event', 'Report localarea', 'Search area - hits', suppliedpattern); setSearchingEnabled(true); } } } function createPCfunc(pattern, t) { var pat = pattern; var tp = t; var matches = []; return function(complete) { $.getJSON('/api/v01/dataset/NM_' + pcSearchContext + '_1/geography/POSTCODE|' + pat + ';' + tp.type + '.def.sdmx.json', function(data) { try { data.structure.codelists.codelist[0].code.map(function(obj, idx, arr) { if(typeof obj.value === 'number') { var a = lookup(obj.value); if(a) this.push(a); else if(!tp.hasAreaLookup) { // Capture this as a new area var at = getAreas(tp.type); if(at) { a = { value: obj.value, label: obj.description.value, gss: obj.description.value, parents: [] }; at.push(a); this.push(a); } } } }, matches); } catch(err) { ; } complete({ matches: matches, geogtype: t }); }); }; } function addqueue(queue, type) { queue.add(function(complete) { setAreaType(type, complete); }); } function isSupported(t) { for(var i = 0; i > 22; } else { // Get the Nomis type by checking 3 characters of the GSS of the first geography in each of the type lists // taking the value and right-shifting the keyval var part = kvOrGss.substring(0,3); for (var prop in areatypelist) { var atp = areatypelist[prop]; if(atp.length > 0 && atp[0].gss.substring(0,3) == part) return atp[0].value >> 22; } return 0; } } function lookup(kv) { var tp = resolveType(kv); if(tp != 0) { // Found the type, look in the list var list = areatypelist['type' + tp]; if(list) { for(var i = 0; i = 1)) currgeog = compared[0].value; var selctrl = ui.select({ label: (modes[mode].displaySelectedAreas)? 'Choose an area for comparison' : 'Choose an area', id: 'areaselector', list: optgrplist, selected: currgeog }); var selbtn = ui.button({ label: (modes[mode].displaySelectedAreas)? 'Add' : 'View', classname: 'positive', onclick: function() { selbtn.disabled = true; var a = lookup(document.getElementById('areaselector').value); if(modes[mode].destroyReportOnSearch) { compared = []; } if(hasComparison(a.value)) window.alert('You have already seleted ' + a.label + '.'); else if(compared.length >= maxcomparisons) window.alert('Maximum of ' + maxcomparisons + ' areas can be compared, please remove an area before adding more.'); else addComparison(a); }}); selbtn.disabled = true; selctrl.onchange = function() { selbtn.disabled = false; } selectbox.appendChild(selctrl); selectbox.appendChild(selbtn); } function hideSearch() { document.getElementById('searchbox').style.display = 'none'; // Hide the search box } function hidePulldown() { document.getElementById('selectbox').style.display = 'none'; // Hide the select box } function uimodeCtrl() { var c = document.getElementById('uimodes'); c.style.display = 'none'; // hidden for now var optlist = []; modes.map(function(m, i) { if(m.name != undefined && m.hidden != true) { optlist.push({ label: m.name, value: i }); } }); c.appendChild(ui.select({ label: 'Report type', id: 'uimode', list: optlist, onchange: function() { var loc = document.location.href; ga('send', 'event', 'Report localarea', 'Change mode', modes[this.value].name); if(!modes[this.value].retainComparisonOnModeSwitch) { // Dump the entire querystring if(loc.indexOf('?') != -1) loc = loc.substring(0, loc.indexOf('?')); if(this.value != 0) { loc += '?mode=' + this.value; // Don't need mode for mode 0 as this is default } } else if(loc.indexOf('mode=' + mode) != -1) { // Tweak URL loc = loc.replace('mode=' + mode, 'mode=' + this.value); } else { // Add mode to URL if(loc.indexOf('?') != -1) loc = loc.replace('?', '?mode=' + this.value + '&'); else if(loc.indexOf('&') != -1) loc = loc.replace('&', '&mode=' + this.value + '&'); else loc += '?mode=' + this.value; } document.location.href = loc; } })); document.getElementById('uimode').value = mode; } function findAnnot(annots, title, defaultval) { if(annots != null) { for(var i = 0; i > 22); if(tp != null) { var at = getAreas(tp.type); if(at) { at.push(a); compared.push(a); } } } catch(e) { } complete(); }); }); } $(document).ready(function () { if(window.history) window.history.replaceState({path:document.location.href},'',document.location.href); // Initial state push window.onpopstate = function() { if(event && (event.state !== null)) { compared = []; reinstate(); } } var sections = document.getElementById('template-wrapper'); var searchbox = document.getElementById('searchbox'); var inputsearch = ui.inputsearch({ id: 'searchtxt', placeholder: 'Postcode or area name', onkeyup: function(event) { keycode = event.keyCode || event.which; if(keycode == 13) search(this.value); } }); searchbox.appendChild(inputsearch); searchbox.appendChild(ui.button({ id: 'searchbtn', label: 'Search', classname: 'positive', onclick: function() { search(inputsearch.value); } })); function err(msg) { var errbox = document.getElementById('err'); errbox.innerHTML = msg; errbox.style.display = 'block'; } var firstReinstate = true; function reinstate() { // Interface mode var qmode = ui.getQueryString('mode'); if(qmode) { try { mode = parseInt(qmode); } catch(e) { mode = 0; } } if(firstReinstate) { uimodeCtrl(); } if(!modes[mode].displaySelectedAreas) document.getElementById('comparisonareas').style.display = 'none'; initialSearch = ui.getQueryString('search'); if(initialSearch != null && initialSearch.length > 0) initialSearch = decodeURIComponent(initialSearch); var qcomp = ui.getQueryString('compare'); var unresolvedqueue = null; if(qcomp) { var qcomplist = qcomp.split(','); for(var i = 0; i 0) { var par = lookup(item.parents[0]); if(par) lbl += ' (' + par.label + ')'; } var meta = getGeogType(item.value).singular; return $( '

  • ' ).data('item.autocomplete', item) .append( '

    ' + lbl + '

    ' + meta + '

    ') .appendTo( ul ); }; } } } setSearchingEnabled(true); document.getElementById('loading').style.display = 'none'; document.getElementById('areacompdiv').style.display = 'block'; go(); var stxt = document.getElementById('searchtxt'); stxt.focus(); if(initialSearch != null && initialSearch.length > 0) { stxt.value = initialSearch; var sbtn = document.getElementById('searchbtn'); sbtn.click(); } firstReinstate = false; } // Load template loadingMsg('Loading report'); $.getJSON('/json/templates/localarea.json?3', function(template) { params = { config: { geography: [] }, profile: template, target: sections, lazyload: false, onRenderComplete: function () { } }; if(template.pageinfo) { if(template.pageinfo.title) { document.getElementById('dsname').innerHTML = template.pageinfo.title; document.title = template.pageinfo.title + ' - Nomis'; } if(template.pageinfo.breadcrumbs) SetBreadCrumbs(template.pageinfo.breadcrumbs); if(template.pageinfo.patterns) patterns = template.pageinfo.patterns; } var queue = FuncQueue.create({ ignoreErrors: false, timeout: 30000, onError: function(message) { console.log(message); }, onTimeout: function() { console.log('failed'); } }); if(template.postcodeSearchDataset) pcSearchContext = template.postcodeSearchDataset; if(template.countryCoverage) countryCoverage = template.countryCoverage; // For each of the valid geography types for this dataset. if(template.validity && template.validity.geography) template.validity.geography.map(function(t) { // Which ones are for name search? var ns = shouldAddToNameSearch(t); if(ns) namegeogtypes.push(ns); // Which ones are for postcode search? var ps = shouldAddToPostcodeSearch(t); if(ps) pcgeogtypes.push(ps); // Which ones are valid var st = isSupported(t); if(st) { validgeogtypes.push(st); // Add to GSS search always. gssgeogtypes.push(st); // Add geography type name search lookup calls to pre-load lists. if(st.hasAreaLookup) addqueue(queue, t.type); else { // Create an empty list to hold captured areas. areatypelist['type' + st.type] = []; } } }); if(validgeogtypes.length > 0) { queue.run(function(data) { // Reinstate areas reinstate(); }); } else console.log('No geography types supported'); }); }); setTimeout(function () { window.ABCpdf_go = true; }, 5000);