import { ChartType , Legend , LegendIconType , Options , RawSeries , Series } from '@t/store/store' ; import { BubbleChartOptions , HeatmapChartOptions , TreemapChartOptions , TreemapChartSeriesOptions , GaugeChartOptions , } from '@t/options' ; import { includes , isUndefined } from '@src/helpers/utils' ; export type OptionsWithNormalLegendType = Exclude < Options , TreemapChartOptions | HeatmapChartOptions | GaugeChartOptions > ; export function getActiveSeriesMap ( legend ) { return legend . data . reduce ( ( acc , { active , label } ) => ( { ... acc , [ label ] : active } ) , { } ) ; } export function showCircleLegend ( options ) { return options ?. circleLegend ?. visible ?? true ; } export function showLegend ( options , series ) { if ( series . gauge || ( series . treemap && ! ( options . series as TreemapChartSeriesOptions ) ?. useColorValue ) ) { return false ; } return isUndefined ( options . legend ?. visible ) ? true : ! ! options . legend ?. visible ; } export function showCheckbox ( options ) { return isUndefined ( options . legend ?. showCheckbox ) ? true : ! ! options . legend ?. showCheckbox ; } function useRectIcon ( type ) { return includes ( [ 'bar' , 'column' , 'area' , 'pie' , 'boxPlot' , 'bullet' , 'radialBar' ] , type ) ; } function useCircleIcon ( type ) { return includes ( [ 'bubble' , 'scatter' ] , type ) ; } function useLineIcon ( type ) { return includes ( [ 'line' , 'radar' ] , type ) ; } export function getIconType ( type ) { let iconType = 'spectrum' ; if ( useCircleIcon ( type ) ) { iconType = 'circle' ; } else if ( useRectIcon ( type ) ) { iconType = 'rect' ; } else if ( useLineIcon ( type ) ) { iconType = 'line' ; } return iconType ; } export function getLegendAlign ( options ) { return options . legend ?. align ?? 'right' ; }