Skip to content

Commit 05c3eb9

Browse files
Merge pull request wuhan2020#118 from shadowings-zy/react
进行手机端/PC端/预览端三种不同使用类型的适配,调整手机端交互方式
2 parents 9945f14 + a61504a commit 05c3eb9

File tree

14 files changed

+352
-90
lines changed

14 files changed

+352
-90
lines changed

.gitignore

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
/node_modules/
2-
tmp/*
3-
.vscode/
4-
.idea/
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
515
.DS_Store
6-
package-lock.json
7-
dist/
8-
.cache/
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
/dist
26+
/.cache
27+
/tmp
28+
/.vscode
29+
/.idea
30+
/.DS_Store

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,35 @@
66

77
提供基于 ECharts 可视化库的前端组件。
88

9-
### 创建一个完整独立的疫情地图
9+
### 1、提供一个完整独立的疫情地图组件
1010

1111
- **目的&设计**:创建一个独立的疫情地图可视化,有两个主要目标
1212
1. 地理精度:有市级地理粒度,最开始是一个全国地图的 heatmap,点击一个省重绘成省 map。([重绘参考](https://gallery.echartsjs.com/editor.html?c=xm3iS_cb0g)
1313
- optional: 可能会做成县级精度,具体见[讨论](https://github.com/wuhan2020/map-viz/issues/52)
1414
2. 时间信息:有时间轴,点击一个地区可以画出[stacked area chart](https://echarts.apache.org/examples/en/editor.html?c=area-stack)之类的疫情发展图 (确诊/疑似/死亡为不同层),也可以根据选择的时间点重绘地图。([时间轴参考案例](https://echarts.apache.org/examples/en/editor.html?c=mix-timeline-finance))
15-
- **使用**:取决于数据
16-
- 如果自动抓取省市级数据:疫情地图与前端其他组件交互较少,且数据可以[通过 API 直接获取](http://lab.isaaclin.cn/nCoV/api/area?latest=0),可以作为单独 webpage,最终作为 iframe 整合进前端页面。
17-
- 如果使用手动抓取的县级数据,则作为组件融入前端,接受传入数据。[讨论](https://github.com/wuhan2020/map-viz/issues/52)
15+
1816
- **进度**
1917

20-
![img0](./screenshots/virus-map-overview.gif)
21-
2218
- [x] 基础疫情地图,并用统计图(线图+ stacked area chart)显示疫情发展数据
2319
- [x] 省市层级交互
2420
- [x] 时间轴交互
2521
- [ ] 接入手动收集的省级数据
2622
- [ ] 疫情地图时间轴与统计图联动
2723

28-
### 创建一个通用地图组件
24+
### 2、提供一个通用地图组件
2925

3026
- **目的**:用于可视化各种不同地理信息(例如医院位置,酒店位置,etc.)
3127
- **使用**:作为组件被前端调用,数据来自前端。
32-
- **基础设计**:点图+地图([参考例子](https://www.echartsjs.com/examples/zh/editor.html?c=effectScatter-bmap)
33-
- **交互**
34-
- 不自带过滤等交互组件,上层应该自己创建 checkbox, slider, etc. 过滤后数据传入地图组件可以重绘地图
35-
- 接受传入的 mouseEvent,可以帮助做信息过滤及定位(e.g., 点击一个省选中它的信息)
36-
- ([相关讨论](https://github.com/wuhan2020/map-viz/issues/2#issuecomment-578626578))
37-
- [数据格式设计讨论](https://github.com/wuhan2020/map-viz/issues/3)
38-
- **进度**
39-
40-
![img3](./screenshots/info-map-demo.gif)
4128

4229
## 使用
4330

44-
详情参考/src/pages/hierarchicalVirusMapDemo.tsx以及/src/pages/informationMapDemo.tsx
31+
详情参考:
32+
[/src/pages/hierarchicalVirusMapDemo.tsx](./src/pages/hierarchicalVirusMapDemo.tsx)
33+
[/src/pages/informationMapDemo.tsx](./src/pages/informationMapDemo.tsx)
34+
35+
具体组件说明请参考:
36+
[/src/components/virusMap/README.md](./src/components/virusMap/README.md)
37+
[/src/components/informationMap/README.md](./src/components/informationMap/README.md)
4538

4639
## 本地开发
4740

@@ -53,17 +46,19 @@
5346
```sh
5447
# clone the repo
5548
git clone [email protected]:wuhan2020/map-viz.git
56-
# setup the npm env
49+
5750
cd map-viz
51+
# checkout react branch
52+
git checkout react
53+
# setup the npm env
5854
npm install
5955
# start the project
6056
npm start
6157
```
6258

6359
### 任务拆分&参与指南
6460

65-
[合作指南参考主 repo](https://github.com/wuhan2020/wuhan2020/blob/master/CONTRIBUTING.md)(viz 没有项目机器人+注意将 demo script 改成我们的 repo)
66-
TL;DR:
61+
[合作指南参考](https://github.com/wuhan2020/wuhan2020/blob/master/CONTRIBUTING.md)(注意将 demo script 改成我们的 repo)
6762

6863
1. 请在[project 面板](https://github.com/wuhan2020/map-viz/projects/1)自行认领&self-assign issues(如果不能更改 assignee,请回复 issue 表示认领,我们会后面添加 assign)
6964
2. 对数据和设计如果有讨论请参见如下 issue:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# React 地图信息可视化组件
2+
3+
本地图组件对百度地图API进行了封装,提供了开箱即用的百度地图接入组件。
4+
本组件固定了地图上 Marker 的格式以及样式。
5+
@author: shadowingszy
6+
7+
## 传入参数及说明:
8+
9+
mapOptions: 地图配置项,可参考百度地图 API 进行配置。(可参考/mock/information_map_general_mock_data.js)
10+
11+
mapOptions 入参样例:
12+
13+
```js
14+
{
15+
initPoint: [116.350658, 39.938285], // 地图初始化时中心点坐标
16+
zoom: 6, // 地图初始化时缩放比例
17+
markers: [ // 地图上标记点数组
18+
{
19+
name: '华中科技大学同济医学院附属协和医院',
20+
//目前支持的 type 有:hospital,hotel,others 三种
21+
type: "hospital",
22+
// 坐标
23+
coord: [114.281196, 30.590103],
24+
// 有则填,无则不填
25+
url?: 'https://mp.weixin.qq.com/s/geO3CCd0_8B3L-r_xlBbZQ',
26+
// 一些属性,可能会不同
27+
metadata: []
28+
}
29+
]
30+
}
31+
```
32+
33+
其中 metadata 的 type:
34+
35+
```js
36+
{
37+
key: string; // 一个关键词
38+
label?: string; // 如果有label,这个作为显示词,覆盖key
39+
value: string|number|InquiryMeta[], // 具体值
40+
}
41+
// 例子
42+
metadata: [
43+
{ // 酒店
44+
key: "request",
45+
label: "物资需求",
46+
value: [
47+
['普通医用口罩', 10000],
48+
['医用外科口罩', true]
49+
]
50+
}, { // 地理位置
51+
key: "address",
52+
value: '湖北省武汉市江汉区解放大道1277号华中科技大学同济医学院附属协和医院总务处',
53+
label: "邮寄地址",
54+
}, { // 酒店容量
55+
key: "capability",
56+
value: 100,
57+
label: "容量",
58+
}
59+
]
60+
```
61+
62+
## 使用样例
63+
64+
```js
65+
<InformationMap initPoint={initPoint} zoom={zoom} markers={makerArray} />
66+
```

src/components/virusMap/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# React 疫情地图可视化组件
2+
3+
本地图组件提供了完整的全国疫情查看功能,并提供增加聚焦到省显示市级数据与回到省级的功能。
4+
@author: shadowingszy,yarray
5+
6+
## 传入参数:
7+
8+
resolution: 时间精度。
9+
data: echarts 中每个区域的疫情数据。
10+
type: 三种不同的charts显示方式(可选值为: overview, pc, mobile)。
11+
12+
## 参数说明:
13+
14+
传入参数的数据格式为:
15+
16+
```typescript
17+
interface Props {
18+
resolution: number; // 地图放大的程度
19+
data: { [name: string]: PatientStatData };//echarts 中每个区域的疫情数据。
20+
type: 'overview' | 'pc' | 'mobile';
21+
}
22+
23+
interface PatientStatData {
24+
confirmed: number;
25+
suspected: number;
26+
cured: number;
27+
dead: number;
28+
}
29+
```
30+
31+
data属性数据样例1:
32+
33+
```json
34+
{
35+
"吉林": {
36+
"name": "吉林",
37+
"timestamp": 1580260529915,
38+
"confirmed": 9,
39+
"suspected": 0,
40+
"cured": 0,
41+
"dead": 0
42+
},
43+
"西藏": {
44+
"name": "西藏",
45+
"timestamp": 1580264158978,
46+
"confirmed": 0,
47+
"suspected": 1,
48+
"cured": 0,
49+
"dead": 0
50+
},
51+
"北京": {
52+
"confirmed": 102,
53+
"suspected": 0,
54+
"cured": 4,
55+
"dead": 1
56+
},
57+
```
58+
59+
数据样例2:
60+
61+
```json
62+
{
63+
"晋中": {
64+
"name": "晋中",
65+
"confirmed": 9,
66+
"suspected": 0,
67+
"cured": 0,
68+
"dead": 0
69+
},
70+
"运城": {
71+
"name": "运城",
72+
"confirmed": 4,
73+
"suspected": 0,
74+
"cured": 0,
75+
"dead": 0
76+
},
77+
"太原": {
78+
"name": "太原",
79+
"confirmed": 3,
80+
"suspected": 0,
81+
"cured": 0,
82+
"dead": 0
83+
},
84+
"大同": {
85+
"name": "大同",
86+
"confirmed": 3,
87+
"suspected": 0,
88+
"cured": 0,
89+
"dead": 0
90+
},
91+
"吕梁": {
92+
"name": "吕梁",
93+
"confirmed": 3,
94+
"suspected": 0,
95+
"cured": 0,
96+
"dead": 0
97+
},
98+
"朔州": {
99+
"name": "朔州",
100+
"confirmed": 2,
101+
"suspected": 0,
102+
"cured": 0,
103+
"dead": 0
104+
},
105+
"阳泉": {
106+
"name": "阳泉",
107+
"confirmed": 1,
108+
"suspected": 0,
109+
"cured": 0,
110+
"dead": 0
111+
},
112+
"长治": {
113+
"name": "长治",
114+
"confirmed": 1,
115+
"suspected": 0,
116+
"cured": 0,
117+
"dead": 0
118+
},
119+
"临汾": {
120+
"name": "临汾",
121+
"confirmed": 1,
122+
"suspected": 0,
123+
"cured": 0,
124+
"dead": 0
125+
}
126+
}
127+
```
128+
129+
## 使用样例
130+
131+
```js
132+
<HierarchicalVirusMap data={data} resolution={resolution} type={'overview'} />
133+
<HierarchicalVirusMap data={data} resolution={resolution} type={'pc'} />
134+
<HierarchicalVirusMap data={data} resolution={resolution} type={'mobile'} />
135+
```

src/components/virus-map/echartsMap.tsx renamed to src/components/virusMap/echartsMap.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* mapUrl: 地图json文件地址
88
* chartOptions: echarts中的所有options
99
* mapName: 地图名称
10+
* mobile: 是否为手机端
1011
* chartOnClickCallBack: 点击地图后的回调函数
1112
*/
1213

