Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions app/components/chart.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// chart.js
app.component('chart', {
template: `
<table class="table table-borderless table-sm">
<thead>
<tr>
<th scope="col">Nombre d’injections</th>
<th scope="col">Nombre de personnes vaccinées</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>{{ Number(data.n_tot_dose1[0]).toLocaleString() }} ({{ data.rate_dose1[0] }} %)</td>
</tr>
<tr>
<th scope="row">2</th>
<td>{{ Number(data.n_tot_dose2[0]).toLocaleString() }} ({{ data.rate_dose2[0] }} %)</td>
</tr>
</tbody>
</table>
<canvas id="chart" height="300"></canvas>
`,
template: `<canvas id="chart" height="300"></canvas>`,
data() {
return {
labels: Array(),
Expand Down
26 changes: 26 additions & 0 deletions app/components/nb-vax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// nb-vax.js
app.component('nb-vax', {
template: `
<table class="table table-borderless table-sm">
<thead>
<tr>
<th scope="col">Nombre d’injections</th>
<th scope="col">Nombre de personnes vaccinées</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>{{ metrics.n_tot_dose1.toLocaleString() }} ({{ metrics.rate_dose1 }} %)</td>
</tr>
<tr>
<th scope="row">2</th>
<td>{{ metrics.n_tot_dose2.toLocaleString() }} ({{ metrics.rate_dose2 }} %)</td>
</tr>
</tbody>
</table>
`,
props: {
metrics: Object
}
})
48 changes: 47 additions & 1 deletion app/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
const app = Vue.createApp({
data() {
return {
area: 'france'
area: 'france',
metrics: {
'n_tot_dose1': Array(),
'n_tot_dose2': Array(),
'rate_dose1': Array(),
'rate_dose2': Array()
}
}
},
created() {
// Fetches the default metrics (i.e. France)
this.getMetrics(this.area);
},
methods: {
/*
* Flushes the metrics.
*/
flushMetrics() {
this.metrics = {
'n_tot_dose1': Array(),
'n_tot_dose2': Array(),
'rate_dose1': Array(),
'rate_dose2': Array()
}
},
/*
* Fetches the metrics.
*/
getMetrics(area) {

// Defines the area to display
this.area = area;

// Fetch API
fetch('./data/metrics-' + this.area + '.json')
.then(stream => stream.json())
.then(metrics => {
this.labels = Object.keys(metrics);
for (var age in this.labels) {
this.metrics.n_tot_dose1.push(metrics[this.labels[age]]['n_tot_dose1'])
this.metrics.n_tot_dose2.push(metrics[this.labels[age]]['n_tot_dose2'])
this.metrics.rate_dose1.push(metrics[this.labels[age]]['rate_dose1'])
this.metrics.rate_dose2.push(metrics[this.labels[age]]['rate_dose2'])
}
});
},
/*
* Zoom to a specific department
*/
setArea(area) {
// The zone is fixed to the department
this.area = area;
// Obsolete metrics are removed…
this.flushMetrics();
// … and we get new ones.
this.getMetrics(this.area);
// Removes the old chart.
this.$refs.chart.removeChart();
// Sets a new Chart with accurate metrics.
Expand Down
8 changes: 8 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ <h1>La vaccination en France</h1>
<!-- Geographical area -->
<geo-area :area="area" @set-area="setArea"></geo-area>
<!-- Nb vaccinated people -->
<nb-vax
:metrics="{
n_tot_dose1: Number(metrics.n_tot_dose1[0]),
n_tot_dose2: Number(metrics.n_tot_dose2[0]),
rate_dose1: metrics.rate_dose1[0],
rate_dose2: metrics.rate_dose2[0]
}"></nb-vax>
<!-- Metrics -->
<chart ref="chart"></chart>
</div>
Expand Down Expand Up @@ -63,6 +70,7 @@ <h1>La vaccination en France</h1>
<script src="./app/components/chart.js"></script>
<script src="./app/components/fr-map.js"></script>
<script src="./app/components/geo-area.js"></script>
<script src="./app/components/nb-vax.js"></script>

<!-- Mount the app -->
<script>
Expand Down