Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
AgencyRepository を導入
Browse files Browse the repository at this point in the history
  • Loading branch information
nard-tech committed Jun 10, 2021
1 parent 35985bc commit 69443fd
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 78 deletions.
68 changes: 45 additions & 23 deletions components/index/CardsReference/Agency/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
:title="$t('都庁来庁者数の推移')"
:title-id="'agency'"
:chart-id="'agency'"
:chart-data="agencyData"
:date="agencyData.date"
:chart-data="agency"
:date="date"
:labels="labels"
:periods="periods"
:items="agencyItems"
:periods="agencyData.periods"
:unit="$t('')"
>
<template #additionalDescription>
Expand All @@ -19,37 +20,58 @@
</v-col>
</template>

<script>
import dayjs from 'dayjs'
<script lang="ts">
import Vue from 'vue'
import Chart from '@/components/index/CardsReference/Agency/Chart.vue'
import AgencyData from '@/data/agency.json'
import { Agency as IAgency } from '@/libraries/auto_generated/data_converter/convertAgency'
import { convertDateToISO8601Format } from '@/utils/formatDate'
export default {
type Data = {
agencyItems: string[]
}
type Methods = {}
type Computed = {
agency: IAgency
date: string
labels: string[]
periods: string[]
}
type Props = {}
export default Vue.extend<Data, Methods, Computed, Props>({
components: {
Chart,
},
data() {
const labels = AgencyData.periods.map((p) => p.begin)
const periods = AgencyData.periods.map((p) => {
const from = this.$d(dayjs(p.begin).toDate(), 'dateWithoutYear')
const to = this.$d(dayjs(p.end).toDate(), 'dateWithoutYear')
return `${from}~${to}`
})
const agencyData = {
...AgencyData,
labels,
periods,
}
const agencyItems = [
this.$t('第一庁舎計'),
this.$t('第二庁舎計'),
this.$t('議事堂計'),
this.$t('第一庁舎計') as string,
this.$t('第二庁舎計') as string,
this.$t('議事堂計') as string,
]
return {
agencyData,
agencyItems,
}
},
}
computed: {
agency() {
return this.$store.state.agency
},
date() {
return this.agency.date
},
labels() {
return this.agency.periods.map((p) => {
return convertDateToISO8601Format(p.begin)
})
},
periods() {
return this.agency.periods.map((p) => {
const from = this.$d(p.begin, 'dateWithoutYear')
const to = this.$d(p.end, 'dateWithoutYear')
return `${from}~${to}`
})
},
},
})
</script>
116 changes: 61 additions & 55 deletions components/index/CardsReference/Agency/Chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,25 @@
</template>

