rails_pivot_table_js 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/rails_pivot_table_js/application.js +13 -0
- data/app/assets/javascripts/rails_pivot_table_js/d3_renderers.js +84 -0
- data/app/assets/javascripts/rails_pivot_table_js/gchart_renderers.js +183 -0
- data/app/assets/javascripts/rails_pivot_table_js/nrecopivottableext.js +356 -0
- data/app/assets/javascripts/rails_pivot_table_js/pivot.js +1510 -0
- data/app/assets/javascripts/rails_pivot_table_js/pivot.pt.js +83 -0
- data/app/assets/stylesheets/rails_pivot_table_js/application.css +15 -0
- data/app/assets/stylesheets/rails_pivot_table_js/pivot.css +228 -0
- data/app/controllers/rails_pivot_table_js/application_controller.rb +4 -0
- data/app/helpers/rails_pivot_table_js/application_helper.rb +7 -0
- data/app/views/layouts/rails_pivot_table_js/application.html.erb +14 -0
- data/app/views/rails_pivot_table_js/_pivot.html.haml +61 -0
- data/config/routes.rb +2 -0
- data/lib/rails_pivot_table_js/engine.rb +5 -0
- data/lib/rails_pivot_table_js/version.rb +3 -0
- data/lib/rails_pivot_table_js.rb +4 -0
- data/lib/tasks/rails_pivot_table_js_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/rails_pivot_table_js_test.rb +7 -0
- data/test/test_helper.rb +21 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45184e4ab117c2b2e5c10607d8a5d6c10de0f296
|
4
|
+
data.tar.gz: eb85155d0b126f90d0c96d21bf2b1af79b523de5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e90e43e0a519c9b4a1bc50465beaea63f6c36dae4aa37ae5bb3c29b316eed48512997f8b442842b86629997cc6f29808679e7d59cc74dde8938a11565b619074
|
7
|
+
data.tar.gz: 81d52c6406cba20d674c603dc8f522952f18e7c438d0e382a07180aca5c1c9b5863896a6d85636620b968e5acdc585e9568d5e08ea4f7a62eeb43ab0c026f367
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 José Lopes Neto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsPivotTableJs'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,84 @@
|
|
1
|
+
// Generated by CoffeeScript 1.7.1
|
2
|
+
(function() {
|
3
|
+
var $;
|
4
|
+
|
5
|
+
$ = jQuery;
|
6
|
+
|
7
|
+
$.pivotUtilities.d3_renderers = {
|
8
|
+
Treemap: function(pivotData, opts) {
|
9
|
+
var addToTree, color, defaults, height, margin, result, rowKey, tree, treemap, value, width, _i, _len, _ref;
|
10
|
+
defaults = {
|
11
|
+
localeStrings: {}
|
12
|
+
};
|
13
|
+
opts = $.extend(defaults, opts);
|
14
|
+
result = $("<div style='width: 100%; height: 100%;'>");
|
15
|
+
tree = {
|
16
|
+
name: "All",
|
17
|
+
children: []
|
18
|
+
};
|
19
|
+
addToTree = function(tree, path, value) {
|
20
|
+
var child, newChild, x, _i, _len, _ref;
|
21
|
+
if (path.length === 0) {
|
22
|
+
tree.value = value;
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
if (tree.children == null) {
|
26
|
+
tree.children = [];
|
27
|
+
}
|
28
|
+
x = path.shift();
|
29
|
+
_ref = tree.children;
|
30
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
31
|
+
child = _ref[_i];
|
32
|
+
if (!(child.name === x)) {
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
addToTree(child, path, value);
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
newChild = {
|
39
|
+
name: x
|
40
|
+
};
|
41
|
+
addToTree(newChild, path, value);
|
42
|
+
return tree.children.push(newChild);
|
43
|
+
};
|
44
|
+
_ref = pivotData.getRowKeys();
|
45
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
46
|
+
rowKey = _ref[_i];
|
47
|
+
value = pivotData.getAggregator(rowKey, []).value();
|
48
|
+
if (value != null) {
|
49
|
+
addToTree(tree, rowKey, value);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
color = d3.scale.category10();
|
53
|
+
width = $(window).width() / 1.4;
|
54
|
+
height = $(window).height() / 1.4;
|
55
|
+
margin = 10;
|
56
|
+
treemap = d3.layout.treemap().size([width, height]).sticky(true).value(function(d) {
|
57
|
+
return d.size;
|
58
|
+
});
|
59
|
+
d3.select(result[0]).append("div").style("position", "relative").style("width", (width + margin * 2) + "px").style("height", (height + margin * 2) + "px").style("left", margin + "px").style("top", margin + "px").datum(tree).selectAll(".node").data(treemap.padding([15, 0, 0, 0]).value(function(d) {
|
60
|
+
return d.value;
|
61
|
+
}).nodes).enter().append("div").attr("class", "node").style("background", function(d) {
|
62
|
+
if (d.children != null) {
|
63
|
+
return "lightgrey";
|
64
|
+
} else {
|
65
|
+
return color(d.name);
|
66
|
+
}
|
67
|
+
}).text(function(d) {
|
68
|
+
return d.name;
|
69
|
+
}).call(function() {
|
70
|
+
this.style("left", function(d) {
|
71
|
+
return d.x + "px";
|
72
|
+
}).style("top", function(d) {
|
73
|
+
return d.y + "px";
|
74
|
+
}).style("width", function(d) {
|
75
|
+
return Math.max(0, d.dx - 1) + "px";
|
76
|
+
}).style("height", function(d) {
|
77
|
+
return Math.max(0, d.dy - 1) + "px";
|
78
|
+
});
|
79
|
+
});
|
80
|
+
return result;
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
}).call(this);
|
@@ -0,0 +1,183 @@
|
|
1
|
+
(function() {
|
2
|
+
var callWithJQuery;
|
3
|
+
|
4
|
+
callWithJQuery = function(pivotModule) {
|
5
|
+
if (typeof exports === "object" && typeof module === "object") {
|
6
|
+
return pivotModule(require("jquery"));
|
7
|
+
} else if (typeof define === "function" && define.amd) {
|
8
|
+
return define(["jquery"], pivotModule);
|
9
|
+
} else {
|
10
|
+
return pivotModule(jQuery);
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
callWithJQuery(function($) {
|
15
|
+
var makeGoogleChart;
|
16
|
+
makeGoogleChart = function(chartType, extraOptions) {
|
17
|
+
return function(pivotData, opts) {
|
18
|
+
var agg, base, base1, colKey, colKeys, dataArray, dataTable, defaults, fullAggName, groupByTitle, h, hAxisTitle, headers, i, j, len, len1, numCharsInHAxis, options, ref, result, row, rowKey, rowKeys, title, tree2, vAxisTitle, val, wrapper, x, y;
|
19
|
+
defaults = {
|
20
|
+
localeStrings: {
|
21
|
+
vs: "vs",
|
22
|
+
by: "by"
|
23
|
+
},
|
24
|
+
gchart: {}
|
25
|
+
};
|
26
|
+
opts = $.extend(true, defaults, opts);
|
27
|
+
if ((base = opts.gchart).width == null) {
|
28
|
+
base.width = window.innerWidth / 1.4;
|
29
|
+
}
|
30
|
+
if ((base1 = opts.gchart).height == null) {
|
31
|
+
base1.height = window.innerHeight / 1.4;
|
32
|
+
}
|
33
|
+
rowKeys = pivotData.getRowKeys();
|
34
|
+
if (rowKeys.length === 0) {
|
35
|
+
rowKeys.push([]);
|
36
|
+
}
|
37
|
+
colKeys = pivotData.getColKeys();
|
38
|
+
if (colKeys.length === 0) {
|
39
|
+
colKeys.push([]);
|
40
|
+
}
|
41
|
+
fullAggName = pivotData.aggregatorName;
|
42
|
+
if (pivotData.valAttrs.length) {
|
43
|
+
fullAggName += "(" + (pivotData.valAttrs.join(", ")) + ")";
|
44
|
+
}
|
45
|
+
headers = (function() {
|
46
|
+
var i, len, results;
|
47
|
+
results = [];
|
48
|
+
for (i = 0, len = rowKeys.length; i < len; i++) {
|
49
|
+
h = rowKeys[i];
|
50
|
+
results.push(h.join("-"));
|
51
|
+
}
|
52
|
+
return results;
|
53
|
+
})();
|
54
|
+
headers.unshift("");
|
55
|
+
numCharsInHAxis = 0;
|
56
|
+
if (chartType === "ScatterChart") {
|
57
|
+
dataArray = [];
|
58
|
+
ref = pivotData.tree;
|
59
|
+
for (y in ref) {
|
60
|
+
tree2 = ref[y];
|
61
|
+
for (x in tree2) {
|
62
|
+
agg = tree2[x];
|
63
|
+
dataArray.push([parseFloat(x), parseFloat(y), fullAggName + ": \n" + agg.format(agg.value())]);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
dataTable = new google.visualization.DataTable();
|
67
|
+
dataTable.addColumn('number', pivotData.colAttrs.join("-"));
|
68
|
+
dataTable.addColumn('number', pivotData.rowAttrs.join("-"));
|
69
|
+
dataTable.addColumn({
|
70
|
+
type: "string",
|
71
|
+
role: "tooltip"
|
72
|
+
});
|
73
|
+
dataTable.addRows(dataArray);
|
74
|
+
hAxisTitle = pivotData.colAttrs.join("-");
|
75
|
+
vAxisTitle = pivotData.rowAttrs.join("-");
|
76
|
+
title = "";
|
77
|
+
} else {
|
78
|
+
dataArray = [headers];
|
79
|
+
for (i = 0, len = colKeys.length; i < len; i++) {
|
80
|
+
colKey = colKeys[i];
|
81
|
+
row = [colKey.join("-")];
|
82
|
+
numCharsInHAxis += row[0].length;
|
83
|
+
for (j = 0, len1 = rowKeys.length; j < len1; j++) {
|
84
|
+
rowKey = rowKeys[j];
|
85
|
+
agg = pivotData.getAggregator(rowKey, colKey);
|
86
|
+
if (agg.value() != null) {
|
87
|
+
val = agg.value();
|
88
|
+
if ($.isNumeric(val)) {
|
89
|
+
if (val < 1) {
|
90
|
+
row.push(parseFloat(val.toPrecision(3)));
|
91
|
+
} else {
|
92
|
+
row.push(parseFloat(val.toFixed(3)));
|
93
|
+
}
|
94
|
+
} else {
|
95
|
+
row.push(val);
|
96
|
+
}
|
97
|
+
} else {
|
98
|
+
row.push(null);
|
99
|
+
}
|
100
|
+
}
|
101
|
+
dataArray.push(row);
|
102
|
+
}
|
103
|
+
dataTable = google.visualization.arrayToDataTable(dataArray);
|
104
|
+
title = vAxisTitle = fullAggName;
|
105
|
+
hAxisTitle = pivotData.colAttrs.join("-");
|
106
|
+
if (hAxisTitle !== "") {
|
107
|
+
title += " " + opts.localeStrings.vs + " " + hAxisTitle;
|
108
|
+
}
|
109
|
+
groupByTitle = pivotData.rowAttrs.join("-");
|
110
|
+
if (groupByTitle !== "") {
|
111
|
+
title += " " + opts.localeStrings.by + " " + groupByTitle;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
options = {
|
115
|
+
title: title,
|
116
|
+
hAxis: {
|
117
|
+
title: hAxisTitle,
|
118
|
+
slantedText: numCharsInHAxis > 50
|
119
|
+
},
|
120
|
+
vAxis: {
|
121
|
+
title: vAxisTitle
|
122
|
+
},
|
123
|
+
tooltip: {
|
124
|
+
textStyle: {
|
125
|
+
fontName: 'Arial',
|
126
|
+
fontSize: 12
|
127
|
+
}
|
128
|
+
}
|
129
|
+
};
|
130
|
+
if (chartType === "ColumnChart") {
|
131
|
+
options.vAxis.minValue = 0;
|
132
|
+
}
|
133
|
+
if (chartType === "ScatterChart") {
|
134
|
+
options.legend = {
|
135
|
+
position: "none"
|
136
|
+
};
|
137
|
+
options.chartArea = {
|
138
|
+
'width': '80%',
|
139
|
+
'height': '80%'
|
140
|
+
};
|
141
|
+
} else if (dataArray[0].length === 2 && dataArray[0][1] === "") {
|
142
|
+
options.legend = {
|
143
|
+
position: "none"
|
144
|
+
};
|
145
|
+
}
|
146
|
+
$.extend(options, opts.gchart, extraOptions);
|
147
|
+
result = $("<div>").css({
|
148
|
+
width: "100%",
|
149
|
+
height: "100%"
|
150
|
+
});
|
151
|
+
wrapper = new google.visualization.ChartWrapper({
|
152
|
+
dataTable: dataTable,
|
153
|
+
chartType: chartType,
|
154
|
+
options: options
|
155
|
+
});
|
156
|
+
wrapper.draw(result[0]);
|
157
|
+
result.bind("dblclick", function() {
|
158
|
+
var editor;
|
159
|
+
editor = new google.visualization.ChartEditor();
|
160
|
+
google.visualization.events.addListener(editor, 'ok', function() {
|
161
|
+
return editor.getChartWrapper().draw(result[0]);
|
162
|
+
});
|
163
|
+
return editor.openDialog(wrapper);
|
164
|
+
});
|
165
|
+
return result;
|
166
|
+
};
|
167
|
+
};
|
168
|
+
return $.pivotUtilities.gchart_renderers = {
|
169
|
+
"Line Chart": makeGoogleChart("LineChart"),
|
170
|
+
"Bar Chart": makeGoogleChart("ColumnChart"),
|
171
|
+
"Stacked Bar Chart": makeGoogleChart("ColumnChart", {
|
172
|
+
isStacked: true
|
173
|
+
}),
|
174
|
+
"Area Chart": makeGoogleChart("AreaChart", {
|
175
|
+
isStacked: true
|
176
|
+
}),
|
177
|
+
"Scatter Chart": makeGoogleChart("ScatterChart")
|
178
|
+
};
|
179
|
+
});
|
180
|
+
|
181
|
+
}).call(this);
|
182
|
+
|
183
|
+
//# sourceMappingURL=gchart_renderers.js.map
|