rorschart 0.10.3 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7076b6347dbe789e849121a6b3782c4f1155c33
4
- data.tar.gz: 4d6771206d3564302ad9d1ffd708faa94a54f9b3
3
+ metadata.gz: 1796e18cfc48a16921780aaecd6d52d4d0512610
4
+ data.tar.gz: f4df16d9dfcfd300a31fc0009d231f59f042ba1e
5
5
  SHA512:
6
- metadata.gz: 5642f0fe2f4dba943438e1d15b9be1fd47da107b077e3f2123e4b9bb444a0cba5ee528418a5e409d45f8f751bb060942905eeba287f91374b6dcbb3acdb17cae
7
- data.tar.gz: 06b0d461066635aa45ca217918ef3852a8a40d1e8beb82d320aa24658b1ac5d71ca6a5c99e48b2b266bf544670e2c7b3875f7778e679b4464f66ced7435647d5
6
+ metadata.gz: 033abe8fa201b49fbdc8fa14b8b4b87123cfbf995110762a303994a7531399b6e56e4c68c73700b542718f52213f61b6d944d57a084c3eb039e02f8f5a2285a0
7
+ data.tar.gz: 170940cb189d42cbf961fbc9f748c6f783c365dd2e7684510466610bdb93e91ec1e9552bae68ebdb434df7c97abc13f0bd727f6d6c1e49284961aab01d699a69
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rorschart (0.10.3)
4
+ rorschart (0.11.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/rorschart.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "rorschart/version"
2
2
  require "rorschart/helper"
3
- require "rorschart/multiple_series"
3
+ require "rorschart/data/multiple_series"
4
+ require "rorschart/data/pivot_series"
4
5
  require "rorschart/rails" if defined?(Rails)
@@ -1,22 +1,21 @@
1
1
  module Rorschart
2
- class MultipleSeries
2
+ class MultipleSeries < RorschartData
3
3
 
4
- attr_accessor :raw_series, :pivot_series
4
+ attr_accessor :raw_series, :rorschart_series
5
5
 
6
6
  def initialize(raw_series)
7
7
  @raw_series = raw_series
8
- @pivot_series = raw_series.collect { |serie|
9
- PivotData.new(serie)
8
+ @rorschart_series = raw_series.collect { |serie|
9
+ RorschartData.new(serie)
10
10
  }
11
11
  end
12
12
 
13
13
  def cols
14
- cols_with_dup = @pivot_series.inject([]) { |cols, series|
15
- cols + series.cols
14
+ cols_with_dup = @rorschart_series.inject([]) { |cols, series|
15
+ cols + (series.cols || [])
16
16
  }
17
17
 
18
18
  cols_with_dup.uniq
19
-
20
19
  end
21
20
 
22
21
  def rows
@@ -25,8 +24,8 @@ module Rorschart
25
24
 
26
25
  # Preparation: store all series rows in a hash indexed by first column
27
26
  series_indexed = []
28
- @pivot_series.each { |serie|
29
- series_indexed << index_series_by_first_col(serie)
27
+ @rorschart_series.each { |serie|
28
+ series_indexed << index_series_by_first_col(serie) if !serie.cols.nil?
30
29
  }
31
30
 
32
31
  # The Merge:
@@ -46,12 +45,9 @@ module Rorschart
46
45
 
47
46
  private
48
47
 
49
- def uniq_label(label)
50
- end
51
-
52
48
  def union_of_first_columns
53
49
  (
54
- @pivot_series.inject([]) { |union, serie|
50
+ @rorschart_series.inject([]) { |union, serie|
55
51
  union + serie.rows
56
52
  }
57
53
  ).collect{|r| r[0]}.uniq.sort
@@ -68,4 +64,4 @@ module Rorschart
68
64
  end
69
65
 
70
66
  end
71
- end
67
+ end
@@ -0,0 +1,44 @@
1
+ module Rorschart
2
+ class PivotSeries < RorschartData
3
+
4
+ def initialize(raw_serie)
5
+ rorschart_serie = RorschartData.new(raw_serie)
6
+
7
+ # Initialiaze a default row with nil values
8
+ row_nil = init_cols_with_nil(rorschart_serie)
9
+
10
+ rows_by_x = {}
11
+ rorschart_serie.rows.each { |r|
12
+ rows_by_x[r[0]] = row_nil.dup if rows_by_x[r[0]].nil?
13
+ rows_by_x[r[0]][r[1]] = r[2]
14
+ }
15
+
16
+ # Flatten rows hash into array matrix
17
+ @rows = rows_by_x.collect { |row|
18
+ [row[0], row[1].values].flatten
19
+ }
20
+
21
+ #cols
22
+ type = rorschart_serie.cols[2][:type]
23
+ @cols = []
24
+ @cols << rorschart_serie.cols[0]
25
+ row_nil.keys.each { |r|
26
+ @cols << { :type => type, :label => r }
27
+ }
28
+
29
+ sort_by_date!
30
+ end
31
+
32
+ private
33
+
34
+ def init_cols_with_nil(rorschart_serie)
35
+ col_nil = {}
36
+ rorschart_serie.rows.collect{|r| r[1]}.uniq.each{ |c|
37
+ col_nil[c] = nil
38
+ }
39
+ return col_nil
40
+ end
41
+
42
+
43
+ end
44
+ end
@@ -1,13 +1,12 @@
1
1
  module Rorschart
2
2
 
3
- class PivotData
3
+ class RorschartData
4
4
 
5
5
  attr_accessor :cols, :rows
6
6
 
7
7
  def initialize(raw_data)
8
8
 
9
9
  data = convert_objects_to_array_of_hash(raw_data)
10
- data = data.to_pivot if data.is_a? Rorschart::MultipleSeries
11
10
 
12
11
  case data
13
12
  when Array
@@ -29,7 +28,7 @@ module Rorschart
29
28
  def sort_by_date!
30
29
 
31
30
  if ['datetime', 'date'].include? @cols.first[:type]
32
- @rows.sort!
31
+ @rows = @rows.sort_by{ |c| c.first }
33
32
  end
34
33
 
35
34
  end
@@ -2,7 +2,7 @@ module Rorschart
2
2
  module GoogleChart
3
3
  module Mapper
4
4
 
5
- require 'rorschart/pivot_data'
5
+ require 'rorschart/data/rorschart_data'
6
6
 
7
7
  def format_if_needed(data_source)
8
8
  data_source.is_a?(String) ? data_source : to_datatable_format(data_source)
@@ -12,14 +12,14 @@ module Rorschart
12
12
 
13
13
  return data if is_already_converted? data
14
14
 
15
- if (data.is_a? Rorschart::MultipleSeries)
16
- pivot = data
15
+ if (data.is_a? RorschartData)
16
+ r_data = data
17
17
  else
18
- pivot = PivotData.new(data)
19
- pivot.sort_by_date!
18
+ r_data = RorschartData.new(data)
19
+ r_data.sort_by_date!
20
20
  end
21
21
 
22
- return {cols: pivot.cols, rows: add_rows(pivot.rows) }
22
+ return {cols: r_data.cols, rows: add_rows(r_data.rows) }
23
23
  end
24
24
 
25
25
  def is_already_converted?(data)
@@ -62,8 +62,7 @@ module Rorschart
62
62
  tableRow: 'table_row',
63
63
  headerRow: 'header_row',
64
64
  headerCell: 'header_cel'
65
- },
66
- height: "auto"
65
+ }
67
66
  },
68
67
  "AreaChart" => {
69
68
  isStacked: true,
@@ -19,11 +19,6 @@ module Rorschart
19
19
  rorschart_chart "ColumnChart", data_source, options
20
20
  end
21
21
 
22
- def stacked_column_chart(data_source, options = {})
23
- options = {:isStacked => true}.merge(options)
24
- rorschart_chart "ColumnChart", data_source, options
25
- end
26
-
27
22
  def bar_chart(data_source, options = {})
28
23
  rorschart_chart "BarChart", data_source, options
29
24
  end
@@ -77,4 +72,4 @@ JS
77
72
  end
78
73
 
79
74
  end
80
- end
75
+ end
@@ -1,3 +1,3 @@
1
1
  module Rorschart
2
- VERSION = "0.10.3"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -0,0 +1,78 @@
1
+ require "test_helper"
2
+ require "rorschart/data/rorschart_data"
3
+
4
+ module Rorschart
5
+
6
+ class TestPivotSeries < Minitest::Unit::TestCase
7
+
8
+ def test_pivot
9
+
10
+ # Given
11
+ data = [
12
+ {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "A", "count"=> 1},
13
+ {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "B", "count"=> 2},
14
+ {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "C", "count"=> 3},
15
+ {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "D", "count"=> 4},
16
+ {"collector_tstamp"=> Date.parse("2013-12-01"), "series" => "A", "count"=> 5},
17
+ {"collector_tstamp"=> Date.parse("2013-12-01"), "series" => "B", "count"=> 6},
18
+ {"collector_tstamp"=> Date.parse("2013-12-01"), "series" => "D", "count"=> 7}
19
+
20
+ ]
21
+
22
+ # When
23
+
24
+ pivot_series = PivotSeries.new(data)
25
+
26
+ # assert
27
+ expected_cols = [
28
+ {:type=>"date", :label=>"collector_tstamp"},
29
+ {:type=>"number", :label=>"A"},
30
+ {:type=>"number", :label=>"B"},
31
+ {:type=>"number", :label=>"C"},
32
+ {:type=>"number", :label=>"D"}
33
+
34
+ ]
35
+
36
+ expected_rows = [
37
+ [Date.parse("2013-11-02"), 1, 2, 3, 4],
38
+ [Date.parse("2013-12-01"), 5, 6, nil, 7]
39
+ ]
40
+
41
+ assert_equal expected_cols, pivot_series.cols
42
+ assert_equal expected_rows, pivot_series.rows
43
+
44
+ end
45
+
46
+ # def test_convert_numeric_grouped_dy_date_and_multiple_fields_into_multiseries
47
+
48
+ # # Given
49
+ # data = [
50
+ # {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "A", "count"=> 1},
51
+ # {"collector_tstamp"=> Date.parse("2013-11-02"), "series" => "B", "count"=> 2},
52
+ # {"collector_tstamp"=> Date.parse("2013-12-01"), "series" => "A", "count"=> 3},
53
+ # {"collector_tstamp"=> Date.parse("2013-12-01"), "series" => "B", "count"=> 4}
54
+ # ]
55
+
56
+ # # When
57
+ # dataTable = to_datatable_format(data)
58
+
59
+ # # Then
60
+ # excepted = {
61
+ # cols: [
62
+ # {type: 'date', label: 'collector_tstamp'},
63
+ # {type: 'number', label: 'A'},
64
+ # {type: 'number', label: 'B'}
65
+ # ],
66
+ # rows: [
67
+ # {c:[{v: Date.parse("2013-11-02")}, {v: 1}, {v: 2}]},
68
+ # {c:[{v: Date.parse("2013-12-01")}, {v: 3}, {v: 4}]}
69
+ # ]
70
+ # }
71
+
72
+ # compare_dataTable excepted, dataTable
73
+ # end
74
+
75
+
76
+ end
77
+
78
+ end
@@ -1,9 +1,9 @@
1
1
  require "test_helper"
2
- require "rorschart/pivot_data"
2
+ require "rorschart/data/rorschart_data"
3
3
 
4
4
  module Rorschart
5
5
 
6
- class TestPivotData < Minitest::Unit::TestCase
6
+ class TestRorschartData < Minitest::Unit::TestCase
7
7
 
8
8
  def test_flatten_data
9
9
 
@@ -16,8 +16,8 @@ module Rorschart
16
16
 
17
17
  # When
18
18
 
19
- pivot_data = PivotData.new(nil)
20
- flat = pivot_data.send(:flatten_array_hash, data)
19
+ rorschart_data = RorschartData.new(nil)
20
+ flat = rorschart_data.send(:flatten_array_hash, data)
21
21
 
22
22
  # flat = flatten_array_hash(data)
23
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorschart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Pantera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-27 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,17 +97,19 @@ files:
97
97
  - app/assets/javascripts/rorschart.js
98
98
  - app/assets/stylesheets/rorschart.css
99
99
  - lib/rorschart.rb
100
+ - lib/rorschart/data/multiple_series.rb
101
+ - lib/rorschart/data/pivot_series.rb
102
+ - lib/rorschart/data/rorschart_data.rb
100
103
  - lib/rorschart/engine.rb
101
104
  - lib/rorschart/google_chart_mapper.rb
102
105
  - lib/rorschart/google_chart_options.rb
103
106
  - lib/rorschart/helper.rb
104
- - lib/rorschart/multiple_series.rb
105
- - lib/rorschart/pivot_data.rb
106
107
  - lib/rorschart/rails.rb
107
108
  - lib/rorschart/version.rb
108
109
  - rorschart.gemspec
110
+ - test/data/pivot_series_test.rb
111
+ - test/data/rorschart_data_test.rb
109
112
  - test/google_chart_mapper_test.rb
110
- - test/pivot_data_test.rb
111
113
  - test/test_helper.rb
112
114
  homepage: https://github.com/epantera/rorschart
113
115
  licenses:
@@ -134,6 +136,7 @@ signing_key:
134
136
  specification_version: 4
135
137
  summary: Beautiful Google Charts from Rails data structures
136
138
  test_files:
139
+ - test/data/pivot_series_test.rb
140
+ - test/data/rorschart_data_test.rb
137
141
  - test/google_chart_mapper_test.rb
138
- - test/pivot_data_test.rb
139
142
  - test/test_helper.rb