import { Axis , MarkType , AxisOrientation , ViewSize , } from '@chart-parts/interfaces' ; import { buildMark } from '@chart-parts/scenegraph' ; import { SceneFrame } from '../context/SceneFrame' ; import { SGMarkAny } from '../processNode' ; import { components } from './components' ; import { getContext } from './getContext' ; import { AxisSpace , AxisContext } from './interfaces' ; ignore export function buildAxis ( axis , frame , axisSpace ) { const context = createPopulatedContext ( axis , frame , axisSpace ) ; const groupSize = getGroupSize ( context , frame . view ) ; const origin = getGroupOrigin ( context , frame . view ) ; const items = [ ] ; components . forEach ( e => { if ( e . isScenegraphElementGenerated ( context ) ) { items . push ( e . createScenegraphElement ( context ) ) ; } } ) ; return buildMark ( MarkType . Group ) . role ( 'axis' ) . items ( { items , x : origin . x , y : origin . y , ... groupSize , } ) . build ( ) ; } function createPopulatedContext ( axis , frame , axisSpace ) { const initialContext = getContext ( axis , frame , axisSpace ) ; let result = initialContext ; components . forEach ( component => ( result = component . createContext ( result ) ) ) ; return result as AxisContext ; } function getGroupOrigin ( context , availableSpace ) { const { height = 0 , width = 0 } = availableSpace ; switch ( context . axis . orient ) { case AxisOrientation . Top : return { x : 0 , y : 0 } ; case AxisOrientation . Bottom : return { x : 0 , y : height - context . thickness , } ; case AxisOrientation . Left : return { x : 0 , y : 0 } ; case AxisOrientation . Right : return { x : width - context . thickness , y : 0 } ; } } function getGroupSize ( context , availableSpace ) { const { height = 0 , width = 0 } = availableSpace ; if ( context . horizontal ) { return { width , height : context . thickness , } ; } else { return { width : context . thickness , height , } ; } }