Class: Rorschart::MultipleSeries
- Inherits:
-
RorschartData
- Object
- RorschartData
- Rorschart::MultipleSeries
- Defined in:
- lib/rorschart/data/multiple_series.rb
Instance Attribute Summary collapse
-
#raw_series ⇒ Object
Returns the value of attribute raw_series.
-
#rorschart_series ⇒ Object
Returns the value of attribute rorschart_series.
-
#to_sql ⇒ Object
Returns the value of attribute to_sql.
Instance Method Summary collapse
- #cols ⇒ Object
-
#initialize(raw_series) ⇒ MultipleSeries
constructor
A new instance of MultipleSeries.
- #rows ⇒ Object
Methods inherited from RorschartData
Constructor Details
#initialize(raw_series) ⇒ MultipleSeries
Returns a new instance of MultipleSeries.
6 7 8 9 10 11 12 |
# File 'lib/rorschart/data/multiple_series.rb', line 6 def initialize(raw_series) @to_sql = raw_series.map { |serie| serie.to_sql rescue nil }.delete_if { |serie| serie.nil? } @raw_series = raw_series @rorschart_series = raw_series.collect { |serie| RorschartData.new(serie) } end |
Instance Attribute Details
#raw_series ⇒ Object
Returns the value of attribute raw_series.
4 5 6 |
# File 'lib/rorschart/data/multiple_series.rb', line 4 def raw_series @raw_series end |
#rorschart_series ⇒ Object
Returns the value of attribute rorschart_series.
4 5 6 |
# File 'lib/rorschart/data/multiple_series.rb', line 4 def rorschart_series @rorschart_series end |
#to_sql ⇒ Object
Returns the value of attribute to_sql.
4 5 6 |
# File 'lib/rorschart/data/multiple_series.rb', line 4 def to_sql @to_sql end |
Instance Method Details
#cols ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rorschart/data/multiple_series.rb', line 14 def cols cols_with_dup = @rorschart_series.inject([]) { |cols, series| cols + (series.cols || []) } cols_with_dup.uniq end |
#rows ⇒ Object
22 23 24 25 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 |
# File 'lib/rorschart/data/multiple_series.rb', line 22 def rows # create union of all series first columns, to represent all abscisse values available union_x = union_of_first_columns() # Preparation: store all series rows in a hash indexed by first column series_indexed = [] @rorschart_series.each { |serie| series_indexed << index_series_by_first_col(serie) if !serie.cols.nil? } # The Merge: # For abscisse value, grab for each serie the corresponding row - or nil union_series = [] asc = true union_x.each { |x| row = [x] series_indexed.each { |serie_hash| row << serie_hash[x] asc = asc && ascending?(serie_hash) } union_series << row.flatten } if !asc union_series = union_series.reverse end # Return union of all series union_series end |