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