import { euiLightVars as lightTheme , euiDarkVars as darkTheme , } from '@kbn/ui-shared-deps-src/theme' ; import { JobCreatorType , isMultiMetricJobCreator , isPopulationJobCreator , } from '../../../../common/job_creator' ; import { getTimeBucketsFromCache , TimeBuckets } from '../../../../../../util/time_buckets' ; import { useUiSettings } from '../../../../../../contexts/kibana/use_ui_settings_context' ; export function useChartColors ( ) { const IS_DARK_THEME = useUiSettings ( ) . get ( 'theme:darkMode' ) ; const themeName = IS_DARK_THEME ? darkTheme : lightTheme ; return { LINE_COLOR : themeName . euiColorPrimary , MODEL_COLOR : themeName . euiColorPrimary , EVENT_RATE_COLOR : themeName . euiColorPrimary , EVENT_RATE_COLOR_WITH_ANOMALIES : themeName . euiColorLightShade , } ; } export interface ChartSettings { width : string ; height : string ; cols : 1 | 2 | 3 ; intervalMs : number ; } export const defaultChartSettings = { width : '100%' , height : '300px' , cols : 1 , intervalMs : 0 , } ; export const seriesStyle = { line : { strokeWidth : 2 , visible : true , opacity : 1 , } , border : { visible : false , strokeWidth : 0 , } , point : { visible : false , radius : 2 , strokeWidth : 4 , opacity : 0.5 , } , area : { opacity : 0.25 , visible : false , } , } ; export function getChartSettings ( jobCreator , chartInterval ) { const cs = { ... defaultChartSettings , intervalMs : chartInterval . getInterval ( ) . asMilliseconds ( ) , } ; if ( isPopulationJobCreator ( jobCreator ) ) { const interval = getTimeBucketsFromCache ( ) ; interval . setInterval ( 'auto' ) ; interval . setBounds ( chartInterval . getBounds ( ) ) ; cs . intervalMs = interval . getInterval ( ) . asMilliseconds ( ) ; } if ( cs . intervalMs < jobCreator . bucketSpanMs ) { cs . intervalMs = jobCreator . bucketSpanMs ; } if ( isMultiMetricJobCreator ( jobCreator ) || isPopulationJobCreator ( jobCreator ) ) { if ( jobCreator . aggFieldPairs . length > 2 && isMultiMetricJobCreator ( jobCreator ) ) { cs . cols = 3 ; cs . height = '150px' ; cs . intervalMs = cs . intervalMs * 3 ; } else if ( jobCreator . aggFieldPairs . length > 1 ) { cs . cols = 2 ; cs . height = '200px' ; cs . intervalMs = cs . intervalMs * 2 ; } } return cs ; }