2 from .base
import PIXELS_PER_METER
3 from gi.repository
import Pango
4 from gi.repository
import Gtk
5 from gi.repository
import GooCanvas
26 @param self: this object
27 @param viz: visualization object
31 self.
hlineshlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
32 self.
hlineshlines.lower(
None)
33 self.
vlinesvlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
34 self.
vlinesvlines.lower(
None)
36 hadj = self.
vizviz.get_hadjustment()
37 vadj = self.
vizviz.get_vadjustment()
41 hadj.connect(
"value-changed", update)
42 vadj.connect(
"value-changed", update)
43 hadj.connect(
"changed", update)
44 vadj.connect(
"changed", update)
52 @param self: this object
53 @param visible: visible indicator
58 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
59 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
61 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
62 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
63 for label
in self.
labelslabels:
64 label.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
68 Compute divisions function
70 @param self: this object
79 text_width = dx/ndiv/2
83 Compute divisions function
88 return math.floor(x+0.5)
90 dx_over_ndiv = dx / ndiv
93 tbe = math.log10(dx_over_ndiv)
94 div = pow(10, rint(tbe))
95 if math.fabs(div/2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
97 elif math.fabs(div*2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
99 x0 = div*math.ceil(xi / div) - div
101 ndiv = rint(size / text_width)
109 @param self: this object
112 if self.
vizviz.zoom
is None:
115 unused_labels = self.
labelslabels
117 for label
in unused_labels:
118 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.HIDDEN)
123 @param self: this object
127 label = unused_labels.pop(0)
129 label = GooCanvas.CanvasText(parent=self.
vizviz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
131 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.VISIBLE)
133 self.
labelslabels.append(label)
136 hadj = self.
vizviz.get_hadjustment()
137 vadj = self.
vizviz.get_vadjustment()
138 zoom = self.
vizviz.zoom.get_value()
141 x1, y1 = self.
vizviz.canvas.convert_from_pixels(hadj.get_value(), vadj.get_value())
142 x2, y2 = self.
vizviz.canvas.convert_from_pixels(hadj.get_value() + hadj.get_page_size(), vadj.get_value() + vadj.get_page_size())
143 line_width = 5.0/self.
vizviz.zoom.get_value()
146 self.
hlineshlines.set_property(
"line-width", line_width)
147 yc = y2 - line_width/2
149 sim_x1 = x1/PIXELS_PER_METER
150 sim_x2 = x2/PIXELS_PER_METER
152 path = [
"M %r %r L %r %r" % (x1, yc, x2, yc)]
155 path.append(
"M %r %r L %r %r" % (PIXELS_PER_METER*x, yc - offset, PIXELS_PER_METER*x, yc))
157 label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
159 fill_color_rgba=self.
colorcolor,
160 alignment=Pango.Alignment.CENTER,
162 x=PIXELS_PER_METER*x,
167 self.
hlineshlines.set_property(
"data",
" ".join(path))
170 self.
vlinesvlines.set_property(
"line-width", line_width)
171 xc = x1 + line_width/2
173 sim_y1 = y1/PIXELS_PER_METER
174 sim_y2 = y2/PIXELS_PER_METER
178 path = [
"M %r %r L %r %r" % (xc, y1, xc, y2)]
181 path.append(
"M %r %r L %r %r" % (xc, PIXELS_PER_METER*y, xc + offset, PIXELS_PER_METER*y))
183 label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
185 fill_color_rgba=self.
colorcolor,
186 alignment=Pango.Alignment.LEFT,
189 y=PIXELS_PER_METER*y)
192 self.
vlinesvlines.set_property(
"data",
" ".join(path))
196 self.
labelslabels.extend(unused_labels)
def _compute_divisions(self, xi, xf)
Compute divisions function.
def __init__(self, viz)
Initializer function.
def update_view(self)
Update view function.
def set_visible(self, visible)
Set visible function.