@@ -18,6 +19,7 @@ interface Props {
1819
mapUrl: string;
1920
chartOptions: any;
2021
mapName: string;
22+
mobile: boolean;
2123
chartOnClickCallBack: Function;
2224
}
2325

@@ -27,6 +29,7 @@ export class EchartsMap extends React.Component<Props> {
2729
mapUrl: '',
2830
chartOptions: {},
2931
mapName: '',
32+
mobile: true,
3033
chartOnClickCallBack: (param: any, chart: any) => {
3134
console.log(param, chart);
3235
}
@@ -62,25 +65,27 @@ export class EchartsMap extends React.Component<Props> {
6265
);
6366
echarts.registerMap(mapName, data);
6467
if (!this.chart) {
68+
let previousClick = {
69+
times: 0,
70+
name: ''
71+
}
72+
6573
this.chart = echarts.init((document.getElementById(this.chartId)) as HTMLDivElement);
66-
// implement hover-then-click on mobile devices
67-
let eventState = {
68-
hovered: ''
69-
};
70-
this.chart.on('mouseover', 'series', (params: { name: string; }) => {
71-
// prevent click event to trigger immediately
72-
setTimeout(() => (eventState.hovered = params.name), 0);
73-
});
74-
this.chart.on('mouseout', 'series', () => {
75-
eventState.hovered = '';
76-
});
7774
this.chart.on('click', 'series', (params: any) => {
78-
if (eventState.hovered.length > 0) {
75+
console.log(params);
76+
if (this.props.mobile) {
77+
if (previousClick.name === params.name && previousClick.times === 1) {
78+
chartOnClickCallBack(params, this.chart);
79+
previousClick.times = 0;
80+
previousClick.name = '';
81+
} else {
82+
previousClick.times = 1;
83+
previousClick.name = params.name;
84+
}
85+
} else {
7986
chartOnClickCallBack(params, this.chart);
80-
eventState.hovered = '';
8187
}
8288
});
83-
8489
this.chart.on('click', 'timeline', (params: { dataIndex: any; }) => {
8590
this.chart.dispatchAction({
8691
type: 'timelineChange',

0 commit comments

Comments
 (0)