Class: VIBes::Figure
- Inherits:
-
Object
- Object
- VIBes::Figure
- Defined in:
- lib/vibes-rb.rb
Overview
Figure is the class used to handle a single figure with the viewer.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Name of the figure that will appear on the viewer.
Figure management collapse
-
#[]=(key, value) ⇒ self
Set a property using the form [property]=value.
-
#clear ⇒ self
Clear the content of the figure.
-
#close ⇒ self
Close the figure.
-
#initialize(figure_name = 'default') ⇒ Figure
constructor
Create a new figure name figname.
-
#method_missing(m, *args, &block) ⇒ self
Set a property using the form
self.property=value. -
#save_image(file_name = nil, **kwargs) ⇒ self
Save the figure on disk.
-
#set_pos(x, y) ⇒ self
Set the position of the figure window on the screen.
-
#set_properties(**kwargs) ⇒ self
Set figure properties using keyword arguments.
-
#set_size(width, height) ⇒ self
Set the size of the figure.
Axis management collapse
-
#axis_auto ⇒ self
Set axes limits to the bounding box of the drawing.
-
#axis_equal ⇒ self
Same as #axis_auto but with the same ratio on the two axis.
-
#axis_labels(x_label, y_label) ⇒ self
Set axis labels.
-
#axis_limits(*v) ⇒ self
Set the rectangle to be displayed.
Groups collapse
-
#clear_group(group_name, **kwargs) ⇒ self
Clear the content of the group group_name from the figure.
-
#new_group(group_name, **kwargs) ⇒ self
Create a new group with the specified group name and parameters.
Drawing functions collapse
-
#draw_arrow(ps = nil, pe = nil, tl = nil, p1: [0, 0], p2: [1, 1], tip_length: nil, color: nil, **kwargs) ⇒ self
Draw an arrow.
-
#draw_AUV(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw an AUV (yellow submarine) centered at center, with heading heading degrees and size length.
-
#draw_box(*a, color: nil, **kwargs) ⇒ self
Draw a box.
-
#draw_boxes(*boxes, color: nil, **kwargs) ⇒ self
Draw multiple boxes at once.
-
#draw_boxes_union(*boxes, color: nil, **kwargs) ⇒ self
Draw the union of multiple boxes.
-
#draw_circle(c, r, color: nil, **kwargs) ⇒ self
Draw a circle.
- #draw_confidence_ellipse(cent = nil, cov = nil, sig = nil, center: nil, cx: 0.0, cy: 0.0, covariance: nil, sxx: 1.0, sxy: 1.0, syy: 1.0, sigma: 1.0, color: nil, **kwargs) ⇒ self
-
#draw_ellipse(cent = nil, ax = nil, rt = nil, center: nil, cx: 0.0, cy: 0.0, axis: nil, a: 1.0, b: a, rot: 0.0, color: nil, **kwargs) ⇒ self
Draw an ellipse centered at (cx,cy) with semi-major and minor axes a and b, and rotated by rot degrees.
-
#draw_line(ps = nil, pe = nil, p1: [0, 0], p2: [1, 1], color: nil, **kwargs) ⇒ self
Draw a line between two points.
-
#draw_pie(cent = nil, rad = nil, thet = nil, center: [0, 0], radius: [1, 2], theta: [0, 45], use_radians: false, color: nil, **kwargs) ⇒ self
Draw a pie.
-
#draw_point(cx, cy, radius: 2, color: 'k', **kwargs) ⇒ self
Draw a point.
-
#draw_points(*a, radius: 2, color: nil, **kwargs) ⇒ self
Draw multiple points at once.
-
#draw_polygon(*a, color: nil, **kwargs) ⇒ self
Draw a polygon.
-
#draw_raster(fname, po = nil, re = nil, pos: [0, 0], resolution: [1, -1], **kwargs) ⇒ self
Draw an image.
-
#draw_ring(cent = nil, rad = nil, center: [0, 0], radius: [1, 2], color: nil, **kwargs) ⇒ self
Draw a Ring.
-
#draw_tank(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw a tank centered at center, with heading heading degrees and of size length.
-
#draw_text(str = nil, po = nil, s = nil, text: '', pos: [0, 0], scale: 1, color: nil, **kwargs) ⇒ self
Draw text on the figure.
-
#draw_vehicle(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw a vehicle centered at center, with heading heading degrees and of size length.
Instance Method Summary collapse
Constructor Details
#initialize(figure_name = 'default') ⇒ Figure
Create a new figure name figname.
127 128 129 130 131 |
# File 'lib/vibes-rb.rb', line 127 def initialize(figure_name = 'default') figure_name = 'default' if not(figure_name.is_a?(String)) or figure_name.empty? @name = figure_name VIBes.msg "{\"action\":\"new\",\"figure\":\"#{@name}\"}\n\n" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ self
Set a property using the form self.property=value.
If the method is not known to the figure and is in the form 'figure.method=val',
call the #set_properties method whith the method name as key val as value.
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/vibes-rb.rb', line 197 def method_missing(m, *args, &block) if m.to_s =~ /=$/ then raise 'not expecting a block' if block raise 'expecting 1 and only 1 argument' if args.length != 1 self[m.to_s.sub(/=$/, '')] = args.first else super end self end |
Instance Attribute Details
#name ⇒ String (readonly)
Name of the figure that will appear on the viewer. If two instances of VIBes::Figure have the same name, they will treat the same figure on the viewer.
116 117 118 |
# File 'lib/vibes-rb.rb', line 116 def name @name end |
Instance Method Details
#[]=(key, value) ⇒ self
Set a property using the form [property]=value
179 180 181 |
# File 'lib/vibes-rb.rb', line 179 def []=(key, value) set_properties(**{key.to_sym => value}) end |
#axis_auto ⇒ self
Set axes limits to the bounding box of the drawing.
230 231 232 |
# File 'lib/vibes-rb.rb', line 230 def axis_auto set_properties(viewbox: :auto) end |
#axis_equal ⇒ self
Same as #axis_auto but with the same ratio on the two axis.
237 238 239 |
# File 'lib/vibes-rb.rb', line 237 def axis_equal set_properties(viewbox: :equal) end |
#axis_labels(x_label, y_label) ⇒ self
Set axis labels
293 294 295 |
# File 'lib/vibes-rb.rb', line 293 def axis_labels(*labels) set_properties(axislabels: labels.collect!{|o| o.to_s}) end |
#axis_limits(x_min, x_max, y_min, y_max) ⇒ self #axis_limits(x_range, y_range) ⇒ self #axis_limits(x_interval, y_interval) ⇒ self #axis_limits(xy_box) ⇒ self
Set the rectangle to be displayed.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/vibes-rb.rb', line 251 def axis_limits(*v) a = [] v.each do |e| case e when Numeric a << e.to_f when Range l = e.begin.to_f u = e.end.to_f l, u = [u, l] if l > u a << l a << u when Array raise "array must have 1 or 2 elements" if e.length < 1 or e.length > 2 l = e.first.to_f u = e.last.to_f l, u = [u, l] if l > u a << l a << u else if VIBes::object_is_an_interval?(e) a << e.lower_bound a << e.upper_bound elsif VIBes::object_is_a_box?(e) raise "the box is expected to have 2 dimensions, not #{e.length}" if e.length != 2 a << e[0].lower_bound a << e[0].upper_bound a << e[1].lower_bound a << e[1].upper_bound else raise "expecting floats, ranges, 2 element arrays, intervals or box, not #{e.class}" end end end raise "Should have 4 coordinates, not #{a.length}" if a.length != 4 set_properties(viewbox: a) end |
#clear ⇒ self
Clear the content of the figure
142 143 144 145 |
# File 'lib/vibes-rb.rb', line 142 def clear VIBes.msg "{\"action\":\"clear\",\"figure\":\"#{@name}\"}\n\n" self end |
#clear_group(group_name, **kwargs) ⇒ self
Clear the content of the group group_name from the figure.
322 323 324 325 326 327 328 |
# File 'lib/vibes-rb.rb', line 322 def clear_group(group_name, **kwargs) kwargs[:action] = :clear kwargs[:figure] = @name kwargs[:group] = group_name.to_s VIBes.msg "#{kwargs.to_json}\n\n" self end |
#close ⇒ self
Close the figure
135 136 137 138 |
# File 'lib/vibes-rb.rb', line 135 def close VIBes.msg "{\"action\":\"close\",\"figure\":\"#{@name}\"}\n\n" self end |
#draw_arrow(ps = nil, pe = nil, tl = nil, p1: [0, 0], p2: [1, 1], tip_length: nil, color: nil, **kwargs) ⇒ self
Draw an arrow
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/vibes-rb.rb', line 505 def draw_arrow(ps=nil, pe=nil, tl=nil, p1: [0, 0], p2: [1, 1], tip_length: nil, color: nil, **kwargs) kwargs[:type] = :arrow p1 = ps if ps.is_a?(Array) p2 = pe if pe.is_a?(Array) raise 'The start and end points must have the same number of coordinates' if p1.length != p2.length kwargs[:points] = [p1.collect(&:to_f), p2.collect(&:to_f)] kwargs[:format] = color if color.is_a?(String) if tl != nil then kwargs[:tip_length] = tl.to_f elsif tip_length.kind_of?(Numeric) then kwargs[:tip_length] = tip_length.to_f elsif p1.length == 2 and p2.length == 2 then kwargs[:tip_length] = Math.sqrt((p2.first - p1.first)**2 + (p2.last - p1.last)**2)/10.0 else kwargs[:tip_length] = 0.1 end draw(kwargs) end |
#draw_AUV(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw an AUV (yellow submarine) centered at center, with heading heading degrees and size length.
619 620 621 622 623 624 625 626 |
# File 'lib/vibes-rb.rb', line 619 def draw_AUV(cent=nil, rt=nil, len=nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) kwargs[:type] = :vehicle_auv kwargs[:center] = (cent.is_a?(Array) ? cent : center).collect(&:to_f) kwargs[:orientation] = (rt.nil? ? heading : rt).to_f kwargs[:length] = Math.sqrt((len.nil? ? length : len).to_f) kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_box(*a, color: nil, **kwargs) ⇒ self
Draw a box
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/vibes-rb.rb', line 353 def draw_box(*a, color: nil, **kwargs) c = [] f = nil a.each do |e| case e when Numeric c << e.to_f when Range l = e.begin.to_f u = e.end.to_f l, u = [u, l] if l > u c << l c << u when Array raise "array must have 1 or 2 elements" if e.length < 1 or e.length > 2 l = e.first.to_f u = e.last.to_f l, u = [u, l] if l > u c << l c << u when String f = e else if VIBes::object_is_an_interval?(e) then c << e.lower_bound c << e.upper_bound elsif VIBes::object_is_a_box?(e) then e.each do |v| c << v.lower_bound c << v.upper_bound end else raise "expecting floats, ranges, 2 element arrays, intervals or boxes, not #{e.class}" end end end raise "Should have a multiple of 2 coordinates, not #{c.length}" if c.length % 2 != 0 kwargs[:format] = f if f kwargs[:format] = color if color.is_a?(String) kwargs[:type] = :box kwargs[:bounds] = c draw(kwargs) end |
#draw_boxes(*boxes, color: nil, **kwargs) ⇒ self
Draw multiple boxes at once
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/vibes-rb.rb', line 400 def draw_boxes(*boxes, color: nil, **kwargs) kwargs[:bounds] = [] boxes.flatten! color = boxes.select{|v| v.is_a?(String)}.first if color.nil? boxes.reject!{|v| v.is_a?(String)} boxes.each do |b| if VIBes::object_is_a_box?(b) then ba = [] b.each do |v| ba << v.lower_bound ba << v.upper_bound end kwargs[:bounds] << ba else raise "expecting interval vectors, not #{b.class}" end end kwargs[:type] = 'boxes' kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_boxes_union(*boxes, color: nil, **kwargs) ⇒ self
Draw the union of multiple boxes.
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/vibes-rb.rb', line 425 def draw_boxes_union(*boxes, color: nil, **kwargs) kwargs[:bounds] = [] boxes.flatten! color = boxes.select{|v| v.is_a?(String)}.first if color.nil? boxes.reject!{|v| v.is_a?(String)} boxes.each do |b| if VIBes::object_is_a_box?(b) then ba = [] b.each do |v| ba << v.lower_bound ba << v.upper_bound end kwargs[:bounds] << ba else raise "expecting interval vectors, not #{b.class}" end end kwargs[:type] = 'boxes union' kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_circle(c, r, color: nil, **kwargs) ⇒ self
Draw a circle.
529 530 531 |
# File 'lib/vibes-rb.rb', line 529 def draw_circle(c, r, color: nil, **kwargs) draw_ellipse(c, [r, r], color: color, **kwargs) end |
#draw_confidence_ellipse(cent = nil, cov = nil, sig = nil, center: nil, cx: 0.0, cy: 0.0, covariance: nil, sxx: 1.0, sxy: 1.0, syy: 1.0, sigma: 1.0, color: nil, **kwargs) ⇒ self
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 |
# File 'lib/vibes-rb.rb', line 677 def draw_confidence_ellipse(cent=nil, cov=nil, sig=nil, center: nil, cx: 0.0, cy: 0.0, covariance: nil, sxx: 1.0, sxy: 1.0, syy: 1.0, sigma: 1.0, color: nil, **kwargs) kwargs = {} if kwargs.nil? kwargs[:type] = :ellipse if cent.is_a?(Array) then kwargs[:center] = cent.collect(&:to_f) else kwargs[:center] = center.is_a?(Array) ? center.collect(&:to_f) : [cx.to_f, cy.to_f] end if cov.is_a?(Array) then kwargs[:covariance] = cov.collect(&:to_f) else kwargs[:covariance] = covariance.is_a?(Array) ? covariance.collect(&:to_f) : [sxx.to_f, sxy.to_f, sxy.to_f, syy.to_f] end kwargs[:sigma] = sig.nil? ? sigma.to_f : sig.to_f kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_ellipse(cent = nil, ax = nil, rt = nil, center: nil, cx: 0.0, cy: 0.0, axis: nil, a: 1.0, b: a, rot: 0.0, color: nil, **kwargs) ⇒ self
Draw an ellipse centered at (cx,cy) with semi-major and minor axes a and b, and rotated by rot degrees.
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/vibes-rb.rb', line 658 def draw_ellipse(cent=nil, ax=nil, rt=nil, center: nil, cx: 0.0, cy: 0.0, axis: nil, a: 1.0, b: a, rot: 0.0, color: nil, **kwargs) kwargs = {} if kwargs.nil? kwargs[:type] = :ellipse if cent.is_a?(Array) then kwargs[:center] = cent.collect(&:to_f) else kwargs[:center] = center.is_a?(Array) ? center.collect(&:to_f) : [cx.to_f, cy.to_f] end if ax.is_a?(Array) then kwargs[:axis] = ax.collect(&:to_f) else kwargs[:axis] = axis.is_a?(Array) ? axis.collect(&:to_f) : [a.to_f, b.to_f] end kwargs[:orientation] = rt.nil? ? rot.to_f : rt.to_f kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_line(a_start, a_end, color: 'r', **kwargs) ⇒ self #draw_line(p1: a_start, p2: a_end, color: 'k', **kwargs) ⇒ self
Draw a line between two points
489 490 491 492 493 494 495 496 497 |
# File 'lib/vibes-rb.rb', line 489 def draw_line(ps=nil, pe=nil, p1: [0, 0], p2: [1, 1], color: nil, **kwargs) kwargs[:type] = :line p1 = ps if ps.is_a?(Array) p2 = pe if pe.is_a?(Array) raise 'The start and end points must have the same number of coordinates' if p1.length != p2.length kwargs[:points] = [p1.collect(&:to_f), p2.collect(&:to_f)] kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_pie(cent = nil, rad = nil, thet = nil, center: [0, 0], radius: [1, 2], theta: [0, 45], use_radians: false, color: nil, **kwargs) ⇒ self
Draw a pie
589 590 591 592 593 594 595 596 597 |
# File 'lib/vibes-rb.rb', line 589 def draw_pie(cent=nil, rad=nil, thet=nil, center: [0, 0], radius: [1, 2], theta: [0, 45], use_radians: false, color: nil, **kwargs) kwargs[:type] = :pie kwargs[:center] = (cent.is_a?(Array) ? cent : center).collect(&:to_f) kwargs[:rho] = (rad.is_a?(Array) ? rad : radius).collect(&:to_f) kwargs[:theta] = (thet.is_a?(Array) ? thet : theta).collect(&:to_f) kwargs[:theta].collect!{|v| v*180/Math::PI} if use_radians kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_point(cx, cy, radius: 2, color: 'k', **kwargs) ⇒ self
Draw a point.
453 454 455 456 457 458 459 |
# File 'lib/vibes-rb.rb', line 453 def draw_point(*a, radius: 2, color: nil, **kwargs) kwargs[:type] = :point kwargs[:point] = a.flatten.collect(&:to_f) kwargs[:Radius] = radius.to_f if radius kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_points(*a, radius: 2, color: nil, **kwargs) ⇒ self
Draw multiple points at once
467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'lib/vibes-rb.rb', line 467 def draw_points(*a, radius: 2, color: nil, **kwargs) el = nil a.each do |e| raise "expecting arrays of the same size" unless e.is_a?(Array) and (el.nil? or e.length == el) el = e.length end kwargs[:type] = :points kwargs[:centers] = a.collect{|e| e.collect(&:to_f)} kwargs[:Radius] = radius.to_f if radius kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_polygon(*a, color: nil, **kwargs) ⇒ self
Draw a polygon
551 552 553 554 555 556 557 558 559 560 561 |
# File 'lib/vibes-rb.rb', line 551 def draw_polygon(*a, color: nil, **kwargs) el = nil a.each do |e| raise "expecting arrays of the same size" unless e.is_a?(Array) and (e.length == el or el.nil?) el = e.length end kwargs[:type] = :polygon kwargs[:bounds] = a.collect{|e| e.collect(&:to_f)} kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_raster(fname, po = nil, re = nil, pos: [0, 0], resolution: [1, -1], **kwargs) ⇒ self
Draw an image.
572 573 574 575 576 577 578 |
# File 'lib/vibes-rb.rb', line 572 def draw_raster(fname, po=nil, re=nil, pos: [0, 0], resolution: [1, -1], **kwargs) kwargs[:type] = :raster kwargs[:filename] = fname.to_s kwargs[:ul_corner] = (po.is_a?(Array) ? po : pos).collect(&:to_f) kwargs[:scale] = (re.is_a?(Array) ? re : resolution).collect(&:to_f) draw(kwargs) end |
#draw_ring(cent = nil, rad = nil, center: [0, 0], radius: [1, 2], color: nil, **kwargs) ⇒ self
Draw a Ring.
539 540 541 542 543 544 545 |
# File 'lib/vibes-rb.rb', line 539 def draw_ring(cent=nil, rad=nil, center: [0, 0], radius: [1, 2], color: nil, **kwargs) kwargs[:type] = :ring kwargs[:center] = (cent.is_a?(Array) ? cent : center).collect(&:to_f) kwargs[:rho] = (rad.is_a?(Array) ? rad : radius).collect(&:to_f) kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_tank(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw a tank centered at center, with heading heading degrees and of size length.
647 648 649 650 651 652 653 654 |
# File 'lib/vibes-rb.rb', line 647 def draw_tank(cent=nil, rt=nil, len=nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) kwargs[:type] = :vehicle_tank kwargs[:center] = (cent.is_a?(Array) ? cent : center).collect(&:to_f) kwargs[:orientation] = (rt.nil? ? heading : rt).to_f kwargs[:length] = (len.nil? ? length : len).to_f kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_text(str = nil, po = nil, s = nil, text: '', pos: [0, 0], scale: 1, color: nil, **kwargs) ⇒ self
Does not seem to work on Linux
Draw text on the figure
602 603 604 605 606 607 608 609 |
# File 'lib/vibes-rb.rb', line 602 def draw_text(str=nil, po=nil, s=nil, text: '', pos: [0, 0], scale: 1, color: nil, **kwargs) kwargs[:type] = :text kwargs[:text] = (str.nil? ? text : str).to_s kwargs[:position] = (po.is_a?(Array) ? po : pos).collect(&:to_f) kwargs[:scale] = (s.nil? ? scale : s).to_f kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#draw_vehicle(cent = nil, rt = nil, len = nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) ⇒ self
Draw a vehicle centered at center, with heading heading degrees and of size length.
633 634 635 636 637 638 639 640 |
# File 'lib/vibes-rb.rb', line 633 def draw_vehicle(cent=nil, rt=nil, len=nil, center: [0, 0], heading: 0.0, length: 1.0, color: nil, **kwargs) kwargs[:type] = :vehicle kwargs[:center] = (cent.is_a?(Array) ? cent : center).collect(&:to_f) kwargs[:orientation] = (rt.nil? ? heading : rt).to_f kwargs[:length] = Math.sqrt((len.nil? ? length : len).to_f) kwargs[:format] = color if color.is_a?(String) draw(kwargs) end |
#new_group(group_name, **kwargs) ⇒ self
Create a new group with the specified group name and parameters.
Groups can be created to gather objects which share common properties (color, ...). Then objects can be added to groups by using the group: keyword.
312 313 314 315 316 |
# File 'lib/vibes-rb.rb', line 312 def new_group(group_name, **kwargs) kwargs = {type: :group, name: group_name.to_s} kwargs.each{|k, v| kwargs[k.to_sym] = v} draw kwargs end |
#remove_object(object_name, **kwargs) ⇒ self
699 700 701 702 703 704 705 |
# File 'lib/vibes-rb.rb', line 699 def remove_object(object_name, **kwargs) kwargs[:action] = :delete kwargs[:figure] = @name kwargs[:object] = object_name.to_s VIBes.msg "#{kwargs.to_json}\n\n" self end |
#save_image(file_name = nil, **kwargs) ⇒ self
Save the figure on disk. Available formats are: png, jpeg, bmp and svg.
151 152 153 154 155 156 157 158 |
# File 'lib/vibes-rb.rb', line 151 def save_image(file_name = nil, **kwargs) file_name = '' unless file_name.is_a?(String) and file_name.length > 0 kwargs[:action] = :export kwargs[:figure] = @name kwargs[:file] = File.(file_name) VIBes.msg "#{kwargs.to_json}\n\n" self end |
#set_object_properties(object_name, **kwargs) ⇒ self
708 709 710 711 712 |
# File 'lib/vibes-rb.rb', line 708 def set_object_properties(object_name, **kwargs) h = {action: :set, figure: @name, object: object_name.to_s, properties: kwargs.to_json} VIBes.msg "#{h.to_json}\n\n" self end |
#set_pos(x, y) ⇒ self
Set the position of the figure window on the screen
220 221 222 |
# File 'lib/vibes-rb.rb', line 220 def set_pos(x, y) set_properties(x: x.to_i, y: y.to_i) end |
#set_properties(**kwargs) ⇒ self
Set figure properties using keyword arguments.
167 168 169 170 |
# File 'lib/vibes-rb.rb', line 167 def set_properties(**kwargs) VIBes.msg "{\"action\":\"set\",\"figure\":\"#{@name}\",\"properties\":#{kwargs.to_json}}\n\n" self end |
#set_size(width, height) ⇒ self
Set the size of the figure
212 213 214 |
# File 'lib/vibes-rb.rb', line 212 def set_size(width, height) set_properties(width: width.to_i, height: height.to_i) end |