Class: Rust::Plots::BasePlot

Inherits:
Object
  • Object
show all
Defined in:
lib/rust-plots.rb

Direct Known Subclasses

DistributionPlot, ScatterPlot

Instance Method Summary collapse

Constructor Details

#initializeBasePlot

Returns a new instance of BasePlot.



6
7
8
9
# File 'lib/rust-plots.rb', line 6

def initialize
    @plugins = []
    @options = Rust::Options.new
end

Instance Method Details

#[]=(option, value) ⇒ Object



63
64
65
# File 'lib/rust-plots.rb', line 63

def []=(option, value)
    @options[option] = value
end

#axis(axis) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/rust-plots.rb', line 35

def axis(axis)
    @options['xaxt'] = 'n'
    @options['yaxt'] = 'n'
    
    self.plug(axis)
    
    return self
end

#color(color) ⇒ Object



50
51
52
53
54
# File 'lib/rust-plots.rb', line 50

def color(color)
    @options['col'] = color
    
    return self
end

#pdf(path, **options) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rust-plots.rb', line 76

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._run_plugins
        Rust._eval("dev.off()")
    end
    
    return self
end

#plug(plugin) ⇒ Object

Raises:

  • (TypeError)


56
57
58
59
60
61
# File 'lib/rust-plots.rb', line 56

def plug(plugin)
    raise TypeError, "Expected Plugin" unless plugin.is_a?(Plugin)
    @plugins << plugin
    
    return self
end

#showObject



67
68
69
70
71
72
73
74
# File 'lib/rust-plots.rb', line 67

def show()
    Rust.exclusive do
        self._show
        self._run_plugins
    end
    
    return self
end

#title(title) ⇒ Object



44
45
46
47
48
# File 'lib/rust-plots.rb', line 44

def title(title)
    @options['main'] = title
    
    return self
end

#x_label(label) ⇒ Object



11
12
13
14
15
# File 'lib/rust-plots.rb', line 11

def x_label(label)
    @options['xlab'] = label
    
    return self
end

#x_range(range) ⇒ Object



23
24
25
26
27
# File 'lib/rust-plots.rb', line 23

def x_range(range)
    @options['xlim'] = range
    
    return self
end

#y_label(label) ⇒ Object



17
18
19
20
21
# File 'lib/rust-plots.rb', line 17

def y_label(label)
    @options['ylab'] = label
    
    return self
end

#y_range(range) ⇒ Object



29
30
31
32
33
# File 'lib/rust-plots.rb', line 29

def y_range(range)
    @options['ylim'] = range
    
    return self
end