2from .base
import PIXELS_PER_METER
3from gi.repository
import Pango
4from gi.repository
import Gtk
5from gi.repository
import GooCanvas
26 @param self: this object
27 @param viz: visualization object
31 self.hlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.color)
33 self.
vlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.
color)
36 hadj = self.
viz.get_hadjustment()
37 vadj = self.
viz.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.
hlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
59 self.
vlines.props.visibility = GooCanvas.CanvasItemVisibility.VISIBLE
61 self.
hlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
62 self.
vlines.props.visibility = GooCanvas.CanvasItemVisibility.HIDDEN
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.
viz.zoom
is None:
115 unused_labels = self.
labels
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.
viz.canvas.get_root_item(), stroke_color_rgba=self.
color)
131 label.set_property(
"visibility", GooCanvas.CanvasItemVisibility.VISIBLE)
136 hadj = self.
viz.get_hadjustment()
137 vadj = self.
viz.get_vadjustment()
138 zoom = self.
viz.zoom.get_value()
141 x1, y1 = self.
viz.canvas.convert_from_pixels(hadj.get_value(), vadj.get_value())
142 x2, y2 = self.
viz.canvas.convert_from_pixels(hadj.get_value() + hadj.get_page_size(), vadj.get_value() + vadj.get_page_size())
143 line_width = 5.0/self.
viz.zoom.get_value()
146 self.
hlines.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.
color,
160 alignment=Pango.Alignment.CENTER,
162 x=PIXELS_PER_METER*x,
167 self.
hlines.set_property(
"data",
" ".join(path))
170 self.
vlines.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.
color,
186 alignment=Pango.Alignment.LEFT,
189 y=PIXELS_PER_METER*y)
192 self.
vlines.set_property(
"data",
" ".join(path))
196 self.
labels.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.