From 453ad488ed320a7d07cd82ddbfbaf16b9ca34702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 23 Oct 2024 10:36:53 +0200 Subject: [PATCH] SolarSystem two tiles for real + scaled AND added distanceToSun --- .../src/app/solar-system/SolarSystemBody.ts | 21 ++++++---- .../solar-system/solar-system.component.html | 42 +++++++++++++++---- .../solar-system/solar-system.component.less | 7 ++-- .../solar-system/solar-system.component.ts | 25 ++++++++--- 4 files changed, 70 insertions(+), 25 deletions(-) diff --git a/src/main/angular/src/app/solar-system/SolarSystemBody.ts b/src/main/angular/src/app/solar-system/SolarSystemBody.ts index a13d2bc..af8c419 100644 --- a/src/main/angular/src/app/solar-system/SolarSystemBody.ts +++ b/src/main/angular/src/app/solar-system/SolarSystemBody.ts @@ -1,21 +1,28 @@ +export const MIO_KM: number = 1000 * 1000 * 1000; + export class SolarSystemBody { - readonly realDistanceMeters: number; + readonly realDistance: number; - modelMeters: number; + scaledDiameter: number; - modelDistance: number; + scaledDistance: number; constructor( readonly name: string, - readonly realMeters: number, + readonly realDiameter: number, realDistanceMioKm: number, readonly massKg: number, readonly moons: SolarSystemBody[], ) { - this.realDistanceMeters = realDistanceMioKm * 1000 * 1000 * 1000; - this.modelMeters = realMeters; - this.modelDistance = realDistanceMioKm; + this.realDistance = realDistanceMioKm * MIO_KM; + this.scaledDiameter = realDiameter; + this.scaledDistance = realDistanceMioKm; + } + + scale(scale: number) { + this.scaledDiameter = this.realDiameter * scale; + this.scaledDistance = this.realDistance * scale; } } diff --git a/src/main/angular/src/app/solar-system/solar-system.component.html b/src/main/angular/src/app/solar-system/solar-system.component.html index 7d7af58..9ef220b 100644 --- a/src/main/angular/src/app/solar-system/solar-system.component.html +++ b/src/main/angular/src/app/solar-system/solar-system.component.html @@ -1,22 +1,43 @@
-
- Sonnensystem Skalieren + Realität
- - + + - - + + + +
NameRealitätSkaliertDurchmesserZur Sonne
{{ mass.name }}{{ applyPrefixUnit(mass.realMeters, 'm', 1000, 'k', 0, locale) }}{{ diameterUnit.applyPrefixUnit(mass.modelMeters) }}{{ applyPrefixUnit(mass.realDiameter, 'm', 1000, 'k', 0, locale) }}{{ applyPrefixUnit(mass.realDistance, 'm', MIO_KM, 'Mio. k', 0, locale) }}
+
+
+
+ +
+
+
+ Skaliert +
+
+ + + + + + + + + +
NameDurchmesserZur Sonne
{{ mass.name }}{{ diameterUnit.applyPrefixUnit(mass.scaledDiameter) }}{{ distanceUnit.applyPrefixUnit(mass.scaledDistance) }}
@@ -27,16 +48,21 @@ + +
- +  m + + +  x +
-
diff --git a/src/main/angular/src/app/solar-system/solar-system.component.less b/src/main/angular/src/app/solar-system/solar-system.component.less index 82f7970..2ee3b56 100644 --- a/src/main/angular/src/app/solar-system/solar-system.component.less +++ b/src/main/angular/src/app/solar-system/solar-system.component.less @@ -15,14 +15,13 @@ td { width: 33.33%; } -.real { +td { text-align: right; width: 33.33%; } -.model { - text-align: right; - width: 33.33%; +.name { + text-align: left; } input { diff --git a/src/main/angular/src/app/solar-system/solar-system.component.ts b/src/main/angular/src/app/solar-system/solar-system.component.ts index 8e0a7a3..66e6626 100644 --- a/src/main/angular/src/app/solar-system/solar-system.component.ts +++ b/src/main/angular/src/app/solar-system/solar-system.component.ts @@ -1,7 +1,7 @@ import {Component, Inject, LOCALE_ID, OnInit} from '@angular/core'; import {DecimalPipe, NgForOf} from "@angular/common"; import {FormsModule} from "@angular/forms"; -import {SolarSystemBody} from "./SolarSystemBody"; +import {MIO_KM, SolarSystemBody} from "./SolarSystemBody"; import {BODIES, JUPITER} from "./SOLAR_SYSTEM"; import {applyPrefixUnit, Unit} from "../Unit"; @@ -22,25 +22,38 @@ export class SolarSystemComponent implements OnInit { protected readonly BODIES = BODIES; + protected readonly MIO_KM = MIO_KM; + + protected readonly diameterUnit: Unit; + + protected readonly distanceUnit: Unit; + protected pivot: SolarSystemBody = JUPITER; - protected diameterUnit: Unit; + protected scale: number = 1; constructor( @Inject(LOCALE_ID) readonly locale: string, ) { this.diameterUnit = new Unit('m', this.locale); + this.distanceUnit = new Unit('m', this.locale); } ngOnInit() { - this.pivot.modelMeters = 0.18; + this.pivot.scaledDiameter = 0.18; + this.update(); + } + + updateViaScale() { + this.pivot.scaledDiameter = this.pivot.realDiameter * this.scale; this.update(); } protected update() { - const scale = this.pivot.modelMeters / this.pivot.realMeters; - BODIES.filter(m => m != this.pivot).forEach(m => m.modelMeters = scale * m.realMeters); - this.diameterUnit.update(this.pivot.modelMeters); + this.scale = this.pivot.scaledDiameter / this.pivot.realDiameter; + BODIES.forEach(m => m.scale(this.scale)); + this.diameterUnit.update(JUPITER.scaledDiameter); + this.distanceUnit.update(JUPITER.scaledDistance); } }