From a85c659df296cffe7c401924a3c2e9e9c762768a Mon Sep 17 00:00:00 2001 From: kengoy Date: Tue, 7 Jul 2020 01:33:39 -0700 Subject: [PATCH 1/2] Added a line chart for cases per 1000 people --- components/Stats.vue | 91 ++++++++- components/TimeBarChart.vue | 5 +- components/TimeLineChartCountyComparison.vue | 198 +++++++++++++++++++ static/data/countyColor.json | 11 ++ utils/formatCountyData.ts | 4 +- 5 files changed, 301 insertions(+), 8 deletions(-) create mode 100644 components/TimeLineChartCountyComparison.vue create mode 100644 static/data/countyColor.json diff --git a/components/Stats.vue b/components/Stats.vue index 9cd59411..a7a9f28b 100644 --- a/components/Stats.vue +++ b/components/Stats.vue @@ -122,23 +122,69 @@ :url="'https://coronadatascraper.com'" /> + + +
+ +
+
+ + {{ countyName.name }} + +
+
+
+ + + + + diff --git a/static/data/countyColor.json b/static/data/countyColor.json new file mode 100644 index 00000000..8f12cb6f --- /dev/null +++ b/static/data/countyColor.json @@ -0,0 +1,11 @@ +{ + "Solano County": "#999900", + "Alameda County": "#009900", + "Santa Clara County": "#ff0000", + "San Francisco County": "#7f00ff", + "Contra Costa County": "#ff8800", + "San Mateo County": "#0080ff", + "Sonoma County": "#ff00ff", + "Napa County": "#808080", + "Marin County": "#0000ff" +} \ No newline at end of file diff --git a/utils/formatCountyData.ts b/utils/formatCountyData.ts index b28c5f38..b2d74ac0 100644 --- a/utils/formatCountyData.ts +++ b/utils/formatCountyData.ts @@ -22,6 +22,7 @@ type GraphDataType = { type CountyDataFormattedType = { name: string + population: number graph: Array lastUpdatedAt: Date } @@ -47,9 +48,10 @@ export default (data: Array, countyFilter?: Array) => { for (const countyName in data) { if (countyFilter && !includedCounties[countyName]) continue - const { name, cases } = data[countyName] + const { name, population, cases } = data[countyName] const county: CountyDataFormattedType = { name, + population, graph: formatGraph(cases), lastUpdatedAt: cases.slice(-1)[0].date } From 544e5c7a6f6a2d3593cb30803c6a101d5f9b69f4 Mon Sep 17 00:00:00 2001 From: kengoy Date: Wed, 8 Jul 2020 00:03:16 -0700 Subject: [PATCH 2/2] Added a line chart for Percent Increase in 7 Days --- components/Stats.vue | 17 +++++++ components/TimeLineChartCountyComparison.vue | 51 +++++++++++++++----- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/components/Stats.vue b/components/Stats.vue index a7a9f28b..bbec840e 100644 --- a/components/Stats.vue +++ b/components/Stats.vue @@ -165,6 +165,23 @@ :url="'https://coronadatascraper.com'" /> + + + diff --git a/components/TimeLineChartCountyComparison.vue b/components/TimeLineChartCountyComparison.vue index c0ef9f2e..e7bf3ef2 100644 --- a/components/TimeLineChartCountyComparison.vue +++ b/components/TimeLineChartCountyComparison.vue @@ -56,9 +56,9 @@ export default { }, computed: { displayData() { - if (this.chartDataType === 'casesperpeople') { - if (this.selectedCounties.length) { - const dataSets = [] + if (this.selectedCounties.length) { + const dataSets = [] + if (this.chartDataType === 'casesperpeople') { for (const county of this.selectedCounties) { dataSets.push({ type: 'line', @@ -74,8 +74,7 @@ export default { d.confirmedTransition / (this.chartData[county.name].population / 1000) ) - }), - backgroundColor: '#473A8C' + }) }) } @@ -88,12 +87,44 @@ export default { datasets: dataSets } } else { + // Percent Increase in 7 days + for (const county of this.selectedCounties) { + const confirmedCumulativeIn7daysQueue = [] + dataSets.push({ + type: 'line', + fill: false, + borderWidth: 1, + pointBackgroundColor: 'rgba(0,0,0,0)', + pointBorderColor: 'rgba(0,0,0,0)', + borderColor: county.color, + lineTension: 0, + label: county.name, + data: this.chartData[county.name].graph.map(d => { + confirmedCumulativeIn7daysQueue.push(d.cumulative) + if (confirmedCumulativeIn7daysQueue.length > 7) { + const confirmedCumulative7daysBefore = confirmedCumulativeIn7daysQueue.shift() + return ( + ((d.cumulative - confirmedCumulative7daysBefore) / + confirmedCumulative7daysBefore) * + 100 + ) + } else { + return null + } + }) + }) + } + return { - datasets: [] + labels: this.chartData[this.selectedCounties[0].name].graph.map( + d => { + return d.label + } + ), + datasets: dataSets } } } else { - // TBD for past 7 days return { datasets: [] } @@ -191,8 +222,4 @@ export default { } - +