Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

疫情图表性能优化 #93

Merged
merged 14 commits into from
Sep 5, 2024
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"classnames": "^2.5.1",
"dom-renderer": "^2.1.8",
"echarts": "^5.5.0",
"echarts-jsx": "^1.2.0",
"echarts-jsx": "^1.2.1",
"github-web-widget": "^4.0.0-rc.2",
"koajax": "^1.1.2",
"mobx": "^6.12.4",
Expand Down Expand Up @@ -76,7 +76,7 @@
"clean": "rm -rf .parcel-cache/ dist/",
ziwu7 marked this conversation as resolved.
Show resolved Hide resolved
"start:local": "npm run clean && cross-env HTTP_ENV=local parcel source/index.html --open",
"start:remote": "npm run clean && cross-env HTTP_ENV=remote parcel source/index.html --open",
"start": "npm run clean && cross-env HTTP_ENV=test parcel source/index.html --open",
"start": "npm run && cross-env HTTP_ENV=test parcel source/index.html --open",
ziwu7 marked this conversation as resolved.
Show resolved Hide resolved
"pack-dist": "parcel build source/index.html --public-url . --no-source-maps && tsx fix-script",
"pack-sw": "rm -f dist/sw.js.map && workbox generateSW",
"build": "npm run clean && npm run pack-dist && npm run pack-sw"
Expand Down
69 changes: 40 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions source/page/Map/adapter/isaaclin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function fillForward<T extends ProvinceData | CityData | CountryData>(
series: Series<T>
) {
const all_ts = Object.keys(series).sort();

for (const [i, t] of all_ts.entries())
if (i < all_ts.length - 1)
for (const name of Object.keys(series[t])) {
Expand All @@ -100,17 +100,17 @@ export function convertProvincesSeries(
source = [...source].sort(
({ updateTime: a }, { updateTime: b }) => +b - +a
);

console.log('source',source);
for (const item of source) {
const t = roundTime(+item.updateTime, resolution);

const date = new Date(item.updateTime);
const timestamp = date.getTime();
const t = roundTime(timestamp, resolution);
ziwu7 marked this conversation as resolved.
Show resolved Hide resolved
if (res[t] === undefined) res[t] = {};

const prov = convertProvince(item);
ziwu7 marked this conversation as resolved.
Show resolved Hide resolved

res[t][prov.name] = prov;
}

if (shouldFillForward) fillForward(res);

return res;
Expand Down Expand Up @@ -146,5 +146,9 @@ export const convertCountrySeries = (
resolution: number
): Series<CountryOverviewData> =>
Object.fromEntries(
source.map(item => [roundTime(+item.updateTime, resolution), item])
source.map(item => {
const date = new Date(item.updateTime);
const timestamp = date.getTime();
return [roundTime(timestamp, resolution), item]
})
);
2 changes: 1 addition & 1 deletion source/page/Map/component/HierarchicalVirusMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class HierarchicalVirusMap
)
)
];

return (
<>
<VirusMap
Expand Down
25 changes: 19 additions & 6 deletions source/page/Map/component/VirusChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,25 @@ export class VirusChart
mountedCallback() {
this.classList.add('d-flex', 'flex-column');
}

toMonth(dateString){
let date = new Date(dateString);
let year = date.getFullYear();
let month = date.getMonth();
return new Date(year, month);
}
render() {
const { data, area, path } = this.props;

const orderedProvincesData = this.getOrderedTimeData(
data.provincesSeries
),
orderedCountryData = this.getOrderedTimeData(data.countrySeries);

return (
let confirmedCount = orderedCountryData.map(item=>[this.toMonth(item.updateTime),item.confirmed])
let suspectedCount = orderedCountryData.map(item=>[this.toMonth(item.updateTime),item.suspected])
let curedCount = orderedCountryData.map(item=>[this.toMonth(item.updateTime),item.cured])
let deadCount = orderedCountryData.map(item=>[this.toMonth(item.updateTime),item.dead])

return (
<>
<ec-svg-renderer
className="w-100 h-50"
Expand All @@ -284,11 +293,13 @@ export class VirusChart
name="确诊"
stack="总量"
areaStyle={{ color: '#f6bdcd' }}
data={confirmedCount}
/>
<ec-line-chart
name="疑似"
stack="总量"
areaStyle={{ color: '#f9e4ba' }}
data={suspectedCount}
/>
<ec-tooltip trigger="axis" />
</ec-svg-renderer>
Expand All @@ -306,10 +317,12 @@ export class VirusChart
<ec-grid bottom="25%" left={60} />
<ec-x-axis name="日期" type="time" nameGap={5} />
<ec-y-axis name="人数" nameGap={10} />
<ec-line-chart name="治愈" />
<ec-line-chart name="死亡" />
<ec-line-chart name="治愈" data={curedCount} />
<ec-line-chart name="死亡" data={deadCount} />
<ec-tooltip trigger="axis" />
</ec-svg-renderer>


</>
);
}
Expand Down
Loading