Class: Charty::Gruff

Inherits:
PlotterAdapter show all
Defined in:
lib/charty/backends/gruff.rb

Constant Summary collapse

Name =
"gruff"

Instance Method Summary collapse

Methods inherited from PlotterAdapter

create, inherited

Constructor Details

#initializeGruff


7
8
9
# File 'lib/charty/backends/gruff.rb', line 7

def initialize
  @plot = ::Gruff
end

Instance Method Details

#label(x, y) ⇒ Object


11
12
# File 'lib/charty/backends/gruff.rb', line 11

def label(x, y)
end

#plot(plot, context) ⇒ Object


27
28
29
30
31
32
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
75
76
77
78
79
# File 'lib/charty/backends/gruff.rb', line 27

def plot(plot, context)
  # case
  # when plot.respond_to?(:xlim)
  #   plot.xlim(context.range_x.begin, context.range_x.end)
  #   plot.ylim(context.range_y.begin, context.range_y.end)
  # when plot.respond_to?(:set_xlim)
  #   plot.set_xlim(context.range_x.begin, context.range_x.end)
  #   plot.set_ylim(context.range_y.begin, context.range_y.end)
  # end

  case context.method
  when :bar
    p = plot::Bar.new
    p.title = context.title if context.title
    p.x_axis_label = context.xlabel if context.xlabel
    p.y_axis_label = context.ylabel if context.ylabel
    context.series.each do |data|
      p.data(data.label, data.xs.to_a)
    end
    p
  when :barh
    # TODO: To implement
    raise NotImplementedError
  when :box_plot
    # refs. https://github.com/topfunky/gruff/issues/155
    raise NotImplementedError
  when :bubble
    raise NotImplementedError
  when :curve
    p = plot::Line.new
    p.title = context.title if context.title
    p.x_axis_label = context.xlabel if context.xlabel
    p.y_axis_label = context.ylabel if context.ylabel
    context.series.each do |data|
      p.data(data.label, data.xs.to_a)
    end
    p
  when :scatter
    p = plot::Scatter.new
    p.title = context.title if context.title
    p.x_axis_label = context.xlabel if context.xlabel
    p.y_axis_label = context.ylabel if context.ylabel
    context.series.each do |data|
      p.data(data.label, data.xs.to_a, data.ys.to_a)
    end
    p
  when :error_bar
    # refs. https://github.com/topfunky/gruff/issues/163
    raise NotImplementedError
  when :hist
    raise NotImplementedError
  end
end

#render(context, filename = "") ⇒ Object


22
23
24
25
# File 'lib/charty/backends/gruff.rb', line 22

def render(context, filename="")
  FileUtils.mkdir_p(File.dirname(filename))
  plot(@plot, context).write(filename)
end

#render_layout(layout) ⇒ Object

Raises:

  • (NotImplementedError)

18
19
20
# File 'lib/charty/backends/gruff.rb', line 18

def render_layout(layout)
  raise NotImplementedError
end

#series=(series) ⇒ Object


14
15
16
# File 'lib/charty/backends/gruff.rb', line 14

def series=(series)
  @series = series
end