google_visualr 2.1.9 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cdeb2c496a711317a315455953579c86bdfe2fd7
4
- data.tar.gz: dd0d015e0ddab7360cb95512a818ad69d36f282d
3
+ metadata.gz: c9e5ef85f15735729d999bbc550dc078ce306a82
4
+ data.tar.gz: d00153d2e742e7f679114ce0a676dc6030f40149
5
5
  SHA512:
6
- metadata.gz: 77d7ae125c8a8fdb2bfebbdbff75a4099d7f9966834eaad8b97176f6192b8f6f69dd428333ec61b70a5ff3ee23e7233a01e72ebde0c642e272a0a0d9dc029641
7
- data.tar.gz: c731f811d48ad402c4402366fd2077f2220750ccbebe1784870244e5c6068a706d3b7023023f7c3739283625ce572d244f4b01eae6dfc5854aab3c02f539cb10
6
+ metadata.gz: 8a2a3b6c8d47e5692030c241dc60a2fe9bd649fca44a4e0026b05d895bdbaf1a5dfd5e1b35c1dc6c3e593d26162c976f307ff92cdc8dc115ac303696399757b8
7
+ data.tar.gz: f8bd40ffd09089f9eb9cb1809dd3f8f55c6dd7b10c61a1bcf2c3f11be6647484383efadaab389e5e88fcd39e91f57db08cf4296173caa4c3e036d8f4e4527453
@@ -88,7 +88,12 @@ I would like to collect some data about who's using this Gem. [Please drop me a
88
88
 
89
89
  ## Change Log
90
90
 
