rgviz-rails 0.48 → 0.49

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  == Rgviz-rails
2
2
 
3
- This library makes it easy to implement a Visualization data source so that you can easily chart or visualize your data from ActiveRecord[http://ar.rubyonrails.org/] models. The library implements the {Google Visualization API wire protocol}[http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html].
3
+ This library makes it easy to implement a Visualization data source so that you can easily chart or visualize your data from ActiveRecord[http://ar.rubyonrails.org/] models or from in-memory arrays. The library implements the {Google Visualization API wire protocol}[http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html].
4
4
 
5
5
  It also allows you to {render the visualizations in a view template}[https://github.com/asterite/rgviz-rails/wiki/Showing-a-visualization-in-a-view] in a very simple but powerful way.
6
6
 
@@ -102,6 +102,21 @@ You can invoke the rgviz method in your views. {Read more about this}[https://gi
102
102
 
103
103
  You can always do it the {old way}[http://code.google.com/apis/visualization/documentation/using_overview.html].
104
104
 
105
+ === Executing queries over in-memory arrays
106
+
107
+ You can also apply a query over an array of arrays that contains your "records" to be queried.
108
+
109
+ types = [[:id, :number], [:name, :string], [:age, :number]]
110
+ records = [
111
+ [1, 'John', 23],
112
+ [2, 'Pete', 36]
113
+ ]
114
+ executor = Rgviz::MemoryExecutor.new records, types
115
+
116
+ render :rgviz => executor
117
+
118
+ This is very useful if you need to present visualizations against data coming from a CSV file.
119
+
105
120
  === Current Limitations
106
121
  * The *format* clause is ignored (If someone knows of a working icu library for ruby, please tell me)
107
122
  * Only supports MySQL, PostgreSQL and SQLite adapters
@@ -15,7 +15,7 @@ module Rgviz
15
15
  when 'sqlite'
16
16
  require File.dirname(__FILE__) + '/adapters/sqlite_adapter.rb'
17
17
  @adapter = SqliteAdapter.new
18
- when 'mysql'
18
+ when 'mysql', 'mysql2'
19
19
  require File.dirname(__FILE__) + '/adapters/mysql_adapter.rb'
20
20
  @adapter = MySqlAdapter.new
21
21
  when 'postgresql'
@@ -334,6 +334,33 @@ module Rgviz
334
334
  i == f ? i : f
335
335
  when :boolean
336
336
  value == 1 || value == '1' ? true : false
337
+ when :date
338
+ value = Time.parse(value).to_date if value.is_a? String
339
+ def value.as_json(options = {})
340
+ self
341
+ end
342
+ def value.encode_json(*)
343
+ "new Date(#{strftime('%Y, %d, %m')})"
344
+ end
345
+ value
346
+ when :datetime
347
+ value = Time.parse(value) if value.is_a? String
348
+ def value.as_json(*)
349
+ self
350
+ end
351
+ def value.encode_json(*)
352
+ "new Date(#{strftime('%Y, %d, %m, %H, %M, %S')})"
353
+ end
354
+ value
355
+ when :timeofday
356
+ value = Time.parse(value) if value.is_a? String
357
+ def value.as_json(*)
358
+ self
359
+ end
360
+ def value.encode_json(*)
361
+ "new Date(#{strftime('0, 0, 0, %H, %M, %S')})"
362
+ end
363
+ value
337
364
  else
338
365
  value.to_s
339
366
  end
@@ -394,15 +421,15 @@ module Rgviz
394
421
  end
395
422
 
396
423
  def visit_date_column(node)
397
- @string += escaped_string(node.value.to_s)
424
+ @string += "date #{escaped_string(node.value.to_s)}"
398
425
  end
399
426
 
400
427
  def visit_date_time_column(node)
401
- @string += escaped_string(node.value.strftime("%Y-%m-%d %H:%M:%S"))
428
+ @string += "timestamp #{escaped_string(node.value.strftime("%Y-%m-%d %H:%M:%S"))}"
402
429
  end
403
430
 
404
431
  def visit_time_of_day_column(node)
405
- @string += escaped_string(node.value.strftime("%H:%M:%S"))
432
+ @string += "time #{escaped_string(node.value.strftime("%H:%M:%S"))}"
406
433
  end
407
434
 
408
435
  def visit_scalar_function_column(node)
@@ -25,7 +25,7 @@ module Rgviz
25
25
  elsif model.respond_to? :execute
26
26
  executor = model
27
27
  else
28
- raise "The parameter to :rgviz => ... must extend from ActiveRecord::Base or respond to execute"
28
+ raise "The argument to render :rgviz => ... must extend from ActiveRecord::Base or respond to execute"
29
29
  end
30
30
  options = {}
31
31
  options[:conditions] = conditions if conditions
@@ -251,7 +251,11 @@ module Rgviz
251
251
 
252
252
  def visit_query(node)
253
253
  @s << "var q = '"
254
- node.select.accept self if node.select
254
+ if node.select && node.select.columns && node.select.columns.length > 0
255
+ node.select.accept self
256
+ else
257
+ @s << 'select * '
258
+ end
255
259
  node.where.accept self if node.where
256
260
  node.group_by.accept self if node.group_by
257
261
  node.pivot.accept self if node.pivot
@@ -14,15 +14,15 @@ describe Executor do
14
14
  end
15
15
 
16
16
  def format_datetime(date)
17
- date.strftime "%Y-%m-%d %H:%M:%S"
17
+ date.strftime "new Date(%Y, %m, %d, %H, %M, %S)"
18
18
  end
19
19
 
20
20
  def format_date(date)
21
- date.strftime "%Y-%m-%d"
21
+ date.strftime "new Date(%Y, %m, %d)"
22
22
  end
23
23
 
24
- def self.it_processes_single_select_column(query, id, type, value, label, options = {})
25
- it "processes select #{query}" do
24
+ def self.it_processes_single_select_column(query, id, type, value, label, options = {}, test_options = {})
25
+ it "processes select #{query}", test_options do
26
26
  if block_given?
27
27
  yield
28
28
  else
@@ -63,8 +63,8 @@ describe Executor do
63
63
  table.rows[0].c.length.should == 7
64
64
 
65
65
  i = 0
66
- [p.id, p.name, p.age, format_date(p.birthday),
67
- format_datetime(p.created_at), format_datetime(p.updated_at), p.city.id].each do |val|
66
+ [p.id, p.name, p.age, p.birthday,
67
+ p.created_at, p.updated_at, p.city.id].each do |val|
68
68
  table.rows[0].c[i].v.should == val
69
69
  i += 1
70
70
  end
@@ -79,9 +79,9 @@ describe Executor do
79
79
  it_processes_single_select_column '"hello"', 'c0', :string, 'hello', "'hello'"
80
80
  it_processes_single_select_column 'false', 'c0', :boolean, false, 'false'
81
81
  it_processes_single_select_column 'true', 'c0', :boolean, true, 'true'
82
- it_processes_single_select_column 'date "2010-01-02"', 'c0', :date, '2010-01-02', "date '2010-01-02'"
83
- it_processes_single_select_column 'datetime "2010-01-02 10:11:12"', 'c0', :datetime, '2010-01-02 10:11:12', "datetime '2010-01-02 10:11:12'"
84
- it_processes_single_select_column 'timeofday "10:11:12"', 'c0', :timeofday, '10:11:12', "timeofday '10:11:12'"
82
+ it_processes_single_select_column 'date "2010-01-02"', 'c0', :date, Time.parse('2010-01-02').to_date, "date '2010-01-02'"
83
+ it_processes_single_select_column 'datetime "2010-01-02 10:11:12"', 'c0', :datetime, Time.parse('2010-01-02 10:11:12'), "datetime '2010-01-02 10:11:12'"
84
+ it_processes_single_select_column 'timeofday "10:11:12"', 'c0', :timeofday, Time.parse('10:11:12'), "timeofday '10:11:12'"
85
85
 
86
86
  it_processes_single_select_column '1 + 2', 'c0', :number, 3, '1 + 2'
87
87
  it_processes_single_select_column '3 - 2', 'c0', :number, 1, '3 - 2'
@@ -250,9 +250,9 @@ describe Executor do
250
250
  # Person.make :created_at => Time.parse('2006-05-02 3:04:09')
251
251
  # end
252
252
 
253
- it_processes_single_select_column "toDate('2008-03-13')", 'c0', :date, Date.parse('2008-03-13').to_s, "toDate('2008-03-13')"
253
+ it_processes_single_select_column "toDate('2008-03-13')", 'c0', :date, Time.parse("2008-03-13").to_date, "toDate('2008-03-13')"
254
254
 
255
- it_processes_single_select_column "toDate(created_at)", 'c0', :date, Date.parse('2008-03-13').to_s, "toDate(created_at)" do
255
+ it_processes_single_select_column "toDate(created_at)", 'c0', :date, Time.parse("2008-03-13").to_date, "toDate(created_at)" do
256
256
  Person.make :created_at => Time.parse('2008-03-13 3:04:09')
257
257
  end
258
258
 
@@ -386,8 +386,8 @@ describe Executor do
386
386
 
387
387
  i = 0
388
388
  [
389
- ['2000-01-12', nil, 1, 10, nil],
390
- [nil, '2001-02-12', 2, nil, 20],
389
+ [Time.parse('2000-01-12').to_date, nil, 1, 10, nil],
390
+ [nil, Time.parse('2001-02-12').to_date, 2, nil, 20],
391
391
  ].each do |values|
392
392
  table.rows[i].c.length.should == 5
393
393
  values.each_with_index do |v, j|
@@ -459,8 +459,8 @@ describe Executor do
459
459
 
460
460
  i = 0
461
461
  [
462
- ['2000-01-12', nil, 10, nil],
463
- [nil, '2001-02-12', nil, 20],
462
+ [Time.parse('2000-01-12').to_date, nil, 10, nil],
463
+ [nil, Time.parse('2001-02-12').to_date, nil, 20],
464
464
  ].each do |values|
465
465
  table.rows[i].c.length.should == 4
466
466
  values.each_with_index do |v, j|
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,8 @@ require 'logger'
5
5
 
6
6
  require 'active_record'
7
7
 
8
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
9
- #ActiveRecord::Base.establish_connection(:adapter => 'mysql', :database => 'rgviz_rails', :username => 'root', :password => '###')
8
+ #ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
9
+ ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'rgviz_rails', :username => 'root', :password => '')
10
10
  #ActiveRecord::Base.establish_connection(:adapter => 'postgresql', :database => 'rgviz_rails', :username => 'postgres', :password => '###', :host => '/var/run/postgresql/')
11
11
 
12
12
  ActiveRecord::Schema.define do
metadata CHANGED
@@ -1,43 +1,34 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 48
8
- version: "0.48"
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.49'
5
+ prerelease:
9
6
  platform: ruby
10
- authors:
7
+ authors:
11
8
  - Ary Borenszweig
12
9
  autorequire:
13
10
  bindir: bin
14
11
  cert_chain: []
15
-
16
- date: 2011-07-08 00:00:00 -03:00
17
- default_executable:
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: rgviz
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70297488435440 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
30
22
  type: :runtime
31
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: *70297488435440
32
25
  description:
33
26
  email: aborenszweig@manas.com.ar
34
27
  executables: []
35
-
36
28
  extensions: []
37
-
38
- extra_rdoc_files:
29
+ extra_rdoc_files:
39
30
  - README.rdoc
40
- files:
31
+ files:
41
32
  - lib/rgviz_rails.rb
42
33
  - lib/rgviz_rails/executor.rb
43
34
  - lib/rgviz_rails/js_renderer.rb
@@ -56,37 +47,28 @@ files:
56
47
  - spec/models/person.rb
57
48
  - spec/rgviz/executor_spec.rb
58
49
  - README.rdoc
59
- has_rdoc: true
60
50
  homepage: http://code.google.com/p/rgviz-rails
61
51
  licenses: []
62
-
63
52
  post_install_message:
64
53
  rdoc_options: []
65
-
66
- require_paths:
54
+ require_paths:
67
55
  - lib
68
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
69
57
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- version: "0"
76
- required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
63
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
- version: "0"
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
84
68
  requirements: []
85
-
86
69
  rubyforge_project:
87
- rubygems_version: 1.3.7
70
+ rubygems_version: 1.8.10
88
71
  signing_key:
89
72
  specification_version: 3
90
73
  summary: rgviz for rails
91
74
  test_files: []
92
-