Skip to content

Commit bed2230

Browse files
committed
Added Timeline
1 parent 274ab0e commit bed2230

File tree

2 files changed

+96
-11
lines changed

2 files changed

+96
-11
lines changed

components/Overview/index.vue

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,20 @@
2020
<p>Daily</p>
2121
<p class="sub">Click or Drag chart to view daily cases</p>
2222
<client-only>
23-
<apexchart height="350" type="line" :options="chartOptions" :series="series"></apexchart>
23+
<apexchart height="320" type="line" :options="chartOptions" :series="series"></apexchart>
2424
</client-only>
2525
</div>
26+
<div class="section timeline">
27+
<p>Timeline</p>
28+
<ul>
29+
<li
30+
v-for="(item, index) in timeline"
31+
:key="index">
32+
<span class="timestamp">{{ item.timestamp.month }} {{ item.timestamp.date }}, {{ item.timestamp.year }}</span>
33+
<span class="summary" v-html="item.summary" />
34+
</li>
35+
</ul>
36+
</div>
2637
</div>
2738
</div>
2839
</template>
@@ -102,6 +113,35 @@ export default {
102113
data: timelineRecovered
103114
}
104115
]
116+
},
117+
timeline() {
118+
const isPlural = (name, total, s) => {
119+
return `<span class="${name}">${total}</span> ${s}${(total > 1) ? 's' : ''}`
120+
}
121+
const perDayConfirmed = this.getPerDay(Object.entries(this.result.timelines.confirmed.timeline))
122+
const perDayDeaths = this.getPerDay(Object.entries(this.result.timelines.deaths.timeline))
123+
const perDayRecovered = this.getPerDay(Object.entries(this.result.timelines.recovered.timeline))
124+
const perDayCases = Object.entries(perDayConfirmed).map((o, index) => {
125+
let summary = ''
126+
if (o[1] || perDayDeaths[o[0]] || perDayRecovered[o[0]]) {
127+
if (o[1]) {
128+
summary += `${isPlural('confirmed', o[1], 'confirmed case')}`
129+
}
130+
if (perDayDeaths[o[0]]) {
131+
summary += o[1] ? ' and ' : ''
132+
summary += `${isPlural('deaths', perDayDeaths[o[0]], 'death')}`
133+
}
134+
if (perDayRecovered[o[0]]) {
135+
summary += !o[1] || !perDayRecovered[o[0]] ? '' : ' and '
136+
summary += `<span class="recovered">${perDayRecovered[o[0]]}</span> recovered`
137+
}
138+
}
139+
return {
140+
timestamp: this.formatDate(o[0]),
141+
summary: summary + '.'
142+
}
143+
})
144+
return perDayCases.filter(o => o.summary !== '.')
105145
}
106146
},
107147
data() {
@@ -124,6 +164,15 @@ export default {
124164
date: da,
125165
year: ye
126166
}
167+
},
168+
getPerDay(data) {
169+
let temp = 0
170+
const trueTimeline = {}
171+
data.forEach(a => {
172+
trueTimeline[a[0]] = a[1] > temp ? a[1] - temp : 0
173+
temp = a[1]
174+
})
175+
return trueTimeline
127176
}
128177
}
129178
}
@@ -132,14 +181,14 @@ export default {
132181
<style lang="scss" scoped>
133182
.overview {
134183
border-radius: 4px;
135-
padding: 24px;
184+
padding: 0 24px 24px;
136185
width: 624px;
137186
height: 100%;
138187
background-color: #ffffff;
139188
overflow: auto;
140189
141190
@media only screen and (min-width: 768px) {
142-
height: auto;
191+
height: 602px;
143192
}
144193
145194
.close {
@@ -158,10 +207,6 @@ export default {
158207
svg {
159208
cursor: pointer;
160209
}
161-
162-
@media only screen and (min-width: 768px) {
163-
transform: translateY(calc(-50% - 16px));
164-
}
165210
}
166211
167212
.content {
@@ -178,10 +223,6 @@ export default {
178223
padding: 32px 0 8px;
179224
font-size: 32px;
180225
background: white;
181-
182-
@media only screen and (min-width: 768px) {
183-
padding: 0 0 8px;
184-
}
185226
}
186227
187228
.section {
@@ -232,5 +273,48 @@ export default {
232273
}
233274
}
234275
}
276+
277+
/deep/ .timeline {
278+
279+
ul {
280+
margin: 8px 0 0;
281+
padding: 0;
282+
}
283+
284+
li {
285+
display: flex;
286+
padding: 8px;
287+
font-size: 14px;
288+
font-weight: 400;
289+
line-height: 18px;
290+
291+
&:nth-child(even) {
292+
background-color: #f1f1f1;
293+
}
294+
}
295+
296+
.timestamp {
297+
padding-right: 16px;
298+
font-weight: 700;
299+
color: #585858;
300+
text-transform: uppercase;
301+
min-width: 100px;
302+
}
303+
304+
.confirmed {
305+
font-weight: 700;
306+
color: #ffa500;
307+
}
308+
309+
.deaths {
310+
font-weight: 700;
311+
color: #b20000;
312+
}
313+
314+
.recovered {
315+
font-weight: 700;
316+
color: #66a266;
317+
}
318+
}
235319
}
236320
</style>

components/Search/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export default {
373373
input,
374374
select {
375375
border: 0;
376+
margin: 0;
376377
padding: 0;
377378
display: block;
378379
font-size: 24px;

0 commit comments

Comments
 (0)