import { DataViewHierarchyNode , DataViewRow , MarkingOperation } from "spotfire-api" ; export interface Serie { index : number ; sum : number ; mark ( mode ? ) : void ; points : Point [ ] ; } export interface Point { tooltip ( ) : string ; mark ( mode ? ) : void ; xIndex : number ; index : number ; color : string ; Y : number ; Y_Formatted : string ; marked : boolean ; virtual : boolean ; } export function buildColorSeries ( colorLeaves , xLeaves , hasX , getTooltip , yMinValue ) { const numberOrZero = ( val ) => ( typeof val == "number" ? val : 0 ) ; let colorSeries = colorLeaves . map ( colorLeaf => ( { mark : m => colorLeaf . mark ( m ) , index : colorLeaf . leafIndex ! , sum : colorLeaf . rows ( ) . reduce ( ( sum , row ) => sum + numberOrZero ( row . continuous ( "Y" ) . value ( ) ) , 0 ) , points : colorLeaf . rows ( ) . map ( row => createPoint ( row , colorLeaf ) ) } ) ) ; colorSeries . forEach ( serie => { if ( serie . points . length == 0 ) { return ; } else if ( serie . points . length == 1 ) { serie . points . push ( { ... serie . points [ 0 ] , Y : 0 , xIndex : serie . points [ 0 ] . xIndex + 1 , virtual : true } ) ; return ; } for ( var pointIndex = 1 ; pointIndex < serie . points . length ; pointIndex ++ ) { let leftPoint ; const rightPoint = serie . points [ pointIndex ] ; leftPoint = serie . points [ pointIndex - 1 ] ; const xGap = rightPoint . xIndex - leftPoint . xIndex ; if ( xGap > 1 ) { serie . points . splice ( pointIndex , 0 , createEmptyX ( serie , leftPoint . xIndex + 1 , leftPoint , rightPoint ) ) ; } } let first = serie . points [ 0 ] ; if ( first . xIndex != 0 ) { serie . points . splice ( 0 , 0 , { ... first , Y : 0 , xIndex : first . xIndex - 1 , virtual : true } ) ; } const lastX = serie . points [ serie . points . length - 1 ] ; if ( lastX . xIndex < xLeaves . length - 1 ) { serie . points . push ( { ... lastX , Y : 0 , xIndex : lastX . xIndex + 1 , virtual : true } ) ; } } ) ; return colorSeries ; function createPoint ( row , colorLeaf ) { return { tooltip ( ) { return getTooltip ( this ) ; } , mark : m => row . mark ( m ) , xIndex : hasX ? row . categorical ( "X" ) . leafIndex : 0 , Y : numberOrZero ( row . continuous ( "Y" ) . value ( ) ) , Y_Formatted : row . continuous ( "Y" ) . formattedValue ( ) , marked : row . isMarked ( ) , color : row . color ( ) . hexCode , index : colorLeaf . leafIndex ! , virtual : false } ; } function createEmptyX ( serie , xIndex , leftPoint , rightPoint ) { return { tooltip ( ) { return getTooltip ( this ) ; } , mark : ( ) => { } , xIndex , Y : yMinValue , Y_Formatted : "-" , index : serie . index , marked : false , color : "" , virtual : true } ; } }