11import 'echarts-jsx/dist/renderers/SVG' ;
22import 'echarts-jsx/dist/components/geo' ;
3+ import 'echarts-jsx/dist/components/timeline' ;
34
45import { DataObject } from 'dom-renderer' ;
56import { EChartsOption , EChartsType , init , registerMap } from 'echarts' ;
6- import { observable } from 'mobx' ;
7+ import { observable , runInAction } from 'mobx' ;
78import { attribute , component , observer , WebCell } from 'web-cell' ;
89import { formatDate } from 'web-utility' ;
910
1011import { getHistory , Province } from '../../../service/Epidemic' ;
1112import { long2short } from '../adapter' ;
13+ import { json } from 'stream/consumers' ;
1214
1315export interface EChartsMapProps {
1416 /**
@@ -53,10 +55,15 @@ export class EChartsMap
5355 @attribute
5456 @observable
5557 accessor mapName = 'map' ;
58+
59+ @attribute
60+ @observable
61+ accessor hovered = '' ;
5662
5763 @observable
5864 accessor chartOptions : EChartsOption = { } ;
5965
66+
6067 chart : EChartsType ;
6168
6269 mountedCallback ( ) {
@@ -67,11 +74,11 @@ export class EChartsMap
6774 this . listen ( ) ;
6875 this . loadData ( ) ;
6976
70- self . addEventListener ( 'resize' , ( ) => {
71- this . chart . resize ( ) ;
77+ // self.addEventListener('resize', () => {
78+ // this.chart.resize();
7279
73- this . adjustLabel ( ) ;
74- } ) ;
80+ // this.adjustLabel();
81+ // });
7582 }
7683
7784 adjustLabel ( ) {
@@ -84,56 +91,121 @@ export class EChartsMap
8491 // implement hover-then-click on mobile devices
8592 let hovered = '' ;
8693
94+
95+
8796 chart
8897 . on ( 'mouseover' , 'series' , ( { name } ) => {
98+ console . log ( 'mouseover-event' ) ;
8999 // prevent click event to trigger immediately
90100 setTimeout ( ( ) => ( hovered = name ) ) ;
91101 } )
92102 . on ( 'mouseout' , 'series' , ( ) => {
103+ console . log ( 'mouseout-event' ) ;
104+
93105 hovered = '' ;
94106 } )
95107 . on ( 'click' , 'series' , params => {
108+ console . log ( 'click-seriesevent' ) ;
96109 if ( hovered ) {
97110 this . emit ( 'seriesclick' , params ) ;
98111 hovered = '' ;
99112 }
100113 } )
101- . on ( 'click' , 'timeline' , ( { dataIndex } ) => {
102- const formattedDate = formatDate ( dataIndex , 'YYYY-MM-DD' ) ;
103- chart . dispatchAction ( {
104- type : 'timelineChange' ,
105- // index of time point
106- currentIndex : data . findIndex ( d => d === dataIndex )
107- } ) ;
108- getHistory ( formattedDate ) . then ( this . updateChartData ) ;
109- } ) ;
114+ // .on('click', 'timeline', ({ dataIndex }) => {
115+ // console.log('click-timelineevent');
116+ // const formattedDate = formatDate(dataIndex, 'YYYY-MM-DD');
117+ // chart.dispatchAction({
118+ // type: 'timelineChange',
119+ // // index of time point
120+ // currentIndex: data.findIndex(d => d === dataIndex)
121+ // });
122+ // getHistory(formattedDate).then(this.updateChartData);
123+ // });
110124 }
125+
126+ // handleSeriesClick = (event: any) => {
127+ // console.log('Series Click Event:', event);
128+ // // 使用原生 ECharts 事件对象
129+ // const params = event.detail || event;
130+ // console.log('Click params:', params);
131+
132+ // if (this.hovered) {
133+ // this.props.onSeriesClick?.(new CustomEvent('seriesclick', {
134+ // detail: params
135+ // }));
136+ // this.hovered = '';
137+ // }
138+ // };
139+
140+ // handleMouseOver = (event: any) => {
141+ // console.log('handleMouseOver Event:', event);
142+ // const eventDetail = event.detail;
143+ // if (eventDetail?.componentType === 'series') {
144+ // const name = eventDetail.name;
145+ // if (name) {
146+ // setTimeout(() => {
147+ // this.hovered = name;
148+ // });
149+ // }
150+ // }
151+ // };
152+
153+
154+
155+ handleTimelineClick = ( event : any ) => {
156+ console . log ( 'Timeline Click Event:' , event ) ;
157+
158+ // const eventDetail = event.detail;
159+ // if (eventDetail?.componentType === 'timeline') {
160+ // const dataIndex = eventDetail.dataIndex;
161+ // const { data } = this.chartOptions.baseOption.timeline;
162+
163+ // const formattedDate = formatDate(dataIndex, 'YYYY-MM-DD');
164+ // getHistory(formattedDate).then(this.updateChartData);
165+ // }
166+ } ;
167+
168+
111169
112170 async loadData ( ) {
113- const { chart, mapUrl, mapName } = this ;
171+ const { chart, mapUrl, mapName, chartOptions } = this ;
114172
115173 chart . showLoading ( ) ;
116174
117175 const data = await ( await fetch ( mapUrl ) ) . json ( ) ;
118-
176+ console . log ( 'data' , data )
177+ console . log ( 'chartOptions' , chartOptions )
119178 for ( const { properties } of data . features )
120179 properties . name = long2short ( properties . name ) ;
121-
180+
122181 registerMap ( mapName , data ) ;
123-
124182 this . adjustLabel ( ) ;
125183 chart . hideLoading ( ) ;
184+ this . emit ( 'chartlabeladjust' ) ;
185+
126186 }
127187 render ( ) {
128188 const options = this . chartOptions ;
129-
189+ console . log ( 'xuanran' , options )
190+ const timelineData = options . baseOption ?. timeline ?. data || [ ] ;
191+ console . log ( 'timelineData' , timelineData )
130192 return (
131- < ec-svg-renderer >
132- < ec-geo
133- map = { this . mapName }
134- data = { options . options [ 0 ] . series [ 0 ] ?. data }
135- />
136- </ ec-svg-renderer >
193+ < >
194+ < ec-svg-renderer >
195+ < ec-geo
196+ map = { this . mapName }
197+ data = { options . options [ 0 ] . series [ 0 ] ?. data }
198+ // onClick={this.handleSeriesClick}
199+ // onMouseover={this.handleMouseOver}
200+ // onMouseout={() => this.hovered = ''}
201+ />
202+
203+ < ec-timeline data = { timelineData }
204+ onClick = { this . handleTimelineClick }
205+ />
206+
207+ </ ec-svg-renderer >
208+ </ >
137209 ) ;
138210 }
139211 updateChartData = ( newData : Province [ ] ) =>
@@ -147,4 +219,6 @@ export class EChartsMap
147219 }
148220 ]
149221 } ) ;
222+
223+
150224}
0 commit comments