Class: DYI::Chart::Base Abstract

Inherits:
Object
  • Object
show all
Extended by:
OptionCreator
Defined in:
lib/dyi/chart/base.rb

Overview

This class is abstract.

Base class of all the chart classes.

Since:

  • 0.0.0

Direct Known Subclasses

LineChart, PieChart, Table

Constant Summary collapse

DEFAULT_CHART_COLOR =

Since:

  • 0.0.0

['#ff0f00', '#ff6600', '#ff9e01', '#fcd202', '#f8ff01', '#b0de09', '#04d215', '#0d8ecf', '#0d52d1', '#2a0cd0', '#8a0ccf', '#cd0d74']

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionCreator

opt_accessor, opt_reader, opt_writer

Constructor Details

#initialize(width, height, options = {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • width (Length)

    width of the chart image

  • height (Length)

    height of the chart image

  • options (Hash{Symbol => Object}) (defaults to: {})

    the options to creat the chart image. See Instance Attribute of the each chart class (DYI::Chart::Base, PieChart, LineChart, etc…).

Since:

  • 0.0.0



255
256
257
258
259
260
261
# File 'lib/dyi/chart/base.rb', line 255

def initialize(width, height, options={})
  @canvas = Canvas.new(width, height)
  @options = {}
  options.each do |key, value|
    __send__("#{key}=", value) if respond_to?("#{key}=")
  end
end

Instance Attribute Details

#canvasCanvas (readonly)

Returns the canvas of the image body.

Returns:

  • (Canvas)

    the canvas of the image body

Since:

  • 0.0.0



210
211
212
# File 'lib/dyi/chart/base.rb', line 210

def canvas
  @canvas
end

#dataChart::ArrayReader (readonly)

Returns the data for the chart.

Returns:

Since:

  • 0.0.0



206
207
208
# File 'lib/dyi/chart/base.rb', line 206

def data
  @data
end

Instance Method Details

#clear_real_sizeObject

Clears real size of the chart image, and sets chart size as values of width and height properties. See #set_real_size, #width, #height, DYI::Canvas#real_width and DYI::Canvas#real_height.

Since:

  • 0.0.0



298
299
300
301
# File 'lib/dyi/chart/base.rb', line 298

def clear_real_size
  @canvas.real_width = nil
  @canvas.real_height = nil
end

#heightLength

Returns height of the chart image on user unit.

Returns:

  • (Length)

    height of the chart image on user unit

Since:

  • 0.0.0



277
278
279
# File 'lib/dyi/chart/base.rb', line 277

def height
  @canvas.height
end

#height=(height) ⇒ Object

Sets height of the chart image on user unit.

Parameters:

  • height (Length)

    height of the chart image on user unit

Since:

  • 0.0.0



283
284
285
# File 'lib/dyi/chart/base.rb', line 283

def height=(height)
  @canvas.height = height
end

#load_data(reader) ⇒ Object

Loads the data, and creates chart image.

Parameters:

  • reader (ArrayReader)

    the ArrayReader or its sub class that has the data of the chart

Since:

  • 0.0.0



306
307
308
309
# File 'lib/dyi/chart/base.rb', line 306

def load_data(reader)
  @data = reader
  create_vector_image
end

#puts_in_io(format = nil, io = $>, options = {}) ⇒ Object

Outputs the chart image to IO stream.

Parameters:

  • format (Symbol) (defaults to: nil)

    the file format. Supports the following formats:

    :svg

    SVG (Scalable Vector Graphics). If format equals nil, output SVG format.

    :eps

    EPS (Encapsulated Post Script).

    :xaml

    XAML (Extensible Application Markup Language).

    :emf

    EMF (Enhanced Metafile). Using IronRuby only.

    :png

    PNG (Portable Network Graphics). librsvg must have been installed on the system.

  • io (IO) (defaults to: $>)

    the io which the chart image is outputed to

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :inline_mode (Boolean)

    true if outputs the inlime-mode, false otherwise. SVG format only.

Since:

  • 0.0.0



340
341
342
# File 'lib/dyi/chart/base.rb', line 340

def puts_in_io(format=nil, io=$>, options={})
  @canvas.puts_in_io(format, io, options)
end

#save(file_name, format = nil, options = {}) ⇒ Object

Save the chart image as a file.

Parameters:

  • file_name (String)

    the file name which is saved the chart image as

  • format (Symbol) (defaults to: nil)

    the file format. Supports the following formats:

    :svg

    SVG (Scalable Vector Graphics). If format equals nil, output SVG format.

    :eps

    EPS (Encapsulated Post Script).

    :xaml

    XAML (Extensible Application Markup Language).

    :emf

    EMF (Enhanced Metafile). Using IronRuby only.

    :png

    PNG (Portable Network Graphics). librsvg must have been installed on the system.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :inline_mode (Boolean)

    true if outputs the inlime-mode, false otherwise. SVG format only.

Since:

  • 0.0.0



324
325
326
# File 'lib/dyi/chart/base.rb', line 324

def save(file_name, format=nil, options={})
  @canvas.save(file_name, format, options)
end

#set_real_size(width, height) ⇒ Object

Sets size of the chart image.

Parameters:

  • width (Length)

    width of the chart image

  • height (Length)

    height of the chart image

Since:

  • 0.0.0



290
291
292
293
# File 'lib/dyi/chart/base.rb', line 290

def set_real_size(width, height)
  @canvas.real_width = Length.new(width)
  @canvas.real_height = Length.new(height)
end

#string(format = nil, options = {}) ⇒ Object

Outputs the chart image as a String (binary).

Parameters:

  • format (Symbol) (defaults to: nil)

    the file format. Supports the following formats:

    :svg

    SVG (Scalable Vector Graphics). If format equals nil, output SVG format.

    :eps

    EPS (Encapsulated Post Script).

    :xaml

    XAML (Extensible Application Markup Language).

    :emf

    EMF (Enhanced Metafile). Using IronRuby only.

    :png

    PNG (Portable Network Graphics). librsvg must have been installed on the system.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :inline_mode (Boolean)

    true if outputs the inlime-mode, false otherwise. SVG format only.

Since:

  • 0.0.0



355
356
357
# File 'lib/dyi/chart/base.rb', line 355

def string(format=nil, options={})
  @canvas.string(format, options)
end

#widthLength

Returns width of the chart image on user unit.

Returns:

  • (Length)

    width of the chart image on user unit

Since:

  • 0.0.0



265
266
267
# File 'lib/dyi/chart/base.rb', line 265

def width
  @canvas.width
end

#width=(width) ⇒ Object

Sets width of the chart image on user unit.

Parameters:

  • width (Length)

    width of the chart image on user unit

Since:

  • 0.0.0



271
272
273
# File 'lib/dyi/chart/base.rb', line 271

def width=(width)
  @canvas.width = width
end