9     def __init__(self, viz):
 
   11         self.
color = 0x8080C0FF
 
   12         self.
hlines = goocanvas.Path(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
color)
 
   13         self.hlines.lower(
None)
 
   14         self.
vlines = goocanvas.Path(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
color)
 
   15         self.vlines.lower(
None)
 
   17         hadj = self.viz.get_hadjustment()
 
   18         vadj = self.viz.get_vadjustment()
 
   22         hadj.connect(
"value-changed", update)
 
   23         vadj.connect(
"value-changed", update)
 
   24         hadj.connect(
"changed", update)
 
   25         vadj.connect(
"changed", update)
 
   29     def set_visible(self, visible):
 
   32             self.hlines.props.visibility = goocanvas.ITEM_VISIBLE
 
   33             self.vlines.props.visibility = goocanvas.ITEM_VISIBLE
 
   35             self.hlines.props.visibility = goocanvas.ITEM_HIDDEN
 
   36             self.vlines.props.visibility = goocanvas.ITEM_HIDDEN
 
   38                 label.props.visibility = goocanvas.ITEM_HIDDEN
 
   40     def _compute_divisions(self, xi, xf):
 
   45         text_width = dx/ndiv/2
 
   48             return math.floor(x+0.5)
 
   50         dx_over_ndiv = dx / ndiv
 
   53             tbe = math.log10(dx_over_ndiv)
 
   54             div = pow(10, rint(tbe))
 
   55             if math.fabs(div/2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv): 
 
   57             elif math.fabs(div*2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
 
   59             x0 = div*math.ceil(xi / div) - div
 
   61                 ndiv = rint(size / text_width)
 
   65     def update_view(self):
 
   66         if self.viz.zoom 
is None:
 
   69         unused_labels = self.
labels 
   71         for label 
in unused_labels:
 
   72             label.set_property(
"visibility", goocanvas.ITEM_HIDDEN)
 
   75                 label = unused_labels.pop(0)
 
   77                 label = goocanvas.Text(parent=self.viz.canvas.get_root_item(), stroke_color_rgba=self.
color)
 
   79                 label.set_property(
"visibility", goocanvas.ITEM_VISIBLE)
 
   81             self.labels.append(label)
 
   84         hadj = self.viz.get_hadjustment()
 
   85         vadj = self.viz.get_vadjustment()
 
   86         zoom = self.viz.zoom.value
 
   89         x1, y1 = self.viz.canvas.convert_from_pixels(hadj.value, vadj.value)
 
   90         x2, y2 = self.viz.canvas.convert_from_pixels(hadj.value + hadj.page_size, vadj.value + vadj.page_size)
 
   91         line_width = 5.0/self.viz.zoom.value
 
   94         self.hlines.set_property(
"line-width", line_width)
 
   95         yc = y2 - line_width/2
 
   97         sim_x1 = x1/core.PIXELS_PER_METER
 
   98         sim_x2 = x2/core.PIXELS_PER_METER
 
  100         path = [
"M %r %r L %r %r" % (x1, yc, x2, yc)]
 
  103             path.append(
"M %r %r L %r %r" % (core.PIXELS_PER_METER*x, yc - offset, core.PIXELS_PER_METER*x, yc))
 
  105             label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
 
  107                                  fill_color_rgba=self.
color,
 
  108                                  alignment=pango.ALIGN_CENTER,
 
  110                                  x=core.PIXELS_PER_METER*x,
 
  115         self.hlines.set_property(
"data", 
" ".join(path))
 
  118         self.vlines.set_property(
"line-width", line_width)
 
  119         xc = x1 + line_width/2
 
  121         sim_y1 = y1/core.PIXELS_PER_METER
 
  122         sim_y2 = y2/core.PIXELS_PER_METER
 
  126         path = [
"M %r %r L %r %r" % (xc, y1, xc, y2)]
 
  129             path.append(
"M %r %r L %r %r" % (xc, core.PIXELS_PER_METER*y, xc + offset, core.PIXELS_PER_METER*y))
 
  131             label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
 
  133                                  fill_color_rgba=self.
color,
 
  134                                  alignment=pango.ALIGN_LEFT,
 
  137                                  y=core.PIXELS_PER_METER*y)
 
  140         self.vlines.set_property(
"data", 
" ".join(path))
 
  144         self.labels.extend(unused_labels)