import { ScaleCreationContext , Dimension , Scales , Scale , } from '@chart-parts/interfaces' ; import { scaleBand } from 'd3-scale' ; import { DomainRangeScale } from '../DomainRangeScale' ; import { getBoundRange } from '../getBoundRange' ; export interface BandScaleProps { /**
     * The name of the band-width static scale
     */ bandWidth ? : string ; /**
     * The outer and inner padding value
     */ padding ? : number ; /**
     * The outer and inner padding value
     */ paddingInner ? : number ; /**
     * The outer and inner padding value
     */ paddingOuter ? : number ; /**
     * Bin alignment 0-beginning, 1=end
     */ align ? : number ; } export class BandScale extends DomainRangeScale < string [ ] , [ number , number ] , Dimension > { private paddingValue ? : number ; private paddingInnerValue ? : number ; private paddingOuterValue ? : number ; private alignValue ? : number ; private bandwidthValue ? : string ; private roundValue ? : boolean ; /**
     * The name of the band-width static scale
     */ public bandwidthName ( value ? ) { this . bandwidthValue = value ; return this ; } /**
     * The outer and inner padding value
     */ public padding ( value ? ) { this . paddingValue = value ; return this ; } /**
     * The inner padding value
     */ public paddingInner ( value ? ) { this . paddingInnerValue = value ; return this ; } /**
     * The outer padding value
     */ public paddingOuter ( value ? ) { this . paddingOuterValue = value ; return this ; } /**
     * Bin alignment 0-beginning, 1=end
     */ public align ( value ? ) { this . alignValue = value ; return this ; } public round ( value ? ) { this . roundValue = value ; return this ; } protected createScale ( args ) { const domain = this . getDomain ( args ) ; const range = this . getRange ( args ) ; const bandscale = scaleBand ( ) . domain ( domain . map ( d => '' + d ) ) . range ( range ) ; if ( this . alignValue ) { bandscale . align ( this . alignValue ) ; } if ( this . paddingValue ) { bandscale . padding ( this . paddingValue ) ; } if ( this . paddingOuterValue ) { bandscale . paddingOuter ( this . paddingOuterValue ) ; } if ( this . paddingInnerValue ) { bandscale . paddingInner ( this . paddingInnerValue ) ; } if ( this . roundValue ) { bandscale . round ( this . roundValue ) ; } if ( ! this . nameValue ) { throw new Error ( 'scale name must be defined' ) ; } const result = { [ this . nameValue ] : bandscale } ; if ( this . bandwidthValue ) { result [ this . bandwidthValue as string ] = bandscale . bandwidth as Scale < any , number > ; } return result ; } protected handleRangeBind ( args , rangeBind ) { return getBoundRange ( args , rangeBind ) ; } }