Class: Rust::Plots::BasePlot

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

Direct Known Subclasses

BarPlot, DistributionPlot, ScatterPlot

Instance Method Summary collapse

Constructor Details

#initializeBasePlot

Returns a new instance of BasePlot.



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

def initialize
    @renderables = []
    @options = Rust::Options.new
    @override_options = true
end

Instance Method Details

#[]=(option, value) ⇒ Object



78
79
80
# File 'lib/rust-plots.rb', line 78

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

#_add_renderable(renderable) ⇒ Object

Raises:

  • (TypeError)


71
72
73
74
75
76
# 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!Object



82
83
84
# File 'lib/rust-plots.rb', line 82

def _do_not_override_options!
    @override_options = false
end

#axis(axis) ⇒ Object



44
45
46
47
48
49
50
51
# 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) ⇒ Object



65
66
67
68
69
# File 'lib/rust-plots.rb', line 65

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

#grid(grid) ⇒ Object



53
54
55
56
57
# File 'lib/rust-plots.rb', line 53

def grid(grid)
    self._add_renderable(grid)
    
    return self
end

#palette(size) ⇒ Object



24
25
26
27
28
29
30
# 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) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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

#showObject



86
87
88
89
90
91
92
93
# File 'lib/rust-plots.rb', line 86

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

#title(title) ⇒ Object



59
60
61
62
63
# File 'lib/rust-plots.rb', line 59

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

#x_label(label) ⇒ Object



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

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

#x_range(range) ⇒ Object



32
33
34
35
36
# File 'lib/rust-plots.rb', line 32

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

#y_label(label) ⇒ Object



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

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

#y_range(range) ⇒ Object



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

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