pivottable_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +37 -0
  9. data/Rakefile +2 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/pivottable_rails.rb +5 -0
  13. data/lib/pivottable_rails/engine.rb +4 -0
  14. data/lib/pivottable_rails/version.rb +3 -0
  15. data/pivottable_rails.gemspec +24 -0
  16. data/vendor/assets/javascripts/pivottable/c3_renderers.js +256 -0
  17. data/vendor/assets/javascripts/pivottable/c3_renderers.js.map +1 -0
  18. data/vendor/assets/javascripts/pivottable/d3_renderers.js +105 -0
  19. data/vendor/assets/javascripts/pivottable/d3_renderers.js.map +1 -0
  20. data/vendor/assets/javascripts/pivottable/export_renderers.js +80 -0
  21. data/vendor/assets/javascripts/pivottable/export_renderers.js.map +1 -0
  22. data/vendor/assets/javascripts/pivottable/gchart_renderers.js +183 -0
  23. data/vendor/assets/javascripts/pivottable/locales/gchart_renderers.js.map +1 -0
  24. data/vendor/assets/javascripts/pivottable/locales/pivot.es.js +78 -0
  25. data/vendor/assets/javascripts/pivottable/locales/pivot.es.js.map +1 -0
  26. data/vendor/assets/javascripts/pivottable/locales/pivot.fr.js +78 -0
  27. data/vendor/assets/javascripts/pivottable/locales/pivot.fr.js.map +1 -0
  28. data/vendor/assets/javascripts/pivottable/locales/pivot.nl.js +78 -0
  29. data/vendor/assets/javascripts/pivottable/locales/pivot.nl.js.map +1 -0
  30. data/vendor/assets/javascripts/pivottable/locales/pivot.pt.js +104 -0
  31. data/vendor/assets/javascripts/pivottable/locales/pivot.pt.js.map +1 -0
  32. data/vendor/assets/javascripts/pivottable/locales/pivot.ru.js +78 -0
  33. data/vendor/assets/javascripts/pivottable/locales/pivot.ru.js.map +1 -0
  34. data/vendor/assets/javascripts/pivottable/locales/pivot.tr.js +104 -0
  35. data/vendor/assets/javascripts/pivottable/locales/pivot.tr.js.map +1 -0
  36. data/vendor/assets/javascripts/pivottable/locales/pivot_main.js +3 -0
  37. data/vendor/assets/javascripts/pivottable/pivot.js +1511 -0
  38. data/vendor/assets/javascripts/pivottable/pivot.js.map +1 -0
  39. data/vendor/assets/stylesheets/pivottable/pivot.css +97 -0
  40. metadata +113 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d26f727a741aa7dc5b176984f742cc71d36acf20
