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
32 self.
hlineshlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
33 self.
hlineshlines.lower(
None)
34 self.
vlinesvlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
35 self.
vlinesvlines.lower(
None)
37 hadj = self.
vizviz.get_hadjustment()
38 vadj = self.
vizviz.get_vadjustment()
42 hadj.connect(
"value-changed", update)
43 vadj.connect(
"value-changed", update)
44 hadj.connect(
"changed", update)
45 vadj.connect(
"changed", update)
53 @param self: this object
54 @param visible: visible indicator
59 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
60 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
62 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
63 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
64 for label
in self.
labelslabels:
65 label.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
69 Compute divisions function
71 @param self: this object
80 text_width = dx/ndiv/2
84 Compute divisions function
89 return math.floor(x+0.5)
91 dx_over_ndiv = dx / ndiv
94 tbe = math.log10(dx_over_ndiv)
95 div = pow(10, rint(tbe))
96 if math.fabs(div/2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
98 elif math.fabs(div*2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
100 x0 = div*math.ceil(xi / div) - div
102 ndiv = rint(size / text_width)
110 @param self: this object
113 if self.
vizviz.zoom
is None:
116 unused_labels = self.
labelslabels
118 for label
in unused_labels:
119 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.HIDDEN)
124 @param self: this object
128 label = unused_labels.pop(0)
130 label = GooCanvas.CanvasText(parent=self.
vizviz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor)
132 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.VISIBLE)
134 self.
labelslabels.append(label)
137 hadj = self.
vizviz.get_hadjustment()
138 vadj = self.
vizviz.get_vadjustment()
139 zoom = self.
vizviz.zoom.get_value()
142 x1, y1 = self.
vizviz.canvas.convert_from_pixels(hadj.get_value(), vadj.get_value())
143 x2, y2 = self.
vizviz.canvas.convert_from_pixels(hadj.get_value() + hadj.get_page_size(), vadj.get_value() + vadj.get_page_size())
144 line_width = 5.0/self.
vizviz.zoom.get_value()
147 self.
hlineshlines.set_property(
"line-width", line_width)
148 yc = y2 - line_width/2
150 sim_x1 = x1/PIXELS_PER_METER
151 sim_x2 = x2/PIXELS_PER_METER
153 path = [
"M %r %r L %r %r" % (x1, yc, x2, yc)]
156 path.append(
"M %r %r L %r %r" % (PIXELS_PER_METER*x, yc - offset, PIXELS_PER_METER*x, yc))
158 label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
160 fill_color_rgba=self.
colorcolor,
161 alignment=Pango.Alignment.CENTER,
163 x=PIXELS_PER_METER*x,
168 self.
hlineshlines.set_property(
"data",
" ".join(path))
171 self.
vlinesvlines.set_property(
"line-width", line_width)
172 xc = x1 + line_width/2
174 sim_y1 = y1/PIXELS_PER_METER
175 sim_y2 = y2/PIXELS_PER_METER
179 path = [
"M %r %r L %r %r" % (xc, y1, xc, y2)]
182 path.append(
"M %r %r L %r %r" % (xc, PIXELS_PER_METER*y, xc + offset, PIXELS_PER_METER*y))
184 label.set_properties(font=(
"Sans Serif %f" % int(12/zoom)),
186 fill_color_rgba=self.
colorcolor,
187 alignment=Pango.Alignment.LEFT,
190 y=PIXELS_PER_METER*y)
193 self.
vlinesvlines.set_property(
"data",
" ".join(path))
197 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.