]> git.r.bdr.sh - rbdr/map/blob - Map/MapRenderComponents/MapAxes.swift
e7d65f4677afb1ff642bfd9e9eecee958cdc51a3
[rbdr/map] / Map / MapRenderComponents / MapAxes.swift
1 import SwiftUI
2
3 struct MapAxes: View {
4
5 @Environment(\.colorScheme) var colorScheme
6
7 let mapSize: CGSize
8 let lineWidth: CGFloat
9 let evolution: Stage
10 let stages: [CGFloat]
11 let stageHeight = CGFloat(50.0)
12 let padding = CGFloat(5.0)
13
14 var color: Color {
15 MapColor.colorForScheme(colorScheme).foreground
16 }
17
18 var body: some View {
19 ZStack(alignment: .topLeading) {
20
21 // Axis Lines
22 Path { path in
23 path.move(to: CGPoint(x: 0, y: 0))
24 path.addLine(to: CGPoint(x: 0, y: mapSize.height))
25 path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height))
26 path.move(to: CGPoint(x: mapSize.width, y: mapSize.height))
27 path.closeSubpath()
28 }.stroke(color, lineWidth: lineWidth * 2)
29
30 // Y Labels
31 Text("Visible").font(.title3).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
32 .offset(CGSize(width: -35.0, height: 0.0))
33 Text("Value Chain").font(.title).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
34 .offset(CGSize(width: -72.0, height: mapSize.height / 2 - 20))
35 Text("Invisible").font(.title3).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
36 .offset(CGSize(width: -40.0, height: mapSize.height - 20))
37
38 // X Labels
39
40 Text("Uncharted")
41 .font(.title3)
42 .foregroundColor(color)
43 .frame(width: mapSize.width / 4, height: stageHeight, alignment: .topLeading)
44 .offset(CGSize(width: 0.0, height: -stageHeight / 2.0))
45 Text("Industrialised")
46 .font(.title3)
47 .foregroundColor(color)
48 .frame(width: mapSize.width / 4, height: stageHeight, alignment: .topLeading)
49 .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 2.0))
50
51 Text(evolution.i)
52 .font(.title3)
53 .foregroundColor(color)
54 .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
55 .offset(CGSize(width: 0.0, height: mapSize.height + padding))
56
57 Text(evolution.ii)
58 .font(.title3)
59 .foregroundColor(color)
60 .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading)
61 .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding))
62
63 Text(evolution.iii)
64 .font(.title3)
65 .foregroundColor(color)
66 .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading)
67 .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding))
68
69 Text(evolution.iv)
70 .font(.title3)
71 .foregroundColor(color)
72 .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading)
73 .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding))
74 }
75 }
76
77 func w(_ dimension: CGFloat) -> CGFloat {
78 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
79 }
80 }
81
82 struct MapAxes_Previews: PreviewProvider {
83 static var previews: some View {
84 MapAxes(
85 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
86 evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0]
87 ).padding(50.0)
88 }
89 }