Skip to content

Commit

Permalink
Merge pull request #254 from sfbrigade/feature/issue250
Browse files Browse the repository at this point in the history
Feature/issue250
  • Loading branch information
thuongho authored Jul 8, 2020
2 parents fc296fa + 544e5c7 commit cb6c0a6
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 8 deletions.
108 changes: 105 additions & 3 deletions components/Stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,47 +122,131 @@
:url="'https://coronadatascraper.com'"
/>
</v-col>
<v-col cols="12" md="12" class="DataCard">
<DataView>
<div class="county-compare-select-container">
<label>Select Counties to Compare:</label>
</div>
<div class="county-select-buttons">
<v-btn
v-for="countyName in countiesForCompare"
:key="countyName.name"
class="county-select-button"
outlined
:style="{
'background-color': contains(selectedCounties, countyName)
? countyName.color
: 'white',
color: contains(selectedCounties, countyName)
? 'white'
: 'black'
}"
type="button"
@click="provide(countyName)"
>
{{ countyName.name }}
</v-btn>
</div>
</DataView>
</v-col>
<v-col
:county="CountyData[currentCounty]"
cols="12"
md="6"
class="DataCard"
>
<time-line-chart-county-comparison
:title="`Cases per 1,000 People`"
:title-id="'cases-per-people'"
:chart-data="CountyData"
:selected-counties="selectedCounties"
:chart-data-type="'casesperpeople'"
:date="CountyData[currentCounty].lastUpdatedAt"
:url="'https://coronadatascraper.com'"
/>
</v-col>
<v-col
:county="CountyData[currentCounty]"
cols="12"
md="6"
class="DataCard"
>
<time-line-chart-county-comparison
:title="`Percent Increase in 7 Days`"
:title-id="'percent-increase-in7days'"
:chart-data="CountyData"
:selected-counties="selectedCounties"
:chart-data-type="'percentincrease'"
:date="CountyData[currentCounty].lastUpdatedAt"
:unit="'%'"
:url="'https://coronadatascraper.com'"
/>
</v-col>
</v-row>
</div>
</template>

<script>
import TimeBarChart from '@/components/TimeBarChart.vue'
import TimeLineChartCountyComparison from '@/components/TimeLineChartCountyComparison.vue'
import CasesSummary from '@/components/CasesSummary.vue'
import Data from '@/data/data.json'
import formatCountyData from '@/utils/formatCountyData'
import consolidateAllData from '@/utils/consolidateAllData'
import DataView from '@/components/DataView.vue'
import { calculateTotalCases, calculateTotalDeaths } from '@/utils/calculations'
import countyColor from '@/static/data/countyColor.json'
export default {
components: {
CasesSummary,
TimeBarChart,
TimeLineChartCountyComparison,
DataView
},
data() {
const currentCounty = 'San Francisco County'
const CountyData = formatCountyData(Data)
const ConsolidatedData = consolidateAllData(Data)
const countyNames = Object.keys(Data)
const selectedCountyData = Data[currentCounty]
const totalCases = calculateTotalCases(Data)
const totalDeaths = calculateTotalDeaths(Data)
const countiesForCompare = []
for (const countyName of countyNames) {
countiesForCompare.push({
name: countyName,
color: countyColor[countyName]
})
}
const selectedCounties = []
const data = {
Data,
CountyData,
ConsolidatedData,
currentCounty,
countyNames,
selectedCountyData,
totalCases,
totalDeaths
totalDeaths,
countiesForCompare,
selectedCounties
}
return data
},
methods: {
provide(item) {
if (!this.selectedCounties.includes(item)) {
this.selectedCounties.push(item)
} else {
this.selectedCounties.splice(this.selectedCounties.indexOf(item), 1)
}
},
contains(arr, item) {
return arr.includes(item)
}
},
head() {
return {
title: 'Bay Area Pandemic Dashboard'
Expand Down Expand Up @@ -228,6 +312,24 @@ export default {
align-items: center;
}
}
.county-compare-select-container {
display: grid;
align-items: center;
label {
text-align: center;
font-style: normal;
font-weight: bold;
font-size: 24px;
color: black;
line-height: 33px;
}
}
.county-select-buttons {
padding: 20px;
}
.county-select-button {
margin: 10px 10px;
}
@include lessThan($small) {
.county-select-container {
display: initial;
Expand Down
5 changes: 1 addition & 4 deletions components/TimeBarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,7 @@ export default {
return labelText
},
title(tooltipItem, data) {
return data.labels[tooltipItem[0].index].replace(
/(\w+)\/(\w+)/,
'$1 $2 '
)
return data.labels[tooltipItem[0].index]
}
}
},
Expand Down
225 changes: 225 additions & 0 deletions components/TimeLineChartCountyComparison.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<template>
<data-view :title="title" :date="date" :url="url">
<bar
v-if="displayData != null"
:chart-data="displayData"
:options="displayOption"
:height="240"
/>
</data-view>
</template>

<script>
import DataView from '@/components/DataView.vue'
export default {
components: { DataView },
props: {
title: {
type: String,
required: false,
default: ''
},
chartData: {
type: Array,
required: false,
default: () => []
},
selectedCounties: {
type: Array,
required: false,
default: () => []
},
chartDataType: {
type: String,
required: true,
default: 'cases'
},
date: {
type: String,
required: true,
default: ''
},
unit: {
type: String,
required: false,
default: ''
},
url: {
type: String,
required: false,
default: ''
}
},
data() {
return {}
},
computed: {
displayData() {
if (this.selectedCounties.length) {
const dataSets = []
if (this.chartDataType === 'casesperpeople') {
for (const county of this.selectedCounties) {
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 => {
return (
d.confirmedTransition /
(this.chartData[county.name].population / 1000)
)
})
})
}
return {
labels: this.chartData[this.selectedCounties[0].name].graph.map(
d => {
return d.label
}
),
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 {
labels: this.chartData[this.selectedCounties[0].name].graph.map(
d => {
return d.label
}
),
datasets: dataSets
}
}
} else {
return {
datasets: []
}
}
},
displayOption() {
const unit = this.unit
return {
tooltips: {
displayColors: false,
callbacks: {
label(tooltipItem) {
const labelText =
(Math.round(tooltipItem.value * 100) / 100).toLocaleString() +
unit
return labelText
},
title(tooltipItem, data) {
return data.labels[tooltipItem[0].index]
}
}
},
barValueSpacing: 20,
responsive: true,
maintainAspectRatio: false,
legend: {
display: true
},
scales: {
xAxes: [
{
id: 'day',
stacked: false,
gridLines: {
display: false
},
ticks: {
fontSize: 12,
maxTicksLimit: 20,
fontColor: '#808080',
maxRotation: 0,
minRotation: 0,
callback: label => {
return label.split('/')[1]
}
}
},
{
id: 'month',
stacked: false,
gridLines: {
drawOnChartArea: false,
drawTicks: true,
drawBorder: false,
tickMarkLength: 10
},
ticks: {
fontSize: 12,
fontColor: '#808080',
padding: 3,
fontStyle: 'bold',
gridLines: {
display: true
},
callback: label => {
const month = label.split(' ')[0]
return month
}
},
type: 'time',
time: {
unit: 'month'
}
}
],
yAxes: [
{
location: 'bottom',
stacked: false,
gridLines: {
display: true,
color: '#E5E5E5'
},
ticks: {
suggestedMin: 0,
maxTicksLimit: 8,
fontColor: '#808080'
}
}
]
}
}
}
}
}
</script>

<style lang="scss" scoped></style>
Loading

0 comments on commit cb6c0a6

Please sign in to comment.