Skip to content

Commit

Permalink
Fix/1632/reset street layout global config (#1633)
Browse files Browse the repository at this point in the history
* initial street layout introduction

* may be a  fix for e2e filechooser test

* street layout flattening fix, filechooser e2e fix, global setting dialog layout improvement, code refactoring

* fixed TMStreet layout

* added max treemap files

* fixing linting, added remark about e2e falky test fix, added streetlayout todo

* edited changelog

* fixes after @BridgeAR review

* updated changelog

* Apply code formating #1543

* Update visualization/app/codeCharta/ui/maxTreeMapFiles/maxTreeMapFiles.component.ts

* Update visualization/app/codeCharta/util/algorithm/streetLayout/horizontalStreet.ts

* Update visualization/app/codeCharta/streetLayoutTodo.md

* Update visualization/app/codeCharta/util/algorithm/streetLayout/streetViewHelper.ts

* Update visualization/app/codeCharta/util/algorithm/streetLayout/verticalStreet.ts

* Update visualization/app/codeCharta/util/algorithm/treeMapLayout/treeMapHelper.ts

* Improve identation #905

* Merge main, Fix label position conflicts #905

* Fix scaling bug and improve performance

* adding layout reset behavior

* Fix hard coded year in unit test

* fix #1624

* fix #1624

* fix test

* fix test

* fix test

* fix flaky test

* fix flaky test

* fix flaky Integration test

* added agenda regression tests for 53 week years

* Update CalendarWeekTest.kt

* Update CalendarWeekTest.kt

* Update CalendarWeekTest.kt

* possible fix for flaky test timeout

* added some comments & updated changelog

* remove trailing spaces

Co-authored-by: Cedrik Bormann <cedrikbormann@gmail.com>
Co-authored-by: Cedrik Bormann <26900540+ce-bo@users.noreply.github.com>
Co-authored-by: Torsten Knauf <Torsten.Knauf@maibornwolff.de>
  • Loading branch information
4 people committed Jan 11, 2021
1 parent f7a852a commit 14df6a2
Show file tree
Hide file tree
Showing 13 changed files with 2,266 additions and 2,140 deletions.
4,211 changes: 2,107 additions & 2,104 deletions CHANGELOG.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package de.maibornwolff.codecharta.importer.scmlogparser.input.metrics

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.temporal.ChronoUnit
import java.time.temporal.WeekFields

internal data class CalendarWeek(private val week: Int, private val year: Int) : Comparable<CalendarWeek> {

override fun compareTo(o: CalendarWeek): Int {
return numberOfWeeksBetween(this, o)
override fun compareTo(other: CalendarWeek): Int {
return numberOfWeeksBetween(this, other)
}

companion object {
Expand All @@ -19,7 +20,16 @@ internal data class CalendarWeek(private val week: Int, private val year: Int) :
}

fun numberOfWeeksBetween(a: CalendarWeek, b: CalendarWeek): Int {
return b.week + 52 * b.year - (a.week + 52 * a.year)
return ChronoUnit.WEEKS.between(getWeekDate(a.year, a.week), getWeekDate(b.year, b.week)).toInt()
}

private fun getWeekDate(year: Int, week: Int): OffsetDateTime? {
// returns the date of Monday based on the week and year
return OffsetDateTime.now().withYear(year)
.with(WeekFields.ISO.weekOfWeekBasedYear(), week.toLong())
.with(WeekFields.ISO.dayOfWeek(), 1)
.withHour(12).withMinute(0).withSecond(0).withNano(0)
.withOffsetSameInstant(ZoneOffset.UTC)
}

private fun modifyYear(dateTime: OffsetDateTime, cwWeek: Int, cwYear: Int): Int {
Expand All @@ -36,8 +46,8 @@ internal data class CalendarWeek(private val week: Int, private val year: Int) :
return dateTime.dayOfYear < 7
}

private fun isFirstOrSecondWeek(kalenderWeeknWeek: Int): Boolean {
return kalenderWeeknWeek <= 2
private fun isFirstOrSecondWeek(calendarWeek: Int): Boolean {
return calendarWeek <= 2
}

private fun dayIsOneOfTheLastSevenDaysInYear(dateTime: OffsetDateTime): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,31 @@ class CalendarWeekTest {
}

@Test
fun kalenderwoche_wird_mit_tagimjahr_richtig_berechnet_wenn_tag_am_anfang_des_jahres_und_kw_im_vorjahr() {
fun calendarWeekProperlyCalculated_when_dayAtStartOfYear_and_weekInLastYear_and_53WeeksInLastYear() {
// given
val commitDateTime = OffsetDateTime.of(2016, 1, 3, 12, 0, 0, 0, zoneOffset)

// when
val kw = CalendarWeek.forDateTime(commitDateTime)

// then
assertThat(kw).isEqualTo(CalendarWeek(53, 2015))
assertThat(kw).isEqualTo(CalendarWeek(53, 2015)) // 2015 has 53 Weeks
}

@Test
fun kalenderwoche_wird_mit_tagimjahr_richtig_berechnet_wenn_tag_am_ende_des_jahres_und_kw_im_folgejahr() {
fun calendarWeekProperlyCalculated_when_dayAtStartOfYear_and_weekInLastYear_and_52WeeksInLastYear() {
// given
val commitDateTime = OffsetDateTime.of(2017, 1, 3, 12, 0, 0, 0, zoneOffset)

// when
val kw = CalendarWeek.forDateTime(commitDateTime)

// then
assertThat(kw).isEqualTo(CalendarWeek(1, 2017))
}

@Test
fun calendarWeekProperlyCalculated_when_dayAtEndOfYear_and_weekInNextYear() {
// given
val commitDateTime = OffsetDateTime.of(2018, 12, 31, 12, 0, 0, 0, zoneOffset)

Expand All @@ -46,7 +58,7 @@ class CalendarWeekTest {
}

@Test
fun weeksBetweenCommitsRichtigBerechnet() {
fun weeksBetweenCommitsProperlyCalculated_when_52WeeksInYears() {
// given
val commitDateTime2 = OffsetDateTime.of(2018, 1, 11, 12, 0, 0, 0, zoneOffset)
val commitDateTime3 = OffsetDateTime.of(2017, 12, 13, 12, 0, 0, 0, zoneOffset)
Expand All @@ -60,4 +72,20 @@ class CalendarWeekTest {
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw1)).isEqualTo(0)
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw2)).isEqualTo(0)
}

@Test
fun weeksBetweenCommitsProperlyCalculated_when_firstWeek_and_53WeeksInOldYear() {
// given
val commitDateTime2 = OffsetDateTime.of(2021, 1, 11, 12, 0, 0, 0, zoneOffset)
val commitDateTime3 = OffsetDateTime.of(2020, 12, 13, 12, 0, 0, 0, zoneOffset)

val kw1 = CalendarWeek.forDateTime(commitDateTime2)
val kw2 = CalendarWeek.forDateTime(commitDateTime3)

// then
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw1)).isEqualTo(5)
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw2)).isEqualTo(-5)
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw1)).isEqualTo(0)
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw2)).isEqualTo(0)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package de.maibornwolff.codecharta.importer.scmlogparserv2.input.metrics

