-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/2318/migrate metric choosers (#2825)
migrate edgeChooser.component, metricChooser.componen and codeMap.actions.service ref #2318
- Loading branch information
1 parent
82209aa
commit a8b87a3
Showing
90 changed files
with
850 additions
and
1,371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ization/app/codeCharta/state/effects/updateEdgePreviews/updateEdgePreviews.effect.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ApplicationInitStatus } from "@angular/core" | ||
import { TestBed } from "@angular/core/testing" | ||
import { EffectsModule } from "../../angular-redux/effects/effects.module" | ||
import { setAmountOfEdgePreviews } from "../../store/appSettings/amountOfEdgePreviews/amountOfEdgePreviews.actions" | ||
import { toggleEdgeMetricVisible } from "../../store/appSettings/isEdgeMetricVisible/isEdgeMetricVisible.actions" | ||
import { setEdgeMetric } from "../../store/dynamicSettings/edgeMetric/edgeMetric.actions" | ||
import { setEdges } from "../../store/fileSettings/edges/edges.actions" | ||
import { Store } from "../../store/store" | ||
import { UpdateEdgePreviewsEffect } from "./updateEdgePreviews.effect" | ||
|
||
describe("updateEdgePreviewsEffect", () => { | ||
let dispatchSpy | ||
|
||
beforeEach(async () => { | ||
Store["initialize"]() | ||
TestBed.configureTestingModule({ | ||
imports: [EffectsModule.forRoot([UpdateEdgePreviewsEffect])] | ||
}) | ||
await TestBed.inject(ApplicationInitStatus).donePromise | ||
|
||
dispatchSpy = jest.spyOn(Store.store, "dispatch") | ||
}) | ||
|
||
it("should ignore a not relevant action", () => { | ||
Store.dispatch({ type: "whatever" }) | ||
expect(dispatchSpy).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it("should set isEdgeMetricVisible to true on edgeMetric change, if it was false", () => { | ||
Store.dispatch(toggleEdgeMetricVisible()) // toggle first as it is true initially | ||
Store.dispatch(setEdgeMetric("rloc")) | ||
expect(dispatchSpy.mock.calls[2][0]).toEqual(toggleEdgeMetricVisible()) | ||
}) | ||
|
||
it("should not set isEdgeMetricVisible to false on edgeMetric change, if it was true", () => { | ||
Store.dispatch(setEdgeMetric("rloc")) | ||
expect(dispatchSpy).not.toHaveBeenCalledWith(toggleEdgeMetricVisible()) | ||
}) | ||
|
||
it("should update edges on amountOfEdgePreviewsSelector changed", () => { | ||
Store.dispatch(setAmountOfEdgePreviews(0)) | ||
expect(dispatchSpy).toHaveBeenCalledWith(setEdges([])) | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
visualization/app/codeCharta/state/effects/updateEdgePreviews/updateEdgePreviews.effect.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Inject, Injectable } from "@angular/core" | ||
import { combineLatest, filter, map, withLatestFrom } from "rxjs" | ||
import { createEffect } from "../../angular-redux/effects/createEffect" | ||
import { Store } from "../../angular-redux/store" | ||
import { amountOfEdgePreviewsSelector } from "../../store/appSettings/amountOfEdgePreviews/amountOfEdgePreviews.selector" | ||
import { edgeHeightSelector } from "../../store/appSettings/edgeHeight/edgeHeight.selector" | ||
import { toggleEdgeMetricVisible } from "../../store/appSettings/isEdgeMetricVisible/isEdgeMetricVisible.actions" | ||
import { isEdgeMetricVisibleSelector } from "../../store/appSettings/isEdgeMetricVisible/isEdgeMetricVisible.selector" | ||
import { showOnlyBuildingsWithEdgesSelector } from "../../store/appSettings/showOnlyBuildingsWithEdges/showOnlyBuildingsWithEdges.selector" | ||
import { edgeMetricSelector } from "../../store/dynamicSettings/edgeMetric/edgeMetric.selector" | ||
import { setEdges } from "../../store/fileSettings/edges/edges.actions" | ||
import { edgesSelector } from "../../store/fileSettings/edges/edges.selector" | ||
import { edgePreviewNodesSelector } from "./utils/edgePreviewNodes.selector" | ||
import { setEdgeVisibility } from "./utils/setEdgeVisibility" | ||
|
||
@Injectable() | ||
export class UpdateEdgePreviewsEffect { | ||
constructor(@Inject(Store) private store: Store) {} | ||
|
||
resetIsEdgeMetricVisible$ = createEffect(() => | ||
this.store.select(edgeMetricSelector).pipe( | ||
withLatestFrom(this.store.select(isEdgeMetricVisibleSelector)), | ||
filter(([, isEdgeMetricVisible]) => !isEdgeMetricVisible), | ||
map(() => toggleEdgeMetricVisible()) | ||
) | ||
) | ||
|
||
updateEdgePreviews$ = createEffect(() => | ||
combineLatest([ | ||
this.store.select(edgeMetricSelector), | ||
this.store.select(amountOfEdgePreviewsSelector), | ||
this.store.select(edgeHeightSelector), | ||
this.store.select(showOnlyBuildingsWithEdgesSelector) | ||
]).pipe( | ||
withLatestFrom(this.store.select(edgePreviewNodesSelector), this.store.select(edgesSelector)), | ||
map(([[edgeMetric], edgePreviewNodes, edges]) => { | ||
setEdgeVisibility(edgePreviewNodes, edges, edgeMetric) | ||
return setEdges(edges) | ||
}) | ||
) | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
...n/app/codeCharta/state/effects/updateEdgePreviews/utils/edgePreviewNodes.selector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { EdgeMetricCount } from "../../../../codeCharta.model" | ||
import { _getNodesWithHighestValue } from "./edgePreviewNodes.selector" | ||
|
||
describe("edgePreviewNodesSelector", () => { | ||
it("should return an empty list if there are no data for given metric", () => { | ||
expect(_getNodesWithHighestValue(new Map(), "rloc", 10)).toEqual([]) | ||
}) | ||
|
||
it("should return a first x keys for given metric", () => { | ||
const nodeEdgeMetricsOfRloc = new Map<string, EdgeMetricCount>([ | ||
["0", { incoming: 10, outgoing: 5 }], | ||
["1", { incoming: 1, outgoing: 2 }] | ||
]) | ||
expect(_getNodesWithHighestValue(new Map([["rloc", nodeEdgeMetricsOfRloc]]), "rloc", 1)).toEqual(["0"]) | ||
}) | ||
|
||
it("should return empty list if amountOfEdgePreviews is set to 0", () => { | ||
const nodeEdgeMetricsOfRloc = new Map<string, EdgeMetricCount>([["0", { incoming: 10, outgoing: 5 }]]) | ||
expect(_getNodesWithHighestValue(new Map([["rloc", nodeEdgeMetricsOfRloc]]), "rloc", 0)).toEqual([]) | ||
}) | ||
}) |
32 changes: 32 additions & 0 deletions
32
...zation/app/codeCharta/state/effects/updateEdgePreviews/utils/edgePreviewNodes.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createSelector } from "../../../angular-redux/createSelector" | ||
import { edgeMetricMapSelector, NodeEdgeMetricsMap } from "../../../selectors/accumulatedData/metricData/edgeMetricData.selector" | ||
import { amountOfEdgePreviewsSelector } from "../../../store/appSettings/amountOfEdgePreviews/amountOfEdgePreviews.selector" | ||
import { edgeMetricSelector } from "../../../store/dynamicSettings/edgeMetric/edgeMetric.selector" | ||
|
||
export const edgePreviewNodesSelector = createSelector( | ||
[edgeMetricMapSelector, edgeMetricSelector, amountOfEdgePreviewsSelector], | ||
(edgeMetricMap, edgeMetric, amountOfEdgePreviews) => new Set(_getNodesWithHighestValue(edgeMetricMap, edgeMetric, amountOfEdgePreviews)) | ||
) | ||
|
||
export const _getNodesWithHighestValue = (edgeMetricMap: NodeEdgeMetricsMap, edgeMetric: string, amountOfEdgePreviews: number) => { | ||
const keys: string[] = [] | ||
|
||
if (amountOfEdgePreviews === 0) { | ||
return keys | ||
} | ||
|
||
const nodeEdgeMetrics = edgeMetricMap.get(edgeMetric) | ||
|
||
if (nodeEdgeMetrics === undefined) { | ||
return keys | ||
} | ||
|
||
// note that this depends on the fact, that edgeMetricMap is created by a list which is sorted by max value | ||
for (const key of nodeEdgeMetrics.keys()) { | ||
keys.push(key) | ||
if (keys.length === amountOfEdgePreviews) { | ||
break | ||
} | ||
} | ||
return keys | ||
} |
36 changes: 36 additions & 0 deletions
36
...alization/app/codeCharta/state/effects/updateEdgePreviews/utils/setEdgeVisibility.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Edge, EdgeVisibility } from "../../../../codeCharta.model" | ||
import { setEdgeVisibility } from "./setEdgeVisibility" | ||
|
||
describe("setEdgeVisibility", () => { | ||
const edgePreviewNodes = new Set(["aNode", "anotherNode"]) | ||
|
||
it("should set edge's visibility to 'none' if edge has no attributes for given metric", () => { | ||
const edges: Edge[] = [{ attributes: {}, fromNodeName: "from", toNodeName: "to" }] | ||
setEdgeVisibility(edgePreviewNodes, edges, "loc") | ||
expect(edges[0].visible).toBe(EdgeVisibility.none) | ||
}) | ||
|
||
it("should set edge's visibility to 'none' if edge has neither from nor to", () => { | ||
const edges: Edge[] = [{ attributes: { loc: 12 }, fromNodeName: "from", toNodeName: "to" }] | ||
setEdgeVisibility(edgePreviewNodes, edges, "loc") | ||
expect(edges[0].visible).toBe(EdgeVisibility.none) | ||
}) | ||
|
||
it("should set edge's visibility to 'both' if edge has from and to for given metric", () => { | ||
const edges: Edge[] = [{ attributes: { loc: 12 }, fromNodeName: "aNode", toNodeName: "anotherNode" }] | ||
setEdgeVisibility(edgePreviewNodes, edges, "loc") | ||
expect(edges[0].visible).toBe(EdgeVisibility.both) | ||
}) | ||
|
||
it("should set edge's visibility to 'from' if edge has only from for given metric", () => { | ||
const edges: Edge[] = [{ attributes: { loc: 12 }, fromNodeName: "aNode", toNodeName: "to" }] | ||
setEdgeVisibility(edgePreviewNodes, edges, "loc") | ||
expect(edges[0].visible).toBe(EdgeVisibility.from) | ||
}) | ||
|
||
it("should set edge's visibility to 'to' if edge has only to for given metric", () => { | ||
const edges: Edge[] = [{ attributes: { loc: 12 }, fromNodeName: "from", toNodeName: "aNode" }] | ||
setEdgeVisibility(edgePreviewNodes, edges, "loc") | ||
expect(edges[0].visible).toBe(EdgeVisibility.to) | ||
}) | ||
}) |
20 changes: 20 additions & 0 deletions
20
visualization/app/codeCharta/state/effects/updateEdgePreviews/utils/setEdgeVisibility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Edge, EdgeVisibility } from "../../../../codeCharta.model" | ||
|
||
export const setEdgeVisibility = (edgePreviewNodes: Set<string>, edges: Edge[], edgeMetric: string) => { | ||
for (const edge of edges) { | ||
edge.visible = EdgeVisibility.none | ||
|
||
if (edge.attributes[edgeMetric] !== undefined) { | ||
const hasFromNodeEdgePreview = edgePreviewNodes.has(edge.fromNodeName) | ||
const hasToNodeEdgePreview = edgePreviewNodes.has(edge.toNodeName) | ||
|
||
if (hasFromNodeEdgePreview && hasToNodeEdgePreview) { | ||
edge.visible = EdgeVisibility.both | ||
} else if (hasFromNodeEdgePreview) { | ||
edge.visible = EdgeVisibility.from | ||
} else if (hasToNodeEdgePreview) { | ||
edge.visible = EdgeVisibility.to | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
.../codeCharta/state/store/appSettings/amountOfEdgePreviews/amountOfEdgePreviews.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { createSelector } from "../../../angular-redux/createSelector" | ||
import { appSettingsSelector } from "../appSettings.selector" | ||
|
||
export const amountOfEdgePreviewsSelector = createSelector([appSettingsSelector], appSettings => appSettings.amountOfEdgePreviews) |
Oops, something went wrong.