Local debugging switches
[bus.git] / origin-src / marey_graph.pyc
1
2
3
4
5 Marey graphs are a visualization form typically used for timetables. Time
6 is on the x-axis and position on the y-axis. This module reads data from a
7 transitfeed.Schedule and creates a marey graph in svg/xml format. The graph
8 shows the speed between stops for each trip of a route.
9
10 TODO: This module was taken from an internal Google tool. It works but is not
11 well intergrated into transitfeed and schedule_viewer. Also, it has lots of
12 ugly hacks to compensate set canvas size and so on which could be cleaned up.
13
14 For a little more information see (I didn't make this URL ;-)
15 http://transliteracies.english.ucsb.edu/post/research-project/research-clearinghouse-individual/research-reports/the-indexical-imagination-marey%e2%80%99s-graphic-method-and-the-technological-transformation-of-writing-in-the-nineteenth-century
16
17 MareyGraph: Class, keeps cache of graph data and graph properties
18 and draws marey graphs in svg/xml format on request.
19
20
21
22
23
24
25
26
27 g}n|p
28
29
30
31 If called without arguments, the data generated in the previous call
32 will be used. New decorators can be added between calls.
33
34 Args:
35 # Class Stop is defined in transitfeed.py
36 stoplist: [Stop, Stop, ...]
37 # Class Trip is defined in transitfeed.py
38 triplist: [Trip, Trip, ...]
39
40 Returns:
41 # A string that contain a svg/xml web-page with a marey graph.
42 " <svg width="1440" height="520" version="1.1" ... "
43 s %s %s %s %s(RRt_gheightRt_slistRt_BuildStationsRt_DrawBoxt
44 _DrawHourst _DrawStationst
45 _DrawTripst _DrawHeadert_DrawDecoratorst _DrawFooter(Rtstoplistttriplisttheighttoutput((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pytDrawHs( 
46 
47          cCsKd|i|id|id|i|id|i|i|if}|S(NsY
48 <svg width="%s" height="%s" version="1.1"
49 xmlns="http://www.w3.org/2000/svg">
50 <script type="text/ecmascript"><![CDATA[
51 function init(evt) {
52 if ( window.svgDocument == null )
53 svgDocument = evt.target.ownerDocument;
54 }
55 var oldLine = 0;
56 var oldStroke = 0;
57 var hoffset= %s; // Data from python
58
59 function parseLinePoints(pointnode){
60 var wordlist = pointnode.split(" ");
61 var xlist = new Array();
62 var h;
63 var m;
64 // TODO: add linebreaks as appropriate
65 var xstr = " Stop Times :";
66 for (i=0;i<wordlist.length;i=i+2){
67 var coord = wordlist[i].split(",");
68 h = Math.floor(parseInt((coord[0])-20)/60);
69 m = parseInt((coord[0]-20))%%60;
70 xstr = xstr +" "+ (hoffset+h) +":"+m;
71 }
72
73 return xstr;
74 }
75
76 function LineClick(tripid, x) {
77 var line = document.getElementById(tripid);
78 if (oldLine)
79 oldLine.setAttribute("stroke",oldStroke);
80 oldLine = line;
81 oldStroke = line.getAttribute("stroke");
82
83 line.setAttribute("stroke","#fff");
84
85 var dynTxt = document.getElementById("dynamicText");
86 var tripIdTxt = document.createTextNode(x);
87 while (dynTxt.hasChildNodes()){
88 dynTxt.removeChild(dynTxt.firstChild);
89 }
90 dynTxt.appendChild(tripIdTxt);
91 }
92 ]]> </script>
93 <style type="text/css"><![CDATA[
94 .T { fill:none; stroke-width:1.5 }
95 .TB { fill:none; stroke:#e20; stroke-width:2 }
96 .Station { fill:none; stroke-width:1 }
97 .Dec { fill:none; stroke-width:1.5 }
98 .FullHour { fill:none; stroke:#eee; stroke-width:1 }
99 .SubHour { fill:none; stroke:#ddd; stroke-width:1 }
100 .Label { fill:#aaa; font-family:Helvetica,Arial,sans;
101 text-anchor:middle }
102 .Info { fill:#111; font-family:Helvetica,Arial,sans;
103 text-anchor:start; }
104 ]]></style>
105 <text class="Info" id="dynamicText" x="0" y="%d"></text>
106 <g id="mcanvas" transform="translate(%s,%s)">
107 <g id="zcanvas" transform="scale(%s)">
108
109 iii
110 (RR RR RR (Rt
111
112 fill="lightgrey" stroke="%s" stroke-width="2" />
113
114
115 Args:
116 # Class Stop is defined in transitfeed.py
117 stoplist: [Stop, Stop, ...]
118 # Class Trip is defined in transitfeed.py
119 triplist: [Trip, Trip, ...]
120
121 Returns:
122 # One integer y-coordinate for each station normalized between
123 # 0 and X, where X is the height of the graph in pixels
124 [0, 33, 140, ... , X]
125
126
127 Uses the stoplists long/lats to approximate distances
128 between stations and build a list with y-coordinates for the
129 horizontal lines in the graph.
130
131 Args:
132 # Class Stop is defined in transitfeed.py
133 stoplist: [Stop, Stop, ...]
134
135 Returns:
136 # One integer for each pair of stations
137 # indicating the approximate distance
138 [0,33,140, ... ,X]
139
140
141
142 Args:
143 # One integer for each pair of stations
144 # indicating the approximate distance
145 dists: [0,33,140, ... ,X]
146
147 Returns:
148 # One integer y-coordinate for each station normalized between
149 # 0 and X, where X is the height of the graph in pixels
150 [0, 33, 140, ... , X]
151 ii(tsumtfloatRt enumeratetint(
152 RR)ttot_distR/tdt
153 pixel_distt_[2]titpdt
154
155
156 Uses a timetable to approximate distances
157 between stations
158
159 Args:
160 # Class Trip is defined in transitfeed.py
161 triplist: [Trip, Trip, ...]
162 # (Optional) Index of Triplist prefered for timetable Calculation
163 index: 3
164
165 Returns:
166 # One integer for each pair of stations
167 # indicating the approximate distance
168 [0,33,140, ... ,X]
169
170   iiii(tlenR*R+t GetTimeStops( RRtindexRBttripR/R0R1tt_dists2((RsO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyt _TravelTimess$
171 McCs |GHdS(N((RR((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyt _AddWarning&stc
172
173
174
175 d
176
177
178 Args:
179 # Class Trip is defined in transitfeed.py
180 [Trip, Trip, ...]
181
182 Returns:
183 # A string containing a polyline tag for each trip
184 ' <polyline class="T" stroke="#336633" points="433,0 ...'
185
186 service_idtappendR6RERCthexRDR5ttrip_idR,tFormatSecondsSinceMidnightt GetStartTimeRtNoneR
187 R R$(RRtcolparR(ttmpstrstservlisttttshadetcolort start_offsetst
188 first_stoptjt freq_offsett
189 scriptcallt
190 tmpstrheadR;tstarr_ttdep_ttarr_xtdep_x((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyR)sV 
191  
192    *  
193    
194 
195
196
197 Args:
198 # Class Stop is defined in transitfeed.py
199 stations: [Stop, Stop, ...]
200
201 Returns:
202 # A string containing a polyline tag for each stop
203 " <polyline class="Station" stroke="#336633" points="20,0 ..."
204
205
206 Returns:
207 # A string containing a polyline tag for each grid line
208 " <polyline class="FullHour" points="20,0 ..."
209
210 RNRR R$(RRUR;((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyR{s ' 
211
212
213
214 Args:
215 # Integer, index of stop to be highlighted.
216 index: 4
217 # An optional string with a html color code
218 color: "#fff"
219
220
221
222 Args:
223 # Class Trip is defined in transitfeed.py
224 triplist: [Trip, Trip, ...]
225 # An optional string with a html color code
226 color: "#fff"
227
228
229 1.0 is the original canvas size.
230
231 Args:
232 # float value between 0.0 and 5.0
233 newfactor: 0.7
234
235
236
237 N(t__name__t
238 __module__t__doc__RmR>RRSR!RRRRRR&R'RHRIRRLRRRkRlRoRpRqRrRtR|(((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyR(s4 ) E       $  :        ((RR*R,R(((sO/var/www/busstop/origin-src/transitfeed-1.2.5/gtfsscheduleviewer/marey_graph.pyt<module>"s