From 8877cbe61ecde66609f385b35d3d0b2117bade44 Mon Sep 17 00:00:00 2001 From: Daiki Date: Sat, 18 Apr 2020 23:19:11 +0900 Subject: [PATCH 1/4] Add line chart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 一時的に「陽性患者数」の累計と置き換え --- components/LineChart.vue | 416 ++++++++++++++++++ components/cards/ConfirmedCasesNumberCard.vue | 6 +- plugins/vue-chart.ts | 19 +- 3 files changed, 437 insertions(+), 4 deletions(-) create mode 100644 components/LineChart.vue diff --git a/components/LineChart.vue b/components/LineChart.vue new file mode 100644 index 0000000000000..768ee5955c76e --- /dev/null +++ b/components/LineChart.vue @@ -0,0 +1,416 @@ + + + diff --git a/components/cards/ConfirmedCasesNumberCard.vue b/components/cards/ConfirmedCasesNumberCard.vue index 8c8cd6f380ffa..0986760b0bcc5 100644 --- a/components/cards/ConfirmedCasesNumberCard.vue +++ b/components/cards/ConfirmedCasesNumberCard.vue @@ -1,6 +1,6 @@ + string isNotLoaded: () => boolean + displayValue: (chartType: 'bar' | 'line') => 'block' | 'none' + isTransition: () => boolean + isCumulative: () => boolean } type Computed = { displayCumulativeRatio: string @@ -142,7 +153,7 @@ const options: ThisTypedComponentOptionsWithRecordProps< }, chartId: { type: String, - default: 'time-bar-chart' + default: 'line-chart' }, chartData: { type: Array, @@ -162,7 +173,7 @@ const options: ThisTypedComponentOptionsWithRecordProps< } }, data: () => ({ - dataKind: 'transition', + dataKind: 'cumulative', canvas: true }), computed: { @@ -193,7 +204,7 @@ const options: ThisTypedComponentOptionsWithRecordProps< } } - if (this.dataKind === 'transition') { + if (this.isTransition()) { return { lText: `${this.chartData.slice(-1)[0].transition.toLocaleString()}`, sText: `${this.chartData.slice(-1)[0].label} ${this.$t( @@ -233,7 +244,7 @@ const options: ThisTypedComponentOptionsWithRecordProps< } const style = getGraphSeriesStyle(1)[0] - if (this.dataKind === 'transition') { + if (this.isTransition()) { return { labels: this.chartData.map(d => { return d.label @@ -259,9 +270,9 @@ const options: ThisTypedComponentOptionsWithRecordProps< data: this.chartData.map(d => { return d.cumulative }), - backgroundColor: style.fillColor, + backgroundColor: '#edfff3', borderColor: style.strokeColor, - borderWidth: 1 + borderWidth: 2 } ] } @@ -362,8 +373,7 @@ const options: ThisTypedComponentOptionsWithRecordProps< }, scaledTicksYAxisMax() { const yAxisMax = 1.2 - const dataKind = - this.dataKind === 'transition' ? 'transition' : 'cumulative' + const dataKind = this.isTransition() ? 'transition' : 'cumulative' const values = this.chartData.map(d => d[dataKind]) return Math.max(...values) * yAxisMax }, @@ -396,17 +406,19 @@ const options: ThisTypedComponentOptionsWithRecordProps< }, isNotLoaded() { return this.chartData.length === 0 - } - }, - mounted() { - const barChart = this.$refs.barChart as Vue - const barElement = barChart.$el - const canvas = barElement.querySelector('canvas') - const labelledbyId = `${this.titleId}-graph` + }, + displayValue(chartType) { + if (chartType === 'bar') { + return this.isTransition() ? 'block' : 'none' + } - if (canvas) { - canvas.setAttribute('role', 'img') - canvas.setAttribute('aria-labelledby', labelledbyId) + return this.isCumulative() ? 'block' : 'none' + }, + isTransition() { + return this.dataKind === 'transition' + }, + isCumulative() { + return this.dataKind === 'cumulative' } } } diff --git a/components/cards/ConfirmedCasesNumberCard.vue b/components/cards/ConfirmedCasesNumberCard.vue index 0986760b0bcc5..8c8cd6f380ffa 100644 --- a/components/cards/ConfirmedCasesNumberCard.vue +++ b/components/cards/ConfirmedCasesNumberCard.vue @@ -1,6 +1,6 @@