aboutsummaryrefslogtreecommitdiff
path: root/Map/MapRenderComponents
diff options
context:
space:
mode:
Diffstat (limited to 'Map/MapRenderComponents')
-rw-r--r--Map/MapRenderComponents/MapAxes.swift89
-rw-r--r--Map/MapRenderComponents/MapBlockers.swift49
-rw-r--r--Map/MapRenderComponents/MapEdges.swift92
-rw-r--r--Map/MapRenderComponents/MapOpportunities.swift84
-rw-r--r--Map/MapRenderComponents/MapStages.swift60
-rw-r--r--Map/MapRenderComponents/MapVertices.swift90
6 files changed, 0 insertions, 464 deletions
diff --git a/Map/MapRenderComponents/MapAxes.swift b/Map/MapRenderComponents/MapAxes.swift
deleted file mode 100644
index a6e2f87..0000000
--- a/Map/MapRenderComponents/MapAxes.swift
+++ /dev/null
@@ -1,89 +0,0 @@
-import SwiftUI
-
-struct MapAxes: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let lineWidth: CGFloat
- let evolution: Stage
- let stages: [CGFloat]
- let stageHeight = CGFloat(100.0)
- let padding = CGFloat(5.0)
-
- var color: Color {
- MapColor.colorForScheme(colorScheme).foreground
- }
-
- 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, lineWidth: lineWidth * 2)
-
- // Y Labels
- Text("Visible").font(.title3).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
- .offset(CGSize(width: -35.0, height: 0.0))
- Text("Value Chain").font(.title).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
- .offset(CGSize(width: -72.0, height: mapSize.height / 2 - 20))
- Text("Invisible").font(.title3).foregroundColor(color).rotationEffect(Angle(degrees: -90.0))
- .offset(CGSize(width: -40.0, height: mapSize.height - 20))
-
- // X Labels
-
- Text("Uncharted")
- .font(.title3)
- .foregroundColor(color)
- .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading)
- .offset(CGSize(width: 0.0, height: -stageHeight / 4.0))
- Text("Industrialised")
- .font(.title3)
- .foregroundColor(color)
- .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(.title3)
- .foregroundColor(color)
- .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading)
- .offset(CGSize(width: 0.0, height: mapSize.height + padding))
-
- Text(evolution.ii)
- .font(.title3)
- .foregroundColor(color)
- .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(.title3)
- .foregroundColor(color)
- .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(.title3)
- .foregroundColor(color)
- .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))
- }
-}
-
-struct MapAxes_Previews: PreviewProvider {
- static var previews: some View {
- 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)
- }
-}
diff --git a/Map/MapRenderComponents/MapBlockers.swift b/Map/MapRenderComponents/MapBlockers.swift
deleted file mode 100644
index b668b30..0000000
--- a/Map/MapRenderComponents/MapBlockers.swift
+++ /dev/null
@@ -1,49 +0,0 @@
-import SwiftUI
-
-struct MapBlockers: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let vertexSize: CGSize
- let blockers: [Blocker]
-
- var color: Color {
- MapColor.colorForScheme(colorScheme).blocker
- }
-
- let cornerSize = CGSize(width: 2.0, height: 2.0)
-
- var body: some View {
- ForEach(blockers, id: \.id) { vertex in
- Path { path in
- path.addRoundedRect(
- in: CGRect(
- origin: CGPoint(
- x: w(vertex.position.x) + 3 * vertexSize.width,
- y: h(vertex.position.y) - vertexSize.height * 2 / 3),
- size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2)
- ), cornerSize: cornerSize)
- }.fill(color)
- }
- }
-
- func h(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
-}
-
-struct MapBlockers_Previews: PreviewProvider {
- static var previews: some View {
- MapBlockers(
- mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
- blockers: [
- Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)),
- Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)),
- ])
- }
-}
diff --git a/Map/MapRenderComponents/MapEdges.swift b/Map/MapRenderComponents/MapEdges.swift
deleted file mode 100644
index d40d2aa..0000000
--- a/Map/MapRenderComponents/MapEdges.swift
+++ /dev/null
@@ -1,92 +0,0 @@
-//
-// MapEdges.swift
-// Map
-//
-// Created by Ruben Beltran del Rio on 2/2/21.
-//
-
-import SwiftUI
-
-struct MapEdges: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let lineWidth: CGFloat
- let vertexSize: CGSize
- let edges: [MapEdge]
-
- let arrowheadSize = CGFloat(10.0)
-
- var color: Color {
- MapColor.colorForScheme(colorScheme).foreground
- }
-
- var body: some View {
- ForEach(edges, id: \.id) { edge in
- Path { path in
-
- // First we transform edges from percentage to map coordinates
- let origin = CGPoint(x: w(edge.origin.x), y: h(edge.origin.y))
- let destination = CGPoint(x: w(edge.destination.x), y: h(edge.destination.y))
-
- let slope = (destination.y - origin.y) / (destination.x - origin.x)
- let angle = atan(slope)
- let multiplier = CGFloat(slope < 0 ? -1.0 : 1.0)
- let upperAngle = angle - CGFloat.pi / 4.0
- let lowerAngle = angle + CGFloat.pi / 4.0
-
- let offsetOrigin = CGPoint(
- x: origin.x + multiplier * (vertexSize.width / 2.0) * cos(angle),
- y: origin.y + multiplier * (vertexSize.height / 2.0) * sin(angle))
- let offsetDestination = CGPoint(
- x: destination.x - multiplier * (vertexSize.width / 2.0) * cos(angle),
- y: destination.y - multiplier * (vertexSize.height / 2.0) * sin(angle))
-
- path.move(to: offsetOrigin)
- path.addLine(to: offsetDestination)
-
- if edge.arrowhead {
- path.move(to: offsetDestination)
- path.addLine(
- to: CGPoint(
- x: offsetDestination.x - multiplier * arrowheadSize * cos(upperAngle),
- y:
- offsetDestination.y - multiplier * arrowheadSize * sin(upperAngle)))
-
- path.move(to: offsetDestination)
- path.addLine(
- to: CGPoint(
- x: offsetDestination.x - multiplier * arrowheadSize * cos(lowerAngle),
- y:
- offsetDestination.y - multiplier * arrowheadSize * sin(lowerAngle)))
- }
- path.move(to: offsetDestination)
- path.closeSubpath()
- }.applying(
- CGAffineTransform(translationX: vertexSize.width / 2.0, y: vertexSize.height / 2.0)
- ).stroke(color, lineWidth: lineWidth)
- }
- }
-
- func h(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
-}
-
-struct MapEdges_Previews: PreviewProvider {
- static var previews: some View {
- MapEdges(
- mapSize: CGSize(width: 400.0, height: 400.0), lineWidth: 1.0,
- vertexSize: CGSize(width: 25.0, height: 25.0),
- edges: [
- MapEdge(
- id: 1, origin: CGPoint(x: 2.0, y: 34.0), destination: CGPoint(x: 23.0, y: 76.2),
- arrowhead: true)
- ])
- }
-}
diff --git a/Map/MapRenderComponents/MapOpportunities.swift b/Map/MapRenderComponents/MapOpportunities.swift
deleted file mode 100644
index 68d3fb5..0000000
--- a/Map/MapRenderComponents/MapOpportunities.swift
+++ /dev/null
@@ -1,84 +0,0 @@
-//
-// MapEdges.swift
-// Map
-//
-// Created by Ruben Beltran del Rio on 2/2/21.
-//
-
-import SwiftUI
-
-struct MapOpportunities: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let lineWidth: CGFloat
- let vertexSize: CGSize
- let opportunities: [Opportunity]
-
- let arrowheadSize = CGFloat(10.0)
-
- var color: Color {
- MapColor.colorForScheme(colorScheme).opportunity
- }
-
- var body: some View {
- ForEach(opportunities, id: \.id) { edge in
- Path { path in
-
- // First we transform edges from percentage to map coordinates
- let origin = CGPoint(x: w(edge.origin.x), y: h(edge.origin.y))
- let destination = CGPoint(x: w(edge.destination.x), y: h(edge.destination.y))
-
- let multiplier = CGFloat(edge.destination.x > edge.origin.x ? 1.0 : -1.0)
- let upperAngle = -CGFloat.pi / 4.0
- let lowerAngle = CGFloat.pi / 4.0
-
- let offsetOrigin = CGPoint(x: origin.x + multiplier * (vertexSize.width / 2.0), y: origin.y)
- let offsetDestination = CGPoint(
- x: destination.x - multiplier * (vertexSize.width / 2.0), y: destination.y)
-
- path.move(to: offsetOrigin)
- path.addLine(to: offsetDestination)
-
- path.move(to: offsetDestination)
- path.addLine(
- to: CGPoint(
- x: offsetDestination.x - multiplier * arrowheadSize * cos(upperAngle),
- y:
- offsetDestination.y - multiplier * arrowheadSize * sin(upperAngle)))
-
- path.move(to: offsetDestination)
- path.addLine(
- to: CGPoint(
- x: offsetDestination.x - multiplier * arrowheadSize * cos(lowerAngle),
- y:
- offsetDestination.y - multiplier * arrowheadSize * sin(lowerAngle)))
-
- path.move(to: offsetDestination)
- path.closeSubpath()
- }.applying(
- CGAffineTransform(translationX: vertexSize.width / 2.0, y: vertexSize.height / 2.0)
- ).strokedPath(StrokeStyle(lineWidth: lineWidth * 2, dash: [10.0])).stroke(color)
- }
- }
-
- func h(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
-}
-
-struct MapOpportunities_Previews: PreviewProvider {
- static var previews: some View {
- MapOpportunities(
- mapSize: CGSize(width: 400.0, height: 400.0), lineWidth: 1.0,
- vertexSize: CGSize(width: 25.0, height: 25.0),
- opportunities: [
- Opportunity(id: 1, origin: CGPoint(x: 2.0, y: 34.0), destination: CGPoint(x: 23.0, y: 76.2))
- ])
- }
-}
diff --git a/Map/MapRenderComponents/MapStages.swift b/Map/MapRenderComponents/MapStages.swift
deleted file mode 100644
index 052a315..0000000
--- a/Map/MapRenderComponents/MapStages.swift
+++ /dev/null
@@ -1,60 +0,0 @@
-import SwiftUI
-
-struct MapStages: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let lineWidth: CGFloat
- let stages: [CGFloat]
- let opacity = 0.1
-
- var color: MapColor {
- MapColor.colorForScheme(colorScheme)
- }
-
- var body: some View {
-
- ZStack(alignment: .topLeading) {
- Path { path in
- path.addRect(CGRect(x: 0, y: 0, width: w(stages[0]), height: mapSize.height))
- }.fill(color.stages.i)
- Path { path in
- path.addRect(
- CGRect(x: w(stages[0]), y: 0, width: w(stages[1]) - w(stages[0]), height: mapSize.height))
- }.fill(color.stages.ii)
- Path { path in
- path.addRect(
- CGRect(x: w(stages[1]), y: 0, width: w(stages[2]) - w(stages[1]), height: mapSize.height))
- }.fill(color.stages.iii)
- Path { path in
- path.addRect(
- CGRect(x: w(stages[2]), y: 0, width: mapSize.width - w(stages[2]), height: mapSize.height)
- )
- }.fill(color.stages.iv)
-
- Path { path in
- path.move(to: CGPoint(x: w(stages[0]), y: 0))
- path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height))
- path.move(to: CGPoint(x: w(stages[1]), y: 0))
- path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height))
- path.move(to: CGPoint(x: w(stages[2]), y: 0))
- path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height))
- path.move(to: CGPoint(x: w(stages[0]), y: 0))
- path.closeSubpath()
- }.strokedPath(StrokeStyle(lineWidth: lineWidth, dash: [10.0])).stroke(color.foreground)
- }
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
-}
-
-struct MapStages_Previews: PreviewProvider {
- static var previews: some View {
- MapStages(
- mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0),
- stages: [25.0, 50.0, 75.0])
- }
-}
diff --git a/Map/MapRenderComponents/MapVertices.swift b/Map/MapRenderComponents/MapVertices.swift
deleted file mode 100644
index 24d49b8..0000000
--- a/Map/MapRenderComponents/MapVertices.swift
+++ /dev/null
@@ -1,90 +0,0 @@
-import SwiftUI
-
-struct MapVertices: View {
-
- @Environment(\.colorScheme) var colorScheme
-
- let mapSize: CGSize
- let vertexSize: CGSize
- let vertices: [Vertex]
- let padding = CGFloat(4.0)
-
- var color: MapColor {
- MapColor.colorForScheme(colorScheme)
- }
-
- var body: some View {
- ForEach(vertices, id: \.id) { vertex in
- getVertexShape(vertex).fill(color.foreground)
- Text(vertex.label).foregroundColor(color.secondary).offset(
- CGSize(
- width: w(vertex.position.x) + vertexSize.width + padding,
- height: h(vertex.position.y)))
- }
- }
-
- func h(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
- }
-
- func w(_ dimension: CGFloat) -> CGFloat {
- max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
- }
-
- func getVertexShape(_ vertex: Vertex) -> Path {
- switch vertex.shape {
- case .circle:
- return Path { path in
- path.addEllipse(
- in: CGRect(
- origin: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y)), size: vertexSize
- ))
- }
- case .square:
- return Path { path in
- path.addRect(
- CGRect(
- x: w(vertex.position.x), y: h(vertex.position.y), width: vertexSize.width,
- height: vertexSize.height
- ))
- }
- case .triangle:
- return Path { path in
- path.move(to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y) + vertexSize.height))
- path.addLine(
- to: CGPoint(
- x: w(vertex.position.x) + vertexSize.width, y: h(vertex.position.y) + vertexSize.height)
- )
- path.addLine(
- to: CGPoint(x: w(vertex.position.x) + vertexSize.width / 2.0, y: h(vertex.position.y)))
- path.addLine(
- to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y) + vertexSize.height))
- path.closeSubpath()
- }
- case .x:
- return Path { path in
- path.move(to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y)))
- path.addLine(
- to: CGPoint(
- x: w(vertex.position.x) + vertexSize.width, y: h(vertex.position.y) + vertexSize.height)
- )
- path.closeSubpath()
- path.move(to: CGPoint(x: w(vertex.position.x) + vertexSize.width, y: h(vertex.position.y)))
- path.addLine(
- to: CGPoint(x: w(vertex.position.x), y: h(vertex.position.y) + vertexSize.height))
- path.closeSubpath()
- }.strokedPath(StrokeStyle(lineWidth: 5.0, lineCap: .butt))
- }
- }
-}
-
-struct MapVertices_Previews: PreviewProvider {
- static var previews: some View {
- MapVertices(
- mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
- vertices: [
- Vertex(id: 0, label: "A", position: CGPoint(x: 50.0, y: 50.0)),
- Vertex(id: 0, label: "A", position: CGPoint(x: 10.0, y: 20.0)),
- ])
- }
-}