import { merge , rebind } from "../utils" ; import { wma } from "../calculator" ; import { WMAOptions } from "../calculator/wma" ; import baseIndicator from "./baseIndicator" ; const ALGORITHM_TYPE = "WMA" ; interface WMAIndicator { ( data , options ? ) : any ; id ( ) : number ; id ( x ) : WMAIndicator ; accessor ( ) : any ; accessor ( x ) : WMAIndicator ; stroke ( ) : string | any ; stroke ( x ) : WMAIndicator ; fill ( ) : string | any ; fill ( x ) : WMAIndicator ; echo ( ) : any ; echo ( x ) : WMAIndicator ; type ( ) : string ; type ( x ) : WMAIndicator ; merge ( ) : any ; merge ( newMerge ) : WMAIndicator ; options ( ) : WMAOptions ; options ( newOptions ) : WMAIndicator ; } export default function ( ) { const base = baseIndicator ( ) . type ( ALGORITHM_TYPE ) . accessor ( ( d ) => d . wma ) ; const underlyingAlgorithm = wma ( ) ; const mergedAlgorithm = merge ( ) . algorithm ( underlyingAlgorithm ) . merge ( ( datum , i ) => { datum . wma = i ; } ) ; const indicator = ( data , options = { merge : true } ) => { if ( options . merge ) { if ( ! base . accessor ( ) ) { throw new Error ( `Set an accessor to ${ ALGORITHM_TYPE } before calculating` ) ; } return mergedAlgorithm ( data ) ; } return underlyingAlgorithm ( data ) ; } ; rebind ( indicator , base , "id" , "accessor" , "stroke" , "fill" , "echo" , "type" ) ; rebind ( indicator , underlyingAlgorithm , "options" , "undefinedLength" ) ; rebind ( indicator , mergedAlgorithm , "merge" , "skipUndefined" ) ; return indicator as WMAIndicator ; }