@@ -63,42 +63,52 @@ const UserEngagementByRegionChart = ({ data }: Props) => {
63
63
}
64
64
} , [ ] )
65
65
66
+ const geoPoints = useMemo ( ( ) => {
67
+ return data . reduce ( ( acc , log ) => {
68
+ const region = log ?. geolocationDataJsonb ?. city ?. names ?. en || 'Unknown' ; // assuming `region` is added to each event
69
+ let regionData = {
70
+ latitude : log ?. geolocationDataJsonb ?. location ?. latitude ?? 55 ,
71
+ longitude : log ?. geolocationDataJsonb ?. location ?. longitude ?? 15 ,
72
+ count : 0 ,
73
+ } ;
74
+ if ( acc [ region ] ) {
75
+ acc [ region ] = {
76
+ ...acc [ region ] ,
77
+ count : acc [ region ] . count + 1 ,
78
+ }
79
+ } else {
80
+ acc [ region ] = regionData ;
81
+ }
82
+ return acc ;
83
+ } , { } as Record < string , number > ) ;
84
+ } , [ data ] ) ;
85
+
66
86
const series = useMemo ( ( ) => {
67
87
return [
68
88
{
69
- "name" : "Company Size " ,
89
+ "name" : "Users/Region " ,
70
90
"type" : "scatter" ,
71
91
"coordinateSystem" : "gmap" ,
72
92
"itemStyle" : {
73
93
"color" : "#ff00ff"
74
94
} ,
75
- "data" : data
76
- // .filter(item => {
77
- // if (!item.geolocationDataJsonb) return false;
78
- // return item.geolocationDataJsonb.longitude !== null &&
79
- // item.geolocationDataJsonb.latitude !== null
80
- // })
81
- . map ( item => ( {
82
- name : item . details ?. applicationName ,
83
- value : [
84
- ...getRandomLatLng ( 35 , 72 , 25 , 65 ) ,
85
- 1 ,
86
- ]
87
- // value: [
88
- // geoLocation.location.longitude, // item.longitude,
89
- // geoLocation.location.latitude, // item.latitude,
90
- // 1
91
- // ]
92
- } ) )
93
- ,
95
+ "data" : Object . keys ( geoPoints ) . map ( key => ( {
96
+ name : key ,
97
+ value : [
98
+ geoPoints [ key ] . longitude ,
99
+ geoPoints [ key ] . latitude ,
100
+ geoPoints [ key ] . count ,
101
+ ]
102
+ } ) ) ,
103
+ "symbolSize" : ( val : number [ ] ) => { return 8 + ( ( Math . log ( val [ 2 ] ) - Math . log ( 2 ) ) / ( Math . log ( 40 ) - Math . log ( 2 ) ) ) * ( 40 - 8 ) } ,
94
104
"encode" : {
95
105
"value" : 2 ,
96
106
"lng" : 0 ,
97
107
"lat" : 1
98
108
}
99
109
}
100
110
]
101
- } , [ data ] ) ;
111
+ } , [ geoPoints ] ) ;
102
112
103
113
return (
104
114
< >
@@ -115,7 +125,9 @@ const UserEngagementByRegionChart = ({ data }: Props) => {
115
125
} ,
116
126
tooltip : {
117
127
trigger : "item" ,
118
- formatter : "{b}"
128
+ formatter : ( params : { data : { name : string ; value : any [ ] ; } ; } ) => {
129
+ return `${ params . data . name } : ${ params . data . value [ 2 ] } ` ;
130
+ }
119
131
} ,
120
132
animation : true ,
121
133
series : series ,
0 commit comments