import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.temporal.ChronoUnit
import java.time.temporal.WeekFields

internal data class CalendarWeek(private val week: Int, private val year: Int) : Comparable<CalendarWeek> {

override fun compareTo(week: CalendarWeek): Int {
return numberOfWeeksBetween(this, week)
override fun compareTo(other: CalendarWeek): Int {
return numberOfWeeksBetween(this, other)
}

companion object {
Expand All @@ -19,7 +20,16 @@ internal data class CalendarWeek(private val week: Int, private val year: Int) :
}

fun numberOfWeeksBetween(a: CalendarWeek, b: CalendarWeek): Int {
return b.week + 52 * b.year - (a.week + 52 * a.year)
return ChronoUnit.WEEKS.between(getWeekDate(a.year, a.week), getWeekDate(b.year, b.week)).toInt()
}

private fun getWeekDate(year: Int, week: Int): OffsetDateTime? {
// returns the date of Monday based on the week and year
return OffsetDateTime.now().withYear(year)
.with(WeekFields.ISO.weekOfWeekBasedYear(), week.toLong())
.with(WeekFields.ISO.dayOfWeek(), 1)
.withHour(12).withMinute(0).withSecond(0).withNano(0)
.withOffsetSameInstant(ZoneOffset.UTC)
}

private fun modifyYear(dateTime: OffsetDateTime, week: Int, initialYear: Int): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,31 @@ class CalendarWeekTest {
}

@Test
fun kalenderwoche_wird_mit_tagimjahr_richtig_berechnet_wenn_tag_am_anfang_des_jahres_und_kw_im_vorjahr() {
fun calendarWeekProperlyCalculated_when_dayAtStartOfYear_and_weekInLastYear_and_53WeeksInLastYear() {
// given
val commitDateTime = OffsetDateTime.of(2016, 1, 3, 12, 0, 0, 0, zoneOffset)

// when
val kw = CalendarWeek.forDateTime(commitDateTime)

// then
assertThat(kw).isEqualTo(CalendarWeek(53, 2015))
assertThat(kw).isEqualTo(CalendarWeek(53, 2015)) // 2015 has 53 Weeks
}

@Test
fun kalenderwoche_wird_mit_tagimjahr_richtig_berechnet_wenn_tag_am_ende_des_jahres_und_kw_im_folgejahr() {
fun calendarWeekProperlyCalculated_when_dayAtStartOfYear_and_weekInLastYear_and_52WeeksInLastYear() {
// given
val commitDateTime = OffsetDateTime.of(2017, 1, 3, 12, 0, 0, 0, zoneOffset)

// when
val kw = CalendarWeek.forDateTime(commitDateTime)

// then
assertThat(kw).isEqualTo(CalendarWeek(1, 2017))
}

@Test
fun calendarWeekProperlyCalculated_when_dayAtEndOfYear_and_weekInNextYear() {
// given
val commitDateTime = OffsetDateTime.of(2018, 12, 31, 12, 0, 0, 0, zoneOffset)

Expand All @@ -46,7 +58,7 @@ class CalendarWeekTest {
}

@Test
fun weeksBetweenCommitsRichtigBerechnet() {
fun weeksBetweenCommitsProperlyCalculated_when_52WeeksInYears() {
// given
val commitDateTime2 = OffsetDateTime.of(2018, 1, 11, 12, 0, 0, 0, zoneOffset)
val commitDateTime3 = OffsetDateTime.of(2017, 12, 13, 12, 0, 0, 0, zoneOffset)
Expand All @@ -60,4 +72,20 @@ class CalendarWeekTest {
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw1)).isEqualTo(0)
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw2)).isEqualTo(0)
}

@Test
fun weeksBetweenCommitsProperlyCalculated_when_firstWeek_and_53WeeksInOldYear() {
// given
val commitDateTime2 = OffsetDateTime.of(2021, 1, 11, 12, 0, 0, 0, zoneOffset)
val commitDateTime3 = OffsetDateTime.of(2020, 12, 13, 12, 0, 0, 0, zoneOffset)

val kw1 = CalendarWeek.forDateTime(commitDateTime2)
val kw2 = CalendarWeek.forDateTime(commitDateTime3)

// then
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw1)).isEqualTo(5)
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw2)).isEqualTo(-5)
assertThat(CalendarWeek.numberOfWeeksBetween(kw1, kw1)).isEqualTo(0)
assertThat(CalendarWeek.numberOfWeeksBetween(kw2, kw2)).isEqualTo(0)
}
}
8 changes: 7 additions & 1 deletion visualization/app/codeCharta/ui/dialog/dialog.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
}
}

