Skip to content

Commit

Permalink
refactor: simplify extraction of attribute type
Browse files Browse the repository at this point in the history
ref #2731
ref #2630
  • Loading branch information
Torsten Knauf authored and Torsten Knauf committed Mar 22, 2022
1 parent 499a1e0 commit 010bddd
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 65 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,4 +1,4 @@
<mat-button-toggle-group [value]="getAttributeType$ | async | aggregationType: metricType:metricName">
<mat-button-toggle-group [value]="(attributeTypes$ | async)[metricType][metricName] ?? 'absolute'">
<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>
@@ -1,10 +1,9 @@
import "./attributeTypeSelector.component.scss"
import { Component, Inject, Input } from "@angular/core"
import { Observable } from "rxjs"
import { AttributeTypes, AttributeTypeValue } from "../../../codeCharta.model"
import { updateAttributeType } from "../../../state/store/fileSettings/attributeTypes/attributeTypes.actions"
import { Store } from "../../../state/angular-redux/store"
import { GetAttributeType, getAttributeTypeSelector } from "../../../state/selectors/getAttributeTypeOfNodesByMetric.selector"
import { attributeTypesSelector } from "../../../state/store/fileSettings/attributeTypes/attributeTypes.selector"

@Component({
selector: "cc-attribute-type-selector",
Expand All @@ -14,11 +13,9 @@ export class AttributeTypeSelectorComponent {
@Input() metricName: string
@Input() metricType: keyof AttributeTypes

getAttributeType$: Observable<GetAttributeType>
attributeTypes$ = this.store.select(attributeTypesSelector)

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

setToAbsolute() {
this.setAttributeType(AttributeTypeValue.absolute)
Expand Down
Expand Up @@ -3,10 +3,9 @@ import { CommonModule } from "@angular/common"

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

@NgModule({
imports: [CommonModule, MaterialModule, AggregationTypeModule],
imports: [CommonModule, MaterialModule],
declarations: [AttributeTypeSelectorComponent],
exports: [AttributeTypeSelectorComponent]
})
Expand Down
@@ -1,9 +1,10 @@
import { AttributeTypes, PrimaryMetrics } from "../../../codeCharta.model"
import { createSelector } from "../../../state/angular-redux/createSelector"
import { getAttributeTypeSelector } from "../../../state/selectors/getAttributeTypeOfNodesByMetric.selector"
import { attributeTypesSelector } from "../../../state/store/fileSettings/attributeTypes/attributeTypes.selector"
import { primaryMetricNamesSelector } from "../../attributeSideBar/attributeSideBarPrimaryMetrics/primaryMetricNames.selector"

export const createAttributeTypeSelector = (metricType: keyof AttributeTypes, metricFor: keyof PrimaryMetrics) =>
createSelector([primaryMetricNamesSelector, getAttributeTypeSelector], (primaryMetricNames, getAttributeType) =>
getAttributeType(metricType, primaryMetricNames[metricFor]) === "relative" ? "x͂" : "Σ"
)
createSelector([primaryMetricNamesSelector, attributeTypesSelector], (primaryMetricNames, attributeTypes) => {
const metricName = primaryMetricNames[metricFor]
return attributeTypes[metricType][metricName] === "relative" ? "x͂" : "Σ"
})

0 comments on commit 010bddd

Please sign in to comment.