Class: Cosmos::OverviewGraph
- Defined in:
- lib/cosmos/gui/line_graph/overview_graph.rb
Constant Summary collapse
- DEFAULT_ZOOM_FACTOR =
10 percent
0.1
- DEFAULT_PAN_FACTOR =
10 percent
0.1
Constants inherited from LineGraph
LineGraph::DOUBLE_CLICK_SECONDS, LineGraph::FRAME_OFFSET, LineGraph::GRAPH_SPACER, LineGraph::LABEL_TICK_SIZE, LineGraph::LEFT_X_LABEL_WIDTH_ADJUST
Instance Attribute Summary collapse
-
#callback ⇒ Object
Callback called when the window changes.
-
#window_max_size ⇒ Object
Maximum allowed size of the window in seconds plotted.
-
#window_max_x ⇒ Object
readonly
Maximum x value in window.
-
#window_min_size ⇒ Object
Minimum allowed size of the window in seconds plotted.
-
#window_min_x ⇒ Object
readonly
Minimum x value in window.
-
#window_size ⇒ Object
Window size in seconds plotted.
Attributes inherited from LineGraph
#draw_cursor_line_callback, #horizontal_lines, #left_y_max, #left_y_min, #mouse_leave_callback, #mouse_left_button_press_callback, #post_error_callback, #pre_error_callback, #right_y_max, #right_y_min, #x_max, #x_max_label, #x_min, #x_min_label
Instance Method Summary collapse
- #back_color=(value) ⇒ Object
- #drag_bar(x) ⇒ Object
- #drag_lasso(x) ⇒ Object
- #drag_window(x) ⇒ Object
- #focusInEvent(event) ⇒ Object
- #focusOutEvent(event) ⇒ Object
-
#graph(move_window = false) ⇒ Object
Draws the overview graph.
-
#initialize(parent) ⇒ OverviewGraph
constructor
A new instance of OverviewGraph.
- #keyPressEvent(event) ⇒ Object
-
#leaveEvent(event) ⇒ Object
Handler for leaveEvent.
-
#mouseMoveEvent(event) ⇒ Object
Handles the mouse moving over the overview graph.
-
#mousePressEvent(event) ⇒ Object
Handles the left button being pressed in the overview graph.
-
#mouseReleaseEvent(event) ⇒ Object
Handles the left button being released.
- #pan(amount) ⇒ Object
- #pan_left ⇒ Object
- #pan_right ⇒ Object
- #set_window_pos(window_min_x, window_max_x, use_callback) ⇒ Object
- #set_window_size(new_window_size, use_callback) ⇒ Object
- #show_cursor(x) ⇒ Object
- #sizeHint ⇒ Object
- #zoom(zoom_factor) ⇒ Object
- #zoom_in ⇒ Object
- #zoom_out ⇒ Object
Methods inherited from LineGraph
#add_horizontal_line, #add_line, #add_popups_for_lines, #adjust_popup_positions, attr_accessor_with_redraw, #auto_scale_x, #auto_scale_y, #auto_scale_y_axis, #build_popups_from_x_value, #build_x_grid_lines, #build_y_grid_lines, #calculate_base, #calculate_scaling_factors, #calculate_x_grid_lines, #calculate_y_grid_lines, #calculate_y_labels, #clear_horizontal_lines, #clear_lines, #convert_x_value_to_text, #convert_y_value_to_text, #draw_cursor_line_and_popups, #draw_cursor_line_and_popups_at_x, #draw_error_icon, #draw_frame, #draw_graph_background, #draw_graph_to_screen, #draw_horizontal_lines, #draw_legend, #draw_legend_text, #draw_line, #draw_lines, #draw_origin_lines, #draw_popups, #draw_title, #draw_x_axis_grid_lines, #draw_x_axis_title, #draw_x_label, #draw_y_axis_grid_lines, #draw_y_axis_title, #draw_y_label, #get_legend_position, #manual_scale_x, #manual_scale_y, #paintEvent, #remote_draw_cursor_line_at_x, #resizeEvent, #scale_graph, #scale_graph_to_value_x, #scale_left_to_right_y, #scale_value_to_graph_x, #scale_value_to_graph_y, #update_graph_size
Constructor Details
#initialize(parent) ⇒ OverviewGraph
Returns a new instance of OverviewGraph.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 33 def initialize(parent) super(parent) setMaximumHeight(50) setFocusPolicy(Qt::StrongFocus) @qt_back_color = Cosmos::getColor(@back_color) @point_size = 0 # Adjust minimum height for overview @minimum_height = 50 @size_hint = Qt::Size.new(0, @minimum_height) # Size of the window in value space @window_size = 100.0 # Minimum size of the window @window_min_size = 0.0 # Maximum size of the window @window_max_size = nil # Minimum window x value @window_min_x = 0 # Maximum window x value @window_max_x = 0 # Flag to indicate if we are currently dragging the window @drag_window = false # Cursor position at start of drag @drag_start_x = nil # Variable to hold callback function that indicates the window position @callback = nil # window_min_x in graph coordinates @window_min_start = 0 # window_max_x in graph coordinates @window_max_start = 0 # Flag to indicate if we are currently dragging the bar @drag_bar = false # Flag to indicate if the cursor is in the selection window @cursor_in_window = false # The true maximum x value @true_max_x = 0 @show_cursor_and_popups = false @window_left_x = 0 @window_right_x = 0 end |
Instance Attribute Details
#callback ⇒ Object
Callback called when the window changes
25 26 27 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 25 def callback @callback end |
#window_max_size ⇒ Object
Maximum allowed size of the window in seconds plotted
23 24 25 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 23 def window_max_size @window_max_size end |
#window_max_x ⇒ Object (readonly)
Maximum x value in window
31 32 33 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 31 def window_max_x @window_max_x end |
#window_min_size ⇒ Object
Minimum allowed size of the window in seconds plotted
21 22 23 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 21 def window_min_size @window_min_size end |
#window_min_x ⇒ Object (readonly)
Minimum x value in window
29 30 31 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 29 def window_min_x @window_min_x end |
#window_size ⇒ Object
Window size in seconds plotted
27 28 29 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 27 def window_size @window_size end |
Instance Method Details
#back_color=(value) ⇒ Object
305 306 307 308 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 305 def back_color=(value) super(value) @qt_back_color = Cosmos::getColor(@back_color) end |
#drag_bar(x) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 133 def (x) if @cursor_on_bar == :LEFT temp_min = (@window_min_start + (x - @drag_start_x)) temp_max = @window_max_start else temp_min = @window_min_start temp_max = (@window_max_start + (x - @drag_start_x)) end value_temp_min = scale_graph_to_value_x(temp_min) value_temp_max = scale_graph_to_value_x(temp_max) # Verify the left bar hasn't moved past the minimum size if value_temp_min > (@window_max_x - @window_min_size) @window_min_x = @window_max_x - @window_min_size # Verify the left bar hasn't moved past the maximum size elsif @window_max_size and value_temp_min < (@window_max_x - @window_max_size) @window_min_x = @window_max_x - @window_max_size else @window_min_x = value_temp_min end # Verify the left bar hasn't been moved past the end if scale_value_to_graph_x(@window_min_x) < @graph_left_x @window_min_x = @x_min end # Verify the right bar hasn't moved past the minimum size if value_temp_max < (@window_min_x + @window_min_size) @window_max_x = @window_min_x + @window_min_size # Verify the right bar hasn't moved past the maximum size elsif @window_max_size and value_temp_max > (@window_min_x + @window_max_size) @window_max_x = @window_min_x + @window_max_size else @window_max_x = value_temp_max end # Verify the right bar hasn't been moved past the end if scale_value_to_graph_x(@window_max_x) > @graph_right_x @window_max_x = @x_max end # Update window size @window_min_x = @x_min if @window_min_x < @x_min @window_max_x = @x_max if @window_max_x > @x_max @window_size = @window_max_x - @window_min_x @redraw_needed = true graph() end |
#drag_lasso(x) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 184 def drag_lasso(x) if (x - @drag_start_x).abs > 5 @drag_bar = true @window_min_start = @drag_start_x @window_max_start = @drag_start_x if x > @drag_start_x @cursor_on_bar = :RIGHT else @cursor_on_bar = :LEFT end end end |
#drag_window(x) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 105 def drag_window(x) @cursor = Qt::Cursor.new(Qt::ClosedHandCursor) self.setCursor(@cursor) # Calculate the movement in terms of the graph coordinates (not the x values) temp_min = (@window_min_start + (x - @drag_start_x)) temp_max = (@window_max_start + (x - @drag_start_x)) # Only graph if the user hasn't dragged the window outside the graph if temp_min >= @graph_left_x and temp_max <= @graph_right_x #Now convert the graph coordinates back to the x values @window_min_x = scale_graph_to_value_x(temp_min) @window_max_x = scale_graph_to_value_x(temp_max) else # The user dragged outside the allowable area if temp_min < @graph_left_x @window_min_x = @x_min @window_max_x = @x_min + @window_size elsif temp_max > @graph_right_x @window_max_x = scale_graph_to_value_x(@graph_right_x) @window_min_x = @window_max_x - @window_size end end @window_min_x = @x_min if @window_min_x < @x_min @window_max_x = @x_max if @window_max_x > @x_max @redraw_needed = true graph() end |
#focusInEvent(event) ⇒ Object
387 388 389 390 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 387 def focusInEvent(event) self.frame_color = 'gray' update() end |
#focusOutEvent(event) ⇒ Object
392 393 394 395 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 392 def focusOutEvent(event) self.frame_color = 'black' update() end |
#graph(move_window = false) ⇒ Object
Draws the overview graph
296 297 298 299 300 301 302 303 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 296 def graph(move_window = false) @move_window = move_window determine_graph_size() scale_graph() calculate_scaling_factors() calculate_window_lines() super() end |
#keyPressEvent(event) ⇒ Object
373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 373 def keyPressEvent(event) case event.key when Qt::Key_Up zoom_in() when Qt::Key_Down zoom_out() when Qt::Key_Left pan_left() when Qt::Key_Right pan_right() end super(event) end |
#leaveEvent(event) ⇒ Object
Handler for leaveEvent
241 242 243 244 245 246 247 248 249 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 241 def leaveEvent(event) super(event) self.unsetCursor() @cursor_in_window = false @cursor_on_bar = nil @drag_start_x = nil @drag_bar = false @drag_window = false end |
#mouseMoveEvent(event) ⇒ Object
Handles the mouse moving over the overview graph
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 224 def mouseMoveEvent(event) super(event) # Get the cursor position x = mapFromGlobal(self.cursor.pos).x if @drag_window drag_window(x) elsif @drag_bar # We're in the middle of moving one of the window bars (x) elsif @drag_start_x # Lasso start drag_lasso(x) else # We're not dragging the window, the user just moused around so show the right cursor show_cursor(x) end end |
#mousePressEvent(event) ⇒ Object
Handles the left button being pressed in the overview graph
252 253 254 255 256 257 258 259 260 261 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 252 def mousePressEvent(event) super(event) # Store off the mouse click x coordinate on the graph and the window x coordinates @drag_start_x = mapFromGlobal(self.cursor.pos).x @window_min_start = scale_value_to_graph_x(@window_min_x) @window_max_start = scale_value_to_graph_x(@window_max_x) @drag_window = true if @cursor_in_window @drag_bar = true if @cursor_on_bar end |
#mouseReleaseEvent(event) ⇒ Object
Handles the left button being released
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 264 def mouseReleaseEvent(event) self.unsetCursor() if !(@drag_bar or @drag_window) and @drag_start_x # Figure out what x value the click corresponds to xpoint = scale_graph_to_value_x(@drag_start_x) # Move the window values to make them equidistant from the click @window_min_x = xpoint - @window_size / 2 @window_max_x = xpoint + @window_size / 2 # Ensure we don't put the window outside the graphable points if @window_min_x < @x_min @window_min_x = @x_min @window_max_x = @x_min + @window_size elsif @window_max_x > @x_max @window_max_x = @x_max @window_min_x = @x_max - @window_size end @drag_window = true @redraw_needed = true graph() @drag_window = false end @drag_start_x = nil @drag_bar = false @drag_window = false @callback.call(self) unless @callback.nil? end |
#pan(amount) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 339 def pan(amount) # Move the window values to make them equidistant from the click new_window_min_x = @window_min_x + amount new_window_max_x = @window_max_x + amount # Ensure we don't put the window outside the graphable points if new_window_min_x >= @x_min and new_window_max_x <= @x_max @window_min_x = new_window_min_x @window_max_x = new_window_max_x elsif new_window_min_x < @x_min @window_min_x = @x_min @window_max_x = @x_min + @window_size else @window_min_x = @x_max - @window_size @window_max_x = @x_max end @window_min_x = @x_min if @window_min_x < @x_min @window_max_x = @x_max if @window_max_x > @x_max @drag_window = true @redraw_needed = true graph() @drag_window = false @callback.call(self) unless @callback.nil? end |
#pan_left ⇒ Object
365 366 367 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 365 def pan_left pan(-@window_size * DEFAULT_PAN_FACTOR) end |
#pan_right ⇒ Object
369 370 371 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 369 def pan_right pan(@window_size * DEFAULT_PAN_FACTOR) end |
#set_window_pos(window_min_x, window_max_x, use_callback) ⇒ Object
99 100 101 102 103 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 99 def set_window_pos(window_min_x, window_max_x, use_callback) @window_min_x = window_min_x @window_max_x = window_max_x @callback.call(self) if use_callback and @callback end |
#set_window_size(new_window_size, use_callback) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 80 def set_window_size(new_window_size, use_callback) @window_size = new_window_size @window_size = @window_min_size if @window_min_size and @window_size < @window_min_size @window_size = @window_max_size if @window_max_size and @window_size > @window_max_size if @lines.empty? @window_max_x = 1.0 @window_min_x = -1.0 else @window_min_x = @window_max_x - @window_size end graph(false) @callback.call(self) if use_callback and @callback end |
#show_cursor(x) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 197 def show_cursor(x) # Initially set the variables so the cursor isn't anywhere special @cursor_on_bar = nil @cursor_in_window = false # Figure out if the mouse is inside the graph so we show the Hand cursor gx = scale_graph_to_value_x(x) # Allow the user to drag the white window bars to increase the main view width if (scale_value_to_graph_x(@window_min_x) - x).abs < 5 @cursor = Qt::Cursor.new(Qt::SizeHorCursor) self.setCursor(@cursor) @cursor_on_bar = :LEFT elsif (scale_value_to_graph_x(@window_max_x) - x).abs < 5 @cursor = Qt::Cursor.new(Qt::SizeHorCursor) self.setCursor(@cursor) @cursor_on_bar = :RIGHT elsif (@window_min_x) < gx and gx < (@window_max_x) @cursor = Qt::Cursor.new(Qt::OpenHandCursor) self.setCursor(@cursor) @cursor_in_window = true else self.unsetCursor() end end |
#sizeHint ⇒ Object
76 77 78 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 76 def sizeHint return @size_hint end |
#zoom(zoom_factor) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 310 def zoom(zoom_factor) @window_size = @window_size * zoom_factor @window_size = @window_min_size if @window_min_size and @window_size < @window_min_size @window_size = @window_max_size if @window_max_size and @window_size > @window_max_size if @lines.empty? @window_max_x = 1.0 @window_min_x = -1.0 else center = (@window_max_x + @window_min_x) / 2 @window_min_x = center - @window_size / 2 @window_max_x = center + @window_size / 2 end @window_min_x = @x_min if @window_min_x < @x_min @window_max_x = @x_max if @window_max_x > @x_max @drag_window = true @redraw_needed = true graph() @drag_window = false @callback.call(self) if @callback end |
#zoom_in ⇒ Object
331 332 333 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 331 def zoom_in zoom(1 - DEFAULT_ZOOM_FACTOR) end |
#zoom_out ⇒ Object
335 336 337 |
# File 'lib/cosmos/gui/line_graph/overview_graph.rb', line 335 def zoom_out zoom(1 + DEFAULT_ZOOM_FACTOR) end |