Skip to content

Commit

Permalink
fix: handling of attribute type
Browse files Browse the repository at this point in the history
- set initial primary edges metric correctly
- dispatch secondary metric type correctly

ref #2731
ref #2630
  • Loading branch information
Torsten Knauf authored and Torsten Knauf committed Mar 21, 2022
1 parent 80c9cf3 commit 499a1e0
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NgModule } from "@angular/core"
import { AggregationTypePipe } from "./aggregationType.pipe"

@NgModule({
declarations: [AggregationTypePipe],
exports: [AggregationTypePipe]
})
export class AggregationTypeModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GetAttributeType } from "../../state/selectors/getAttributeTypeOfNodesByMetric.selector"
import { AggregationTypePipe } from "./aggregationType.pipe"

describe("AggregationType", () => {
const aggregationTypePipe = new AggregationTypePipe()
const aggregationTypes = {
nodes: { rloc: "absolute" },
edges: { mcc: "relative" }
}
const getAttributeType: GetAttributeType = (metricType, metricName) => aggregationTypes[metricType][metricName]

it("should default to 'absolute", () => {
expect(aggregationTypePipe.transform(getAttributeType, "nodes", "non-existing")).toBe("absolute")
})

it("should get nodes value", () => {
expect(aggregationTypePipe.transform(getAttributeType, "nodes", "rloc")).toBe("absolute")
})

it("should get edges value", () => {
expect(aggregationTypePipe.transform(getAttributeType, "edges", "mcc")).toBe("relative")
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Pipe, PipeTransform } from "@angular/core"
import { AttributeTypes } from "../../codeCharta.model"
import { GetAttributeType } from "../../state/selectors/getAttributeTypeOfNodesByMetric.selector"

@Pipe({ name: "aggregationType" })
export class AggregationTypePipe implements PipeTransform {
transform(getAttributeType: GetAttributeType, metricType: keyof AttributeTypes, metricName: string): string {
return getAttributeType(metricType, metricName) ?? "absolute"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*ngIf="showAttributeTypeSelector$ | async"
class="attribute-type-select"
[metricName]="secondaryMetric.name"
[metricType]="'nodes'"
>
</cc-attribute-type-selector>
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mat-button-toggle-group [value]="(metricName | nodeMetricAggregationType: (getAttributeTypeOfNodesByMetric$ | async)) || 'absolute'">
<mat-button-toggle-group [value]="getAttributeType$ | async | aggregationType: metricType:metricName">
<mat-button-toggle title="Select Sum" (click)="setToAbsolute()" value="absolute">Σ</mat-button-toggle>
<mat-button-toggle title="Select Median" (click)="setToRelative()" value="relative"></mat-button-toggle>
</mat-button-toggle-group>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class AttributeTypeSelectorComponent {
@Input() metricName: string
@Input() metricType: keyof AttributeTypes

getAttributeTypeOfNodesByMetric$: Observable<GetAttributeType>
getAttributeType$: Observable<GetAttributeType>

constructor(@Inject(Store) private store: Store) {
this.getAttributeTypeOfNodesByMetric$ = this.store.select(getAttributeTypeSelector)
this.getAttributeType$ = this.store.select(getAttributeTypeSelector)
}

setToAbsolute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { CommonModule } from "@angular/common"

import { AttributeTypeSelectorComponent } from "./attributeTypeSelector.component"
import { MaterialModule } from "../../../../material/material.module"
import { NodeMetricAggregationTypeModule } from "../../../pipes/nodeMetricAggregationType/nodeMetricAggregationType.module"
import { AggregationTypeModule } from "../../../pipes/aggregationType/aggregationType.module"

@NgModule({
imports: [CommonModule, MaterialModule, NodeMetricAggregationTypeModule],
imports: [CommonModule, MaterialModule, AggregationTypeModule],
declarations: [AttributeTypeSelectorComponent],
exports: [AttributeTypeSelectorComponent]
})
Expand Down

0 comments on commit 499a1e0

Please sign in to comment.