Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset color range correctly within color settings panel #2877

Merged
merged 7 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

- Fix packaging of standalone app for macOS and Windows [#2847](https://github.com/MaibornWolff/codecharta/pull/2847)
- Fix dialogparser test of sourcecode parser[#2860](https://github.com/MaibornWolff/codecharta/pull/2860)
- Fix resetting of color range within color settings panel [#2877](https://github.com/MaibornWolff/codecharta/pull/2877)
shaman-apprentice marked this conversation as resolved.
Show resolved Hide resolved

### Chore 👨‍💻 👩‍💻

Expand Down
6 changes: 4 additions & 2 deletions visualization/app/codeCharta/codeCharta.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ export interface MapColors {
}

export interface ColorRange {
from: number
to: number
/** null means to be reset */
from: number | null
/** null means to be reset */
to: number | null
}

export interface AttributeTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export function setColorRange(colorRange: Partial<ColorRange> = defaultColorRang
}
}

export const defaultColorRange: ColorRange = { from: 0, to: 0 }
export const defaultColorRange: ColorRange = { from: null, to: null }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable } from "@angular/core"
import { combineLatest, filter, map } from "rxjs"
import { isActionOfType } from "../../../../util/reduxHelper"
import { isAction, isActionOfType } from "../../../../util/reduxHelper"
import { createEffect } from "../../../angular-redux/effects/createEffect"
import { Actions, ActionsToken } from "../../../angular-redux/effects/effects.module"
import { Store } from "../../../angular-redux/store"
Expand All @@ -9,14 +9,19 @@ import {
selectedColorMetricDataSelector
} from "../../../selectors/accumulatedData/metricData/selectedColorMetricData.selector"
import { FilesSelectionActions } from "../../files/files.actions"
import { ColorMetricActions } from "../colorMetric/colorMetric.actions"
import { setColorRange } from "./colorRange.actions"
import { ColorRangeActions, setColorRange, SetColorRangeAction } from "./colorRange.actions"

@Injectable()
export class ResetColorRangeEffect {
private selectedColorMetricData$ = this.store.select(selectedColorMetricDataSelector)
private resetActions$ = this.actions$.pipe(
filter(action => isActionOfType(action.type, FilesSelectionActions) || isActionOfType(action.type, ColorMetricActions))
filter(
action =>
isActionOfType(action.type, FilesSelectionActions) ||
(isAction<SetColorRangeAction>(action, ColorRangeActions.SET_COLOR_RANGE) &&
action.payload.from === null &&
action.payload.to === null)
)
)

constructor(@Inject(ActionsToken) private actions$: Actions, @Inject(Store) private store: Store) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ describe("mapColorLabelPipe", () => {
it("should transform 'incomingEdge'", () => {
expect(new MapColorLabelPipe().transform("incomingEdge", colorRange, nodeMetricDataRange)).toBe("Incoming Edge")
})

it("should not throw when called with default null color range values", () => {
expect(() => new MapColorLabelPipe().transform("incomingEdge", { from: null, to: null }, nodeMetricDataRange)).not.toThrow()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { MetricMinMax } from "../../state/selectors/accumulatedData/metricData/s
@Pipe({ name: "mapColorLabel" })
export class MapColorLabelPipe implements PipeTransform {
transform(metricName: keyof MapColors, colorRange: ColorRange, nodeMetricRange: MetricMinMax): string {
if (colorRange.from === null && colorRange.to === null) {
return ""
}

switch (metricName) {
case "positive":
return `${nodeMetricRange.minValue} to < ${this.formatNumber(colorRange.from)}`
Expand Down