]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapAxes.swift
bdbafbdaa87f681d213c29ccac79367fd150904f
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapAxes.swift
1 /*
2 Copyright (C) 2024 Rubén Beltrán del Río
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see https://map.tranquil.systems.
16 */
17 import SwiftUI
18
19 struct MapAxes: View {
20
21 let mapSize: CGSize
22 let lineWidth: CGFloat
23 let evolution: Stage
24 let stages: [CGFloat]
25 let stageHeight = CGFloat(100.0)
26 let padding = CGFloat(5.0)
27
28 var body: some View {
29 ZStack(alignment: .topLeading) {
30
31 // Axis Lines
32 Path { path in
33 path.move(to: CGPoint(x: 0, y: 0))
34 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
35 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
36 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
37 path.closeSubpath()
38 }.stroke(Color.map.axisColor, lineWidth: lineWidth * 2)
39
40 // Y Labels
41 Text("Visible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(
42 Angle(degrees: -90.0)
43 )
44 .offset(CGSize(width: -35.0, height: 0.0))
45 Text("Invisible").font(.theme.axisLabel).foregroundColor(.map.labelColor).rotationEffect(
46 Angle(degrees: -90.0)
47 )
48 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
49
50 // X Labels
51
52 Text("Uncharted")
53 .font(.theme.axisLabel)
54 .foregroundColor(.map.labelColor)
55 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
56 .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
57 Text("Industrialised")
58 .font(.theme.axisLabel)
59 .foregroundColor(.map.labelColor)
60 .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
61 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0))
62
63 Text(evolution.i)
64 .font(.theme.axisLabel)
65 .foregroundColor(.map.labelColor)
66 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
67 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
68
69 Text(evolution.ii)
70 .font(.theme.axisLabel)
71 .foregroundColor(.map.labelColor)
72 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
73 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
74
75 Text(evolution.iii)
76 .font(.theme.axisLabel)
77 .foregroundColor(.map.labelColor)
78 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
79 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
80
81 Text(evolution.iv)
82 .font(.theme.axisLabel)
83 .foregroundColor(.map.labelColor)
84 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
85 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
86 }
87 }
88
89 func w(_ dimension: CGFloat) -> CGFloat {
90 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
91 }
92 }
93
94 #Preview {
95 MapAxes(
96 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
97 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]
98 ).padding(50.0)
99 }