Class: Sol::Chart

Inherits:
Object
  • Object
show all
Includes:
BaseChart
Defined in:
lib/sol/chart.rb

Overview

Direct Known Subclasses

BarChart, LineChart

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseChart

#data, #dimension, #group, #grouped?, #height, #min_height, #min_width, #transition_duration, #width

Constructor Details

#initialize(type, x_column, y_column, name) ⇒ Chart





81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sol/chart.rb', line 81

def initialize(type, x_column, y_column, name)

  @type = type
  @dim = x_column + "Dimension"
  @jstype = Chart.chart_map[type]
  @y_column = y_column
  @name = name
  @spot = name + "Chart"
  @properties = Hash.new

  dimension(Sol.camelcase(@dim.to_s))
  
end

Class Attribute Details

.chart_mapObject (readonly)

Returns the value of attribute chart_map.



63
64
65
# File 'lib/sol/chart.rb', line 63

def chart_map
  @chart_map
end

Instance Attribute Details

#dimObject (readonly)

Returns the value of attribute dim.



69
70
71
# File 'lib/sol/chart.rb', line 69

def dim
  @dim
end

#jstypeObject (readonly)

Returns the value of attribute jstype.



70
71
72
# File 'lib/sol/chart.rb', line 70

def jstype
  @jstype
end

#nameObject (readonly)

Returns the value of attribute name.



71
72
73
# File 'lib/sol/chart.rb', line 71

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



75
76
77
# File 'lib/sol/chart.rb', line 75

def properties
  @properties
end

#spotObject (readonly)

Returns the value of attribute spot.



74
75
76
# File 'lib/sol/chart.rb', line 74

def spot
  @spot
end

#typeObject (readonly)

Returns the value of attribute type.



68
69
70
# File 'lib/sol/chart.rb', line 68

def type
  @type
end

#y_columnObject (readonly)

Returns the value of attribute y_column.



72
73
74
# File 'lib/sol/chart.rb', line 72

def y_column
  @y_column
end

Class Method Details

.build(type, x_column, y_column, name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sol/chart.rb', line 46

def self.build(type, x_column, y_column, name)
  case type
  when :line_chart
    return LineChart.new(type, x_column, y_column, name)
  when :bar_chart
    return BarChart.new(type, x_column, y_column, name)
  else
    return Chart.new(type, x_column, y_column, name)
  end

end

Instance Method Details

#headerObject





115
116
117
118
119
120
121
122
# File 'lib/sol/chart.rb', line 115

def header

<<-EOS
var #{@name} = dc.#{@jstype}(\"##{@spot}\"); 
#{@group}
EOS

end

#js_specObject





128
129
130
131
# File 'lib/sol/chart.rb', line 128

def js_spec
  gr = header + props
  gr
end

#propsObject





99
100
101
102
103
104
105
106
107
108
109
# File 'lib/sol/chart.rb', line 99

def props

  # start the chart specification
  str = @name
  @properties.each_pair do |key, value|
    str << "." + "#{key}(#{value})"
  end
  str << ";"
  str

end