remove intermediate level routeparts
This commit is contained in:
parent
d6736670d4
commit
1e46ee10ae
3 changed files with 49 additions and 31 deletions
|
@ -19,37 +19,50 @@ class Route:
|
||||||
def routeparts(self):
|
def routeparts(self):
|
||||||
routeparts = []
|
routeparts = []
|
||||||
connections = []
|
connections = []
|
||||||
|
add_connections = []
|
||||||
level = self.connections[0].from_point.level
|
level = self.connections[0].from_point.level
|
||||||
|
|
||||||
for connection in self.connections:
|
for connection in self.connections:
|
||||||
connections.append(connection)
|
connections.append(connection)
|
||||||
point = connection.to_point
|
point = connection.to_point
|
||||||
if point.level and point.level != level:
|
if point.level and point.level != level:
|
||||||
routeparts.append(RoutePart(level, connections))
|
if routeparts:
|
||||||
|
routeparts[-1].connections.extend(connections[:1])
|
||||||
|
routeparts.append(RoutePart(level, add_connections+connections))
|
||||||
level = point.level
|
level = point.level
|
||||||
connections = [connection]
|
add_connections = connections[-3:]
|
||||||
|
connections = []
|
||||||
|
|
||||||
if connections:
|
if connections:
|
||||||
routeparts.append(RoutePart(level, connections))
|
if routeparts:
|
||||||
|
routeparts[-1].connections.extend(connections[:1])
|
||||||
|
routeparts.append(RoutePart(level, add_connections+connections))
|
||||||
|
|
||||||
|
routeparts = [routepart for routepart in routeparts if not routepart.level.intermediate]
|
||||||
|
|
||||||
|
for routepart in routeparts:
|
||||||
|
routepart.render_svg_coordinates()
|
||||||
|
|
||||||
return tuple(routeparts)
|
return tuple(routeparts)
|
||||||
|
|
||||||
|
|
||||||
class RoutePart:
|
class RoutePart:
|
||||||
def __init__(self, level, connections):
|
def __init__(self, graphlevel, connections):
|
||||||
self.level = level
|
self.graphlevel = graphlevel
|
||||||
self.level_name = level.level.name
|
self.level = graphlevel.level
|
||||||
self.connections = connections
|
self.connections = connections
|
||||||
|
|
||||||
|
def render_svg_coordinates(self):
|
||||||
svg_width, svg_height = get_dimensions()
|
svg_width, svg_height = get_dimensions()
|
||||||
|
|
||||||
points = (connections[0].from_point, ) + tuple(connection.to_point for connection in connections)
|
points = (self.connections[0].from_point, ) + tuple(connection.to_point for connection in self.connections)
|
||||||
for point in points:
|
for point in points:
|
||||||
point.svg_x = point.x * 6
|
point.svg_x = point.x * 6
|
||||||
point.svg_y = (svg_height - point.y) * 6
|
point.svg_y = (svg_height - point.y) * 6
|
||||||
|
|
||||||
x, y = zip(*((point.svg_x, point.svg_y) for point in points if point.level == level))
|
x, y = zip(*((point.svg_x, point.svg_y) for point in points if point.level == self.graphlevel))
|
||||||
|
|
||||||
self.distance = sum(connection.distance for connection in connections)
|
self.distance = sum(connection.distance for connection in self.connections)
|
||||||
|
|
||||||
# bounds for rendering
|
# bounds for rendering
|
||||||
self.svg_min_x = min(x) - 20
|
self.svg_min_x = min(x) - 20
|
||||||
|
|
|
@ -2,29 +2,34 @@
|
||||||
|
|
||||||
<h2>Your Route</h2>
|
<h2>Your Route</h2>
|
||||||
<div class="routeparts">
|
<div class="routeparts">
|
||||||
|
|
||||||
{% for routepart in route.routeparts %}
|
{% for routepart in route.routeparts %}
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="map" data-level="{{ routepart.level_name }}"
|
<div class="row">
|
||||||
viewBox="0 0 {{ routepart.svg_width | stringformat:"f" }} {{ routepart.svg_height | stringformat:"f" }}"
|
<div class="form-group col-md-6">
|
||||||
style="max-height:{% if routepart.svg_height > 300 %}300{% else %}{{ routepart.svg_height | stringformat:"f" }}{% endif %}px">
|
<svg xmlns="http://www.w3.org/2000/svg" class="map" data-level="{{ routepart.level.name }}"
|
||||||
<defs>
|
viewBox="0 0 {{ routepart.svg_width | stringformat:"f" }} {{ routepart.svg_height | stringformat:"f" }}"
|
||||||
<marker id="arrow-{{ forloop.counter0 }}" markerWidth="4" markerHeight="4" refX="2.5" refY="2" orient="auto">
|
style="max-height:{% if routepart.svg_height > 300 %}300{% else %}{{ routepart.svg_height | stringformat:"f" }}{% endif %}px">
|
||||||
<path d="M0,0 L3,2 L0,4 L0,0" style="fill: #FF0000; stroke: 0;"></path>
|
<defs>
|
||||||
</marker>
|
<marker id="arrow-{{ forloop.counter0 }}" markerWidth="4" markerHeight="4" refX="2.5" refY="2" orient="auto">
|
||||||
</defs>
|
<path d="M0,0 L3,2 L0,4 L0,0" style="fill: #FF0000; stroke: 0;"></path>
|
||||||
|
</marker>
|
||||||
|
</defs>
|
||||||
|
|
||||||
<image width="{{ svg_width | stringformat:"f" }}" height="{{ svg_height | stringformat:"f" }}"
|
<image width="{{ svg_width | stringformat:"f" }}" height="{{ svg_height | stringformat:"f" }}"
|
||||||
x="{{ routepart.svg_min_x | negate | stringformat:"f" }}" y="{{ routepart.svg_min_y | negate | stringformat:"f" }}"
|
x="{{ routepart.svg_min_x | negate | stringformat:"f" }}" y="{{ routepart.svg_min_y | negate | stringformat:"f" }}"
|
||||||
xlink:href="/map/{{ routepart.level_name }}.png"></image>
|
xlink:href="/map/{{ routepart.level.name }}.png"></image>
|
||||||
|
|
||||||
<g class="connections">
|
<g class="connections">
|
||||||
{% for c in routepart.connections %}
|
{% for c in routepart.connections %}
|
||||||
<line x1="{{ c.from_point.svg_x | subtract:routepart.svg_min_x | stringformat:"f"}}"
|
<line x1="{{ c.from_point.svg_x | subtract:routepart.svg_min_x | stringformat:"f"}}"
|
||||||
y1="{{ c.from_point.svg_y | subtract:routepart.svg_min_y | stringformat:"f" }}"
|
y1="{{ c.from_point.svg_y | subtract:routepart.svg_min_y | stringformat:"f" }}"
|
||||||
x2="{{ c.to_point.svg_x | subtract:routepart.svg_min_x | stringformat:"f" }}"
|
x2="{{ c.to_point.svg_x | subtract:routepart.svg_min_x | stringformat:"f" }}"
|
||||||
y2="{{ c.to_point.svg_y | subtract:routepart.svg_min_y | stringformat:"f" }}"
|
y2="{{ c.to_point.svg_y | subtract:routepart.svg_min_y | stringformat:"f" }}"
|
||||||
marker-end="url(#arrow-{{ forloop.parentloop.counter0 }})"></line>
|
marker-end="url(#arrow-{{ forloop.parentloop.counter0 }})"></line>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -21,7 +21,7 @@ ctype_mapping = {
|
||||||
|
|
||||||
|
|
||||||
def get_ctypes(prefix, value):
|
def get_ctypes(prefix, value):
|
||||||
return tuple((prefix+'_'+direction) for direction in ctype_mapping.get(value, ('up', 'dowm')))
|
return tuple((prefix+'_'+direction) for direction in ctype_mapping.get(value, ('up', 'down')))
|
||||||
|
|
||||||
|
|
||||||
def main(request, origin=None, destination=None):
|
def main(request, origin=None, destination=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue