import { getGreensColorScale } from '../../../../common/color_library_wrappers' ; import { Pixels , PointObject } from '../../../../common/geometry' ; import { SpecType } from '../../../../specs/constants' ; import { ValueFormatter } from '../../../../utils/common' ; import { LIGHT_THEME } from '../../../../utils/themes/light_theme' ; import { Theme } from '../../../../utils/themes/theme' ; import { BandFillColorAccessorInput , GoalLabelAccessor } from '../../specs' ; import { GoalSubtype } from '../../specs/constants' ; internal export interface BandViewModel { value : number ; fillColor : string ; text : string [ ] ; } interface TickViewModel { value : number ; text : string ; } internal export interface BulletViewModel { subtype : string ; base : number ; target ? : number ; actual : number ; bands : Array < BandViewModel > ; ticks : Array < TickViewModel > ; labelMajor : string ; labelMinor : string ; centralMajor : string | GoalLabelAccessor ; centralMinor : string ; highestValue : number ; lowestValue : number ; aboveBaseCount : number ; belowBaseCount : number ; angleStart : number ; angleEnd : number ; tooltipValueFormatter : ValueFormatter ; } internal export type PickFunction = ( x : Pixels , y : Pixels ) => Array < BulletViewModel > ; internal export type ShapeViewModel = { theme : Theme [ 'goal' ] ; bulletViewModel : BulletViewModel ; chartCenter : PointObject ; pickQuads : PickFunction ; } ; const commonDefaults = { base : 0 , actual : 50 , ticks : [ 0 , 25 , 50 , 75 , 100 ] , } ; internal export const defaultGoalSpec = { ... commonDefaults , bands : [ 50 , 75 , 100 ] , bandFillColor : ( { value , highestValue , lowestValue } ) => { return getGreensColorScale ( 0.5 , [ highestValue , lowestValue ] ) ( value ) ; } , tickValueFormatter : ( { value } ) => String ( value ) , labelMajor : ( { base } ) => String ( base ) , labelMinor : ( ) => 'unit' , centralMajor : ( { base } ) => String ( base ) , centralMinor : ( { target } ) => ( target ? String ( target ) : '' ) , bandLabels : [ ] , angleStart : Math . PI + Math . PI / 4 , angleEnd : - Math . PI / 4 , tooltipValueFormatter : ( value ) => String ( value ) , } ; internal export const nullGoalViewModel = { ... commonDefaults , specType : SpecType . Series , subtype : GoalSubtype . Goal , bands : [ ] , ticks : [ ] , labelMajor : '' , labelMinor : '' , centralMajor : '' , centralMinor : '' , highestValue : 100 , lowestValue : 0 , aboveBaseCount : 0 , belowBaseCount : 0 , angleStart : 0 , angleEnd : 0 , tooltipValueFormatter : ( ) => '' , } ; internal export const nullShapeViewModel = ( { goal } = LIGHT_THEME ) : ShapeViewModel => ( { theme : goal , bulletViewModel : nullGoalViewModel , chartCenter : { x : 0 , y : 0 } , pickQuads : ( ) => [ ] , } ) ;