4
+ data.tar.gz: 9dfc78ca521c0cbb8467096a7d0283bc140e7b2b
5
+ SHA512:
6
+ metadata.gz: 04f8d9820ef1c06899a640f39a4db2e21729c119c2a6726d1826904bf4d7e26fd78015a255696ef4e23a5524414157a9ee62a0fbbe191db1f024209d10d79a98
7
+ data.tar.gz: cac561d8cb5f1a03b271f970306ef8b973f616af2c46630a056daee434bb6eee0ec310b58462f73e38e77af4b1f52ae13cac6f7493077ce4742b910294eb077a
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pivottable_rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 David Brusius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # PivottableRails
2
+
3
+ [pivottable](https://github.com/nicolaskruchten/pivottable) is a jQuery plugin to build Pivot Table with you data.
4
+
5
+ The `pivottable-rails` gem integrates the `pivottable` jQuery plugin - version 2.0.2 - with the Rails asset pipeline.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pivottable_rails'
13
+ ```
14
+
15
+ Execute:
16
+
17
+ $ bundle
18
+
19
+ And then add the following to your `app/assets/javascripts/application.js`:
20
+
21
+ //= require pivottable/pivot
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install pivottable_rails
26
+
27
+ ## Usage
28
+
29
+ For usage informations, please refer to the official [pivottable](https://github.com/nicolaskruchten/pivottable) plugin documentation.
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/pivottable_rails/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pivottable_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "pivottable_rails/version"
2
+ require "pivottable_rails/engine"
3
+
4
+ module PivottableRails
5
+ end
@@ -0,0 +1,4 @@
1
+ module PivottableRails
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module PivottableRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pivottable_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pivottable_rails"
8
+ spec.version = PivottableRails::VERSION
9
+ spec.authors = ["David Brusius"]
10
+ spec.email = ["brusiusdavid@gmail.com"]
11
+
12
+ spec.summary = %q{The pivottable-rails gem integrates the pivottable jQuery plugin with the Rails asset pipeline.}
13
+ spec.description = %q{pivottable is a jQuery plugin to build Pivot Table with you data. The `pivottable-rails` gem integrates the `pivottable` jQuery plugin with the Rails asset pipeline.}
14
+ spec.homepage = "https://github.com/davidbrusius/pivottable_rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,256 @@
1
+ (function() {
2
+ var callWithJQuery;
3
+
4
+ callWithJQuery = function(pivotModule) {
5
+ if (typeof exports === "object" && typeof module === "object") {
6
+ return pivotModule(require("jquery"), require("c3"));
7
+ } else if (typeof define === "function" && define.amd) {
8
+ return define(["jquery", "c3"], pivotModule);
9
+ } else {
10
+ return pivotModule(jQuery, c3);
11
+ }
12
+ };
13
+
14
+ callWithJQuery(function($, c3) {
15
+ var makeC3Chart;
16
+ makeC3Chart = function(chartOpts) {
17
+ if (chartOpts == null) {
18
+ chartOpts = {};
19
+ }
20
+ return function(pivotData, opts) {
21
+ var agg, attrs, base, base1, base2, base3, base4, base5, colKey, colKeys, columns, dataColumns, defaults, fullAggName, groupByTitle, h, hAxisTitle, headers, i, j, k, l, len, len1, len2, len3, len4, m, numCharsInHAxis, numSeries, params, ref, ref1, ref2, ref3, renderArea, result, rotationAngle, row, rowHeader, rowKey, rowKeys, s, scatterData, series, title, titleText, vAxisTitle, val, vals, x, xs;
22
+ defaults = {
23
+ localeStrings: {
24
+ vs: "vs",
25
+ by: "by"
26
+ },
27
+ c3: {}
28
+ };
29
+ opts = $.extend(true, defaults, opts);
30
+ if ((base = opts.c3).size == null) {
31
+ base.size = {};
32
+ }
33
+ if ((base1 = opts.c3.size).width == null) {
34
+ base1.width = window.innerWidth / 1.4;
35
+ }
36
+ if ((base2 = opts.c3.size).height == null) {
37
+ base2.height = window.innerHeight / 1.4 - 50;
38
+ }
39
+ if (chartOpts.type == null) {
40
+ chartOpts.type = "line";
41
+ }
42
+ rowKeys = pivotData.getRowKeys();
43
+ if (rowKeys.length === 0) {
44
+ rowKeys.push([]);
45
+ }
46
+ colKeys = pivotData.getColKeys();
47
+ if (colKeys.length === 0) {
48
+ colKeys.push([]);
49
+ }
50
+ headers = (function() {
51
+ var i, len, results;
52
+ results = [];
53
+ for (i = 0, len = colKeys.length; i < len; i++) {
54
+ h = colKeys[i];
55
+ results.push(h.join("-"));
56
+ }
57
+ return results;
58
+ })();
59
+ rotationAngle = 0;
60
+ fullAggName = pivotData.aggregatorName;
61
+ if (pivotData.valAttrs.length) {
62
+ fullAggName += "(" + (pivotData.valAttrs.join(", ")) + ")";
63
+ }
64
+ if (chartOpts.type === "scatter") {
65
+ scatterData = {
66
+ x: {},
67
+ y: {},
68
+ t: {}
69
+ };
70
+ attrs = pivotData.rowAttrs.concat(pivotData.colAttrs);
71
+ vAxisTitle = (ref = attrs[0]) != null ? ref : "";
72
+ hAxisTitle = (ref1 = attrs[1]) != null ? ref1 : "";
73
+ groupByTitle = attrs.slice(2).join("-");
74
+ titleText = vAxisTitle;
75
+ if (hAxisTitle !== "") {
76
+ titleText += " " + opts.localeStrings.vs + " " + hAxisTitle;
77
+ }
78
+ if (groupByTitle !== "") {
79
+ titleText += " " + opts.localeStrings.by + " " + groupByTitle;
80
+ }
81
+ for (i = 0, len = rowKeys.length; i < len; i++) {
82
+ rowKey = rowKeys[i];
83
+ for (j = 0, len1 = colKeys.length; j < len1; j++) {
84
+ colKey = colKeys[j];
85
+ agg = pivotData.getAggregator(rowKey, colKey);
86
+ if (agg.value() != null) {
87
+ vals = rowKey.concat(colKey);
88
+ series = vals.slice(2).join("-");
89
+ if (series === "") {
90
+ series = "series";
91
+ }
92
+ if ((base3 = scatterData.x)[series] == null) {
93
+ base3[series] = [];
94
+ }
95
+ if ((base4 = scatterData.y)[series] == null) {
96
+ base4[series] = [];
97
+ }
98
+ if ((base5 = scatterData.t)[series] == null) {
99
+ base5[series] = [];
100
+ }
101
+ scatterData.y[series].push((ref2 = vals[0]) != null ? ref2 : 0);
102
+ scatterData.x[series].push((ref3 = vals[1]) != null ? ref3 : 0);
103
+ scatterData.t[series].push(agg.format(agg.value()));
104
+ }
105
+ }
106
+ }
107
+ } else {
108
+ numCharsInHAxis = 0;
109
+ for (k = 0, len2 = headers.length; k < len2; k++) {
110
+ x = headers[k];
111
+ numCharsInHAxis += x.length;
112
+ }
113
+ if (numCharsInHAxis > 50) {
114
+ rotationAngle = 45;
115
+ }
116
+ columns = [];
117
+ for (l = 0, len3 = rowKeys.length; l < len3; l++) {
118
+ rowKey = rowKeys[l];
119
+ rowHeader = rowKey.join("-");
120
+ row = [rowHeader === "" ? pivotData.aggregatorName : rowHeader];
121
+ for (m = 0, len4 = colKeys.length; m < len4; m++) {
122
+ colKey = colKeys[m];
123
+ val = parseFloat(pivotData.getAggregator(rowKey, colKey).value());
124
+ if (isFinite(val)) {
125
+ if (val < 1) {
126
+ row.push(val.toPrecision(3));
127
+ } else {
128
+ row.push(val.toFixed(3));
129
+ }
130
+ } else {
131
+ row.push(null);
132
+ }
133
+ }
134
+ columns.push(row);
135
+ }
136
+ vAxisTitle = pivotData.aggregatorName + (pivotData.valAttrs.length ? "(" + (pivotData.valAttrs.join(", ")) + ")" : "");
137
+ hAxisTitle = pivotData.colAttrs.join("-");
138
+ titleText = fullAggName;
139
+ if (hAxisTitle !== "") {
140
+ titleText += " " + opts.localeStrings.vs + " " + hAxisTitle;
141
+ }
142
+ groupByTitle = pivotData.rowAttrs.join("-");
143
+ if (groupByTitle !== "") {
144
+ titleText += " " + opts.localeStrings.by + " " + groupByTitle;
145
+ }
146
+ }
147
+ title = $("<p>", {
148
+ style: "text-align: center; font-weight: bold"
149
+ });
150
+ title.text(titleText);
151
+ params = {
152
+ axis: {
153
+ y: {
154
+ label: vAxisTitle
155
+ },
156
+ x: {
157
+ label: hAxisTitle,
158
+ tick: {
159
+ rotate: rotationAngle,
160
+ multiline: false
161
+ }
162
+ }
163
+ },
164
+ data: {
165
+ type: chartOpts.type
166
+ },
167
+ tooltip: {
168
+ grouped: false
169
+ },
170
+ color: {
171
+ pattern: ["#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00", "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707", "#651067", "#329262", "#5574a6", "#3b3eac"]
172
+ }
173
+ };
174
+ $.extend(params, opts.c3);
175
+ if (chartOpts.type === "scatter") {
176
+ xs = {};
177
+ numSeries = 0;
178
+ dataColumns = [];
179
+ for (s in scatterData.x) {
180
+ numSeries += 1;
181
+ xs[s] = s + "_x";
182
+ dataColumns.push([s + "_x"].concat(scatterData.x[s]));
183
+ dataColumns.push([s].concat(scatterData.y[s]));
184
+ }
185
+ params.data.xs = xs;
186
+ params.data.columns = dataColumns;
187
+ params.axis.x.tick = {
188
+ fit: false
189
+ };
190
+ if (numSeries === 1) {
191
+ params.legend = {
192
+ show: false
193
+ };
194
+ }
195
+ params.tooltip.format = {
196
+ title: function() {
197
+ return fullAggName;
198
+ },
199
+ name: function() {
200
+ return "";
201
+ },
202
+ value: function(a, b, c, d) {
203
+ return scatterData.t[c][d];
204
+ }
205
+ };
206
+ } else {
207
+ params.axis.x.type = 'category';
208
+ params.axis.x.categories = headers;
209
+ params.data.columns = columns;
210
+ }
211
+ if (chartOpts.stacked != null) {
212
+ params.data.groups = [
213
+ (function() {
214
+ var len5, n, results;
215
+ results = [];
216
+ for (n = 0, len5 = rowKeys.length; n < len5; n++) {
217
+ x = rowKeys[n];
218
+ results.push(x.join("-"));
219
+ }
220
+ return results;
221
+ })()
222
+ ];
223
+ }
224
+ renderArea = $("<div>", {
225
+ style: "display:none;"
226
+ }).appendTo($("body"));
227
+ result = $("<div>").appendTo(renderArea);
228
+ params.bindto = result[0];
229
+ c3.generate(params);
230
+ result.detach();
231
+ renderArea.remove();
232
+ return $("<div>").append(title, result);
233
+ };
234
+ };
235
+ return $.pivotUtilities.c3_renderers = {
236
+ "Line Chart": makeC3Chart(),
237
+ "Bar Chart": makeC3Chart({
238
+ type: "bar"
239
+ }),
240
+ "Stacked Bar Chart": makeC3Chart({
241
+ type: "bar",
242
+ stacked: true
243
+ }),
244
+ "Area Chart": makeC3Chart({
245
+ type: "area",
246
+ stacked: true
247
+ }),
248
+ "Scatter Chart": makeC3Chart({
249
+ type: "scatter"
250
+ })
251
+ };
252
+ });
253
+
254
+ }).call(this);
255
+
256
+ //# sourceMappingURL=c3_renderers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["c3_renderers.coffee"],"names":[],"mappings":"AAAA;AAAA,MAAA;;EAAA,cAAA,GAAiB,SAAC,WAAD;IACb,IAAG,OAAO,OAAP,KAAkB,QAAlB,IAA+B,OAAO,MAAP,KAAiB,QAAnD;aACI,WAAA,CAAY,OAAA,CAAQ,QAAR,CAAZ,EAA+B,OAAA,CAAQ,IAAR,CAA/B,EADJ;KAAA,MAEK,IAAG,OAAO,MAAP,KAAiB,UAAjB,IAAgC,MAAM,CAAC,GAA1C;aACD,MAAA,CAAO,CAAC,QAAD,EAAW,IAAX,CAAP,EAAyB,WAAzB,EADC;KAAA,MAAA;aAID,WAAA,CAAY,MAAZ,EAAoB,EAApB,EAJC;;EAHQ;;EASjB,cAAA,CAAe,SAAC,CAAD,EA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,CAAC,CAAC,cAAc,CAAC,YAAjB,GACI;MAAA,YAAA,EAAc,WAAA,CAAA,CAAd;MACA,WAAA,EAAa,WAAA,CAAY;QAAA,IAAA,EAAM,KAAN;OAAZ,CADb;MAEA,mBAAA,EAAqB,WAAA,CAAY;QAAA,IAAA,EAAM,KAAN;QAAa,OAAA,EAAS,IAAtB;OAAZ,CAFrB;MAGA,YAAA,EAAc,WAAA,CAAY;QAAA,IAAA,EAAM,MAAN;QAAc,OAAA,EAAS,IAAvB;OAAZ,CAHd;MAIA,eAAA,EAAiB,WAAA,CAAY;QAAA,IAAA,EAAM,SAAN;OAAZ,CAJjB;;EA7IO,CAAf;AATA","file":"c3_renderers.js","sourceRoot":"/source/","sourcesContent":["callWithJQuery = (pivotModule) ->\n if typeof exports is \"object\" and typeof module is \"object\" # CommonJS\n pivotModule require(\"jquery\"), require(\"c3\")\n else if typeof define is \"function\" and define.amd # AMD\n define [\"jquery\", \"c3\"], pivotModule\n # Plain browser env\n else\n pivotModule jQuery, c3\n \ncallWithJQuery ($, c3) ->\n\n makeC3Chart = (chartOpts = {}) -> (pivotData, opts) ->\n defaults =\n localeStrings:\n vs: \"vs\"\n by: \"by\"\n c3: {}\n\n opts = $.extend true, defaults, opts\n opts.c3.size ?= {}\n opts.c3.size.width ?= window.innerWidth / 1.4\n opts.c3.size.height ?= window.innerHeight / 1.4 - 50\n chartOpts.type ?= \"line\"\n\n rowKeys = pivotData.getRowKeys()\n rowKeys.push [] if rowKeys.length == 0\n colKeys = pivotData.getColKeys()\n colKeys.push [] if colKeys.length == 0\n\n headers = (h.join(\"-\") for h in colKeys)\n rotationAngle = 0\n\n fullAggName = pivotData.aggregatorName \n if pivotData.valAttrs.length\n fullAggName += \"(#{pivotData.valAttrs.join(\", \")})\"\n\n if chartOpts.type == \"scatter\"\n scatterData = x:{}, y:{}, t:{}\n attrs = pivotData.rowAttrs.concat(pivotData.colAttrs)\n vAxisTitle = attrs[0] ? \"\"\n hAxisTitle = attrs[1] ? \"\" \n groupByTitle = attrs.slice(2).join(\"-\")\n titleText = vAxisTitle\n titleText += \" #{opts.localeStrings.vs} #{hAxisTitle}\" if hAxisTitle != \"\"\n titleText += \" #{opts.localeStrings.by} #{groupByTitle}\" if groupByTitle != \"\"\n for rowKey in rowKeys\n for colKey in colKeys\n agg = pivotData.getAggregator(rowKey, colKey)\n if agg.value()?\n vals = rowKey.concat(colKey)\n series = vals.slice(2).join(\"-\")\n if series == \"\" then series = \"series\"\n scatterData.x[series] ?= []\n scatterData.y[series] ?= []\n scatterData.t[series] ?= []\n scatterData.y[series].push vals[0] ? 0\n scatterData.x[series].push vals[1] ? 0\n scatterData.t[series].push agg.format(agg.value())\n else\n numCharsInHAxis = 0\n for x in headers\n numCharsInHAxis += x.length\n if numCharsInHAxis > 50\n rotationAngle = 45\n\n columns = []\n for rowKey in rowKeys\n rowHeader = rowKey.join(\"-\")\n row = [if rowHeader == \"\" then pivotData.aggregatorName else rowHeader]\n for colKey in colKeys\n val = parseFloat pivotData.getAggregator(rowKey, colKey).value()\n if isFinite(val)\n if val < 1\n row.push val.toPrecision(3)\n else\n row.push val.toFixed(3)\n else\n row.push null\n columns.push row\n\n vAxisTitle = pivotData.aggregatorName+ \n if pivotData.valAttrs.length then \"(#{pivotData.valAttrs.join(\", \")})\" else \"\"\n hAxisTitle = pivotData.colAttrs.join(\"-\")\n\n titleText = fullAggName\n titleText += \" #{opts.localeStrings.vs} #{hAxisTitle}\" if hAxisTitle != \"\"\n groupByTitle = pivotData.rowAttrs.join(\"-\")\n titleText += \" #{opts.localeStrings.by} #{groupByTitle}\" if groupByTitle != \"\"\n \n title = $(\"<p>\", {style: \"text-align: center; font-weight: bold\"})\n title.text(titleText)\n\n params = \n axis: \n y:\n label: vAxisTitle\n x:\n label: hAxisTitle\n tick:\n rotate: rotationAngle\n multiline: false\n data: \n type: chartOpts.type\n tooltip:\n grouped: false\n color: \n pattern: [ \"#3366cc\", \"#dc3912\", \"#ff9900\", \"#109618\",\n \"#990099\", \"#0099c6\", \"#dd4477\", \"#66aa00\",\n \"#b82e2e\", \"#316395\", \"#994499\", \"#22aa99\",\n \"#aaaa11\", \"#6633cc\", \"#e67300\", \"#8b0707\",\n \"#651067\", \"#329262\", \"#5574a6\", \"#3b3eac\" ]\n\n\n $.extend params, opts.c3\n\n if chartOpts.type == \"scatter\"\n xs = {}\n numSeries = 0\n dataColumns = []\n for s of scatterData.x\n numSeries += 1\n xs[s] = s+\"_x\"\n dataColumns.push [s+\"_x\"].concat(scatterData.x[s])\n dataColumns.push [s].concat(scatterData.y[s])\n params.data.xs = xs\n params.data.columns = dataColumns\n params.axis.x.tick = fit: false\n if numSeries == 1\n params.legend = show: false \n params.tooltip.format = \n title: -> fullAggName\n name: -> \"\"\n value: (a,b,c,d) -> scatterData.t[c][d]\n else\n params.axis.x.type= 'category'\n params.axis.x.categories = headers\n params.data.columns = columns\n\n\n if chartOpts.stacked?\n params.data.groups = [x.join(\"-\") for x in rowKeys]\n renderArea = $(\"<div>\", style: \"display:none;\").appendTo $(\"body\")\n result = $(\"<div>\").appendTo renderArea\n params.bindto = result[0]\n c3.generate params\n result.detach()\n renderArea.remove()\n return $(\"<div>\").append title, result\n\n $.pivotUtilities.c3_renderers = \n \"Line Chart\": makeC3Chart()\n \"Bar Chart\": makeC3Chart(type: \"bar\")\n \"Stacked Bar Chart\": makeC3Chart(type: \"bar\", stacked: true)\n \"Area Chart\": makeC3Chart(type: \"area\", stacked: true)\n \"Scatter Chart\": makeC3Chart(type: \"scatter\")\n"]}
@@ -0,0 +1,105 @@
1
+ (function() {
2
+ var callWithJQuery;
3
+
4
+ callWithJQuery = function(pivotModule) {
5
+ if (typeof exports === "object" && typeof module === "object") {
6
+ return pivotModule(require("jquery"), require("d3"));
7
+ } else if (typeof define === "function" && define.amd) {
8
+ return define(["jquery", "d3"], pivotModule);
9
+ } else {
10
+ return pivotModule(jQuery, d3);
11
+ }
12
+ };
13
+
14
+ callWithJQuery(function($, d3) {
15
+ return $.pivotUtilities.d3_renderers = {
16
+ Treemap: function(pivotData, opts) {
17
+ var addToTree, color, defaults, height, i, len, ref, result, rowKey, tree, treemap, value, width;
18
+ defaults = {
19
+ localeStrings: {},
20
+ d3: {
21
+ width: function() {
22
+ return $(window).width() / 1.4;
23
+ },
24
+ height: function() {
25
+ return $(window).height() / 1.4;
26
+ }
27
+ }
28
+ };
29
+ opts = $.extend(defaults, opts);
30
+ result = $("<div>").css({
31
+ width: "100%",
32
+ height: "100%"
33
+ });
34
+ tree = {
35
+ name: "All",
36
+ children: []
37
+ };
38
+ addToTree = function(tree, path, value) {
39
+ var child, i, len, newChild, ref, x;
40
+ if (path.length === 0) {
41
+ tree.value = value;
42
+ return;
43
+ }
44
+ if (tree.children == null) {
45
+ tree.children = [];
46
+ }
47
+ x = path.shift();
48
+ ref = tree.children;
49
+ for (i = 0, len = ref.length; i < len; i++) {
50
+ child = ref[i];
51
+ if (!(child.name === x)) {
52
+ continue;
53
+ }
54
+ addToTree(child, path, value);
55
+ return;
56
+ }
57
+ newChild = {
58
+ name: x
59
+ };
60
+ addToTree(newChild, path, value);
61
+ return tree.children.push(newChild);
62
+ };
63
+ ref = pivotData.getRowKeys();
64
+ for (i = 0, len = ref.length; i < len; i++) {
65
+ rowKey = ref[i];
66
+ value = pivotData.getAggregator(rowKey, []).value();
67
+ if (value != null) {
68
+ addToTree(tree, rowKey, value);
69
+ }
70
+ }
71
+ color = d3.scale.category10();
72
+ width = opts.d3.width();
73
+ height = opts.d3.height();
74
+ treemap = d3.layout.treemap().size([width, height]).sticky(true).value(function(d) {
75
+ return d.size;
76
+ });
77
+ d3.select(result[0]).append("div").style("position", "relative").style("width", width + "px").style("height", height + "px").datum(tree).selectAll(".node").data(treemap.padding([15, 0, 0, 0]).value(function(d) {
78
+ return d.value;
79
+ }).nodes).enter().append("div").attr("class", "node").style("background", function(d) {
80
+ if (d.children != null) {
81
+ return "lightgrey";
82
+ } else {
83
+ return color(d.name);
84
+ }
85
+ }).text(function(d) {
86
+ return d.name;
87
+ }).call(function() {
88
+ this.style("left", function(d) {
89
+ return d.x + "px";
90
+ }).style("top", function(d) {
91
+ return d.y + "px";
92
+ }).style("width", function(d) {
93
+ return Math.max(0, d.dx - 1) + "px";
94
+ }).style("height", function(d) {
95
+ return Math.max(0, d.dy - 1) + "px";
96
+ });
97
+ });
98
+ return result;
99
+ }
100
+ };
101
+ });
102
+
103
+ }).call(this);
104
+
105
+ //# sourceMappingURL=d3_renderers.js.map