Skip to content

Commit

Permalink
fix: circle colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jschirrmacher committed Oct 2, 2024
1 parent 3615e9e commit bfd070d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/components/AddressList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
</tr>
</thead>
<tbody>
<tr v-for="(address, index) in filteredAndSortedAddresses" :key="address.id">
<tr v-for="(address) in filteredAndSortedAddresses" :key="address.id">
<td
:style="{
background:
Expand Down
2 changes: 1 addition & 1 deletion src/components/TheMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
:center="constructionSiteCenter"
:radius="isophone"
:track="isophone"
:color="getIsophoneColor(Number(index), time)"
:color="getIsophoneColor(index, time)"
/>
</div>

Expand Down
34 changes: 16 additions & 18 deletions src/services/Calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,22 @@ export function calculateIsophones(machines: Machine[]) {
if (machine.nightHours ?? 0 > 0) {
nightNoiseLevels.push(machine.volume! + calculateNightBonus(machine.nightHours!))
}
}

const dayRadii: number[] = []
const nightRadii: number[] = []
let dayRadii: Record<number, number> = {}
let nightRadii: Record<number, number> = {}

// Berechnung der Radien basierend auf den Geräuschpegeln
if (dayNoiseLevels.length !== 0) {
dayRadii.push(...calculateRadii(sumNoiseLevels(dayNoiseLevels), IMMISSION_THRESHOLDS.day))
}
if (nightNoiseLevels.length !== 0) {
nightRadii.push(
...calculateRadii(sumNoiseLevels(nightNoiseLevels), IMMISSION_THRESHOLDS.night)
)
}
// Berechnung der Radien basierend auf den Geräuschpegeln
if (dayNoiseLevels.length !== 0) {
dayRadii = calculateRadii(sumNoiseLevels(dayNoiseLevels), IMMISSION_THRESHOLDS.day)
}
if (nightNoiseLevels.length !== 0) {
nightRadii = calculateRadii(sumNoiseLevels(nightNoiseLevels), IMMISSION_THRESHOLDS.night)
}

return {
day: dayRadii,
night: nightRadii
}
return {
day: dayRadii,
night: nightRadii
}

// Berechnung des Nachtbonus
Expand Down Expand Up @@ -65,15 +63,15 @@ export function calculateIsophones(machines: Machine[]) {
totalNoiseLevel: number,
immissionThresholds: number[],
sourceHeight = 3.0
): number[] {
const radii: number[] = []
) {
const radii: Record<number, number> = {}

for (let distance = 5; distance <= 100000; distance += 5) {
const soundPressure = calculateSoundPressure(totalNoiseLevel, distance, sourceHeight)

for (let i = 0; i < immissionThresholds.length; i++) {
if (soundPressure >= immissionThresholds[i]) {
radii[i] = distance
radii[immissionThresholds[i]] = distance
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/services/Isophones.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ export type TimeOfDay = 'day' | 'night'
// MUSS ZWINGEND in aufsteigender Ordnung sein.
export const isophoneLevels: Record<TimeOfDay, Record<number, string>> = {
day: {
45: '#66aa22',
50: '#00694c',
55: '#f1d90b',
60: '#996a29',
70: '#cb2e34',
65: '#ee7821',
70: '#cb2e34'
60: '#996a29',
55: '#f1d90b',
50: '#00694c',
45: '#66aa22',
},
night: {
35: '#66aa22',
40: '#ee7821',
45: '#cb2e34',
70: '#824c7c',
50: '#891d20',
70: '#824c7c'
45: '#cb2e34',
40: '#ee7821',
35: '#66aa22',
}
}

Expand All @@ -36,6 +36,6 @@ export function getImmissionThresholds() {
}
}

export function getIsophoneColor(index: number, time: TimeOfDay) {
return Object.values(isophoneLevels[time])[index]
export function getIsophoneColor(isophone: number, time: TimeOfDay) {
return isophoneLevels[time][Number(isophone)]
}
19 changes: 11 additions & 8 deletions src/stores/addressStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,32 @@ export const useAddressStore = defineStore('addressStore', {
lat: number,
lon: number,
isophones: {
isophonesDay: number[]
isophonesNight: number[]
isophonesDay: Record<number, number>
isophonesNight: Record<number, number>
}
) {
const maxRadius = Math.max(...isophones.isophonesDay, ...isophones.isophonesNight)
const { isophonesDay, isophonesNight } = isophones
const isophonesDaySorted = isophonesDay.sort((a, b) => a - b)
const isophonesNightSorted = isophonesNight.sort((a, b) => a - b)
const dayRadii = Object.values(isophones.isophonesDay)
.map(Number)
.sort((a, b) => a - b)
const nightRadii = Object.values(isophones.isophonesNight)
.map(Number)
.sort((a, b) => a - b)
const maxRadius = Math.max(...dayRadii, ...nightRadii)

try {
const addressesInMaxRadius = await fetchAddressInRadius(lat, lon, maxRadius)

const dayMapArray = getIsophonesWithAddresses(
addressesInMaxRadius,
isophonesDaySorted,
dayRadii,
lon,
lat,
'isophoneIndexDay'
)

const nightMapArray = getIsophonesWithAddresses(
addressesInMaxRadius,
isophonesNightSorted,
nightRadii,
lon,
lat,
'isophoneIndexNight'
Expand Down
12 changes: 6 additions & 6 deletions src/stores/constructionSiteStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export const useConstructionSiteStore = defineStore('constructionSiteStore', {
center: undefined as Coordinate | undefined,
radius: 100,
machines: [] as Machine[],
isophonesDay: [] as number[], // radius starting from the center
isophonesNight: [] as number[], // radius starting from the center
isophonesDay: {} as Record<number, number>, // radius indexed by dB
isophonesNight: {} as Record<number, number>, // radius indexed by dB
currentStep: 1,
isophonesCalculated: false as boolean
}),
Expand All @@ -25,14 +25,14 @@ export const useConstructionSiteStore = defineStore('constructionSiteStore', {
},

calculateIsophones() {
this.isophonesDay = []
this.isophonesNight = []
this.isophonesDay = {}
this.isophonesNight = {}
this.isophonesCalculated = false

const isophones = calculateIsophones(this.machines)

this.isophonesDay = isophones!.day?.sort((a, b) => b - a)
this.isophonesNight = isophones!.night?.sort((a, b) => b - a)
this.isophonesDay = isophones!.day
this.isophonesNight = isophones!.night

this.currentStep = 3
this.isophonesCalculated = true
Expand Down

0 comments on commit bfd070d

Please sign in to comment.