query_report 1.0.26 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/views/query_report/_chart.html.erb +1 -1
- data/lib/query_report/chart_adapter.rb +38 -0
- data/lib/query_report/report.rb +2 -4
- data/lib/query_report/version.rb +1 -1
- metadata +19 -9
- data/lib/query_report/chart/chart_base.rb +0 -59
- data/lib/query_report/chart/chart_column.rb +0 -12
- data/lib/query_report/chart/column_chart.rb +0 -40
- data/lib/query_report/chart/pie_chart.rb +0 -41
- data/lib/query_report/chart/themes.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f8d3573e1023f1f75ccfc342c5b499c2190ea2f
|
4
|
+
data.tar.gz: 2395c213bb91c1fce5e11b1e30e7713234515d2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9cd49d9a017a27117ee609c3b284a046450cdfff5e30e215828c22c7a7d8845ed61915e04a06eea6a5d08f69fcf9cf510f86f4890c8252c5f4706a1e53b908b
|
7
|
+
data.tar.gz: 078ec9cf9dbe6a1bd14dd7ab8515bee7c7e08b6a9900d050272997aafae431b7acdaf58ea0916e78da6bbd6803bfec83a7d5318a2c448ccc7e19f0ffbec3ac70
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/query_report.png)](http://badge.fury.io/rb/query_report)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ashrafuzzaman/query_report.png)](https://codeclimate.com/github/ashrafuzzaman/query_report)
|
6
6
|
[![Code coverage](https://codeclimate.com/github/ashrafuzzaman/query_report/coverage.png)](https://codeclimate.com/github/ashrafuzzaman/query_report)
|
7
|
+
[![Dependencies](https://gemnasium.com/ashrafuzzaman/query_report.png)](https://gemnasium.com/ashrafuzzaman/query_report)
|
7
8
|
|
8
9
|
###Write the action with a simple DSL and get a report with PDF and CSV export, gorgeous charts, out of box filters, with I18n support, etc...
|
9
10
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Author:: A.K.M. Ashrafuzzaman (mailto:ashrafuzzaman.g2@gmail.com)
|
2
|
+
# License:: MIT-LICENSE
|
3
|
+
|
4
|
+
# The purpose of the filter module is adapt the chart features form chartify
|
5
|
+
require 'chartify/factory'
|
6
|
+
|
7
|
+
module QueryReport
|
8
|
+
module ChartAdapterModule
|
9
|
+
def chart(chart_type, chart_title, &block)
|
10
|
+
chart_adapter = ChartAdapter.new(filtered_query, chart_type, chart_title)
|
11
|
+
block.call(chart_adapter)
|
12
|
+
@charts << chart_adapter.chart
|
13
|
+
|
14
|
+
ap chart_adapter.chart.data
|
15
|
+
ap chart_adapter.chart
|
16
|
+
end
|
17
|
+
|
18
|
+
class ChartAdapter
|
19
|
+
attr_accessor :query, :chart_type, :chart
|
20
|
+
delegate :data, :data=, :columns, :columns=, :label_column, :label_column=, to: :chart
|
21
|
+
|
22
|
+
def initialize(query, chart_type, chart_title)
|
23
|
+
@query = query
|
24
|
+
@chart_type = chart_type
|
25
|
+
@chart = "Chartify::#{chart_type.to_s.camelize}Chart".constantize.new
|
26
|
+
@chart.title = chart_title
|
27
|
+
# do |chart|
|
28
|
+
# chart.data = [{hours_remain: 100, estimated_hours_remain: 100, day: 3.days.ago.to_date},
|
29
|
+
# {hours_remain: 50, estimated_hours_remain: 45, day: 2.days.ago.to_date},
|
30
|
+
# {hours_remain: 5, estimated_hours_remain: 10, day: 1.days.ago.to_date}]
|
31
|
+
# chart.columns = {hours_remain: 'Hours remaining', estimated_hours_remain: 'Estimated hours remaining'}
|
32
|
+
# chart.label_column = :day
|
33
|
+
# end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/query_report/report.rb
CHANGED
@@ -3,8 +3,7 @@ module QueryReport
|
|
3
3
|
autoload :FilterModule, 'query_report/filter'
|
4
4
|
autoload :PaginateModule, 'query_report/paginate'
|
5
5
|
autoload :Record, 'query_report/record'
|
6
|
-
autoload :
|
7
|
-
autoload :PieChartModule, 'query_report/chart/pie_chart'
|
6
|
+
autoload :ChartAdapterModule, 'query_report/chart_adapter'
|
8
7
|
|
9
8
|
DEFAULT_OPTIONS = {enable_chart: true, chart_on_web: true, chart_on_pdf: true, paginate: true}
|
10
9
|
|
@@ -15,8 +14,7 @@ module QueryReport
|
|
15
14
|
include QueryReport::FilterModule
|
16
15
|
include QueryReport::PaginateModule
|
17
16
|
include QueryReport::Record
|
18
|
-
include QueryReport::
|
19
|
-
include QueryReport::PieChartModule
|
17
|
+
include QueryReport::ChartAdapterModule
|
20
18
|
|
21
19
|
def initialize(params, template, options={}, &block)
|
22
20
|
@params, @template = params, template
|
data/lib/query_report/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- A.K.M. Ashrafuzzaman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '0.
|
95
|
+
version: '0.16'
|
96
96
|
type: :runtime
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '0.
|
102
|
+
version: '0.16'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: prawn
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,6 +114,20 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '1.0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: chartify
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.2'
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.2'
|
117
131
|
- !ruby/object:Gem::Dependency
|
118
132
|
name: rake
|
119
133
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,11 +229,7 @@ files:
|
|
215
229
|
- config/routes.rb
|
216
230
|
- db/schema.rb
|
217
231
|
- lib/query_report.rb
|
218
|
-
- lib/query_report/
|
219
|
-
- lib/query_report/chart/chart_column.rb
|
220
|
-
- lib/query_report/chart/column_chart.rb
|
221
|
-
- lib/query_report/chart/pie_chart.rb
|
222
|
-
- lib/query_report/chart/themes.rb
|
232
|
+
- lib/query_report/chart_adapter.rb
|
223
233
|
- lib/query_report/column.rb
|
224
234
|
- lib/query_report/comparator.rb
|
225
235
|
- lib/query_report/config.rb
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'query_report/chart/chart_column'
|
2
|
-
require 'query_report/chart/themes'
|
3
|
-
|
4
|
-
module QueryReport
|
5
|
-
module Chart
|
6
|
-
class ChartBase
|
7
|
-
attr_reader :title, :options, :columns, :data
|
8
|
-
|
9
|
-
def initialize(title, query, options={})
|
10
|
-
@title = title
|
11
|
-
@query = query
|
12
|
-
@options = {:width => 500, :height => 240}.merge(options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def add(column_title, &block)
|
16
|
-
val = block.call(@query)
|
17
|
-
@columns ||= []
|
18
|
-
@columns << QueryReport::Chart::Column.new(column_title, val.kind_of?(String) ? :string : :number)
|
19
|
-
@data ||= []
|
20
|
-
@data << val
|
21
|
-
end
|
22
|
-
|
23
|
-
def prepare_visualr(type)
|
24
|
-
@data_table = GoogleVisualr::DataTable.new
|
25
|
-
|
26
|
-
##### Adding column header #####
|
27
|
-
@data_table.new_column('string', '') if type == :column
|
28
|
-
@columns.each do |col|
|
29
|
-
@data_table.new_column(col.type.to_s, col.title)
|
30
|
-
end
|
31
|
-
##### Adding column header #####
|
32
|
-
|
33
|
-
##### Adding value #####
|
34
|
-
chart_row_data = type == :column ? [''] + @data : @data
|
35
|
-
@data_table.add_row(chart_row_data)
|
36
|
-
##### Adding value #####
|
37
|
-
|
38
|
-
options = {:title => title, backgroundColor: 'transparent'}.merge(@options)
|
39
|
-
chart_type = "#{type}_chart".classify
|
40
|
-
chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize
|
41
|
-
chart_type.new(@data_table, options)
|
42
|
-
end
|
43
|
-
|
44
|
-
def to_blob(type)
|
45
|
-
chart_type = type.to_s.classify
|
46
|
-
chart_type = "Gruff::#{chart_type}".constantize
|
47
|
-
|
48
|
-
@gruff = chart_type.new(@options[:width])
|
49
|
-
@gruff.title = title
|
50
|
-
@gruff.theme = QueryReport::Chart::Themes::GOOGLE_CHART
|
51
|
-
@data.each_with_index do |value, i|
|
52
|
-
@gruff.data(@columns[i].title, value)
|
53
|
-
end
|
54
|
-
|
55
|
-
@gruff.to_blob
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'query_report/chart/themes'
|
2
|
-
require 'query_report/chart/chart_base'
|
3
|
-
|
4
|
-
module QueryReport
|
5
|
-
module ColumnChartModule
|
6
|
-
def column_chart(title, &block)
|
7
|
-
chart = QueryReport::Chart::ColumnChart.new(title, self.filtered_query)
|
8
|
-
chart.instance_eval &block if block_given?
|
9
|
-
@charts ||= []
|
10
|
-
@charts << chart
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Chart
|
15
|
-
class ColumnChart < QueryReport::Chart::ChartBase
|
16
|
-
def initialize(title, query, options={})
|
17
|
-
super(title, query, options)
|
18
|
-
end
|
19
|
-
|
20
|
-
def prepare_visualr
|
21
|
-
@data_table = GoogleVisualr::DataTable.new
|
22
|
-
|
23
|
-
##### Adding column header #####
|
24
|
-
@data_table.new_column('string', '')
|
25
|
-
@columns.each do |col|
|
26
|
-
@data_table.new_column(col.type.to_s, col.title)
|
27
|
-
end
|
28
|
-
##### Adding column header #####
|
29
|
-
|
30
|
-
@data_table.add_row([''] + @data)
|
31
|
-
options = {:title => title, backgroundColor: 'transparent'}.merge(@options)
|
32
|
-
GoogleVisualr::Interactive::ColumnChart.new(@data_table, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_blob
|
36
|
-
super(:bar)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'query_report/chart/themes'
|
2
|
-
require 'query_report/chart/chart_base'
|
3
|
-
|
4
|
-
module QueryReport
|
5
|
-
module PieChartModule
|
6
|
-
def pie_chart(title, &block)
|
7
|
-
chart = QueryReport::Chart::PieChart.new(title, self.filtered_query)
|
8
|
-
chart.instance_eval &block if block_given?
|
9
|
-
@charts ||= []
|
10
|
-
@charts << chart
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Chart
|
15
|
-
class PieChart < QueryReport::Chart::ChartBase
|
16
|
-
def initialize(title, query, options={})
|
17
|
-
super(title, query, options)
|
18
|
-
end
|
19
|
-
|
20
|
-
def prepare_visualr
|
21
|
-
@data_table = GoogleVisualr::DataTable.new
|
22
|
-
|
23
|
-
##### Adding column header #####
|
24
|
-
@data_table.new_column('string', 'Item')
|
25
|
-
@data_table.new_column('number', 'Value')
|
26
|
-
##### Adding column header #####
|
27
|
-
|
28
|
-
@columns.each_with_index do |column, i|
|
29
|
-
@data_table.add_row([column.title, @data[i]])
|
30
|
-
end
|
31
|
-
|
32
|
-
options = {:title => title, backgroundColor: 'transparent'}.merge(@options)
|
33
|
-
GoogleVisualr::Interactive::PieChart.new(@data_table, options)
|
34
|
-
end
|
35
|
-
|
36
|
-
def to_blob
|
37
|
-
super(:pie)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module QueryReport
|
2
|
-
module Chart
|
3
|
-
module Themes
|
4
|
-
GOOGLE_CHART = {
|
5
|
-
:colors => [
|
6
|
-
'#3366CC', # blue
|
7
|
-
'#DC3912', # red
|
8
|
-
'#FF9900', # yellow
|
9
|
-
'#109618', # green
|
10
|
-
'#990099', # dk purple
|
11
|
-
'#0099C6', # sky
|
12
|
-
'#DD4477' # grey
|
13
|
-
],
|
14
|
-
:marker_color => '#aea9a9', # Grey
|
15
|
-
:font_color => 'black',
|
16
|
-
:background_colors => 'white'
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|