import React , { lazy } from 'react' ; import { get } from 'lodash' ; import { render , unmountComponentAtNode } from 'react-dom' ; import { I18nProvider } from '@kbn/i18n-react' ; import { IUiSettingsClient , ThemeServiceStart } from 'kibana/public' ; import { VisualizationContainer , PersistedState } from '../../../visualizations/public' ; import type { TimeseriesVisData } from '../common/types' ; import { isVisTableData } from '../common/vis_data_utils' ; import type { TimeseriesVisParams } from './types' ; import type { ExpressionRenderDefinition } from '../../../expressions/common' ; import type { TimeseriesRenderValue } from './metrics_fn' ; import { KibanaThemeProvider } from '../../../../../src/plugins/kibana_react/public' ; const TimeseriesVisualization = lazy ( ( ) => import ( './application/components/timeseries_visualization' ) ) ; const checkIfDataExists = ( visData , model ) => { if ( 'type' in visData ) { const data = isVisTableData ( visData ) ? visData . series : visData ?. [ model . id ] ?. series ; return Boolean ( data ?. length ) ; } return false ; } ; export const getTimeseriesVisRenderer = ( { uiSettings , theme } ) => ( { name : 'timeseries_vis' , reuseDomNode : true , render : async ( domNode , config , handlers ) => { import ( './application/index.scss' ) ; handlers . onDestroy ( ( ) => { unmountComponentAtNode ( domNode ) ; } ) ; const { visParams : model , visData , syncColors } = config ; const showNoResult = ! checkIfDataExists ( visData , model ) ; render ( < I18nProvider > < KibanaThemeProvider theme$ = { theme . theme$ } > < VisualizationContainer data - test - subj = "timeseriesVis" handlers = { handlers } showNoResult = { showNoResult } error = { get ( visData , [ model . id , 'error' ] ) } > < TimeseriesVisualization getConfig = { uiSettings . get . bind ( uiSettings ) } handlers = { handlers } model = { model } visData = { visData as TimeseriesVisData } syncColors = { syncColors } uiState = { handlers . uiState ! as PersistedState } / > < /VisualizationContainer> < /KibanaThemeProvider> < /I18nProvider>, domNode, () => { handlers . done ( ) ; } ) ; } , } ) ;