All files / app/codeCharta/ui/codeMap/arrow/utils edgePreviewNodes.selector.ts

100% Statements 19/19
100% Branches 3/3
100% Functions 2/2
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3716x   16x 16x 16x   16x         30x     16x 32x   32x 1x     31x   8x 7x       1x 1x 1x 1x     1x    
import { createSelector } from "@ngrx/store"
import { NodeEdgeMetricsMap } from "../../../../state/selectors/accumulatedData/metricData/edgeMetricData.calculator"
import { amountOfEdgePreviewsSelector } from "../../../../state/store/appSettings/amountOfEdgePreviews/amountOfEdgePreviews.selector"
import { edgeMetricSelector } from "../../../../state/store/dynamicSettings/edgeMetric/edgeMetric.selector"
import { metricDataSelector } from "../../../../state/selectors/accumulatedData/metricData/metricData.selector"
 
export const edgePreviewNodesSelector = createSelector(
    metricDataSelector,
    edgeMetricSelector,
    amountOfEdgePreviewsSelector,
    (metricData, edgeMetric, amountOfEdgePreviews) =>
        new Set(_getNodesWithHighestValue(metricData.nodeEdgeMetricsMap, edgeMetric, amountOfEdgePreviews))
)
 
export const _getNodesWithHighestValue = (edgeMetricMap: NodeEdgeMetricsMap, edgeMetric: string, amountOfEdgePreviews: number) => {
    const keys: string[] = []
 
    if (amountOfEdgePreviews === 0) {
        return keys
    }
 
    const nodeEdgeMetrics = edgeMetricMap.get(edgeMetric)
 
    if (nodeEdgeMetrics === undefined) {
        return keys
    }
 
    // note that this depends on the fact, that edgeMetricMap is created by a list which is sorted by max value
    for (const key of nodeEdgeMetrics.keys()) {
        keys.push(key)
        if (keys.length === amountOfEdgePreviews) {
            break
        }
    }
    return keys
}