All files / app/codeCharta/ui/metricChooser/metricChooserValue metricChooserValue.component.ts

100% Statements 18/18
100% Branches 4/4
100% Functions 2/2
100% Lines 17/17

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 449x 9x     9x 9x 9x 9x 9x                 9x             23x 23x   23x 23x       9x 3x     6x 3x     3x      
import { Component, Input } from "@angular/core"
import { Store } from "@ngrx/store"
import { Observable } from "rxjs"
import { CcState, CodeMapNode, Node, PrimaryMetrics } from "../../../codeCharta.model"
import { primaryMetricNamesSelector } from "../../../state/selectors/primaryMetrics/primaryMetricNames.selector"
import { NodeSelectionService } from "../nodeSelection.service"
import { RoundedBoxComponent } from "../../ribbonBar/roundedBox/roundedBox.component"
import { MetricChooserTypeComponent } from "../metricChooserType/metricChooserType.component"
import { AsyncPipe } from "@angular/common"
 
@Component({
    selector: "cc-metric-chooser-value",
    templateUrl: "./metricChooserValue.component.html",
    styleUrl: "./metricChooserValue.component.scss",
    standalone: true,
    imports: [RoundedBoxComponent, MetricChooserTypeComponent, AsyncPipe]
})
export class MetricChooserValueComponent {
    @Input() metricFor: keyof PrimaryMetrics
 
    node$: Observable<CodeMapNode | Node>
    primaryMetricNames$: Observable<PrimaryMetrics>
 
    constructor(
        private nodeSelectionService: NodeSelectionService,
        private store: Store<CcState>
    ) {
        this.node$ = this.nodeSelectionService.createNodeObservable()
        this.primaryMetricNames$ = this.store.select(primaryMetricNamesSelector)
    }
 
    calculateBackgroundColor(delta: number): string {
        if (this.metricFor === "heightMetric" && delta > 0) {
            return "#b1d8a8"
        }
 
        if (delta < 0) {
            return "#ffcccc"
        }
 
        return "#e6e6e6"
    }
}