import { change } from "../calculator" ; import { merge , rebind } from "../utils" ; import { ChangeOptions } from "../calculator/change" ; import baseIndicator from "./baseIndicator" ; const ALGORITHM_TYPE = "Change" ; interface ChangeIndicator { ( data , options ? ) : any ; id ( ) : number ; id ( x ) : ChangeIndicator ; accessor ( ) : any ; accessor ( x ) : ChangeIndicator ; stroke ( ) : string | any ; stroke ( x ) : ChangeIndicator ; fill ( ) : string | any ; fill ( x ) : ChangeIndicator ; echo ( ) : any ; echo ( x ) : ChangeIndicator ; type ( ) : string ; type ( x ) : ChangeIndicator ; merge ( ) : any ; merge ( newMerge ) : ChangeIndicator ; options ( ) : ChangeOptions ; options ( newOptions ) : ChangeIndicator ; } export default function ( ) { const base = baseIndicator ( ) . type ( ALGORITHM_TYPE ) ; const underlyingAlgorithm = change ( ) ; const mergedAlgorithm = merge ( ) . algorithm ( underlyingAlgorithm ) . merge ( ( datum , i ) => { datum . absoluteChange = i . absoluteChange ; datum . percentChange = i . percentChange ; } ) ; const indicator = ( data , options = { merge : true } ) => { if ( options . merge ) { return mergedAlgorithm ( data ) ; } return underlyingAlgorithm ( data ) ; } ; rebind ( indicator , base , "id" , "accessor" , "stroke" , "fill" , "echo" , "type" ) ; rebind ( indicator , underlyingAlgorithm , "options" ) ; rebind ( indicator , mergedAlgorithm , "merge" , "skipUndefined" ) ; return indicator as ChangeIndicator ; }