type Selection < T > = d3 . Selection < any , T , any , any > ; import powerbi from "powerbi-visuals-api" ; import ISelectionId = powerbi . visuals . ISelectionId ; import { interactivitySelectionService , interactivityBaseService } from "powerbi-visuals-utils-interactivityutils" ; import SelectableDataPoint = interactivitySelectionService . SelectableDataPoint ; import IInteractivityService = interactivityBaseService . IInteractivityService ; import { SankeyDiagramNode , SankeyDiagramLink } from "./dataInterfaces" ; const SelectedClassName = "selected" ; export function getFillOpacity ( selected , highlight , hasSelection , hasPartialHighlights ) { if ( ( hasPartialHighlights && ! highlight ) || ( hasSelection && ! selected ) ) { return true ; } return false ; } export function isTheDataPointNode ( dataPoint ) { let node = < SankeyDiagramNode > dataPoint ; return node . selectableDataPoints && node . selectableDataPoints . length ? true : false ; } export function isDataPointSelected ( dataPoint ) { let node = < SankeyDiagramNode > dataPoint , link = < SankeyDiagramLink > dataPoint , selected = false ; if ( isTheDataPointNode ( dataPoint ) ) { node . selectableDataPoints . forEach ( ( selectableDataPoint ) => { selected = selected || selectableDataPoint . selected ; } ) ; } else if ( link . identity ) { selected = link . selected ; } return selected ; } export function updateFillOpacity ( selection , interactivityService ? , hasSelection = false ) { let hasHighlights = false ; if ( interactivityService ) { hasHighlights = interactivityService . hasSelection ( ) ; } selection . classed ( SelectedClassName , ( dataPoint ) : boolean => { let dataPointSelected = isDataPointSelected ( dataPoint ) , theDataPointNode = isTheDataPointNode ( dataPoint ) , selected ; selected = ! theDataPointNode && hasSelection ? ! dataPointSelected : dataPointSelected ; return getFillOpacity ( selected , false , hasSelection , ! selected && hasHighlights ) ; } ) ; } export function areDataPointsSelected ( selectedDataPoints , dataPoints ) { if ( ! dataPoints || ! selectedDataPoints || dataPoints . length !== selectedDataPoints . length ) { return false ; } return doDataPointsIncludeIdentities ( selectedDataPoints , dataPoints ) ; } export function doDataPointsIncludeIdentities ( selectedDataPoints , dataPoints ) { return selectedDataPoints . every ( ( selectedDataPoint ) => { return doDataPointsIncludeIdentity ( dataPoints , selectedDataPoint ) ; } ) ; } export function doDataPointsIncludeIdentity ( dataPoints , selectedDataPoint ) { return dataPoints . some ( ( dataPoint ) => { return selectedDataPoint && dataPoint && selectedDataPoint . identity && dataPoint . identity && ( < ISelectionId > selectedDataPoint . identity ) . equals ( < ISelectionId > dataPoint . identity ) ; } ) ; }