import { ChartType } from '../../chart_types' ; import { X_SCALE_DEFAULT } from '../../chart_types/heatmap/specs/scale_defaults' ; import { percentFormatter } from '../../chart_types/partition_chart/layout/config' ; import { PartitionLayout } from '../../chart_types/partition_chart/layout/types/config_types' ; import { ShapeTreeNode } from '../../chart_types/partition_chart/layout/types/viewmodel_types' ; import { AGGREGATE_KEY , PrimitiveValue } from '../../chart_types/partition_chart/layout/utils/group_by_rollup' ; import { PartitionSpec } from '../../chart_types/partition_chart/specs' ; import { SeriesSpecs , DEFAULT_GLOBAL_ID , BarSeriesSpec , AreaSeriesSpec , HistogramModeAlignments , HistogramBarSeriesSpec , LineSeriesSpec , BasicSeriesSpec , SeriesType , BubbleSeriesSpec , LineAnnotationSpec , RectAnnotationSpec , AnnotationType , AnnotationDomainType , AxisSpec , } from '../../chart_types/xy_chart/utils/specs' ; import { Predicate } from '../../common/predicate' ; import { ScaleType } from '../../scales/constants' ; import { SettingsSpec , SpecType , DEFAULT_SETTINGS_SPEC , SmallMultiplesSpec , GroupBySpec , Spec , HeatmapSpec , } from '../../specs' ; import { Datum , mergePartial , Position , RecursivePartial } from '../../utils/common' ; import { LIGHT_THEME } from '../../utils/themes/light_theme' ; internal export class MockSeriesSpec { private static readonly barBase : BarSeriesSpec = { chartType : ChartType . XYAxis , specType : SpecType . Series , id : 'spec1' , seriesType : SeriesType . Bar , groupId : DEFAULT_GLOBAL_ID , xScaleType : ScaleType . Ordinal , yScaleType : ScaleType . Linear , xAccessor : 'x' , yAccessors : [ 'y' ] , hideInLegend : false , enableHistogramMode : false , data : [ ] as any [ ] , } ; private static readonly histogramBarBase : HistogramBarSeriesSpec = { chartType : ChartType . XYAxis , specType : SpecType . Series , id : 'spec1' , seriesType : SeriesType . Bar , groupId : DEFAULT_GLOBAL_ID , xScaleType : ScaleType . Ordinal , yScaleType : ScaleType . Linear , xAccessor : 'x' , yAccessors : [ 'y' ] , hideInLegend : false , enableHistogramMode : true , data : [ ] , } ; private static readonly areaBase : AreaSeriesSpec = { chartType : ChartType . XYAxis , specType : SpecType . Series , id : 'spec1' , seriesType : SeriesType . Area , groupId : DEFAULT_GLOBAL_ID , xScaleType : ScaleType . Ordinal , yScaleType : ScaleType . Linear , xAccessor : 'x' , yAccessors : [ 'y' ] , hideInLegend : false , histogramModeAlignment : HistogramModeAlignments . Center , data : [ ] , } ; private static readonly lineBase : LineSeriesSpec = { chartType : ChartType . XYAxis , specType : SpecType . Series , id : 'spec1' , seriesType : SeriesType . Line , groupId : DEFAULT_GLOBAL_ID , xScaleType : ScaleType . Ordinal , yScaleType : ScaleType . Linear , xAccessor : 'x' , yAccessors : [ 'y' ] , hideInLegend : false , histogramModeAlignment : HistogramModeAlignments . Center , data : [ ] , } ; private static readonly bubbleBase : BubbleSeriesSpec = { chartType : ChartType . XYAxis , specType : SpecType . Series , id : 'spec1' , seriesType : SeriesType . Bubble , groupId : DEFAULT_GLOBAL_ID , xScaleType : ScaleType . Ordinal , yScaleType : ScaleType . Linear , xAccessor : 'x' , yAccessors : [ 'y' ] , hideInLegend : false , data : [ ] , } ; private static readonly sunburstBase : PartitionSpec = { chartType : ChartType . Partition , specType : SpecType . Series , id : 'spec1' , layout : PartitionLayout . sunburst , valueAccessor : ( d ) => ( typeof d === 'number' ? d : 0 ) , valueGetter : ( n ) : number => n [ AGGREGATE_KEY ] , valueFormatter : ( d ) : string => String ( d ) , percentFormatter , topGroove : 0 , smallMultiples : null , clockwiseSectors : true , specialFirstInnermostSector : true , drilldown : false , maxRowCount : 12 , fillOutside : false , radiusOutside : 128 , fillRectangleWidth : Infinity , fillRectangleHeight : Infinity , layers : [ { groupByRollup : ( d , i ) => i , nodeLabel : ( d ) => String ( d ) , showAccessor : ( ) => true , fillLabel : { } , } , ] , animation : { duration : 0 } , data : [ ] , } ; private static readonly treemapBase : PartitionSpec = { chartType : ChartType . Partition , specType : SpecType . Series , id : 'spec1' , layout : PartitionLayout . treemap , valueAccessor : ( d ) => ( typeof d === 'number' ? d : 0 ) , valueGetter : ( n ) : number => n [ AGGREGATE_KEY ] , valueFormatter : ( d ) : string => String ( d ) , percentFormatter , topGroove : 20 , smallMultiples : null , clockwiseSectors : true , specialFirstInnermostSector : true , drilldown : false , maxRowCount : 12 , fillOutside : false , radiusOutside : 128 , fillRectangleWidth : Infinity , fillRectangleHeight : Infinity , layers : [ { groupByRollup : ( d , i ) => i , nodeLabel : ( d ) => String ( d ) , showAccessor : ( ) => true , fillLabel : { } , } , ] , animation : { duration : 0 } , data : [ ] , } ; private static readonly heatmapBase : HeatmapSpec = { id : 'spec1' , chartType : ChartType . Heatmap , specType : SpecType . Series , data : [ ] , colorScale : { type : 'bands' , bands : [ { start : 0 , end : 10 , color : 'red' } , { start : 10 , end : 20 , color : 'yellow' } , { start : 20 , end : 30 , color : 'green' } , ] , } , xAccessor : ( { x } ) => x , yAccessor : ( { y } ) => y , xScale : { type : X_SCALE_DEFAULT . type } , valueAccessor : ( { value } ) => value , valueFormatter : ( value ) => `${ value }` , xSortPredicate : Predicate . AlphaAsc , ySortPredicate : Predicate . AlphaAsc , timeZone : 'UTC' , xAxisTitle : '' , yAxisTitle : '' , xAxisLabelName : 'X Value' , xAxisLabelFormatter : String , yAxisLabelName : 'Y Value' , yAxisLabelFormatter : String , } ; static bar ( partial ? ) { return mergePartial < BarSeriesSpec > ( MockSeriesSpec . barBase , partial as RecursivePartial < BarSeriesSpec > ) ; } static histogramBar ( partial ? ) { return mergePartial < HistogramBarSeriesSpec > ( MockSeriesSpec . histogramBarBase , partial as RecursivePartial < HistogramBarSeriesSpec > ) ; } static area ( partial ? ) { return mergePartial < AreaSeriesSpec > ( MockSeriesSpec . areaBase , partial as RecursivePartial < AreaSeriesSpec > ) ; } static line ( partial ? ) { return mergePartial < LineSeriesSpec > ( MockSeriesSpec . lineBase , partial as RecursivePartial < LineSeriesSpec > ) ; } static bubble ( partial ? ) { return mergePartial < BubbleSeriesSpec > ( MockSeriesSpec . bubbleBase , partial as RecursivePartial < BubbleSeriesSpec > ) ; } static sunburst ( partial ? ) { return mergePartial < PartitionSpec > ( MockSeriesSpec . sunburstBase , partial as RecursivePartial < PartitionSpec > ) ; } static treemap ( partial ? ) { return mergePartial < PartitionSpec > ( MockSeriesSpec . treemapBase , partial as RecursivePartial < PartitionSpec > ) ; } static heatmap ( partial ? ) { return mergePartial < HeatmapSpec > ( MockSeriesSpec . heatmapBase , partial as RecursivePartial < HeatmapSpec > ) ; } static byType ( type ? ) { switch ( type ) { case SeriesType . Line : return MockSeriesSpec . lineBase ; case SeriesType . Area : return MockSeriesSpec . areaBase ; case SeriesType . Bubble : return MockSeriesSpec . bubbleBase ; case 'histogram' : return MockSeriesSpec . histogramBarBase ; case SeriesType . Bar : default : return MockSeriesSpec . barBase ; } } static byTypePartial ( type ? ) { switch ( type ) { case 'line' : return MockSeriesSpec . line ; case 'area' : return MockSeriesSpec . area ; case 'histogram' : return MockSeriesSpec . histogramBar ; case 'bar' : default : return MockSeriesSpec . bar ; } } } internal export class MockSeriesSpecs { static fromSpecs ( specs ) { return specs ; } static fromPartialSpecs ( specs ) { return specs . map ( ( { seriesType , ... spec } ) => { const base = MockSeriesSpec . byType ( seriesType ) ; return mergePartial < BasicSeriesSpec > ( base , spec as RecursivePartial < BasicSeriesSpec > ) ; } ) ; } static empty ( ) { return [ ] ; } } internal export class MockGlobalSpec { private static readonly settingsBase : SettingsSpec = DEFAULT_SETTINGS_SPEC ; private static readonly axisBase : AxisSpec = { id : 'yAxis' , chartType : ChartType . XYAxis , specType : SpecType . Axis , groupId : DEFAULT_GLOBAL_ID , hide : false , showOverlappingTicks : false , showOverlappingLabels : false , position : Position . Left , timeAxisLayerCount : 0 , } ; private static readonly settingsBaseNoMargings : SettingsSpec = { ... MockGlobalSpec . settingsBase , theme : { ... LIGHT_THEME , chartMargins : { top : 0 , left : 0 , right : 0 , bottom : 0 } , chartPaddings : { top : 0 , left : 0 , right : 0 , bottom : 0 } , scales : { barsPadding : 0 , histogramPadding : 0 } , } , } ; private static readonly smallMultipleBase : SmallMultiplesSpec = { id : 'smallMultiple' , chartType : ChartType . Global , specType : SpecType . SmallMultiples , style : { verticalPanelPadding : { outer : 0 , inner : 0 } , horizontalPanelPadding : { outer : 0 , inner : 0 } , } , } ; private static readonly groupByBase : GroupBySpec = { id : 'groupBy' , chartType : ChartType . Global , specType : SpecType . IndexOrder , by : ( { id } ) => id , sort : Predicate . DataIndex , } ; static settings ( partial ? ) { return mergePartial < SettingsSpec > ( MockGlobalSpec . settingsBase , partial ) ; } static settingsNoMargins ( partial ? ) { return mergePartial < SettingsSpec > ( MockGlobalSpec . settingsBaseNoMargings , partial ) ; } static axis ( partial ? ) { return mergePartial < AxisSpec > ( MockGlobalSpec . axisBase , partial ) ; } static smallMultiple ( partial ? ) { return mergePartial < SmallMultiplesSpec > ( MockGlobalSpec . smallMultipleBase , partial ) ; } static groupBy ( partial ? ) { return mergePartial < GroupBySpec > ( MockGlobalSpec . groupByBase , partial ) ; } } internal export class MockAnnotationSpec { private static readonly lineBase : LineAnnotationSpec = { id : 'line_annotation_1' , groupId : DEFAULT_GLOBAL_ID , chartType : ChartType . XYAxis , specType : SpecType . Annotation , annotationType : AnnotationType . Line , dataValues : [ ] , domainType : AnnotationDomainType . XDomain , } ; private static readonly rectBase : RectAnnotationSpec = { id : 'rect_annotation_1' , groupId : DEFAULT_GLOBAL_ID , chartType : ChartType . XYAxis , specType : SpecType . Annotation , annotationType : AnnotationType . Rectangle , dataValues : [ ] , } ; static line ( partial ? ) { return mergePartial < LineAnnotationSpec > ( MockAnnotationSpec . lineBase , partial ) ; } static rect ( partial ? ) { return mergePartial < RectAnnotationSpec > ( MockAnnotationSpec . rectBase , partial ) ; } }