export type SampleT = { type: ".omd" | ".ojs", content: string };
export const samples: { [key: string]: SampleT } = {
"Covid-Globe (.omd)": {
"type": ".omd",
"content": "\n# Coronavirus (COVID-19) Globe\n\n\nLatest data regarding Corona Virus cases, provided by the [World Health Organization](https://www.who.int/). Available in API form via [https://github.com/NovelCOVID/API](https://github.com/NovelCOVID/API).\n\nPlotted using [globe.gl](globe.gl).\n\n```\nviewof valMode = radio({\n title: 'Color by',\n options: [\n { label: 'Cases', value: 'cases' },\n { label: 'Cases Today', value: 'todayCases' },\n { label: 'Deaths', value: 'deaths' },\n { label: 'Deaths Today', value: 'todayDeaths' },\n { label: 'Recovered', value: 'recovered' },\n { label: 'Critical', value: 'critical' }\n ],\n value: 'cases'\n})\n\nviewof popRel = checkbox({\n options: [\n { value: \"true\", label: \"Relative to population\" }\n ],\n value: \"true\"\n})\n\n{\n const domEl = document.createElement('div');\n covidGlobe(domEl);\n covidGlobe.pointOfView({ lat: 32, altitude: 1.8 }, 2000); // tilt globe slightly north\n \n return domEl;\n}\n \n```\n${covidData === cachedCovidData ? '(*using cached data*)' : ''}\n```\n{ // globe configuration\n // set color domain\n colorScale.domain([0, Math.max(...covidFeatureData.map(getFeatureVal))]);\n \n covidGlobe\n .width(640)\n .height(640)\n .polygonsData(covidFeatureData)\n .polygonAltitude(0.06)\n .polygonCapColor(feat => colorScale(getFeatureVal(feat)))\n .polygonSideColor(() => 'rgba(0, 100, 0, 0.15)')\n .polygonStrokeColor(() => '#111')\n .polygonLabel(({ covidData, properties }) => { \n const capIt = str => str.charAt(0).toUpperCase() + str.slice(1);\n const relToPop = v => `${d3.format('.2')(v / properties.POP_EST * 100)}%`;\n const popRatio = v => d3.format('.3~s')(properties.POP_EST / v);\n const relToCases = v => `${d3.format('.2')(v / covidData.cases * 100)}%`;\n \n const formatVal = prop => `${covidData[prop]} ${prop === 'cases' ? `(1 in every ${popRatio(covidData[prop])} ppl)` : covidData[prop] ? `(${relToCases(covidData[prop])} of cases)` : ''}${covidData[prop] && covidData.hasOwnProperty(`today${capIt(prop)}`) ? ` | new today: ${covidData[`today${capIt(prop)}`]}` : ''}`;\n \n return`\n ${covidData ? covidData.country : properties.NAME} (${properties.ISO_A2}):
\n ${(!covidData\n ? [['Cases', 0]] \n : [\n ['Cases', formatVal('cases')],\n ['Deaths', formatVal('deaths')],\n ['Recovered', formatVal('recovered')],\n ['Critical', formatVal('critical')],\n ['Population', d3.format(\".3s\")(properties.POP_EST)]\n ]\n ).map(([label, val]) => `${label}: ${val}`)\n .join('
')\n }\n ` })\n .onPolygonHover(hoverD => covidGlobe\n .polygonAltitude(d => d === hoverD ? 0.12 : 0.06)\n .polygonCapColor(d => d === hoverD ? 'steelblue' : colorScale(getFeatureVal(d)))\n )\n .polygonsTransitionDuration(300);\n}\n\ncovidGlobe = Globe()\n .height(640)\n .globeImageUrl('https://cdn.jsdelivr.net/npm/three-globe/example/img/earth-night.jpg')\n // .backgroundImageUrl('//cdn.jsdelivr.net/npm/three-globe/example/img/night-sky.png')\n\ngetFeatureVal = feat => (feat.covidData? feat.covidData[valMode] : 0) / (popRel ? feat.properties.POP_EST : 1)\n```\n**Style**\n```\nhtml``\n```\n**Settings**\n```\ncolorScale = d3.scaleSequentialPow(d3.interpolateYlOrRd)\n .exponent(1/4);\n```\n**Data**\n```\ncovidData = fetch(\n 'https://cors-anywhere.herokuapp.com/corona.lmao.ninja/v2/countries', \n { headers: { 'x-requested-with': 'observablehq.com' }}\n)\n .then(r => r.json())\n .catch(() => cachedCovidData) // use cached data if api is unavailable\n\ncachedCovidData = FileAttachment(/* \"covidData-cached@2.json\" */\"https://static.observableusercontent.com/files/61f477377c4aabc49e40014f77f8758e9de4a58e1e1d46bc2303ef6933b5dfb4f92575f5579996306be447936e9fb2bc140e72d8b712b77f8c6cc2472d784b21\").json()\n\ncountryNameMapper = ({\n 'bosnia and herzegovina': 'bosnia and herz.',\n drc: 'dem. rep. congo',\n 'dominican republic': 'dominican rep.',\n 'ivory coast': 'Côte d\\'Ivoire',\n 's. korea': 'south korea',\n taiwan: 'Taiwan, Province of China',\n uae: 'United Arab Emirates',\n uk: 'United Kingdom',\n usa: 'United States of America'\n})\n\ncovidFeatureData = {\n const dataByCountry = indexBy(covidData, d => (countryNameMapper[d.country.toLowerCase()] || d.country).toLowerCase(), false);\n \n return countries110m.features\n .filter(d => d.properties && d.properties.NAME)\n .map(d => ({\n ...d,\n covidData: dataByCountry[d.properties.NAME.toLowerCase()]\n })); \n}\n\ncountries110m = fetch('https://unpkg.com/globe.gl/example/datasets/ne_110m_admin_0_countries.geojson').then(r => r.json())\n```\n**Logs**\n```\ncountriesMissingGeoJson = {\n const dataByCountry = indexBy(covidData, d => (countryNameMapper[d.country.toLowerCase()] || d.country).toLowerCase(), false);\n const geoJsonCountries = new Set(countries110m.features.map(d => d.properties.NAME.toLowerCase()));\n \n return Object.keys(dataByCountry).filter(country => !geoJsonCountries.has(country)).sort();\n}\n\ncountriesMissingData = {\n const dataByCountry = indexBy(covidData, d => (countryNameMapper[d.country.toLowerCase()] || d.country).toLowerCase(), false);\n const geoJsonCountries = new Set(countries110m.features.map(d => d.properties.NAME.toLowerCase()));\n \n return [...geoJsonCountries].filter(country => !dataByCountry.hasOwnProperty(country)).sort();\n}\n```\n**Dependencies**\n```\nGlobe = require('globe.gl@2.8.6')\n\nindexBy = require('index-array-by')\n\nd3 = require('d3')\n\nimport {radio, checkbox} from '@jashkenas/inputs'\n```"
},
"Data-Wrangler (.omd)": {
"type": ".omd",
"content": "\n---\n```\nWrangler(data)\n``` \n---\n```\n// Function to wrangle data\nWrangler = (data = [], data2 = []) => {\n // Keep track of all the inputs\n let inputs = [];\n\n // Set up the three panels for the UI\n let wrapper = html`