Add titles to regions (Firefox, and possibly others) use them for tooltips.
authorW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 01:08:44 +0000 (21:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 28 Mar 2010 01:30:57 +0000 (21:30 -0400)
Use world.name as template.name and SVG <title>.

pyrisk/graphics.py

index df63232..6e47f2a 100644 (file)
@@ -48,7 +48,7 @@ class TemplateLibrary (object):
         region_pointlists,route_pointlists,continent_colors,line_colors = \
             self._get_data(name)
         regions = self._generate_regions(region_pointlists, route_pointlists)
-        return Template('template', regions, continent_colors, line_colors)
+        return Template(name, regions, continent_colors, line_colors)
     def _get_data(self, name):
         dirname = os.path.join(self.template_dir, name.lower())
         try:
@@ -370,8 +370,9 @@ class WorldRenderer (object):
             % (float(width)/self.dpcm, float(height)/self.dpcm,
                width, height),
             '     xmlns="http://www.w3.org/2000/svg" version="1.1">',
-            '<desc>PyRisk world: %s</desc>' % template,
-            ]
+            '<title>%s</title>' % template,
+            '<desc>A PyRisk world snapshot</desc>',
+           ]
         drawn_rts = {}
         for r in template.regions:
             t = self._matching_territory(world, r)
@@ -382,8 +383,9 @@ class WorldRenderer (object):
                 b_col_attr = 'stroke="%s" stroke-width="%d"' \
                     % (template.line_colors['border'], self.line_width)
             lines.extend([
-                    '<!-- %s -->' % r,
-                    '<polygon fill="%s" %s' % (c_col, b_col_attr),
+                    '<polygon title="%s / %s / %s"'
+                    % (t, t.player, t.armies),                    
+                    '         fill="%s" %s' % (c_col, b_col_attr),
                     '         points="%s" />'
                     % ' '.join(['%d,%d' % ((region_pos[id(r)]+p)
                                            *(1,-1) # svg y value increases down