Module: Rabbit::Parser::Ext::Charty

Includes:
GetText
Defined in:
lib/rabbit/parser/ext/charty.rb

Constant Summary

Constants included from GetText

GetText::DOMAIN

Class Method Summary collapse

Methods included from GetText

included

Class Method Details

.make_image(path, prop, logger) ⇒ Object


26
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
# File 'lib/rabbit/parser/ext/charty.rb', line 26

def make_image(path, prop, logger)
  require "charty"
  backend = prop["backend"]
  ::Charty::Backends.use(backend) if backend
  data = CSV.read(path, headers: true, converters: :all)
  type = prop["type"]
  case type
  when "bar"
    plotter = ::Charty.bar_plot(data: data,
                                x: prop["x"],
                                y: prop["y"],
                                color: prop["color"])
  when "line"
    plotter = ::Charty.line_plot(data: data,
                                 x: prop["x"],
                                 y: prop["y"],
                                 color: prop["color"])
  when "scatter"
    plotter = ::Charty.scatter_plot(data: data,
                                    x: prop["x"],
                                    y: prop["y"],
                                    color: prop["color"])
  else
    raise ArgumentError, "charty: unsupported type: #{type.inspect}"
  end
  image_file = Tempfile.new(["rabbit-image-charty", ".svg"])
  plotter.save(image_file.path)
  image_file
end