@@ -7,9 +7,11 @@ import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react'
77import { ReactWidget , Notification } from '@jupyterlab/apputils' ;
88import { ChartWizardData } from './ChartWizardPlugin' ;
99import { updateChartConfig , ChartConfigVariable } from './utils/parser' ;
10+ import { exportChartImage , type ExportImageFormat } from './utils/chartExport' ;
1011import { convertChartCode , logEvent } from '../../restAPI/RestAPI' ;
1112import { removeMarkdownCodeFormatting } from '../../utils/strings' ;
1213import LoadingDots from '../../components/LoadingDots' ;
14+ import ToggleButton from '../../components/ToggleButton' ;
1315import AddFieldButton from './AddFieldButton' ;
1416import {
1517 BooleanInputRow ,
@@ -45,6 +47,7 @@ const ChartWizardContent: React.FC<ChartWizardContentProps> = ({ chartData }) =>
4547 const widgetRef = useRef < HTMLDivElement > ( null ) ;
4648 const [ overlayHeight , setOverlayHeight ] = useState < number > ( 0 ) ;
4749 const [ isActiveCellMismatch , setIsActiveCellMismatch ] = useState ( false ) ;
50+ const [ exportFormat , setExportFormat ] = useState < ExportImageFormat > ( 'png' ) ;
4851
4952 // Reset currentSourceCode when switching to a different chart
5053 useEffect ( ( ) => {
@@ -214,6 +217,19 @@ const ChartWizardContent: React.FC<ChartWizardContentProps> = ({ chartData }) =>
214217 updateNotebookCell ( updatedCode ) ;
215218 } , [ updateNotebookCell ] ) ;
216219
220+ /**
221+ * Exports the chart image to disk via the chartExport utility; shows a notification on error.
222+ */
223+ const handleExportChart = useCallback ( async ( ) : Promise < void > => {
224+ void logEvent ( 'chart_wizard_export_clicked' ) ;
225+ if ( ! chartData ) return ;
226+
227+ const result = await exportChartImage ( chartData , exportFormat ) ;
228+ if ( ! result . success ) {
229+ Notification . emit ( result . error , 'error' , { autoClose : 5000 } ) ;
230+ }
231+ } , [ chartData , exportFormat ] ) ;
232+
217233 /**
218234 * Renders the appropriate input field component based on variable type.
219235 */
@@ -319,6 +335,25 @@ const ChartWizardContent: React.FC<ChartWizardContentProps> = ({ chartData }) =>
319335 clearPendingUpdate = { clearPendingUpdate }
320336 onLoadingStateChange = { setIsAddingField }
321337 />
338+ < div className = "chart-wizard-export-section" >
339+ < h3 className = "chart-wizard-section-heading" > Export</ h3 >
340+ < div className = "chart-wizard-export-format-row" >
341+ < ToggleButton
342+ leftText = "PNG"
343+ rightText = "JPG"
344+ isLeftSelected = { exportFormat === 'png' }
345+ onChange = { ( isPng ) => setExportFormat ( isPng ? 'png' : 'jpeg' ) }
346+ />
347+ </ div >
348+ < button
349+ className = "button-base button-purple add-field-button"
350+ type = "button"
351+ title = "Save chart image to file"
352+ onClick = { handleExportChart }
353+ >
354+ Export image
355+ </ button >
356+ </ div >
322357 </ div >
323358 ) : (
324359 < div className = "chart-wizard-no-config" >
0 commit comments