utils#getActiveCase TypeScript Examples
The following examples show how to use
utils#getActiveCase.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: region.tsx From covid19-visualized with MIT License | 5 votes |
Page: NextPage = () => {
const countries = useFetch<Country[]>(API_BASEURL + 'confirmed')(
data => (
data.sort(({ countryRegion: prev }, { countryRegion: next }) => (next > prev) ? -1 : 1)
)
)
return (
<>
<Head>
<title>Country and Region | COVID-19 Visualized</title>
{meta}
</Head>
<div className="text-center my-12">
<h1 className="my-2">Country and Region</h1>
</div>
<div className="divider-line mb-32" />
<div className="btn-link mb-24">
<Link href="/">
<Button block color="secondary" text="< Back to Home" />
</Link>
</div>
<DataSearch<Country>
data={countries.data}
loading={countries.loading}
searchPlaceholder="Search country state or province... (eg: indonesia)"
searchFilter={(keyword, item) => {
const region = item.countryRegion.toLowerCase()
const province = item.provinceState?.toLowerCase()
return region.includes(keyword) || (province ? province.includes(keyword) : false)
}}
>
{(data, keyword) => data.length
? (
<FlexList<Country> data={data} wrapperClass="my-12" itemClass="my-12">
{country => (
<Region
chart={{
confirmed: country.confirmed,
recovered: country.recovered,
deaths: country.deaths
}}
header={
country.provinceState
? `${country.provinceState}, ${country.countryRegion}`
: country.countryRegion
}
footer={`Last updated at: ${dateFormat(country.lastUpdate, true)}`}
>
<p>Total Confirmed: <span className="font is-weight-bold color is-txt-warning">{country.confirmed}</span></p>
<p className="mt-8">Active: <span className="font is-weight-bold color is-txt-warning">{getActiveCase(country)}</span></p>
<p>Recovered: <span className="font is-weight-bold color is-txt-success">{country.recovered}</span></p>
<p>Deaths: <span className="font is-weight-bold color is-txt-danger">{country.deaths}</span></p>
</Region>
)}
</FlexList>
) : (
<h3 className="text-center my-24">{
keyword.length
? `No matching country or province "${keyword}" found.`
: 'Please type the name of the country that you want to search.'
}</h3>
)
}
</DataSearch>
</>
)
}
Example #2
Source File: visualize.ts From covid19-visualized with MIT License | 4 votes |
world = async (id: string, data: Country[]): Promise<void> => {
const tooltipHtml = (data: Country): string => `
<div id="covid19-tooltip">
<h3 class="text-center my-2">${data.name}</h3>
<h5>Confirmed: ${data.confirmed}</h5>
<h5>Active: ${getActiveCase(data)} (${getPercentage(getActiveCase(data), data.confirmed)})</h5>
<h5>Recovered: ${data.recovered} (${getPercentage(data.recovered, data.confirmed)})</h5>
<h5>Deaths: ${data.deaths} (${getPercentage(data.deaths, data.confirmed)})</h5>
</div>
`
const mergeSummary = (country: Country) => (
(acc: Country, cur: Country): Country => {
country.iso3 === cur.iso3 && (
acc.countryRegion = cur.countryRegion,
acc.confirmed += cur.confirmed,
acc.recovered += cur.recovered,
acc.deaths += cur.deaths
)
return acc
}
)
const tooltip = select('.tooltip')
const svg = select(`#${id}`)
.append('svg')
.attr('width', 960)
.attr('height', 520)
const path = geoPath().projection(
(geoNaturalEarth1()
.rotate([-9, 0]) as any)
.scale([1300 / (2 * Math.PI)])
.translate([450, 300])
)
const worlds = (await window.fetch('/world-countries-110m.json')
.then(response => response.json()) as Country[])
.map(country => {
const covid19Data = data.reduce(mergeSummary(country), {
countryRegion: '',
confirmed: 0,
recovered: 0,
deaths: 0
} as Country)
return {
...country,
confirmed: covid19Data.confirmed,
recovered: covid19Data.recovered,
deaths: covid19Data.deaths,
name: covid19Data.countryRegion || country.name,
legend: worldLegends.find(({ value }) => !!covid19Data.countryRegion
? covid19Data.confirmed > (value - 1)
: value === 0
).color
}
}) as any[]
svg.selectAll('path')
.data(worlds)
.enter()
.append('path')
.attr('stroke', 'black')
.attr('stroke-width', .75)
.attr('d', path)
.attr('fill', (data: Country) => data.legend)
.on('mouseover', function(data: Country) {
tooltip.style('hidden', false).html(tooltipHtml(data))
select(this)
.attr('fill', '#ddd')
.attr('stroke', 'white')
.attr('stroke-width', 2.5)
})
.on('mousemove', (data: Country) => {
tooltip.classed('hidden', false)
.style('top', event.pageY + 'px')
.style('left', (event.pageX + 10) + 'px')
.html(tooltipHtml(data))
})
.on('mouseout', function(data: Country) {
tooltip.classed('hidden', true)
select(this)
.attr('fill', data.legend)
.attr('stroke', 'black')
.attr('stroke-width', .75)
})
}