import { SCATTER } from '@/services/data/tuples/chart-def/chart-scatter' ; import { ChartDataSet } from '@/services/data/tuples/chart-types' ; import { ECharts } from '@/services/data/tuples/echarts/echarts-types' ; import { Report } from '@/services/data/tuples/report-types' ; import { EChartOption } from 'echarts' ; import { BASE_COLORS_24 } from '../../basic/colors' ; import { DefaultChartUtils , Legend } from './default-chart-utils' ; import { buildEChartsGrid } from './grid-utils' ; import { buildEChartsLegend } from './legend-utils' ; import { buildEChartsTitle } from './title-utils' ; import { buildToolbox } from './toolbox-utils' ; import { ChartOptions } from './types' ; import { buildEChartsXAxis } from './xaxis-utils' ; import { buildEChartsYAxis } from './yaxis-utils' ; export class ChartScatterUtils extends DefaultChartUtils { constructor ( ) { super ( SCATTER ) ; } buildLegends ( report , dataset ) { const { dimensions } = report ; const dimensionColumnIndexOffset = this . getDimensionColumnIndexOffset ( report ) ; if ( dimensions . length === 1 ) { return [ { name : dimensions [ 0 ] . name , rows : dataset . data } ] ; } else { const legendMap = new Map < string , number > ( ) ; return dataset . data . reduce < Array < Legend > > ( ( legends , row ) => { const dimensionValue = `${ row [ dimensionColumnIndexOffset ] }` ; const legendIndex = legendMap . get ( dimensionValue ) ; if ( legendIndex == null ) { legends . push ( { name : dimensionValue , rows : [ row ] } ) ; legendMap . set ( dimensionValue , legends . length - 1 ) ; } else { legends [ legendIndex ] . rows . push ( row ) ; } return legends ; } , [ ] ) ; } } async buildOptions ( report , dataset ) { const { chart } = report ; const { dimensions , indicators } = report ; const dimensionColumnIndexOffset = this . getDimensionColumnIndexOffset ( report ) ; const legends = this . buildLegends ( report , dataset ) ; return { color : BASE_COLORS_24 , title : buildEChartsTitle ( chart as ECharts ) , tooltip : { trigger : 'item' } , legend : legends . length > 1 ? buildEChartsLegend ( chart as ECharts , legends . map ( ( { name } ) => name ) ) : ( void 0 ) , grid : buildEChartsGrid ( chart as ECharts ) , xAxis : [ buildEChartsXAxis ( chart as ECharts , [ dimensions [ dimensions . length - 1 ] . name ] ) ] , yAxis : [ buildEChartsYAxis ( chart as ECharts ) ] , series : legends . map ( ( { name , rows } ) => { return { name , type : 'scatter' , data : rows . map ( row => { return [ row [ dimensions . length - 1 + dimensionColumnIndexOffset ] , ... indicators . map ( ( indicator , index ) => row [ index ] ) ] ; } ) } ; } ) , visualMap : indicators . length === 1 ? ( void 0 ) : indicators . map ( ( indicator , index ) => { switch ( index ) { case 0 : return null ; case 1 : return { show : false , dimension : 2 , ... this . findColumnExtremum ( dataset , 1 ) , inRange : { symbolSize : [ 10 , 50 ] } } ; case 2 : return { show : false , dimension : 2 , ... this . findColumnExtremum ( dataset , 2 ) , inRange : { colorAlpha : [ 0.4 , 1 ] } } ; default : return null ; } } ) . filter ( x => ! x ) as Array < EChartOption . VisualMap > , toolbox : buildToolbox ( chart , report , dataset ) } as EChartOption ; } }