olap-view 0.0.14

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1226b21cda3ab6f85a620277a1d001f56fca798b
4
+ data.tar.gz: ca72e015da575522cfc56cfaa80c2aa333cb62c3
5
+ SHA512:
6
+ metadata.gz: ae13f8c887b6164e5956ef56129010d64cd199b01b834acb7c097d40e4d9cf6a9cffd2d1de31e685da49c05e59acef51d3a6f42810de440e06b6699e044d94e2
7
+ data.tar.gz: 11753a7aafe12b10a5de57e797da16c0ea89b19f19e655b6fa8745d12e4cf474ca3f20dbbb2ebc166db7a1ff522dbe330ef4b2752fbf81a241a4afb311f82cbd
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ /.idea
16
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in olap-view.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Andrey
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Olap::View
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'olap-view'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install olap-view
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/Wondersoft/olap-view/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ .google-visualization-table {
2
+ .dimension{
3
+ text-align: left;
4
+ }
5
+ .measure{
6
+ text-align: right;
7
+ }
8
+ .total{
9
+ background: #e4e9f4;
10
+ }
11
+ .google-visualization-table-th {
12
+ white-space: normal;
13
+ }
14
+ }
@@ -0,0 +1,65 @@
1
+ module OlapViewHelper
2
+
3
+ # Initialize Goole Charts API
4
+ # Paste it into <head> to your layout
5
+ #
6
+ # <head>
7
+ # ...
8
+ # <%= olap_view_charts_init %>
9
+ # </head>
10
+ #
11
+ def olap_view_charts_init
12
+ javascript_include_tag 'https://www.google.com/jsapi'
13
+ end
14
+
15
+ def olap_view_chart_by_mdx chart, mdx, args={}, properties = {}
16
+ xmla = Olap::View.request mdx, args
17
+ olap_view_chart_by_xmla chart, xmla, properties
18
+ end
19
+
20
+ def olap_view_chart_by_xmla chart, xmla, properties = {}
21
+ id = olap_view_random_id
22
+
23
+ if xmla.response.rows && !xmla.response.rows.empty?
24
+ html = "<div id='#{id}'></div>"
25
+ html += javascript_tag(render partial: "olap-view/#{chart}.js",
26
+ locals: {id: id, data: xmla, properties: properties})
27
+ else
28
+ html = "<div id='#{id}'>#{Olap::View.options[:no_data]}</div>"
29
+ end
30
+ html.html_safe
31
+ end
32
+
33
+ def olap_view_render_row row
34
+ row.collect{|r|
35
+ if r[:type] == 'dimension'
36
+ "{v: '#{escape_javascript(r[:value] && !r[:value].empty? ? r[:value] : olap_view_unknown_element)}', p:{className: 'google-visualization-table-td #{r[:type]}'}}"
37
+ else
38
+ "{v: #{r[:value]}, f: '#{r[:fmt_value] || r[:value]}', p:{className: 'google-visualization-table-td #{r[:type]}'}}"
39
+ end
40
+ }.join(',').html_safe
41
+ end
42
+
43
+ def olap_view_filling_table data, dimension = nil, measures = []
44
+ html = ''
45
+ data.dimensions_caption(dimension).each do |d|
46
+ html += "data.addColumn({type: 'string', label: '#{escape_javascript d[:caption]}', id: '#{escape_javascript d[:name]}', p:{'type': 'dimension'}});\n"
47
+ end
48
+ data.measures_caption(measures).each do |m|
49
+ html += "data.addColumn({type: 'number', label: '#{escape_javascript m[:caption]}', id: '#{escape_javascript m[:name]}', p:{'type': 'measure'}});\n"
50
+ end
51
+ data.table(dimension, measures).each do |row|
52
+ html += "data.addRow([#{olap_view_render_row row}]);\n"
53
+ end
54
+ html.html_safe
55
+ end
56
+
57
+ private
58
+ def olap_view_random_id
59
+ (0...8).map { ('a'..'z').to_a[rand(26)] }.join
60
+ end
61
+
62
+ def olap_view_unknown_element
63
+ Olap::View.options[:undefined].html_safe
64
+ end
65
+ end
@@ -0,0 +1,42 @@
1
+ (function(){
2
+ function draw<%= id %>() {
3
+ var name = 'piechart';
4
+ var data = new google.visualization.DataTable();
5
+
6
+ <%= olap_view_filling_table data, properties[:dimension], (properties[:measures] || []) %>
7
+
8
+ var measures_sum = [];
9
+ for (var i = 0; i < data.getNumberOfColumns(); i++) {
10
+ if (data.getColumnProperties(i).type == "measure") {
11
+ var sum = 0;
12
+ for (var j = 0; j < data.getNumberOfRows(); j++) {
13
+ sum += data.getValue(j, i);
14
+ }
15
+ measures_sum[measures_sum.length] = sum;
16
+ }
17
+ }
18
+
19
+ if (measures_sum[0] > 0) {
20
+ var chart = new google.visualization.PieChart(document.getElementById('<%= id %>'));
21
+
22
+ var default_options = {
23
+ allowHtml: true,
24
+ is3D: true,
25
+ chartArea: {left:0,top:20,width:'100%', height:'70%'}
26
+ };
27
+
28
+ <%= properties[:function] && properties[:function].html_safe %>
29
+
30
+ chart.draw(data, $.extend(true, default_options, <%= properties[:options] ? "JSON.parse('#{properties[:options].to_json}')".html_safe : '{}' %>));
31
+ } else {
32
+ $("div#<%= id %>").html('');
33
+ }
34
+ }
35
+
36
+ google.load("visualization", "1", {
37
+ "packages": ["corechart"],
38
+ 'language': 'ru',
39
+ "callback" : function(){
40
+ draw<%= id %>();
41
+ }});
42
+ }());
@@ -0,0 +1,83 @@
1
+ (function(){
2
+ function draw<%= id %>() {
3
+ var name = 'table';
4
+ var data = new google.visualization.DataTable();
5
+
6
+ <%= olap_view_filling_table data, properties[:dimension], (properties[:measures] || []) %>
7
+
8
+ var chart = new google.visualization.Table(document.getElementById('<%= id %>'));
9
+
10
+ var default_options = {
11
+ allowHtml: true,
12
+ width: '100%'
13
+ };
14
+
15
+ <%= properties[:function] && properties[:function].html_safe %>
16
+
17
+ chart.draw(data, $.extend(true, default_options, <%= properties[:options] ? "JSON.parse('#{properties[:options].to_json}')".html_safe : '{}' %>));
18
+
19
+ <%= "rowSpan('#{id}');".html_safe if properties[:rowspan] == true %>
20
+ <%= "total(data);".html_safe if properties[:total] == true %>
21
+ }
22
+
23
+ function rowSpan(id){
24
+ var rows = $('#'+ id +' table tbody tr');
25
+
26
+ var first_row_dimention = [];
27
+
28
+ $.each(rows, function(i, row){
29
+ dimentions = $(row).find('td.dimension');
30
+
31
+ $.each(dimentions, function(j, dimention){
32
+ var prev_row_dimention = $($(rows[i-1]).find('td.dimension')[j]);
33
+
34
+ if ((first_row_dimention[j] == undefined) || ($(dimention).html() != first_row_dimention[j].html())) {
35
+ first_row_dimention[j] = $(dimention);
36
+ prev_row_dimention.css({
37
+ 'border-bottom-style': 'solid'});
38
+ $(dimention).css({'border-bottom-style': 'none'});
39
+ } else {
40
+ $(dimention).html('');
41
+ $(dimention).css({
42
+ backgroundColor: first_row_dimention[j].css('background-color'),
43
+ 'border-top-style': 'none',
44
+ 'border-bottom-style': 'none'
45
+ });
46
+ }
47
+ });
48
+ });
49
+
50
+ rows.last().find("td.dimension").css({'border-bottom-style': 'solid'});
51
+ }
52
+
53
+ function total(data){
54
+ var values_sum = [];
55
+ for (var i = 0; i < data.getNumberOfColumns(); i++) {
56
+ if (data.getColumnProperties(i).type == "measure") {
57
+ var sum = 0;
58
+ for (var j = 0; j < data.getNumberOfRows(); j++) {
59
+ sum += data.getValue(j, i);
60
+ }
61
+ values_sum[values_sum.length] = {v: parseFloat(sum.toFixed(2)), p: {className: "google-visualization-table-td measure total"}};
62
+ } else {
63
+ values_sum[values_sum.length] = {v: '', p: {className: "google-visualization-table-td dimension total"}};
64
+ }
65
+ }
66
+ values_sum[0].v = '<%= escape_javascript Olap::View.options[:total].html_safe %>';
67
+ // data.addRow(values_sum); add row to DataTable()
68
+
69
+ var html = "<thead><tr>";
70
+ for (var i = 0; i < values_sum.length; i++){
71
+ html += "<th class='"+ values_sum[i].p.className +"'>"+ values_sum[i].v +"</th>";
72
+ }
73
+ html += "</tr></thead>";
74
+ $('#<%= id %> table').append(html);
75
+ }
76
+
77
+ google.load("visualization", "1", {
78
+ "packages": ["table"],
79
+ 'language': 'ru',
80
+ "callback" : function(){
81
+ draw<%= id %>();
82
+ }});
83
+ }());
@@ -0,0 +1,6 @@
1
+ module Olap
2
+ module View
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,73 @@
1
+ class Olap::View::Parse
2
+
3
+ attr_reader :response
4
+
5
+ def initialize response
6
+ @response = response
7
+ end
8
+
9
+ # Aggregate result by one of the dimensions and return only listed measures
10
+ def aggregate dimension, measures = []
11
+ result = []
12
+ index = {}
13
+ response.rows.each{|row|
14
+ label = row[:labels].detect{|label| label[:name] == dimension}
15
+ values = row[:values].collect{|v|
16
+ next unless measures.include? v[:measure]
17
+ v.delete :fmt_value
18
+ v
19
+ }.compact
20
+
21
+ if i = index[label]
22
+ for j in 0..result[i][:values].count-1
23
+ result[i][:values][j][:value] = result[i][:values][j][:value].to_f + values[j][:value].to_f
24
+ end
25
+ else
26
+ index[label] = result.count
27
+ result << {
28
+ rownum: result.count + 1,
29
+ labels: [label],
30
+ values: values
31
+ }
32
+ end
33
+ }
34
+ result
35
+ end
36
+ # Return collection of dimensions or selected dimension by name
37
+ #
38
+ # * +:name+ the name of dimension
39
+ # * +:caption+ display name of dimension
40
+ #
41
+ def dimensions_caption dimension = nil
42
+ dimension.nil? ? response.dimensions :
43
+ response.dimensions.collect{|d|
44
+ next unless dimension == d[:name]
45
+ d
46
+ }.compact
47
+ end
48
+
49
+ # Return collection of measures or selected measures by name
50
+ #
51
+ # * +:name+ the name of measure
52
+ # * +:caption+ display name of measure
53
+ #
54
+ def measures_caption measures = []
55
+ (measures.nil? || measures.empty?) ? response.measures :
56
+ response.measures.collect{|m|
57
+ next unless measures.include? m[:name]
58
+ m
59
+ }.compact
60
+ end
61
+
62
+ # Collection of result rows and aggregate collection by dimension and measures
63
+ # type - dimension or measure
64
+ # value - metric value
65
+ # fmt_value - formatted metric value
66
+ def table dimension = nil, measures = []
67
+ (dimension ? aggregate(dimension, measures) : response.rows).collect{|row|
68
+ row[:labels].collect{|label| {type: 'dimension', value: label[:value].to_s, fmt_value: label[:fmt_value]}} +
69
+ row[:values].collect{|value| {type: 'measure', value: value[:value].to_f, fmt_value: value[:fmt_value]}}
70
+ }
71
+ end
72
+
73
+ end
@@ -0,0 +1,5 @@
1
+ module Olap
2
+ module View
3
+ VERSION = "0.0.14"
4
+ end
5
+ end
data/lib/olap/view.rb ADDED
@@ -0,0 +1,39 @@
1
+ require "olap/xmla"
2
+
3
+ require 'olap/view/engine' if ::Rails.version >= '3.1'
4
+ require "olap/view/version"
5
+ require "olap/view/parse"
6
+
7
+ module Olap
8
+ module View
9
+
10
+ @@view_options = {
11
+ no_data: "Not enough data to display",
12
+ undefined: "-",
13
+ total: "Total"
14
+ }
15
+
16
+ # Configure the default options to connect to XMLA server
17
+ # Can be optionally used to setup connection options in one place in application,
18
+ #
19
+ # Example:
20
+ # >> Olap::View.default_options = {no_data: 'Text for no data', undefined: 'Undefined element name', total: 'Total title'}
21
+ # >> Olap::View.request mdx
22
+ # => #<Olap::View::Parse:0x007ffa2b9f60f0 @response=#<Olap::Xmla::Response:0x007ffa2b9f6118 @response={4 ...
23
+ #
24
+ #
25
+ #
26
+ def self.default_options= options = {}
27
+ @@view_options.merge(options)
28
+ end
29
+
30
+ def self.options
31
+ @@view_options
32
+ end
33
+
34
+ def self.request mdx, args = {}
35
+ response = Olap::Xmla.client.request(mdx, args)
36
+ Olap::View::Parse.new response
37
+ end
38
+ end
39
+ end
data/olap-view.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'olap/view/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "olap-view"
7
+ spec.version = Olap::View::VERSION
8
+ spec.authors = ["stepanovit"]
9
+ spec.email = ["stepanov@wondersoft.ru"]
10
+ spec.summary = %q{OLAP VIEW gem}
11
+ spec.description = %q{RubyOnRails gem to visualize by Google Charts MDX queries on OLAP databases using XMLA connection. Can be used with any XMLA-compliant server, like Olaper or Mondrian.}
12
+ spec.homepage = "https://github.com/Wondersoft/olap-view"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = Dir["{app,lib}/**/*"]
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_runtime_dependency "olap-xmla", '~> 0'
22
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: olap-view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.14
5
+ platform: ruby
6
+ authors:
7
+ - stepanovit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: olap-xmla
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: RubyOnRails gem to visualize by Google Charts MDX queries on OLAP databases
56
+ using XMLA connection. Can be used with any XMLA-compliant server, like Olaper or
57
+ Mondrian.
58
+ email:
59
+ - stepanov@wondersoft.ru
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - app/assets/stylesheets/olap-view/olap-view.scss
70
+ - app/helpers/olap_view_helper.rb
71
+ - app/views/olap-view/_piechart.js.erb
72
+ - app/views/olap-view/_table.js.erb
73
+ - lib/olap/view.rb
74
+ - lib/olap/view/engine.rb
75
+ - lib/olap/view/parse.rb
76
+ - lib/olap/view/version.rb
77
+ - olap-view.gemspec
78
+ homepage: https://github.com/Wondersoft/olap-view
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - app/assets
86
+ - app/assets/stylesheets
87
+ - app/assets/stylesheets/olap-view
88
+ - app/assets/stylesheets/olap-view/olap-view.scss
89
+ - app/helpers
90
+ - app/helpers/olap_view_helper.rb
91
+ - app/views
92
+ - app/views/olap-view
93
+ - app/views/olap-view/_piechart.js.erb
94
+ - app/views/olap-view/_table.js.erb
95
+ - lib/olap
96
+ - lib/olap/view
97
+ - lib/olap/view/engine.rb
98
+ - lib/olap/view/parse.rb
99
+ - lib/olap/view/version.rb
100
+ - lib/olap/view.rb
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: OLAP VIEW gem
117
+ test_files: []