1function resetForm(){const chartBuilderForm=document.getElementById("chart-builder-form").reset();updateChart()} 2var blankSpec={$schema:"https://vega.github.io/schema/vega-lite/v5.json",title:{text:"Title",anchor:"start",subtitle:["Subtitle",""],fontSize:"14",subtitleFontSize:"12",color:"#122B39",subtitleColor:"#122B39",},height:"250",width:"container",autosize:{type:'fit',contains:'padding'},background:"white",view:{fill:"white",strokeOpacity:0},data:{url:"",format:{type:"json",},},mark:{type:"line",color:"#F4134D",strokeWidth:"2",},encoding:{x:{field:"date",type:"temporal",axis:{title:"",titleColor:"#122B39",grid:!1,},},y:{field:"value",type:"quantitative",axis:{title:"",titleColor:"#122B39",grid:!1,},},},};var ttq;function handleFormSubmit(event,type=null){event.preventDefault();const data=new FormData(event.target);const formJSON=Object.fromEntries(data.entries());var yourSpec=blankSpec;if(formJSON.dataUrl.includes("api.economicsobservatory.com")||formJSON.dataUrl.includes("api-test.economicsobservatory.com")){if(!formJSON.dataUrl.includes("?vega")){yourSpec.data.url=formJSON.dataUrl.concat("?vega")}else{yourSpec.data.url=formJSON.dataUrl}}else{yourSpec.data.url=formJSON.dataUrl} 3if(formJSON.title!==""){yourSpec.title.text=formJSON.title} 4if(formJSON.titleSize!==""){yourSpec.title.fontSize=formJSON.titleSize} 5if(formJSON.titleColour!==""){yourSpec.title.color=formJSON.titleColour} 6if(formJSON.subtitle!==""){yourSpec.title.subtitle=formJSON.subtitle} 7if(formJSON.subtitleSize!==""){yourSpec.title.subtitleFontSize=formJSON.subtitleSize} 8if(formJSON.subtitleColour!==""){yourSpec.title.subtitleColor=formJSON.subtitleColour} 9if(formJSON.height!==""){yourSpec.height=formJSON.height} 10if(formJSON.width!==""){yourSpec.width=formJSON.width} 11if(formJSON.pageColour!==""){yourSpec.background=formJSON.pageColour} 12if(formJSON.canvasColour!==""){yourSpec.view.fill=formJSON.canvasColour} 13if(formJSON.mark!==""){yourSpec.mark.type=formJSON.mark} 14if(formJSON.graphColour!==""){yourSpec.mark.color=formJSON.graphColour} 15if(formJSON.graphWeight!==""){yourSpec.mark.strokeWidth=formJSON.graphWeight} 16if(formJSON.xField!==""){yourSpec.encoding.x.field=formJSON.xField} 17if(formJSON.xType!==""){yourSpec.encoding.x.type=formJSON.xType} 18if(formJSON.xText!==""){yourSpec.encoding.x.axis.title=formJSON.xText} 19if(formJSON.yField!==""){yourSpec.encoding.y.field=formJSON.yField} 20if(formJSON.yType!==""){yourSpec.encoding.y.type=formJSON.yType} 21if(formJSON.yText!==""){yourSpec.encoding.y.axis.title=formJSON.yText} 22const yourSpecJSON=JSON.stringify(yourSpec,null,2);vegaEmbed("#chart",yourSpec,{actions:!1});output(syntaxHighlight(JSON.stringify(yourSpec,null,2)),".results");let customizableSpec={title:yourSpec.title,mark:yourSpec.mark,height:yourSpec.height,width:yourSpec.width,background:yourSpec.background,view:yourSpec.view,encoding:{x:{field:yourSpec.encoding.x.field,type:yourSpec.encoding.x.type,axis:{title:yourSpec.encoding.x.axis.title,},},y:{field:yourSpec.encoding.x.field,type:yourSpec.encoding.x.type,axis:{title:yourSpec.encoding.x.axis.title,},},}};let customizableSpecJSON=JSON.stringify(yourSpec,null,2);$(".edit-code-area textarea").val(customizableSpecJSON);ttq=yourSpec} 23const form=document.querySelector(".chart-builder-form");if(form){form.addEventListener("submit",handleFormSubmit)} 24function updateChart(){submitButton=document.querySelector(".chart-builder-form .submitButton");if(submitButton){submitButton.click()} 25toggleShareMessage()} 26window.addEventListener("load",function(event){this.setTimeout(()=>{if(typeof fetchJSON==='function'){fetchJSON()} 27updateChart()},10)});function output(inp){document.body.appendChild(document.createElement("pre")).innerHTML=inp} 28function syntaxHighlight(json){json=json.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(match){var cls="number";if(/^"/.test(match)){if(/:$/.test(match)){cls="key"}else{cls="string"}}else if(/true|false/.test(match)){cls="boolean"}else if(/null/.test(match)){cls="null"} 29return'<span class="'+cls+'">'+match+"</span>"})} 30var theObj={a:1,b:"foo",c:[!1,"false",null,"null",{d:{e:1.3e5,f:"1.3e5"}}],};var str=JSON.stringify(theObj,null,4);function output(inp,targetElement){const outputElement=document.querySelector(targetElement);outputElement.innerHTML="";outputElement.appendChild(document.createElement("pre")).innerHTML=inp} 31function scrollToSection(sectionId,clickedButton){var section=document.querySelector(sectionId);section.scrollIntoView();toggleShareMessage()} 32function toggleShareMessage(){const shareMessage=document.querySelector("#createSection");const urlField=document.querySelector("#url");
32if(shareMessage&&urlField&&urlField.value!==""){shareMessage.classList.add("urlLoaded")}} 33function isInViewport(ele){const{top,bottom}=ele.getBoundingClientRect();const vHeight=window.innerHeight||document.documentElement.clientHeight;return(top>0||bottom>150)&&top<vHeight} 34window.addEventListener("scroll",function(){const exploreBtn=document.querySelector("#exploreBtn");const createBtn=document.querySelector("#createBtn");const shareBtn=document.querySelector("#shareBtn");if(!exploreBtn||!createBtn||!shareBtn){return} 35const dataExplorer=document.querySelector("#data-explorer");const chartBuilder=document.querySelector("#chart-builder");if(isInViewport(dataExplorer)){exploreBtn.classList.add("active");if(createBtn!=null) 36createBtn.classList.remove("active");}else if(isInViewport(chartBuilder)){exploreBtn.classList.remove("active");if(createBtn!=null) 37createBtn.classList.add("active");}else{exploreBtn.classList.remove("active");if(createBtn!=null) 38createBtn.classList.remove("active");}});let renderAllCharts=()=>{Object.keys(loadedCharts).forEach((post_id)=>{let mode='nocol';if($('.chart-columns').length){mode='col'} 39if(mode=='col'&&!$('.chart-columns .chart[data-id="'+post_id+'"]').length){return} 40let spec=loadedCharts[post_id].specs;let chartWidth=(mode=='col')?$('.chart-columns .chart[data-id="'+post_id+'"]')[0].offsetWidth:null;let isNotAutoSize=loadedCharts[post_id].no_auto_size=='no-auto-size'?!0:!1;if(isNotAutoSize){if(spec.concat){let totalWidth=0;spec.concat.forEach(function(item){if(item.width){totalWidth+=item.width}});if(mode=='col'){chartWidth=chartWidth-170}else{chartWidth=1} 41spec.concat.forEach(function(item){if(item.width){item.width=(item.width/totalWidth)*chartWidth}})}} 42if(mode=='col'){loadedCharts[post_id].view=new vega.View(vega.parse(spec),{responsive:!1,renderer:"canvas",container:'.chart-columns .chart[data-id="'+post_id+'"]',hover:!0});loadedCharts[post_id].view.runAsync();vegaEmbed('.chart-columns .chart[data-id="'+post_id+'"]',spec,{responsive:!0,renderer:"canvas",})}else{loadedCharts[post_id].view=new vega.View(vega.parse(spec),{responsive:!1,renderer:"canvas",container:'.chart[data-id="'+post_id+'"]',hover:!0});loadedCharts[post_id].view.runAsync();vegaEmbed('.chart[data-id="'+post_id+'"]',spec,{responsive:!0,renderer:"canvas",})}})} 43function updateChartColumns(){$('.chart-column-1').empty();$('.chart-column-2').empty();$(".chart-list").each(function(){$(this).find('.hub__headline-list-item').each(function(index){let parent=$(this).parents('.chart-items-wrap');if(!$(this).hasClass('hide-chart')){if(index%2==0){parent.find(' .chart-column-1').append($(this).clone())}else{parent.find(' .chart-column-2').append($(this).clone())}}})});renderAllCharts()} 44$(window).on('load',function(){if($('.chart-items-wrap').length){updateChartColumns() 45$('.chart-items-wrap').addClass('loaded')}else{if($('.chart').length){renderAllCharts()}}});$('.chart-columns').on("click",".download",function(e){e.preventDefault();var parentItem=$(this).parents('.hub__headline-list-item');var vegaCanvas=$(parentItem).find('.marks')[0];DownloadCanvasAsImage(vegaCanvas)});function DownloadCanvasAsImage(canvas){let downloadLink=document.createElement('a');downloadLink.setAttribute('download','eo-graph.png');let dataURL=canvas.toDataURL('image/png');let url=dataURL.replace(/^data:image\/png/,'data:application/octet-stream');downloadLink.setAttribute('href',url);downloadLink.click()} 46function copyToClipboard(text){var dummy=document.createElement("textarea");document.body.appendChild(dummy);dummy.value=text;dummy.select();document.execCommand("copy");document.body.removeChild(dummy)} 47$('.chart-columns').on("click",".link",function(){var jsoncode=$(this).prev().find('.json').val();copyToClipboard(jsoncode) 48alert('Copied to clipboard')}) 49;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.