1
1
import React from 'react' ;
2
- import HeatmapChartCore from './HeatmapChartCore' ;
3
- import ReactEChartsCore from 'echarts-for-react/lib/core' ;
4
- import html2canvas from 'html2canvas' ;
2
+ import HeatmapChartCore , { HeatmapChartCoreProps } from './core/HeatmapChartCore' ;
5
3
import {
6
4
useServerMapSearchParameters ,
7
5
useStoragedAxisY ,
@@ -11,89 +9,54 @@ import {
11
9
APP_SETTING_KEYS ,
12
10
ApplicationType ,
13
11
GetHeatmapAppData ,
12
+ GetServerMap ,
14
13
} from '@pinpoint-fe/ui/src/constants' ;
15
14
16
15
export interface HeatmapFetcherHandle {
17
16
handleCaptureImage : ( ) => Promise < void > ;
18
17
}
19
18
20
19
export type HeatmapFetcherProps = {
21
- application ?: ApplicationType ;
20
+ nodeData : GetServerMap . NodeData | ApplicationType ;
22
21
agentId ?: string ;
23
- } ;
24
-
25
- export const HeatmapFetcher = React . forwardRef (
26
- ( { application, agentId } : HeatmapFetcherProps , ref ) => {
27
- React . useImperativeHandle ( ref , ( ) => ( {
28
- handleCaptureImage,
29
- } ) ) ;
30
-
31
- const { dateRange, searchParameters } = useServerMapSearchParameters ( ) ;
32
- const chartRef = React . useRef < ReactEChartsCore > ( null ) ;
33
- const [ y ] = useStoragedAxisY ( APP_SETTING_KEYS . HEATMAP_Y_AXIS_MIN_MAX , [ 0 , 10000 ] ) ;
34
- const [ parameters , setParameters ] = React . useState < GetHeatmapAppData . Parameters > ( {
35
- applicationName : application ?. applicationName ,
22
+ } & Pick < HeatmapChartCoreProps , 'toolbarOption' > ;
23
+
24
+ export const HeatmapFetcher = ( { nodeData, agentId, ...props } : HeatmapFetcherProps ) => {
25
+ const { dateRange } = useServerMapSearchParameters ( ) ;
26
+
27
+ const [ y ] = useStoragedAxisY ( APP_SETTING_KEYS . HEATMAP_Y_AXIS_MIN_MAX , [ 0 , 10000 ] ) ;
28
+
29
+ const [ parameters , setParameters ] = React . useState < GetHeatmapAppData . Parameters > ( {
30
+ applicationName : nodeData ?. applicationName ,
31
+ from : dateRange . from . getTime ( ) ,
32
+ to : dateRange . to . getTime ( ) ,
33
+ minElapsedTime : Number ( y [ 0 ] ) ,
34
+ maxElapsedTime : Number ( y [ 1 ] ) ,
35
+ agentId : agentId ,
36
+ } ) ;
37
+ const { data, isLoading } = useGetHeatmapAppData ( parameters ) ;
38
+
39
+ React . useEffect ( ( ) => {
40
+ setParameters ( {
41
+ applicationName : nodeData ?. applicationName ,
36
42
from : dateRange . from . getTime ( ) ,
37
43
to : dateRange . to . getTime ( ) ,
38
44
minElapsedTime : Number ( y [ 0 ] ) ,
39
45
maxElapsedTime : Number ( y [ 1 ] ) ,
40
46
agentId : agentId ,
41
47
} ) ;
42
- const { data, isLoading } = useGetHeatmapAppData ( parameters ) ;
43
-
44
- // console.log('search', searchParameters, 'parameters', parameters);
45
- // console.log('data', data);
46
-
47
- React . useEffect ( ( ) => {
48
- setParameters ( {
49
- applicationName : application ?. applicationName ,
50
- from : dateRange . from . getTime ( ) ,
51
- to : dateRange . to . getTime ( ) ,
52
- minElapsedTime : Number ( y [ 0 ] ) ,
53
- maxElapsedTime : Number ( y [ 1 ] ) ,
54
- agentId : agentId ,
55
- } ) ;
56
- } , [
57
- dateRange . from . getTime ( ) ,
58
- dateRange . to . getTime ( ) ,
59
- y [ 0 ] ,
60
- y [ 1 ] ,
61
- application ?. applicationName ,
62
- agentId ,
63
- ] ) ;
64
-
65
- async function handleCaptureImage ( ) {
66
- if ( ! chartRef . current ) {
67
- return ;
68
- }
69
-
70
- const currentNode = '' ;
71
- const fileName = `Pinpoint_Heatmap_Chart__${ ( agentId ? agentId : currentNode ) || '' } ` ;
72
-
73
- const chartElement = chartRef . current . getEchartsInstance ( ) . getDom ( ) ;
74
- const canvas = await html2canvas ( chartElement ) ;
75
- const image = canvas . toDataURL ( 'image/png' ) ;
76
-
77
- const link = document . createElement ( 'a' ) ;
78
- link . href = image ;
79
- link . download = fileName ;
80
- document . body . appendChild ( link ) ;
81
- link . click ( ) ;
82
- document . body . removeChild ( link ) ;
83
- }
84
-
85
- return (
86
- < div className = "relative w-full h-full" >
87
- < HeatmapChartCore
88
- ref = { chartRef }
89
- isLoading = { isLoading }
90
- data = { data }
91
- setting = { {
92
- yMin : y [ 0 ] ,
93
- yMax : y [ 1 ] ,
94
- } }
95
- />
96
- </ div >
97
- ) ;
98
- } ,
99
- ) ;
48
+ } , [
49
+ dateRange . from . getTime ( ) ,
50
+ dateRange . to . getTime ( ) ,
51
+ y [ 0 ] ,
52
+ y [ 1 ] ,
53
+ nodeData ?. applicationName ,
54
+ agentId ,
55
+ ] ) ;
56
+
57
+ return (
58
+ < div className = "relative w-full h-full" >
59
+ < HeatmapChartCore isLoading = { isLoading } data = { data } { ...props } />
60
+ </ div >
61
+ ) ;
62
+ } ;
0 commit comments