import { Mark , Channels , ChannelHandler , MarkEncoding , MarkEncodings , MarkEncodingKey , Facet , Gradient , MarkType , StrokeCap , StrokeJoin , Orientation , Interpolation , HorizontalAlignment , VerticalAlignment , VerticalTextAlignment , SymbolType , FontWeight , TextDirection , ItemIdGenerator , Metadata , } from '@chart-parts/interfaces' ; import { Subject , Subscription } from 'rxjs' ; import { MarkSpec } from '../spec/MarkSpec' ; import { SceneNodeBuilder } from './SceneNodeBuilder' ; category export class MarkBuilder { public readonly onChange = new Subject ( ) ; public readonly spec : MarkSpec ; private _child ? : SceneNodeBuilder ; private _childSubscription ? : Subscription ; public constructor ( public readonly type ) { this . spec = new MarkSpec ( type ) ; } public table ( table ) { this . spec . table = table ; this . onChange . next ( 'mark table changed' ) ; return this ; } public role ( role ) { this . spec . role = role ; this . onChange . next ( 'mark role changed' ) ; return this ; } public name ( name ) { this . spec . name = name ; this . onChange . next ( 'mark name changed' ) ; return this ; } public idGenerator ( generator ) { this . spec . idGenerator = generator ; this . onChange . next ( 'mark idGenerator changed' ) ; return this ; } public handle ( name , handler ) ; public handle ( channels ) ; public handle ( name , handler ? ) { if ( typeof name === 'string' ) { this . spec . applyHandler ( name , handler ) ; } else { Object . entries ( name as Channels ) . forEach ( ( [ nameVal , handlerVal ] ) => this . spec . applyHandler ( nameVal , handlerVal ) ) ; } this . onChange . next ( 'mark handlers changed' ) ; return this ; } public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( key , encoding ) ; public encode ( encodings ) ; public encode ( first , encoding ? ) { if ( typeof first === 'string' ) { this . spec . applyEncoding ( first as string , encoding ) ; } else { Object . entries ( first as MarkEncodings ) . forEach ( ( [ name , entryEncoding ] ) => { this . spec . applyEncoding ( name , entryEncoding ) ; } ) ; } this . onChange . next ( 'mark encoders changed' ) ; return this ; } public facet ( facet ) { if ( facet !== undefined && this . type !== MarkType . Group ) { throw new Error ( 'faceting can only be applied to "group" type marks' ) ; } this . spec . facet = facet ; this . onChange . next ( 'mark facet changed' ) ; return this ; } /**
     * Pushes a new scene node onto the graph
     */ public child ( callback ) { if ( this . spec . child ) { console . warn ( `MarkBuilder may only have one child at a time` ) ; } if ( this . _childSubscription ) { this . _childSubscription . unsubscribe ( ) ; } this . _child = new SceneNodeBuilder ( ) ; this . spec . child = this . _child . spec ; callback ( this . _child ) ; this . _childSubscription = this . _child . onChange . subscribe ( cause => this . onChange . next ( cause ) ) ; this . onChange . next ( 'mark child changed' ) ; return this ; } public build ( ) { if ( ! this . spec . type ) { throw new Error ( 'mark type must be set' ) ; } return this . spec ; } }