All files / app/codeCharta/ui/colorPickerForMapColor mapColorLabel.pipe.ts

90.62% Statements 29/32
81.25% Branches 13/16
100% Functions 2/2
90% Lines 27/30

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 637x                 7x   112x   12x 12x 12x 12x     12x 3x   9x     9x     12x 12x 12x 4x   8x     8x     11x 11x 3x   8x     15x   15x   23x   12x   12x         41x      
import { Pipe, PipeTransform } from "@angular/core"
 
import { ColorRange, MapColors } from "../../codeCharta.model"
import { MetricMinMax } from "../../state/selectors/accumulatedData/metricData/selectedColorMetricData.selector"
 
@Pipe({
    name: "mapColorLabel",
    standalone: true
})
export class MapColorLabelPipe implements PipeTransform {
    transform(metricName: keyof MapColors, colorRange: ColorRange, nodeMetricRange: MetricMinMax, colorMetric: string): string {
        switch (metricName) {
            case "positive": {
                const isColorMetricUnary = colorMetric === "unary"
                const isFromValueEqualMinValue = nodeMetricRange.minValue === colorRange.from
                const isFromValueEqualMaxValue = nodeMetricRange.maxValue === colorRange.from
                Iif (isColorMetricUnary) {
                    return `${nodeMetricRange.minValue} - ${nodeMetricRange.maxValue}`
                }
                if (isFromValueEqualMinValue) {
                    return `-`
                }
                Iif (isFromValueEqualMaxValue) {
                    return `${nodeMetricRange.minValue} to ${this.formatNumber(colorRange.from)}`
                }
                return `${nodeMetricRange.minValue} to ${this.formatNumber(colorRange.from - 1)}`
            }
            case "neutral": {
                const isFromValueEqualToValue = colorRange.from === colorRange.to
                const isToValueEqualMaxValue = colorRange.to === nodeMetricRange.maxValue
                if (isFromValueEqualToValue) {
                    return `-`
                }
                Iif (isToValueEqualMaxValue) {
                    return `${this.formatNumber(colorRange.from)} to ${this.formatNumber(colorRange.to)}`
                }
                return `${this.formatNumber(colorRange.from)} to ${this.formatNumber(colorRange.to - 1)}`
            }
            case "negative": {
                const isToValueEqualToMaxValue = nodeMetricRange.maxValue === colorRange.to
                if (isToValueEqualToMaxValue) {
                    return `-`
                }
                return `${this.formatNumber(colorRange.to)} to ${this.formatNumber(nodeMetricRange.maxValue)}`
            }
            case "positiveDelta":
                return "+Δ positive delta"
            case "negativeDelta":
                return "–Δ negative delta"
            case "selected":
                return "selected"
            case "outgoingEdge":
                return "Outgoing Edge"
            case "incomingEdge":
                return "Incoming Edge"
        }
    }
 
    private formatNumber(n?: number) {
        return (n || 0).toLocaleString()
    }
}