class Rust::Plots::BasePlot

Public Class Methods

new() click to toggle source
# File lib/rust-plots.rb, line 6
def initialize
    @renderables = []
    @options = Rust::Options.new
    @override_options = true
end

Public Instance Methods

[]=(option, value) click to toggle source
# File lib/rust-plots.rb, line 78
def []=(option, value)
    @options[option.to_s] = value
end
_add_renderable(renderable) click to toggle source
# File lib/rust-plots.rb, line 71
def _add_renderable(renderable)
    raise TypeError, "Expected Renderable" unless renderable.is_a?(Renderable)
    @renderables << renderable
    
    return self
end
_do_not_override_options!() click to toggle source
# File lib/rust-plots.rb, line 82
def _do_not_override_options!
    @override_options = false
end
axis(axis) click to toggle source
# File lib/rust-plots.rb, line 44
def axis(axis)
    @options['xaxt'] = 'n'
    @options['yaxt'] = 'n'
    
    self._add_renderable(axis)
    
    return self
end
color(color) click to toggle source
# File lib/rust-plots.rb, line 65
def color(color)
    @options['col'] = color
    
    return self
end
grid(grid) click to toggle source
# File lib/rust-plots.rb, line 53
def grid(grid)
    self._add_renderable(grid)
    
    return self
end
palette(size) click to toggle source
# File lib/rust-plots.rb, line 24
def palette(size)
    if size <= 1
        return ['black']
    else
        return Rust._pull("hcl.colors(n=#{size})")
    end
end
pdf(path, **options) click to toggle source
# File lib/rust-plots.rb, line 95
def pdf(path, **options)
    pdf_function = Rust::Function.new("pdf")
    pdf_function.options = Rust::Options.from_hash(options)
    pdf_function.options['file'] = path
    
    
    Rust.exclusive do
        pdf_function.call
        self._show
        self._render_others
        Rust._eval("dev.off()")
    end
    
    return self
end
show() click to toggle source
# File lib/rust-plots.rb, line 86
def show()
    Rust.exclusive do
        self._show
        self._render_others
    end
    
    return self
end
title(title) click to toggle source
# File lib/rust-plots.rb, line 59
def title(title)
    @options['main'] = title
    
    return self
end
x_label(label) click to toggle source
# File lib/rust-plots.rb, line 12
def x_label(label)
    @options['xlab'] = label
    
    return self
end
x_range(range) click to toggle source
# File lib/rust-plots.rb, line 32
def x_range(range)
    @options['xlim'] = range
    
    return self
end
y_label(label) click to toggle source
# File lib/rust-plots.rb, line 18
def y_label(label)
    @options['ylab'] = label
    
    return self
end
y_range(range) click to toggle source
# File lib/rust-plots.rb, line 38
def y_range(range)
    @options['ylim'] = range
    
    return self
end

Protected Instance Methods

_augmented_options(options={}) click to toggle source
# File lib/rust-plots.rb, line 124
def _augmented_options(options={})
    result = @options.clone
    
    options.each do |key, value|
        result[key] = value if !result[key] || @override_options
    end
    
    result.select! { |k, v| v != nil }
    
    return result
end
_render_others() click to toggle source
# File lib/rust-plots.rb, line 116
def _render_others()
    @renderables.each do |renderable|
        renderable._render()
    end
    
    return self
end
_show() click to toggle source
# File lib/rust-plots.rb, line 112
def _show()
    raise "You are trying to show a BasePlot"
end