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