1
- import { Empty , Row , Col , Select , Tooltip } from 'antd' ;
2
- import { Advice , Advisor } from '@antv/ava' ;
3
- import { Chart } from '@berryv/g2-react' ;
1
+ import { Empty , Row , Col , Select , Tooltip , Button , Space } from 'antd' ;
2
+ import { Advice , Advisor , Datum } from '@antv/ava' ;
3
+ import { Chart , ChartRef } from '@berryv/g2-react' ;
4
4
import i18n , { I18nKeys } from '@/app/i18n' ;
5
5
import { customizeAdvisor , getVisAdvices } from './advisor/pipeline' ;
6
- import { useContext , useEffect , useMemo , useState } from 'react' ;
6
+ import { useContext , useEffect , useMemo , useRef , useState } from 'react' ;
7
7
import { defaultAdvicesFilter } from './advisor/utils' ;
8
8
import { AutoChartProps , ChartType , CustomAdvisorConfig , CustomChart , Specification } from './types' ;
9
9
import { customCharts } from './charts' ;
10
10
import { ChatContext } from '@/app/chat-context' ;
11
11
import { compact , concat , uniq } from 'lodash' ;
12
- import { sortData } from './charts/util' ;
12
+ import { processNilData , sortData } from './charts/util' ;
13
+ import { downloadImage } from '../helpers/downloadChartImage' ; ;
14
+ import { DownloadOutlined } from '@ant-design/icons' ;
13
15
14
16
const { Option } = Select ;
15
17
16
18
export const AutoChart = ( props : AutoChartProps ) => {
17
- const { data , chartType, scopeOfCharts, ruleConfig } = props ;
19
+ const { chartType, scopeOfCharts, ruleConfig, data : originalData } = props ;
18
20
21
+ // 处理空值数据 (为'-'的数据)
22
+ const data = processNilData ( originalData ) as Datum [ ] ;
19
23
const { mode } = useContext ( ChatContext ) ;
20
24
21
25
const [ advisor , setAdvisor ] = useState < Advisor > ( ) ;
22
26
const [ advices , setAdvices ] = useState < Advice [ ] > ( [ ] ) ;
23
27
const [ renderChartType , setRenderChartType ] = useState < ChartType > ( ) ;
28
+ const chartRef = useRef < ChartRef > ( )
24
29
25
30
useEffect ( ( ) => {
26
31
const input_charts : CustomChart [ ] = customCharts ;
@@ -106,6 +111,7 @@ export const AutoChart = (props: AutoChartProps) => {
106
111
autoFit : true ,
107
112
height : 300 ,
108
113
} }
114
+ ref = { chartRef }
109
115
/>
110
116
) ;
111
117
}
@@ -115,28 +121,38 @@ export const AutoChart = (props: AutoChartProps) => {
115
121
if ( renderChartType ) {
116
122
return (
117
123
< div >
118
- < Row justify = "start" className = "mb-2" >
119
- < Col > { i18n . t ( 'Advices' ) } </ Col >
120
- < Col style = { { marginLeft : 24 } } >
121
- < Select
122
- className = "w-52"
123
- value = { renderChartType }
124
- placeholder = { 'Chart Switcher' }
125
- onChange = { ( value ) => setRenderChartType ( value ) }
126
- size = { 'small' }
127
- >
128
- { advices ?. map ( ( item ) => {
129
- const name = i18n . t ( item . type as I18nKeys ) ;
130
-
131
- return (
132
- < Option key = { item . type } value = { item . type } >
133
- < Tooltip title = { name } placement = { 'right' } >
134
- < div > { name } </ div >
135
- </ Tooltip >
136
- </ Option >
137
- ) ;
138
- } ) }
139
- </ Select >
124
+ < Row justify = 'space-between' className = "mb-2" >
125
+ < Col >
126
+ < Space >
127
+ < span > { i18n . t ( 'Advices' ) } </ span >
128
+ < Select
129
+ className = "w-52"
130
+ value = { renderChartType }
131
+ placeholder = { 'Chart Switcher' }
132
+ onChange = { ( value ) => setRenderChartType ( value ) }
133
+ size = { 'small' }
134
+ >
135
+ { advices ?. map ( ( item ) => {
136
+ const name = i18n . t ( item . type as I18nKeys ) ;
137
+ return (
138
+ < Option key = { item . type } value = { item . type } >
139
+ < Tooltip title = { name } placement = { 'right' } >
140
+ < div > { name } </ div >
141
+ </ Tooltip >
142
+ </ Option >
143
+ ) ;
144
+ } ) }
145
+ </ Select >
146
+ </ Space >
147
+ </ Col >
148
+ < Col >
149
+ < Tooltip title = { i18n . t ( 'Download' ) } >
150
+ < Button
151
+ onClick = { ( ) => downloadImage ( chartRef . current , i18n . t ( renderChartType as I18nKeys ) ) }
152
+ icon = { < DownloadOutlined /> }
153
+ type = 'text'
154
+ />
155
+ </ Tooltip >
140
156
</ Col >
141
157
</ Row >
142
158
< div className = "auto-chart-content" > { visComponent } </ div >
0 commit comments