Package sabx10 :: Package osm :: Module legend
[hide private]
[frames] | no frames]

Module legend

source code

Generate and place the map legend. Look for a space in the map that doesn't have any route items on it. Cheat by splitting the map into 9 squares (3x3) and check each square for ride items intersecting it. Choose the square with the least intersections, or an arbitrary one if there is a tie.

Classes [hide private]
  LegendNode
Holds one item in the legend, one item per legend line.
Functions [hide private]
float,float,float,float,float,float
_calc_box_lats(ride, legend_height)
Split the map into three equal pieces going top to bottom.
source code
float,float,float,float,float,float
_calc_box_lons(ride, legend_width)
Split the map into three equal pieces going left to right.
source code
list of Box
_create_legend_boxes(ride, legend_width, legend_height)
Create the boxes to check against.
source code
 
_check_boxes_for_point(boxes, lat, lon)
Check the list of boxes to see which ones the point is in.
source code
 
_check_boxes(boxes, ride)
Check the list of boxes against all the point items in the ride.
source code
list of Box
_find_legend_box(ride, legend_width, legend_height)
Check the map for a space to place the legend.
source code
LegendNode,float,float
_gen_legend_item(lat, lon, text, dist, node_id)
Generate a LegendNode, and calculate a point below it.
source code
 
generate_legend(the_ride, title, node_id)
Generate the legend items for the map for the given ride.
source code
Variables [hide private]
  __package__ = 'sabx10.osm'
Function Details [hide private]

_calc_box_lats(ride, legend_height)

source code 

Split the map into three equal pieces going top to bottom.

Parameters:
  • ride (Ride) - ride representing map to split
  • legend_height (float) - height of legend
Returns: float,float,float,float,float,float
bottom min, bottom max, middle min, middle max, top min, top max

_calc_box_lons(ride, legend_width)

source code 

Split the map into three equal pieces going left to right.

Parameters:
  • ride (Ride) - ride representing map to split
  • legend_width (float) - width of legend
Returns: float,float,float,float,float,float
left min, left max, middle min, middle max, right min, right max

_create_legend_boxes(ride, legend_width, legend_height)

source code 

Create the boxes to check against. This is a 3x3 grid splitting the map into equal spaces.

Parameters:
  • ride (Ride) - ride representing map to split
  • legend_width (float) - width of legend
  • legend_height (float) - height of legend
Returns: list of Box
list of boxes

_check_boxes_for_point(boxes, lat, lon)

source code 

Check the list of boxes to see which ones the point is in. It really should only be in one box since we divided the map evenly.

Parameters:
  • boxes (list of Box) - list of boxes to check
  • lat (float) - latitude of point to check
  • lon (float) - longitude of point to check

_check_boxes(boxes, ride)

source code 

Check the list of boxes against all the point items in the ride. This includes segment waypoints, stops, pois, and parking.

Parameters:
  • boxes (list of Box) - list of boxes to check
  • ride (Ride) - ride representing map to check

_find_legend_box(ride, legend_width, legend_height)

source code 

Check the map for a space to place the legend.

Parameters:
  • ride (Ride) - ride representing map to check
  • legend_width (float) - width of legend
  • legend_height (float) - height of legend
Returns: list of Box
list of boxes in order of goodness

_gen_legend_item(lat, lon, text, dist, node_id)

source code 

Generate a LegendNode, and calculate a point below it. This allows us to generate the items and "walk" them down the page in the process. We end-up with legend items on successive lines on the map page.

Parameters:
  • lat (float) - latitude of legend item
  • lon (float) - longitude of legend item
  • text (string) - text of legend item
  • dist (float) - distance down page for next item
  • node_id (NodeId) - NodeId to generate id from
Returns: LegendNode,float,float
LegendNode, lat of next legend item, lon of next legend item

generate_legend(the_ride, title, node_id)

source code 

Generate the legend items for the map for the given ride.

Parameters:
  • the_ride (Ride) - Ride to generate the legend for
  • title (string) - title for the map
  • node_id (NodeId) - NodeId to generate legend node ids from