-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrawGraph.lua
201 lines (192 loc) · 7.73 KB
/
drawGraph.lua
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function stationInMain(stationName)
for i=1, numStops[currentTimeTable] do
if stationName == timeTableData[currentTimeTable][i*timeTableFileLength] then
return i
end
end
return 0
end
function drawGraph()
--Figure out graph dimensions
local graphX, graphY
graphX = windowWidth - 260
graphY = windowHeight - 60
love.graphics.setColor( 0,0,0)
local stationPos = {}
stationPos[0] = 0
for i=1, numStops[currentTimeTable] do
stationPos[i] = stationPos[i-1] + tonumber(timeTableData[currentTimeTable][i*timeTableFileLength+1])
end
local minDist
if spaceLimits[1] == 0 then
minDist = math.min(unpack(stationPos))
else
minDist = stationPos[spaceLimits[1]]
end
for i=1, numStops[currentTimeTable] do
stationPos[i] = stationPos[i]-minDist--fixes lowest at 0
end
local maxDist
if spaceLimits[2] == 0 then
maxDist = math.max(unpack(stationPos))
else
maxDist = stationPos[spaceLimits[2]]
end
-- local spaceScale =
for i=1, numStops[currentTimeTable] do
stationPos[i] = math.ceil(stationPos[i]*(graphY-1)/maxDist)--scales it so highest is at graphY
end
for i=1, numStops[currentTimeTable] do
stationPos[i] = stationPos[i] + 1
end
local deltaTime = timeLimits[2]-timeLimits[1]
if deltaTime <= 0 then
deltaTime = 24 + deltaTime
end
local timeWidth = graphX/(deltaTime*60)
for i=0, deltaTime do
local printTime = (timeLimits[1]+i)%24
if printTime == 0 or printTime == 12 then
love.graphics.setColor( 81/255,81/255,81/255)
else
love.graphics.setColor( 48/255,48/255,48/255)
end
love.graphics.line( 251+math.ceil(i*graphX/deltaTime), 10, 251+math.ceil(i*graphX/deltaTime), 10+graphY )
if timeWidth >= 2 then
love.graphics.line( 251+math.ceil((i+0.5)*graphX/deltaTime), 10, 251+math.ceil((i+0.5)*graphX/deltaTime), 10+graphY )
end
end
for i=1, numStops[currentTimeTable] do
love.graphics.setColor( 48/255,48/255,48/255)
love.graphics.line( 252, 10+stationPos[i], 252+graphX, 10+stationPos[i] )
end
--Draw lines
love.graphics.setLineWidth( 2 )
for n=1, numTimeTables do
local startTime = math.floor(tonumber(timeTableData[0][n*masterFileLength+3])/100)*60+tonumber(timeTableData[0][n*masterFileLength+3])%100
local repeatTime = math.floor(tonumber(timeTableData[0][n*masterFileLength+4])/100)*60+tonumber(timeTableData[0][n*masterFileLength+4])%100
local maxTime = math.floor(tonumber(timeTableData[0][n*masterFileLength+5])/100)*60+tonumber(timeTableData[0][n*masterFileLength+5])%100
love.graphics.setColor( lineColour[tonumber(timeTableData[0][n*masterFileLength+2])] )
local currentStartTime = startTime
for k=0, 200 do
local currentTime
if repeatTime == 0 then
currentTime = currentStartTime
else
currentTime = currentStartTime+repeatTime*k
if maxTime < startTime then
if currentTime%1440 > maxTime and currentTime%1440 < startTime then
break
end
else
if currentTime%1440 > maxTime or currentTime%1440 < startTime then
break
end
end
end
currentTime = currentTime - timeLimits[1]*60
--Draw lines
if n == currentTimeTable then
local prevTime = currentTime
for i=1, numStops[n]-1 do
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i+1)*timeTableFileLength+2])
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[i], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[i+1] )
end
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i+1)*timeTableFileLength+3])
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[i+1], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[i+1] )
end
end
if timeTableData[0][n*masterFileLength+6] == 1 then
for i=numStops[n]-1, 1, -1 do
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i)*timeTableFileLength+4])
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[i+1], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[i] )
end
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i)*timeTableFileLength+5])
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[i], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[i] )
end
end
end
if repeatTime == 0 then
break
end
else--for other timetables
local prevTime = currentTime
for i=1, numStops[n]-1 do
local thisStation = stationInMain(timeTableData[n][i*timeTableFileLength])
local nextStation = stationInMain(timeTableData[n][(i+1)*timeTableFileLength])
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i+1)*timeTableFileLength+2])
if thisStation ~= 0 and nextStation ~= 0 then
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[thisStation], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[nextStation] )
end
end
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i+1)*timeTableFileLength+3])
if thisStation ~= 0 and nextStation ~= 0 then
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[nextStation], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[nextStation] )
end
elseif nextStation ~= 0 then
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[nextStation], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[nextStation] )
end
end
end
if timeTableData[0][n*masterFileLength+6] == 1 then
for i=numStops[n]-1, 1, -1 do
local thisStation = stationInMain(timeTableData[n][i*timeTableFileLength])
local nextStation = stationInMain(timeTableData[n][(i+1)*timeTableFileLength])
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i)*timeTableFileLength+4])
if thisStation ~= 0 and nextStation ~= 0 then
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[nextStation], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[thisStation] )
end
end
prevTime = currentTime
currentTime = currentTime + tonumber(timeTableData[n][(i)*timeTableFileLength+5])
if thisStation ~= 0 then
for j=-1, 1 do
love.graphics.line( 251+((prevTime+1440*j)*timeWidth), 10+stationPos[thisStation], 251+((currentTime+1440*j)*timeWidth), 10+stationPos[thisStation] )
end
end
end
end
if repeatTime == 0 then
break
end
end
end
end
love.graphics.setLineWidth( 1 )
--Cover up everything out of bounds
love.graphics.setColor( 152/255, 132/255, 92/255)
love.graphics.rectangle( "fill", 0, 0, 250, windowHeight )
love.graphics.rectangle( "fill", 250, 0, windowWidth-250, 10 )
love.graphics.rectangle( "fill", 250, windowHeight-50, windowWidth-250, 50 )
love.graphics.rectangle( "fill", windowWidth-10, 10, windowWidth-10, windowHeight-50 )
--Draw station names (do last)
for i=1, numStops[currentTimeTable] do
if stationPos[i] >= 10 or stationPos[i] <= windowHeight-35 then
love.graphics.setColor( 0,0,0)
love.graphics.line( 250, 10+stationPos[i], 247, 10+stationPos[i] )
love.graphics.printf(timeTableData[currentTimeTable][i*timeTableFileLength], 96, 4+stationPos[i], 150, "right")
end
end
for i=0, deltaTime do
love.graphics.setColor( 0,0,0)
local printTime = (timeLimits[1]+i)%24
love.graphics.printf(printTime, 241+math.ceil(i*graphX/deltaTime), 8+graphY, 20, "center")
love.graphics.printf(printTime, 241+math.ceil(i*graphX/deltaTime), -1, 20, "center")
end
love.graphics.setColor( lineColour[tonumber(timeTableData[0][currentTimeTable*masterFileLength+2])] )
end