<script lang="ts">
import { ChartOptions } from 'chart.js'
import Vue from 'vue'
import { ThisTypedComponentOptionsWithRecordProps } from 'vue/types/options'
import { ChartData, ChartOptions, ChartTooltipItem } from 'chart.js'
import Vue, { PropType } from 'vue'
import DataView from '@/components/index/_shared/DataView.vue'
import DataViewTable, {
TableHeader,
TableItem,
} from '@/components/index/_shared/DataViewTable.vue'
import ScrollableChart from '@/components/index/_shared/ScrollableChart.vue'
import { Agency as IAgency } from '@/libraries/auto_generated/data_converter/convertAgency'
import { DataSets, DisplayData, yAxesBgPlugin } from '@/plugins/vue-chart'
import { getGraphSeriesStyle, SurfaceStyle } from '@/utils/colors'
interface AgencyDataSets extends DataSets {
label: string
}
interface AgencyDisplayData extends DisplayData {
datasets: AgencyDataSets[]
}
interface AgencyData extends AgencyDisplayData {
labels: string[]
datasets: AgencyDataSets[]
}
type Data = {
Expand All @@ -105,28 +103,19 @@ type Computed = {
tableHeaders: TableHeader[]
tableData: TableItem[]
}
type Props = {
title: string
titleId: string
chartId: string
chartData: AgencyData
chartData: IAgency
date: string
items: string[]
labels: string[]
periods: string[]
items: string[]
unit: string
}
const options: ThisTypedComponentOptionsWithRecordProps<
Vue,
Data,
Methods,
Computed,
Props
> = {
created() {
this.canvas = process.browser
},
export default Vue.extend<Data, Methods, Computed, Props>({
components: { DataView, DataViewTable, ScrollableChart },
props: {
title: {
Expand All @@ -144,17 +133,28 @@ const options: ThisTypedComponentOptionsWithRecordProps<
required: false,
default: 'agency-bar-chart',
},
chartData: Object,
chartData: {
type: Object as PropType<IAgency>,
default: () => ({
date: '',
periods: [],
datasets: [],
}),
},
date: {
type: String,
default: '',
},
items: {
type: Array,
labels: {
type: Array as PropType<string[]>,
default: () => [],
},
periods: {
type: Array,
type: Array as PropType<string[]>,
default: () => [],
},
items: {
type: Array as PropType<string[]>,
default: () => [],
},
unit: {
Expand All @@ -170,33 +170,37 @@ const options: ThisTypedComponentOptionsWithRecordProps<
displayLegends: [true, true, true],
}),
computed: {
displayData() {
displayData(): AgencyDisplayData {
return {
labels: this.chartData.labels,
datasets: this.chartData.datasets.map((item, index) => {
labels: this.labels,
datasets: this.chartData.datasets.map((dataset, index) => {
const label = this.items[index]
const { data } = dataset
const color = this.colors[index]
return {
label: this.items[index] as string,
data: item.data,
backgroundColor: this.colors[index].fillColor,
borderColor: this.colors[index].strokeColor,
label,
data,
backgroundColor: color.fillColor,
borderColor: color.strokeColor,
borderWidth: 1,
}
}),
}
},
displayOption() {
displayOption(): ChartOptions {
const options: ChartOptions = {
maintainAspectRatio: false,
tooltips: {
displayColors: false,
callbacks: {
title: (tooltipItem) => {
const dateString = this.periods[tooltipItem[0].index!]
title: (tooltipItems: ChartTooltipItem[]) => {
const dateString = this.periods[tooltipItems[0].index!]
return this.$t('期間: {duration}', {
duration: dateString!,
}) as string
},
label: (tooltipItem, data) => {
label: (tooltipItem: ChartTooltipItem, data: ChartData) => {
const index = tooltipItem.datasetIndex!
const title = this.$t(data.datasets![index].label!)
const num = parseInt(tooltipItem.value!).toLocaleString()
Expand Down Expand Up @@ -266,14 +270,16 @@ const options: ThisTypedComponentOptionsWithRecordProps<
],
},
}
if (this.$route.query.ogp === 'true') {
Object.assign(options, { animation: { duration: 0 } })
}
return options
},
displayDataHeader() {
displayDataHeader(): AgencyDisplayData {
return {
labels: this.chartData.labels,
labels: this.labels,
datasets: this.chartData.datasets.map((item, index) => {
return {
label: this.items[index] as string,
Expand All @@ -284,8 +290,8 @@ const options: ThisTypedComponentOptionsWithRecordProps<
}),
}
},
displayOptionHeader() {
const options: ChartOptions = {
displayOptionHeader(): ChartOptions {
return {
maintainAspectRatio: false,
legend: {
display: false,
Expand All @@ -301,7 +307,7 @@ const options: ThisTypedComponentOptionsWithRecordProps<
},
ticks: {
fontSize: 9,
fontColor: 'transparent',
fontColor: 'transparent', // displayOption では '#808080'
callback: (_, i) => {
return this.periods[i]
},
Expand All @@ -318,7 +324,7 @@ const options: ThisTypedComponentOptionsWithRecordProps<
},
ticks: {
fontSize: 11,
fontColor: 'transparent', // displayOption では #808080
fontColor: 'transparent', // displayOption では '#808080'
padding: 13, // 3 + 10(tickMarkLength),displayOption では 3
fontStyle: 'bold',
},
Expand All @@ -333,13 +339,13 @@ const options: ThisTypedComponentOptionsWithRecordProps<
stacked: true,
gridLines: {
display: true,
drawOnChartArea: false,
color: '#E5E5E5',
drawOnChartArea: false, // displayOption では定義なし
color: '#E5E5E5', // displayOption では定義なし
},
ticks: {
suggestedMin: 0,
maxTicksLimit: 10,
suggestedMin: 0, // displayOption では定義なし
fontColor: '#808080',
maxTicksLimit: 10,
callback: (label) => {
return `${label}${this.unit}`
},
Expand All @@ -349,17 +355,16 @@ const options: ThisTypedComponentOptionsWithRecordProps<
},
animation: { duration: 0 },
}
return options
},
tableHeaders() {
tableHeaders(): TableHeader[] {
return [
{ text: this.$t('日付'), value: 'text' },
...this.displayData.datasets.map((text, value) => {
return { text: text.label, value: String(value), align: 'end' }
}),
]
},
tableData() {
tableData(): TableItem[] {
return this.displayData.datasets[0].data
.map((_, i) => {
return Object.assign(
Expand All @@ -374,11 +379,8 @@ const options: ThisTypedComponentOptionsWithRecordProps<
.reverse()
},
},
methods: {
onClickLegend(i) {
this.displayLegends[i] = !this.displayLegends[i]
this.displayLegends = this.displayLegends.slice()
},
created() {
this.canvas = process.browser
},
mounted() {
const barChart = this.$refs.barChart as Vue
Expand All @@ -391,9 +393,13 @@ const options: ThisTypedComponentOptionsWithRecordProps<
canvas.setAttribute('aria-labelledby', labelledbyId)
}
},
}
export default Vue.extend(options)
methods: {
onClickLegend(i) {
this.displayLegends[i] = !this.displayLegends[i]
this.displayLegends = this.displayLegends.slice()
},
},
})
</script>

<style module lang="scss">
Expand Down
2 changes: 2 additions & 0 deletions store/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AgencyRepository } from '@/libraries/repositories/AgencyRepository'
import { DataRepository } from '@/libraries/repositories/DataRepository'
// InfectionMedicalcareprovisionStatus ではなく InfectionMedicalCareProvisionStatus とする
import { InfectionMedicalcareprovisionStatusRepository as InfectionMedicalCareProvisionStatusRepository } from '@/libraries/repositories/InfectionMedicalCareProvisionStatusRepository'
Expand All @@ -8,6 +9,7 @@ import { VaccinationRepository } from '@/libraries/repositories/VaccinationRepos
import { VariantRepository } from '@/libraries/repositories/VariantRepository'

export const state = () => ({
agency: new AgencyRepository().data,
data: new DataRepository().data,
infectionMedicalCareProvisionStatus:
new InfectionMedicalCareProvisionStatusRepository().data,
Expand Down

0 comments on commit 69443fd

Please sign in to comment.