This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6730 from kaizumaki/feature/issue-6729-add-chart-…
…over65 「報告日別による陽性者数(65歳以上)の推移」グラフカードを実装
- Loading branch information
Showing
8 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
components/index/CardsReference/PositiveNumberOver65/Card.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template> | ||
<v-col cols="12" md="6" class="DataCard PositiveNumberOver65Card"> | ||
<client-only> | ||
<time-bar-chart | ||
:title="$t('報告日別による陽性者数(65歳以上)の推移')" | ||
:title-id="'positive-number-over65'" | ||
:chart-id="'positive-number-over65'" | ||
:chart-data="positiveOver65Data" | ||
:date="date" | ||
:by-date="true" | ||
:unit="$t('人')" | ||
> | ||
<template #additionalDescription> | ||
<span>{{ $t('(注)') }}</span> | ||
<ul> | ||
<li> | ||
{{ $t('保健所から発生届が提出された日を基準とする') }} | ||
</li> | ||
<li> | ||
{{ $t('医療機関等が行った検査も含む') }} | ||
</li> | ||
<li> | ||
{{ $t('チャーター機帰国者、クルーズ船乗客等は含まれていない') }} | ||
</li> | ||
</ul> | ||
</template> | ||
</time-bar-chart> | ||
</client-only> | ||
</v-col> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Vue from 'vue' | ||
import TimeBarChart from '@/components/index/_shared/TimeBarChart.vue' | ||
import { | ||
Datum as IDatum, | ||
PositiveOver65 as IPositiveOver65, | ||
} from '@/libraries/auto_generated/data_converter/convertPositiveOver65' | ||
import { convertDateToISO8601Format } from '@/utils/formatDate' | ||
import formatGraph, { GraphDataType } from '@/utils/formatGraph' | ||
type Data = {} | ||
type Methods = {} | ||
type Computed = { | ||
date: string | ||
positiveOver65Data: GraphDataType[] | ||
positiveOver65: IPositiveOver65 | ||
} | ||
type Props = {} | ||
type DataType = { | ||
日付: string | ||
小計: number | ||
} | ||
export default Vue.extend<Data, Methods, Computed, Props>({ | ||
components: { | ||
TimeBarChart, | ||
}, | ||
computed: { | ||
date() { | ||
return this.positiveOver65.date | ||
}, | ||
positiveOver65Data() { | ||
const data: DataType[] = this.positiveOver65.data.map((d: IDatum) => { | ||
return { | ||
日付: convertDateToISO8601Format(d.date), | ||
小計: d.count, | ||
} | ||
}) | ||
return formatGraph(data) | ||
}, | ||
positiveOver65() { | ||
return this.$store.state.positiveOver65 | ||
}, | ||
}, | ||
}) | ||
</script> |
173 changes: 173 additions & 0 deletions
173
libraries/auto_generated/data_converter/convertPositiveOver65.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// To parse this data: | ||
// | ||
// import { Convert, PositiveOver65 } from "./file"; | ||
// | ||
// const positiveOver65 = Convert.toPositiveOver65(json); | ||
// | ||
// These functions will throw an error if the JSON doesn't | ||
// match the expected interface, even if the JSON is valid. | ||
|
||
export interface PositiveOver65 { | ||
date: string; | ||
data: Datum[]; | ||
} | ||
|
||
export interface Datum { | ||
date: Date; | ||
count: number; | ||
} | ||
|
||
// Converts JSON strings to/from your types | ||
// and asserts the results of JSON.parse at runtime | ||
export class Convert { | ||
public static toPositiveOver65(json: string): PositiveOver65 { | ||
return cast(JSON.parse(json), r("PositiveOver65")); | ||
} | ||
|
||
public static positiveOver65ToJson(value: PositiveOver65): string { | ||
return JSON.stringify(uncast(value, r("PositiveOver65")), null, 2); | ||
} | ||
} | ||
|
||
function invalidValue(typ: any, val: any, key: any = ''): never { | ||
if (key) { | ||
throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`); | ||
} | ||
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`, ); | ||
} | ||
|
||
function jsonToJSProps(typ: any): any { | ||
if (typ.jsonToJS === undefined) { | ||
const map: any = {}; | ||
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ }); | ||
typ.jsonToJS = map; | ||
} | ||
return typ.jsonToJS; | ||
} | ||
|
||
function jsToJSONProps(typ: any): any { | ||
if (typ.jsToJSON === undefined) { | ||
const map: any = {}; | ||
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ }); | ||
typ.jsToJSON = map; | ||
} | ||
return typ.jsToJSON; | ||
} | ||
|
||
function transform(val: any, typ: any, getProps: any, key: any = ''): any { | ||
function transformPrimitive(typ: string, val: any): any { | ||
if (typeof typ === typeof val) return val; | ||
return invalidValue(typ, val, key); | ||
} | ||
|
||
function transformUnion(typs: any[], val: any): any { | ||
// val must validate against one typ in typs | ||
const l = typs.length; | ||
for (let i = 0; i < l; i++) { | ||
const typ = typs[i]; | ||
try { | ||
return transform(val, typ, getProps); | ||
} catch (_) {} | ||
} | ||
return invalidValue(typs, val); | ||
} | ||
|
||
function transformEnum(cases: string[], val: any): any { | ||
if (cases.indexOf(val) !== -1) return val; | ||
return invalidValue(cases, val); | ||
} | ||
|
||
function transformArray(typ: any, val: any): any { | ||
// val must be an array with no invalid elements | ||
if (!Array.isArray(val)) return invalidValue("array", val); | ||
return val.map(el => transform(el, typ, getProps)); | ||
} | ||
|
||
function transformDate(val: any): any { | ||
if (val === null) { | ||
return null; | ||
} | ||
const d = new Date(val); | ||
if (isNaN(d.valueOf())) { | ||
return invalidValue("Date", val); | ||
} | ||
return d; | ||
} | ||
|
||
function transformObject(props: { [k: string]: any }, additional: any, val: any): any { | ||
if (val === null || typeof val !== "object" || Array.isArray(val)) { | ||
return invalidValue("object", val); | ||
} | ||
const result: any = {}; | ||
Object.getOwnPropertyNames(props).forEach(key => { | ||
const prop = props[key]; | ||
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined; | ||
result[prop.key] = transform(v, prop.typ, getProps, prop.key); | ||
}); | ||
Object.getOwnPropertyNames(val).forEach(key => { | ||
if (!Object.prototype.hasOwnProperty.call(props, key)) { | ||
result[key] = transform(val[key], additional, getProps, key); | ||
} | ||
}); | ||
return result; | ||
} | ||
|
||
if (typ === "any") return val; | ||
if (typ === null) { | ||
if (val === null) return val; | ||
return invalidValue(typ, val); | ||
} | ||
if (typ === false) return invalidValue(typ, val); | ||
while (typeof typ === "object" && typ.ref !== undefined) { | ||
typ = typeMap[typ.ref]; | ||
} | ||
if (Array.isArray(typ)) return transformEnum(typ, val); | ||
if (typeof typ === "object") { | ||
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val) | ||
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val) | ||
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val) | ||
: invalidValue(typ, val); | ||
} | ||
// Numbers can be parsed by Date but shouldn't be. | ||
if (typ === Date && typeof val !== "number") return transformDate(val); | ||
return transformPrimitive(typ, val); | ||
} | ||
|
||
function cast<T>(val: any, typ: any): T { | ||
return transform(val, typ, jsonToJSProps); | ||
} | ||
|
||
function uncast<T>(val: T, typ: any): any { | ||
return transform(val, typ, jsToJSONProps); | ||
} | ||
|
||
function a(typ: any) { | ||
return { arrayItems: typ }; | ||
} | ||
|
||
function u(...typs: any[]) { | ||
return { unionMembers: typs }; | ||
} | ||
|
||
function o(props: any[], additional: any) { | ||
return { props, additional }; | ||
} | ||
|
||
function m(additional: any) { | ||
return { props: [], additional }; | ||
} | ||
|
||
function r(name: string) { | ||
return { ref: name }; | ||
} | ||
|
||
const typeMap: any = { | ||
"PositiveOver65": o([ | ||
{ json: "date", js: "date", typ: "" }, | ||
{ json: "data", js: "data", typ: a(r("Datum")) }, | ||
], false), | ||
"Datum": o([ | ||
{ json: "date", js: "date", typ: Date }, | ||
{ json: "count", js: "count", typ: 0 }, | ||
], false), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// eslint-disable-next-line import/no-named-default | ||
import { default as rawData } from '@/data/positive_over65.json' | ||
import { | ||
Convert, | ||
PositiveOver65, | ||
} from '@/libraries/auto_generated/data_converter/convertPositiveOver65' | ||
import { | ||
BaseRepository, | ||
IBaseRepository, | ||
} from '@/libraries/repositories/BaseRepository' | ||
|
||
export interface IPositiveOver65Repository | ||
extends IBaseRepository<PositiveOver65> {} | ||
|
||
export class PositiveOver65Repository | ||
extends BaseRepository<PositiveOver65> | ||
implements IPositiveOver65Repository | ||
{ | ||
/** | ||
* 使用箇所 | ||
* | ||
* 報告日別による陽性者数(65歳以上)の推移 (components/index/CardsReference/PositiveNumberOver65/Card.vue) | ||
*/ | ||
constructor() { | ||
super(Convert.toPositiveOver65(JSON.stringify(rawData))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters