Class: DYI::Chart::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/dyi/chart/table.rb

Overview

Since:

  • 0.0.0

Constant Summary

Constants inherited from Base

Base::DEFAULT_CHART_COLOR

Instance Attribute Summary collapse

Attributes inherited from Base

#canvas, #data

Instance Method Summary collapse

Methods inherited from Base

#clear_real_size, #height, #height=, #initialize, #load_data, #puts_in_io, #save, #set_real_size, #string, #width, #width=

Methods included from OptionCreator

#opt_accessor, #opt_reader, #opt_writer

Constructor Details

This class inherits a constructor from DYI::Chart::Base

Instance Attribute Details

#data_canvasObject (readonly)

Since:

  • 0.0.0



28
29
30
# File 'lib/dyi/chart/table.rb', line 28

def data_canvas
  @data_canvas
end

#frame_canvasObject (readonly)

Since:

  • 0.0.0



28
29
30
# File 'lib/dyi/chart/table.rb', line 28

def frame_canvas
  @frame_canvas
end

Instance Method Details

#column_colorsObject

Since:

  • 0.0.0



106
107
108
# File 'lib/dyi/chart/table.rb', line 106

def column_colors
  @options[:column_colors]
end

#column_colors=(colors) ⇒ Object

Since:

  • 0.0.0



110
111
112
113
114
115
116
117
# File 'lib/dyi/chart/table.rb', line 110

def column_colors=(colors)
  if colors && !colors.empty?
    @options[:column_colors] = colors
  else
    @options.delete(:column_colors)
  end
  colors
end

#column_width(index) ⇒ Object

Since:

  • 0.0.0



71
72
73
74
75
76
77
# File 'lib/dyi/chart/table.rb', line 71

def column_width(index)
  case column_widths
    when Length then column_widths
    when Array then column_widths[index]
    else width / series.size
  end
end

#column_widthsObject

Since:

  • 0.0.0



56
57
58
# File 'lib/dyi/chart/table.rb', line 56

def column_widths
  @options[:column_widths]
end

#column_widths=(widths) ⇒ Object

Since:

  • 0.0.0



60
61
62
63
64
65
66
67
68
69
# File 'lib/dyi/chart/table.rb', line 60

def column_widths=(widths)
  if widths.kind_of?(Array)
    @options[:column_widths] = widths.map {|width| Length.new_or_nil(width)}
  elsif widths
    @options[:column_widths] = Length.new(widths)
  else
    @options.delete(:column_widths)
  end
  point
end

#fontObject

Since:

  • 0.0.0



30
31
32
# File 'lib/dyi/chart/table.rb', line 30

def font
  @options[:font]
end

#font=(font) ⇒ Object

Since:

  • 0.0.0



34
35
36
37
38
39
40
41
# File 'lib/dyi/chart/table.rb', line 34

def font=(font)
  if font && !font.empty?
    @options[:font] = Font.new(font)
  else
    @options.delete(:font)
  end
  font
end

#horizontal_position(index) ⇒ Object

Since:

  • 0.0.0



102
103
104
# File 'lib/dyi/chart/table.rb', line 102

def horizontal_position(index)
  @options[:horizontal_positions] && @options[:horizontal_positions][index]
end

#horizontal_positionsObject

Since:

  • 0.0.0



89
90
91
# File 'lib/dyi/chart/table.rb', line 89

def horizontal_positions
  @options[:horizontal_positions]
end

#horizontal_positions=(positions) ⇒ Object

Since:

  • 0.0.0



93
94
95
96
97
98
99
100
# File 'lib/dyi/chart/table.rb', line 93

def horizontal_positions=(positions)
  if positions && !positions.empty?
    @options[:horizontal_positions] = positions
  else
    @options.delete(:horizontal_positions)
  end
  positions
end

#row_heightObject

Since:

  • 0.0.0



43
44
45
# File 'lib/dyi/chart/table.rb', line 43

def row_height
  @options[:row_height] ||= (font && font.draw_size || Font::DEFAULT_SIZE) * 1.4
end

#row_height=(height) ⇒ Object

Since:

  • 0.0.0



47
48
49
50
51
52
53
54
# File 'lib/dyi/chart/table.rb', line 47

def row_height=(height)
  if heights
    @options[:row_height] = Length.new(height)
  else
    @options.delete(:row_height)
  end
  point
end

#table_heightObject

Since:

  • 0.0.0



85
86
87
# File 'lib/dyi/chart/table.rb', line 85

def table_height
  row_height * data[series.first].size
end

#table_widthObject

Since:

  • 0.0.0



79
80
81
82
83
# File 'lib/dyi/chart/table.rb', line 79

def table_width
  series.inject(Length.new(0)) do |width, i|
    width + column_width(i)
  end
end