3 from gi.repository
import GooCanvas, Gtk, Pango
5 from .base
import PIXELS_PER_METER
26 @param self: this object
27 @param viz: visualization object
31 self.
hlineshlines = GooCanvas.CanvasPath(
32 parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor
34 self.
hlineshlines.lower(
None)
35 self.
vlinesvlines = GooCanvas.CanvasPath(
36 parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor
38 self.
vlinesvlines.lower(
None)
40 hadj = self.
vizviz.get_hadjustment()
41 vadj = self.
vizviz.get_vadjustment()
47 hadj.connect(
"value-changed", update)
48 vadj.connect(
"value-changed", update)
49 hadj.connect(
"changed", update)
50 vadj.connect(
"changed", update)
58 @param self: this object
59 @param visible: visible indicator
64 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
65 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
67 self.
hlineshlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
68 self.
vlinesvlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
69 for label
in self.
labelslabels:
70 label.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
74 Compute divisions function
76 @param self: this object
85 text_width = dx / ndiv / 2
89 Compute divisions function
94 return math.floor(x + 0.5)
96 dx_over_ndiv = dx / ndiv
100 tbe = math.log10(dx_over_ndiv)
102 div = pow(10, rint(tbe))
104 if math.fabs(div / 2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
106 elif math.fabs(div * 2 - dx_over_ndiv) < math.fabs(div - dx_over_ndiv):
108 x0 = div * math.ceil(xi / div) - div
110 ndiv = rint(size / text_width)
117 @param self: this object
120 if self.
vizviz.zoom
is None:
123 unused_labels = self.
labelslabels
125 for label
in unused_labels:
126 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.HIDDEN)
132 @param self: this object
136 label = unused_labels.pop(0)
138 label = GooCanvas.CanvasText(
139 parent=self.
vizviz.canvas.get_root_item(), stroke_color_rgba=self.
colorcolor
142 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.VISIBLE)
144 self.
labelslabels.append(label)
147 hadj = self.
vizviz.get_hadjustment()
148 vadj = self.
vizviz.get_vadjustment()
149 zoom = self.
vizviz.zoom.get_value()
152 x1, y1 = self.
vizviz.canvas.convert_from_pixels(hadj.get_value(), vadj.get_value())
153 x2, y2 = self.
vizviz.canvas.convert_from_pixels(
154 hadj.get_value() + hadj.get_page_size(), vadj.get_value() + vadj.get_page_size()
156 line_width = 5.0 / self.
vizviz.zoom.get_value()
159 self.
hlineshlines.set_property(
"line-width", line_width)
160 yc = y2 - line_width / 2
162 sim_x1 = x1 / PIXELS_PER_METER
163 sim_x2 = x2 / PIXELS_PER_METER
165 path = [
"M %r %r L %r %r" % (x1, yc, x2, yc)]
169 "M %r %r L %r %r" % (PIXELS_PER_METER * x, yc - offset, PIXELS_PER_METER * x, yc)
172 label.set_properties(
173 font=(
"Sans Serif %f" % int(12 / zoom)),
175 fill_color_rgba=self.
colorcolor,
176 alignment=Pango.Alignment.CENTER,
178 x=PIXELS_PER_METER * x,
184 self.
hlineshlines.set_property(
"data",
" ".join(path))
187 self.
vlinesvlines.set_property(
"line-width", line_width)
188 xc = x1 + line_width / 2
190 sim_y1 = y1 / PIXELS_PER_METER
191 sim_y2 = y2 / PIXELS_PER_METER
194 path = [
"M %r %r L %r %r" % (xc, y1, xc, y2)]
198 "M %r %r L %r %r" % (xc, PIXELS_PER_METER * y, xc + offset, PIXELS_PER_METER * y)
201 label.set_properties(
202 font=(
"Sans Serif %f" % int(12 / zoom)),
204 fill_color_rgba=self.
colorcolor,
205 alignment=Pango.Alignment.LEFT,
208 y=PIXELS_PER_METER * y,
212 self.
vlinesvlines.set_property(
"data",
" ".join(path))
214 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.