91
- <em>Version 2.1.8</em>
91
+ <em>Version 2.2.0</em>
92
+
93
+ * [Issue 64](https://github.com/winston/google_visualr/pull/64) Works with Turbolinks.
94
+ * [Issue 65](https://github.com/winston/google_visualr/pull/65) Add InteractiveTimeline chart.
95
+
96
+ <em>Version 2.1.9</em>
92
97
 
93
98
  * [Issue 61](https://github.com/winston/google_visualr/issues/45) Add MIT license to gemspec.
94
99
 
@@ -37,6 +37,7 @@ require "#{lib_path}/google_visualr/interactive/intensity_map"
37
37
  require "#{lib_path}/google_visualr/interactive/map"
38
38
  require "#{lib_path}/google_visualr/interactive/motion_chart"
39
39
  require "#{lib_path}/google_visualr/interactive/org_chart"
40
+ require "#{lib_path}/google_visualr/interactive/timeline"
40
41
 
41
42
  # Image Charts
42
43
  require "#{lib_path}/google_visualr/image/spark_line"
@@ -39,8 +39,7 @@ module GoogleVisualr
39
39
 
40
40
  def to_js(element_id)
41
41
  js = "\n<script type='text/javascript'>"
42
- js << "\n google.load('visualization','1', {packages: ['#{package_name}']});"
43
- js << "\n google.setOnLoadCallback(#{chart_function_name(element_id)});"
42
+ js << "\n google.load('visualization','1', {packages: ['#{package_name}'], callback: #{chart_function_name(element_id)}});"
44
43
  js << "\n function #{chart_function_name(element_id)}() {"
45
44
  js << "\n #{@data_table.to_js}"
46
45
  js << "\n var chart = new google.visualization.#{chart_name}(document.getElementById('#{element_id}'));"
@@ -171,7 +171,7 @@ module GoogleVisualr
171
171
  def set_cell(row_index, column_index, value)
172
172
  if within_range?(row_index, column_index)
173
173
  verify_against_column_type( @cols[column_index][:type], value )
174
- @rows[row_index][column_index] = GoogleVisualr::DataTable::Cell.new(value)
174
+ @rows[row_index][column_index] = GoogleVisualr::DataTable::Cell.new(value, @cols[column_index][:type])
175
175
  else
176
176
  raise RangeError, "row_index and column_index MUST be < @rows.size and @cols.size", caller
177
177
  end
@@ -205,7 +205,7 @@ module GoogleVisualr
205
205
 
206
206
  @cols.each do |column|
207
207
  js << "data_table.addColumn("
208
- js << column.to_json
208
+ js << display(column)
209
209
  js << ");"
210
210
  end
211
211
 
@@ -226,6 +226,11 @@ module GoogleVisualr
226
226
 
227
227
  private
228
228
 
229
+ def display(column)
230
+ column[:type] = "datetime" if column[:type] == "time"
231
+ column.to_json
232
+ end
233
+
229
234
  def within_range?(row_index, column_index)
230
235
  row_index < @rows.size && column_index < @cols.size
231
236
  end
@@ -244,6 +249,8 @@ module GoogleVisualr
244
249
  raise ArgumentError, "cell value '#{v}' is not a Boolean", caller unless v.is_a?(TrueClass) || v.is_a?(FalseClass)
245
250
  when type == 'datetime'
246
251
  raise ArgumentError, "cell value '#{v}' is not a DateTime", caller unless v.is_a?(DateTime) || v.is_a?(Time)
252
+ when type == 'time'
253
+ raise ArgumentError, "cell value '#{v}' is not a DateTime", caller unless v.is_a?(DateTime) || v.is_a?(Time)
247
254
  when type == "date"
248
255
  raise ArgumentError, "cell value '#{v}' is not a Date", caller unless v.is_a?(Date)
249
256
  end
@@ -256,15 +263,15 @@ module GoogleVisualr
256
263
  attr_accessor :f # formatted
257
264
  attr_accessor :p # properties
258
265
 
259
- def initialize(*args)
260
- options = args.pop
261
-
266
+ def initialize(options, type = nil)
262
267
  if options.is_a?(Hash)
263
268
  @v = options[:v]
264
269
  @f = options[:f]
265
270
  @p = options[:p]
266
- else
271
+ @type = type
272
+ else # should be a string
267
273
  @v = options
274
+ @type = type
268
275
  end
269
276
  end
270
277
 
@@ -272,7 +279,7 @@ module GoogleVisualr
272
279
  return "null" if @v.nil? && @f.nil? && @p.nil?
273
280
 
274
281
  js = "{"
275
- js << "v: #{typecast(@v)}"
282
+ js << "v: #{typecast(@v, @type)}"
276
283
  js << ", f: #{typecast(@f)}" unless @f.nil?
277
284
  js << ", p: #{typecast(@p)}" unless @p.nil?
278
285
  js << "}"
@@ -0,0 +1,11 @@
1
+ module GoogleVisualr
2
+ module Interactive
3
+
4
+ # https://developers.google.com/chart/interactive/docs/gallery/timeline
5
+ class Timeline < BaseChart
6
+ # For Configuration Options, please refer to:
7
+ # https://developers.google.com/chart/interactive/docs/gallery/timeline#Configuration_Options
8
+ end
9
+
10
+ end
11
+ end
@@ -25,7 +25,7 @@ module GoogleVisualr
25
25
  # Returns an array of strings if given an array
26
26
  # Returns 'null' when value is nil.
27
27
  # Recursive typecasting when value is a hash.
28
- def typecast(value)
28
+ def typecast(value, type = nil)
29
29
  case
30
30
  when value.is_a?(String)
31
31
  return value.to_json
@@ -34,7 +34,11 @@ module GoogleVisualr
34
34
  when value.is_a?(TrueClass) || value.is_a?(FalseClass)
35
35
  return "#{value}"
36
36
  when value.is_a?(DateTime) || value.is_a?(Time)
37
- return "new Date(#{value.year}, #{value.month-1}, #{value.day}, #{value.hour}, #{value.min}, #{value.sec})"
37
+ if type == "time"
38
+ return "new Date(0, 0, 0, #{value.hour}, #{value.min}, #{value.sec})"
39
+ else
40
+ return "new Date(#{value.year}, #{value.month-1}, #{value.day}, #{value.hour}, #{value.min}, #{value.sec})"
41
+ end
38
42
  when value.is_a?(Date)
39
43
  return "new Date(#{value.year}, #{value.month-1}, #{value.day})"
40
44
  when value.nil?
@@ -1,3 +1,3 @@
1
1
  module GoogleVisualr
2
- VERSION = "2.1.9"
3
- end
2
+ VERSION = "2.2.0"
3
+ end
@@ -34,8 +34,8 @@ describe "GoogleVisualr::ParamsHelper" do
34
34
  end
35
35
 
36
36
  describe "#typecast" do
37
- def assert_equal(input, expected)
38
- options = @klass.typecast(input)
37
+ def assert_equal(input, expected, type = nil)
38
+ options = @klass.typecast(input, type)
39
39
  options.should == expected
40
40
  end
41
41
 
@@ -64,6 +64,12 @@ describe "GoogleVisualr::ParamsHelper" do
64
64
  assert_equal(date, expected)
65
65
  end
66
66
 
67
+ it "returns time, if specified" do
68
+ date = Time.now
69
+ expected = "new Date(0, 0, 0, #{date.hour}, #{date.min}, #{date.sec})"
70
+ assert_equal(date, expected, "time")
71
+ end
72
+
67
73
  it "returns date" do
68
74
  date = Date.today
69
75
  expected = "new Date(#{date.year}, #{date.month-1}, #{date.day})"
@@ -19,8 +19,7 @@ end
19
19
 
20
20
  def base_chart_js(div_class="div_class")
21
21
  js = "\n<script type='text/javascript'>"
22
- js << "\n google.load('visualization','1', {packages: ['basechart']});"
23
- js << "\n google.setOnLoadCallback(draw_#{div_class});"
22
+ js << "\n google.load('visualization','1', {packages: ['basechart'], callback: draw_#{div_class}});"
24
23
  js << "\n function draw_#{div_class}() {"
25
24
  js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
26
25
  js << "\n chart.draw(data_table, {legend: \"Test Chart\", width: 800, is3D: true});"
@@ -30,8 +29,7 @@ end
30
29
 
31
30
  def base_chart_with_listener_js(div_class="div_class")
32
31
  js = "\n<script type='text/javascript'>"
33
- js << "\n google.load('visualization','1', {packages: ['basechart']});"
34
- js << "\n google.setOnLoadCallback(draw_#{div_class});"
32
+ js << "\n google.load('visualization','1', {packages: ['basechart'], callback: draw_#{div_class}});"
35
33
  js << "\n function draw_#{div_class}() {"
36
34
  js << "\n var data_table = new google.visualization.DataTable();data_table.addColumn({\"type\":\"string\",\"label\":\"Year\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Sales\"});data_table.addColumn({\"type\":\"number\",\"label\":\"Expenses\"});data_table.addRow([{v: \"2004\"}, {v: 1000}, {v: 400}]);data_table.addRow([{v: \"2005\"}, {v: 1200}, {v: 450}]);data_table.addRow([{v: \"2006\"}, {v: 1500}, {v: 600}]);data_table.addRow([{v: \"2007\"}, {v: 800}, {v: 500}]);\n var chart = new google.visualization.BaseChart(document.getElementById('#{div_class}'));"
37
35
  js << "\n google.visualization.events.addListener(chart, 'select', function() {test_event(chart);});"
@@ -0,0 +1,19 @@
1
+ <html>
2
+ <head>
3
+ <script src="https://www.google.com/jsapi"></script>
4
+ <script src="turbolinks.js"></script>
5
+ </head>
6
+ <body>
7
+ <a href="index.html">home</a>
8
+ <div id="chart"> </div>
9
+ <script>
10
+ google.load('visualization','1', {packages: ['corechart']});
11
+ google.setOnLoadCallback(draw_chart);
12
+ function draw_chart() {
13
+ var data_table = new google.visualization.DataTable();data_table.addColumn({"type":"string","label":"Employee"});data_table.addColumn({"type":"number","label":"Base Hourly"});data_table.addRow([{v: "Mike Ross"}, {v: 8}]);data_table.addRow([{v: "Moe Syzlack"}, {v: 12}]);
14
+ var chart = new google.visualization.BarChart(document.getElementById('chart'));
15
+ chart.draw(data_table, {isStacked: true, width: 900, height: 900, title: "Hours Worked by Payroll Category by Employee", vAxis: {title: "Employee"}, hAxis: {title: "Hours Worked"}, chartArea: {top: 20, bottom: 0}});
16
+ };
17
+ </script>
18
+ </body>
19
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <script src="https://www.google.com/jsapi"></script>
4
+ <script src="turbolinks.js"></script>
5
+ </head>
6
+ <body>
7
+ <a href="index.html">home</a>
8
+ <div id="chart"> </div>
9
+ <script>
10
+ google.load('visualization','1', {packages: ['corechart'], callback: draw_chart});
11
+ function draw_chart() {
12
+ var data_table = new google.visualization.DataTable();data_table.addColumn({"type":"string","label":"Employee"});data_table.addColumn({"type":"number","label":"Base Hourly"});data_table.addRow([{v: "Mike Ross"}, {v: 8}]);data_table.addRow([{v: "Moe Syzlack"}, {v: 12}]);
13
+ var chart = new google.visualization.BarChart(document.getElementById('chart'));
14
+ chart.draw(data_table, {isStacked: true, width: 900, height: 900, title: "Hours Worked by Payroll Category by Employee", vAxis: {title: "Employee"}, hAxis: {title: "Hours Worked"}, chartArea: {top: 20, bottom: 0}});
15
+ };
16
+ </script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,15 @@
1
+ <html>
2
+ <head>
3
+ <script src="https://www.google.com/jsapi"></script>
4
+ <script src="turbolinks.js"></script>
5
+ </head>
6
+ <body>
7
+ <h2>Different methods for loading a chart with Turbolinks support</h2>
8
+ You should test these in Firefox. In Chrome, each link click triggers a full page reload if running from localhost (which defeats the purpose of Turbolinks, and doesn't present the bug).
9
+ <ul>
10
+ <li><a href="old.html">One statement: anonymous function in callback</a></li>
11
+ <li><a href="broken.html">Three statements; load packages, set callback, define function. The first statement crashes.</a></li>
12
+ <li><a href="fixed.html">Two statements; load packages with callback defined, define function.</a></li>
13
+ </ul>
14
+ </body>
15
+ </html>
@@ -0,0 +1,17 @@
1
+ <html>
2
+ <head>
3
+ <script src="https://www.google.com/jsapi"></script>
4
+ <script src="turbolinks.js"></script>
5
+ </head>
6
+ <body>
7
+ <a href="index.html">home</a>
8
+ <div id="chart"> </div>
9
+ <script>
10
+ google.load('visualization','1', {packages: ['corechart'], callback: function() {
11
+ var data_table = new google.visualization.DataTable();data_table.addColumn({"type":"string","label":"Employee"});data_table.addColumn({"type":"number","label":"Base Hourly"});data_table.addRow([{v: "Mike Ross"}, {v: 8}]);data_table.addRow([{v: "Moe Syzlack"}, {v: 12}]);
12
+ var chart = new google.visualization.BarChart(document.getElementById('chart'));
13
+ chart.draw(data_table, {isStacked: true, width: 900, height: 900, title: "Hours Worked by Payroll Category by Employee", vAxis: {title: "Employee"}, hAxis: {title: "Hours Worked"}, chartArea: {top: 20, bottom: 0}});
14
+ }});
15
+ </script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,455 @@
1
+ (function() {
2
+ var CSRFToken, anchoredLink, browserCompatibleDocumentParser, browserIsntBuggy, browserSupportsPushState, browserSupportsTurbolinks, cacheCurrentPage, cacheSize, changePage, constrainPageCacheTo, createDocument, crossOriginLink, currentState, executeScriptTags, extractLink, extractTitleAndBody, fetchHistory, fetchReplacement, handleClick, ignoreClick, initializeTurbolinks, installClickHandlerLast, installDocumentReadyPageEventTriggers, installHistoryChangeHandler, installJqueryAjaxSuccessPageUpdateTrigger, loadedAssets, noTurbolink, nonHtmlLink, nonStandardClick, pageCache, pageChangePrevented, pagesCached, popCookie, processResponse, recallScrollPosition, referer, reflectNewUrl, reflectRedirectedUrl, rememberCurrentState, rememberCurrentUrl, rememberReferer, removeHash, removeHashForIE10compatiblity, removeNoscriptTags, requestMethodIsSafe, resetScrollPosition, targetLink, triggerEvent, visit, xhr, _ref,
3
+ __hasProp = {}.hasOwnProperty,
4
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
+
6
+ pageCache = {};
7
+
8
+ cacheSize = 10;
9
+
10
+ currentState = null;
11
+
12
+ loadedAssets = null;
13
+
14
+ referer = null;
15
+
16
+ createDocument = null;
17
+
18
+ xhr = null;
19
+
20
+ fetchReplacement = function(url) {
21
+ rememberReferer();
22
+ cacheCurrentPage();
23
+ triggerEvent('page:fetch', {
24
+ url: url
25
+ });
26
+ if (xhr != null) {
27
+ xhr.abort();
28
+ }
29
+ xhr = new XMLHttpRequest;
30
+ xhr.open('GET', removeHashForIE10compatiblity(url), true);
31
+ xhr.setRequestHeader('Accept', 'text/html, application/xhtml+xml, application/xml');
32
+ xhr.setRequestHeader('X-XHR-Referer', referer);
33
+ xhr.onload = function() {
34
+ var doc;
35
+ triggerEvent('page:receive');
36
+ if (doc = processResponse()) {
37
+ reflectNewUrl(url);
38
+ reflectRedirectedUrl();
39
+ changePage.apply(null, extractTitleAndBody(doc));
40
+ resetScrollPosition();
41
+ return triggerEvent('page:load');
42
+ } else {
43
+ return document.location.href = url;
44
+ }
45
+ };
46
+ xhr.onloadend = function() {
47
+ return xhr = null;
48
+ };
49
+ xhr.onabort = function() {
50
+ return rememberCurrentUrl();
51
+ };
52
+ xhr.onerror = function() {
53
+ return document.location.href = url;
54
+ };
55
+ return xhr.send();
56
+ };
57
+
58
+ fetchHistory = function(cachedPage) {
59
+ cacheCurrentPage();
60
+ if (xhr != null) {
61
+ xhr.abort();
62
+ }
63
+ changePage(cachedPage.title, cachedPage.body);
64
+ recallScrollPosition(cachedPage);
65
+ return triggerEvent('page:restore');
66
+ };
67
+
68
+ cacheCurrentPage = function() {
69
+ pageCache[currentState.position] = {
70
+ url: document.location.href,
71
+ body: document.body,
72
+ title: document.title,
73
+ positionY: window.pageYOffset,
74
+ positionX: window.pageXOffset
75
+ };
76
+ return constrainPageCacheTo(cacheSize);
77
+ };
78
+
79
+ pagesCached = function(size) {
80
+ if (size == null) {
81
+ size = cacheSize;
82
+ }
83
+ if (/^[\d]+$/.test(size)) {
84
+ return cacheSize = parseInt(size);
85
+ }
86
+ };
87
+
88
+ constrainPageCacheTo = function(limit) {
89
+ var key, value;
90
+ for (key in pageCache) {
91
+ if (!__hasProp.call(pageCache, key)) continue;
92
+ value = pageCache[key];
93
+ if (key <= currentState.position - limit) {
94
+ pageCache[key] = null;
95
+ }
96
+ }
97
+ };
98
+
99
+ changePage = function(title, body, csrfToken, runScripts) {
100
+ document.title = title;
101
+ document.documentElement.replaceChild(body, document.body);
102
+ if (csrfToken != null) {
103
+ CSRFToken.update(csrfToken);
104
+ }
105
+ removeNoscriptTags();
106
+ if (runScripts) {
107
+ executeScriptTags();
108
+ }
109
+ currentState = window.history.state;
110
+ triggerEvent('page:change');
111
+ return triggerEvent('page:update');
112
+ };
113
+
114
+ executeScriptTags = function() {
115
+ var attr, copy, nextSibling, parentNode, script, scripts, _i, _j, _len, _len1, _ref, _ref1;
116
+ scripts = Array.prototype.slice.call(document.body.querySelectorAll('script:not([data-turbolinks-eval="false"])'));
117
+ for (_i = 0, _len = scripts.length; _i < _len; _i++) {
118
+ script = scripts[_i];
119
+ if (!((_ref = script.type) === '' || _ref === 'text/javascript')) {
120
+ continue;
121
+ }
122
+ copy = document.createElement('script');
123
+ _ref1 = script.attributes;
124
+ for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
125
+ attr = _ref1[_j];
126
+ copy.setAttribute(attr.name, attr.value);
127
+ }
128
+ copy.appendChild(document.createTextNode(script.innerHTML));
129
+ parentNode = script.parentNode, nextSibling = script.nextSibling;
130
+ parentNode.removeChild(script);
131
+ parentNode.insertBefore(copy, nextSibling);
132
+ }
133
+ };
134
+
135
+ removeNoscriptTags = function() {
136
+ var noscript, noscriptTags, _i, _len;
137
+ noscriptTags = Array.prototype.slice.call(document.body.getElementsByTagName('noscript'));
138
+ for (_i = 0, _len = noscriptTags.length; _i < _len; _i++) {
139
+ noscript = noscriptTags[_i];
140
+ noscript.parentNode.removeChild(noscript);
141
+ }
142
+ };
143
+
144
+ reflectNewUrl = function(url) {
145
+ if (url !== referer) {
146
+ return window.history.pushState({
147
+ turbolinks: true,
148
+ position: currentState.position + 1
149
+ }, '', url);
150
+ }
151
+ };
152
+
153
+ reflectRedirectedUrl = function() {
154
+ var location, preservedHash;
155
+ if (location = xhr.getResponseHeader('X-XHR-Redirected-To')) {
156
+ preservedHash = removeHash(location) === location ? document.location.hash : '';
157
+ return window.history.replaceState(currentState, '', location + preservedHash);
158
+ }
159
+ };
160
+
161
+ rememberReferer = function() {
162
+ return referer = document.location.href;
163
+ };
164
+
165
+ rememberCurrentUrl = function() {
166
+ return window.history.replaceState({
167
+ turbolinks: true,
168
+ position: Date.now()
169
+ }, '', document.location.href);
170
+ };
171
+
172
+ rememberCurrentState = function() {
173
+ return currentState = window.history.state;
174
+ };
175
+
176
+ recallScrollPosition = function(page) {
177
+ return window.scrollTo(page.positionX, page.positionY);
178
+ };
179
+
180
+ resetScrollPosition = function() {
181
+ if (document.location.hash) {
182
+ return document.location.href = document.location.href;
183
+ } else {
184
+ return window.scrollTo(0, 0);
185
+ }
186
+ };
187
+
188
+ removeHashForIE10compatiblity = function(url) {
189
+ return removeHash(url);
190
+ };
191
+
192
+ removeHash = function(url) {
193
+ var link;
194
+ link = url;
195
+ if (url.href == null) {
196
+ link = document.createElement('A');
197
+ link.href = url;
198
+ }
199
+ return link.href.replace(link.hash, '');
200
+ };
201
+
202
+ popCookie = function(name) {
203
+ var value, _ref;
204
+ value = ((_ref = document.cookie.match(new RegExp(name + "=(\\w+)"))) != null ? _ref[1].toUpperCase() : void 0) || '';
205
+ document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/';
206
+ return value;
207
+ };
208
+
209
+ triggerEvent = function(name, data) {
210
+ var event;
211
+ event = document.createEvent('Events');
212
+ if (data) {
213
+ event.data = data;
214
+ }
215
+ event.initEvent(name, true, true);
216
+ return document.dispatchEvent(event);
217
+ };
218
+
219
+ pageChangePrevented = function() {
220
+ return !triggerEvent('page:before-change');
221
+ };
222
+
223
+ processResponse = function() {
224
+ var assetsChanged, clientOrServerError, doc, extractTrackAssets, intersection, validContent;
225
+ clientOrServerError = function() {
226
+ var _ref;
227
+ return (400 <= (_ref = xhr.status) && _ref < 600);
228
+ };
229
+ validContent = function() {
230
+ return xhr.getResponseHeader('Content-Type').match(/^(?:text\/html|application\/xhtml\+xml|application\/xml)(?:;|$)/);
231
+ };
232
+ extractTrackAssets = function(doc) {
233
+ var node, _i, _len, _ref, _results;
234
+ _ref = doc.head.childNodes;
235
+ _results = [];
236
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
237
+ node = _ref[_i];
238
+ if ((typeof node.getAttribute === "function" ? node.getAttribute('data-turbolinks-track') : void 0) != null) {
239
+ _results.push(node.src || node.href);
240
+ }
241
+ }
242
+ return _results;
243
+ };
244
+ assetsChanged = function(doc) {
245
+ var fetchedAssets;
246
+ loadedAssets || (loadedAssets = extractTrackAssets(document));
247
+ fetchedAssets = extractTrackAssets(doc);
248
+ return fetchedAssets.length !== loadedAssets.length || intersection(fetchedAssets, loadedAssets).length !== loadedAssets.length;
249
+ };
250
+ intersection = function(a, b) {
251
+ var value, _i, _len, _ref, _results;
252
+ if (a.length > b.length) {
253
+ _ref = [b, a], a = _ref[0], b = _ref[1];
254
+ }
255
+ _results = [];
256
+ for (_i = 0, _len = a.length; _i < _len; _i++) {
257
+ value = a[_i];
258
+ if (__indexOf.call(b, value) >= 0) {
259
+ _results.push(value);
260
+ }
261
+ }
262
+ return _results;
263
+ };
264
+ if (!clientOrServerError() && validContent()) {
265
+ doc = createDocument(xhr.responseText);
266
+ if (doc && !assetsChanged(doc)) {
267
+ return doc;
268
+ }
269
+ }
270
+ };
271
+
272
+ extractTitleAndBody = function(doc) {
273
+ var title;
274
+ title = doc.querySelector('title');
275
+ return [title != null ? title.textContent : void 0, doc.body, CSRFToken.get(doc).token, 'runScripts'];
276
+ };
277
+
278
+ CSRFToken = {
279
+ get: function(doc) {
280
+ var tag;
281
+ if (doc == null) {
282
+ doc = document;
283
+ }
284
+ return {
285
+ node: tag = doc.querySelector('meta[name="csrf-token"]'),
286
+ token: tag != null ? typeof tag.getAttribute === "function" ? tag.getAttribute('content') : void 0 : void 0
287
+ };
288
+ },
289
+ update: function(latest) {
290
+ var current;
291
+ current = this.get();
292
+ if ((current.token != null) && (latest != null) && current.token !== latest) {
293
+ return current.node.setAttribute('content', latest);
294
+ }
295
+ }
296
+ };
297
+
298
+ browserCompatibleDocumentParser = function() {
299
+ var createDocumentUsingDOM, createDocumentUsingParser, createDocumentUsingWrite, testDoc, _ref;
300
+ createDocumentUsingParser = function(html) {
301
+ return (new DOMParser).parseFromString(html, 'text/html');
302
+ };
303
+ createDocumentUsingDOM = function(html) {
304
+ var doc;
305
+ doc = document.implementation.createHTMLDocument('');
306
+ doc.documentElement.innerHTML = html;
307
+ return doc;
308
+ };
309
+ createDocumentUsingWrite = function(html) {
310
+ var doc;
311
+ doc = document.implementation.createHTMLDocument('');
312
+ doc.open('replace');
313
+ doc.write(html);
314
+ doc.close();
315
+ return doc;
316
+ };
317
+ try {
318
+ if (window.DOMParser) {
319
+ testDoc = createDocumentUsingParser('<html><body><p>test');
320
+ return createDocumentUsingParser;
321
+ }
322
+ } catch (e) {
323
+ testDoc = createDocumentUsingDOM('<html><body><p>test');
324
+ return createDocumentUsingDOM;
325
+ } finally {
326
+ if ((testDoc != null ? (_ref = testDoc.body) != null ? _ref.childNodes.length : void 0 : void 0) !== 1) {
327
+ return createDocumentUsingWrite;
328
+ }
329
+ }
330
+ };
331
+
332
+ installClickHandlerLast = function(event) {
333
+ if (!event.defaultPrevented) {
334
+ document.removeEventListener('click', handleClick, false);
335
+ return document.addEventListener('click', handleClick, false);
336
+ }
337
+ };
338
+
339
+ handleClick = function(event) {
340
+ var link;
341
+ if (!event.defaultPrevented) {
342
+ link = extractLink(event);
343
+ if (link.nodeName === 'A' && !ignoreClick(event, link)) {
344
+ if (!pageChangePrevented()) {
345
+ visit(link.href);
346
+ }
347
+ return event.preventDefault();
348
+ }
349
+ }
350
+ };
351
+
352
+ extractLink = function(event) {
353
+ var link;
354
+ link = event.target;
355
+ while (!(!link.parentNode || link.nodeName === 'A')) {
356
+ link = link.parentNode;
357
+ }
358
+ return link;
359
+ };
360
+
361
+ crossOriginLink = function(link) {
362
+ return location.protocol !== link.protocol || location.host !== link.host;
363
+ };
364
+
365
+ anchoredLink = function(link) {
366
+ return ((link.hash && removeHash(link)) === removeHash(location)) || (link.href === location.href + '#');
367
+ };
368
+
369
+ nonHtmlLink = function(link) {
370
+ var url;
371
+ url = removeHash(link);
372
+ return url.match(/\.[a-z]+(\?.*)?$/g) && !url.match(/\.html?(\?.*)?$/g);
373
+ };
374
+
375
+ noTurbolink = function(link) {
376
+ var ignore;
377
+ while (!(ignore || link === document)) {
378
+ ignore = link.getAttribute('data-no-turbolink') != null;
379
+ link = link.parentNode;
380
+ }
381
+ return ignore;
382
+ };
383
+
384
+ targetLink = function(link) {
385
+ return link.target.length !== 0;
386
+ };
387
+
388
+ nonStandardClick = function(event) {
389
+ return event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey;
390
+ };
391
+
392
+ ignoreClick = function(event, link) {
393
+ return crossOriginLink(link) || anchoredLink(link) || nonHtmlLink(link) || noTurbolink(link) || targetLink(link) || nonStandardClick(event);
394
+ };
395
+
396
+ installDocumentReadyPageEventTriggers = function() {
397
+ triggerEvent('page:change');
398
+ return triggerEvent('page:update');
399
+ };
400
+
401
+ installJqueryAjaxSuccessPageUpdateTrigger = function() {
402
+ if (typeof jQuery !== 'undefined') {
403
+ return $(document).on('ajaxSuccess', function(event, xhr, settings) {
404
+ if (!$.trim(xhr.responseText)) {
405
+ return;
406
+ }
407
+ return triggerEvent('page:update');
408
+ });
409
+ }
410
+ };
411
+
412
+ installHistoryChangeHandler = function(event) {
413
+ var cachedPage, _ref;
414
+ if ((_ref = event.state) != null ? _ref.turbolinks : void 0) {
415
+ if (cachedPage = pageCache[event.state.position]) {
416
+ return fetchHistory(cachedPage);
417
+ } else {
418
+ return visit(event.target.location.href);
419
+ }
420
+ }
421
+ };
422
+
423
+ initializeTurbolinks = function() {
424
+ rememberCurrentUrl();
425
+ rememberCurrentState();
426
+ createDocument = browserCompatibleDocumentParser();
427
+ document.addEventListener('click', installClickHandlerLast, true);
428
+ document.addEventListener('DOMContentLoaded', installDocumentReadyPageEventTriggers, true);
429
+ installJqueryAjaxSuccessPageUpdateTrigger();
430
+ return window.addEventListener('popstate', installHistoryChangeHandler, false);
431
+ };
432
+
433
+ browserSupportsPushState = window.history && window.history.pushState && window.history.replaceState && window.history.state !== void 0;
434
+
435
+ browserIsntBuggy = !navigator.userAgent.match(/CriOS\//);
436
+
437
+ requestMethodIsSafe = (_ref = popCookie('request_method')) === 'GET' || _ref === '';
438
+
439
+ browserSupportsTurbolinks = browserSupportsPushState && browserIsntBuggy && requestMethodIsSafe;
440
+
441
+ if (browserSupportsTurbolinks) {
442
+ visit = fetchReplacement;
443
+ initializeTurbolinks();
444
+ } else {
445
+ visit = function(url) {
446
+ return document.location.href = url;
447
+ };
448
+ }
449
+
450
+ this.Turbolinks = {
451
+ visit: visit,
452
+ pagesCached: pagesCached,
453
+ supported: browserSupportsTurbolinks
454
+ };
455
+ }).call(this);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_visualr
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winston Teo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-23 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/google_visualr/interactive/scatter_chart.rb
90
90
  - lib/google_visualr/interactive/stepped_area_chart.rb
91
91
  - lib/google_visualr/interactive/table.rb
92
+ - lib/google_visualr/interactive/timeline.rb
92
93
  - lib/google_visualr/interactive/tree_map.rb
93
94
  - lib/google_visualr/packages.rb
94
95
  - lib/google_visualr/param_helpers.rb
@@ -148,6 +149,11 @@ files:
148
149
  - spec/google_visualr/param_helpers_spec.rb
149
150
  - spec/spec_helper.rb
150
151
  - spec/support/common.rb
152
+ - spec/turbolinks_tests/broken.html
153
+ - spec/turbolinks_tests/fixed.html
154
+ - spec/turbolinks_tests/index.html
155
+ - spec/turbolinks_tests/old.html
156
+ - spec/turbolinks_tests/turbolinks.js
151
157
  homepage: https://github.com/winston/google_visualr
152
158
  licenses:
153
159
  - MIT
@@ -168,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
174
  version: '0'
169
175
  requirements: []
170
176
  rubyforge_project:
171
- rubygems_version: 2.0.3
177
+ rubygems_version: 2.1.9
172
178
  signing_key:
173
179
  specification_version: 4
174
180
  summary: A Ruby wrapper around the Google Chart Tools that allows anyone to create
@@ -225,3 +231,8 @@ test_files:
225
231
  - spec/google_visualr/param_helpers_spec.rb
226
232
  - spec/spec_helper.rb
227
233
  - spec/support/common.rb
234
+ - spec/turbolinks_tests/broken.html
235
+ - spec/turbolinks_tests/fixed.html
236
+ - spec/turbolinks_tests/index.html
237
+ - spec/turbolinks_tests/old.html
238
+ - spec/turbolinks_tests/turbolinks.js