.icon-link {
font-size: 16px !important;
margin-left: 6px;
margin-right: 13px;
}

.md-toolbar-tools {
color: white;
}
Expand Down Expand Up @@ -40,7 +46,7 @@
.global-settings {
.weblink {
display: block;
margin: 0 0 10px 0;
margin: 10 0 0 36px;
color: rgba(0, 0, 0, 0.870588);
text-decoration: none;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ <h2 class="md-toolbar-tools">Global Settings</h2>

<reset-settings-button-component
autofocus="false"
settings-names="appSettings.hideFlatBuildings, appSettings.isWhiteBackground, appSettings.resetCameraIfNewFileIsLoaded"
settings-names="appSettings.hideFlatBuildings, appSettings.isWhiteBackground, appSettings.resetCameraIfNewFileIsLoaded, appSettings.layoutAlgorithm, appSettings.maxTreeMapFiles"
tooltip="Reset global settings to their defaults"
></reset-settings-button-component>

<md-dialog-content>
<div class="md-dialog-content">
<layout-selection-component></layout-selection-component>
<max-tree-map-files-component></max-tree-map-files-component>
<layout-selection-component
ng-model="$ctrl._viewModel.layoutAlgorithm"
ng-change="$ctrl.applySettingsAlgorithm()">
</layout-selection-component>
<max-tree-map-files-component
ng-model="$ctrl._viewModel.maxTreeMapFiles"
ng-change="$ctrl.applySettingsMaxTreeMapFiles()"
ng-show="$ctrl._viewModel.layoutAlgorithm === 'Squarified TreeMap'">
</max-tree-map-files-component>

<md-input-container class="input-container md-block">
<md-checkbox
Expand Down Expand Up @@ -60,15 +67,15 @@ <h2 class="md-toolbar-tools">Global Settings</h2>
target="_blank"
rel="noopener noreferrer"
>
<em class="fa fa-external-link"></em>Manual
<em class="fa fa-external-link icon-link"></em>Manual
</a>

<a class="weblink" href="https://github.com/MaibornWolff/codecharta/" target="_blank" rel="noopener noreferrer">
<em class="fa fa-external-link"></em>Github
<em class="fa fa-external-link icon-link"></em>Github
</a>

<a class="weblink" href="https://github.com/MaibornWolff/codecharta/wiki" target="_blank" rel="noopener noreferrer">
<em class="fa fa-external-link"></em>Wiki
<em class="fa fa-external-link icon-link"></em>Wiki
</a>
</div>
</md-dialog-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,47 @@ import {
ExperimentalFeaturesEnabledService,
ExperimentalFeaturesEnabledSubscriber
} from "../../state/store/appSettings/enableExperimentalFeatures/experimentalFeaturesEnabled.service"
import { LayoutAlgorithm } from "../../codeCharta.model"
import {
LayoutAlgorithmService,
LayoutAlgorithmSubscriber } from "../../state/store/appSettings/layoutAlgorithm/layoutAlgorithm.service"
import { setLayoutAlgorithm } from "../../state/store/appSettings/layoutAlgorithm/layoutAlgorithm.actions"
import {
MaxTreeMapFilesService,
MaxTreeMapFilesSubscriber } from "../../state/store/appSettings/maxTreeMapFiles/maxTreeMapFiles.service"
import { setMaxTreeMapFiles } from "../../state/store/appSettings/maxTreeMapFiles/maxTreeMapFiles.actions"

export class DialogGlobalSettingsController
implements
HideFlatBuildingsSubscriber,
IsWhiteBackgroundSubscriber,
ResetCameraIfNewFileIsLoadedSubscriber,
ExperimentalFeaturesEnabledSubscriber {
ExperimentalFeaturesEnabledSubscriber,
LayoutAlgorithmSubscriber,
MaxTreeMapFilesSubscriber {
private _viewModel: {
hideFlatBuildings: boolean
isWhiteBackground: boolean
resetCameraIfNewFileIsLoaded: boolean
experimentalFeaturesEnabled: boolean
layoutAlgorithm : LayoutAlgorithm,
maxTreeMapFiles : number
} = {
hideFlatBuildings: null,
isWhiteBackground: null,
resetCameraIfNewFileIsLoaded: null,
experimentalFeaturesEnabled: false
experimentalFeaturesEnabled: false,
layoutAlgorithm : null,
maxTreeMapFiles : null
}

constructor(private $mdDialog, private $rootScope: IRootScopeService, private storeService: StoreService) {
HideFlatBuildingsService.subscribe(this.$rootScope, this)
IsWhiteBackgroundService.subscribe(this.$rootScope, this)
ResetCameraIfNewFileIsLoadedService.subscribe(this.$rootScope, this)
ExperimentalFeaturesEnabledService.subscribe(this.$rootScope, this)

LayoutAlgorithmService.subscribe(this.$rootScope, this)
MaxTreeMapFilesService.subscribe(this.$rootScope, this)
this.initDialogOnClick()
}

Expand All @@ -54,6 +70,7 @@ export class DialogGlobalSettingsController
this.onHideFlatBuildingsChanged(appSettings.hideFlatBuildings)
this.onIsWhiteBackgroundChanged(appSettings.isWhiteBackground)
this.onResetCameraIfNewFileIsLoadedChanged(appSettings.resetCameraIfNewFileIsLoaded)
this.onLayoutAlgorithmChanged(appSettings.layoutAlgorithm)
this.onExperimentalFeaturesEnabledChanged(appSettings.experimentalFeaturesEnabled)
}

Expand All @@ -69,6 +86,14 @@ export class DialogGlobalSettingsController
this._viewModel.resetCameraIfNewFileIsLoaded = resetCameraIfNewFileIsLoaded
}

onLayoutAlgorithmChanged(layoutAlgorithm: LayoutAlgorithm) {
this._viewModel.layoutAlgorithm = layoutAlgorithm
}

onMaxTreeMapFilesChanged(maxTreeMapFiles: number) {
this._viewModel.maxTreeMapFiles = maxTreeMapFiles
}

onExperimentalFeaturesEnabledChanged(experimentalFeaturesEnabled: boolean) {
this._viewModel.experimentalFeaturesEnabled = experimentalFeaturesEnabled
}
Expand All @@ -89,6 +114,14 @@ export class DialogGlobalSettingsController
this.storeService.dispatch(setExperimentalFeaturesEnabled(this._viewModel.experimentalFeaturesEnabled))
}

applySettingsAlgorithm() {
this.storeService.dispatch(setLayoutAlgorithm(this._viewModel.layoutAlgorithm))
}

applySettingsMaxTreeMapFiles() {
this.storeService.dispatch(setMaxTreeMapFiles(this._viewModel.maxTreeMapFiles))
}

hide() {
this.$mdDialog.hide()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ describe("FileChooser", () => {
})

it("should open an valid and an invalid file, close the dialog and open a valid file", async () => {
// !note : openFiles is done in parallel @check Promise.all , first loaded is first served,
// !an empty png file insure that the first loaded file is empty.png
// !fixes bug https://github.com/MaibornWolff/codecharta/issues/1322
await fileChooser.openFiles(["./app/codeCharta/assets/empty.png", "./app/codeCharta/assets/sample3.cc.json"])
expect(await dialogError.getMessage()).toEqual(` ${ERROR_MESSAGES.fileIsInvalid}`)

Expand Down
5 changes: 3 additions & 2 deletions visualization/app/codeCharta/ui/filePanel/filePanel.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ export class FilePanelPageObject {
}

async clickChooser() {
await expect(page).toClick("file-panel-component md-select", { timeout: 3000 })
await expect(page).toClick("file-panel-component md-select") // timeout added globally in puppeteer.helper.ts
}

async getAllNames() {
await this.clickChooser()

await page.waitForSelector(".md-select-menu-container.md-active > md-select-menu");

await page.waitForSelector(".md-select-menu-container.md-active > md-select-menu")
const content = await page.$eval(".md-select-menu-container.md-active > md-select-menu", element => element["innerText"])
return content.split("\n")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
reset-settings-button-component {
height: 10px;
height: 30px;
.md-button {
top: 0px;
margin-left: 0;
Expand Down

0 comments on commit 14df6a2

Please sign in to comment.