chartkick 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chartkick might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30de4fc2979a15f05f88ea0b616f62165f44af98
4
- data.tar.gz: 3ce7c4dcc8cc46808a071beb0893631f2a21c2ea
3
+ metadata.gz: 2d0f0bc351764e3b7e4667d14958ba9672d72949
4
+ data.tar.gz: 4d063d2c8ed4d3e6443f8d7ed39c8b2bca48636a
5
5
  SHA512:
6
- metadata.gz: c112540f2ab9e67a2a0438f034c3297c7b328e73a9c693e3ce84460a9e089735e20d7273fff294ab6e9d4693d74fa2619ae6352fb74aaf2288a3b3c602197ca1
7
- data.tar.gz: 19460f79f6cfdd72025902fb2816167878356f8bf7b01c4b22dbfad9ae024a5ffe0e095d3d5dd4eda719eb98ff5db46d441360a4f060e4ce8631e0b305af5753
6
+ metadata.gz: 747033c51547a541ce97c4e0c193cd5049484e7cc918df5df3e1c29c453b87f3ac61f0a19e6024f39e9e688bb9f6b419c0267d991491dd5f3d06ef7a6d85907b
7
+ data.tar.gz: fa38a2827ad09bb112307fa9ba9d8dd4ce7f7560dc3d6b6927c7954941567f90e1f53e0f5b1a7069821ad758b049a5bcfa6852424beb5c4ee5992edacd3f9281
@@ -1,3 +1,7 @@
1
+ ## 1.1.2
2
+
3
+ - Updated chartkick.js to v1.0.1
4
+
1
5
  ## 1.1.1
2
6
 
3
7
  - Added support for Sinatra
data/README.md CHANGED
@@ -58,18 +58,24 @@ end
58
58
 
59
59
  ### Options
60
60
 
61
- id and height
61
+ Id and height
62
62
 
63
63
  ```erb
64
64
  <%= line_chart User.group_by_day(:created_at).count, :id => "users-chart", :height => "500px" %>
65
65
  ```
66
66
 
67
- min and max values (except pie chart)
67
+ Min and max values (except pie chart)
68
68
 
69
69
  ```erb
70
70
  <%= line_chart User.group_by_day(:created_at).count, :min => 1000, :max => 5000 %>
71
71
  ```
72
72
 
73
+ You can pass options directly to the charting library with:
74
+
75
+ ```erb
76
+ <%= line_chart User.group_by_day(:created_at).count, :library => {:backgroundColor => "#eee"} %>
77
+ ```
78
+
73
79
  ### Data
74
80
 
75
81
  Pass data as a Hash or Array
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
@@ -2,7 +2,7 @@
2
2
  * Chartkick.js
3
3
  * Create beautiful Javascript charts with minimal code
4
4
  * https://github.com/ankane/chartkick.js
5
- * v1.0.1
5
+ * v1.0.2
6
6
  * MIT License
7
7
  */
8
8
 
@@ -12,43 +12,40 @@
12
12
  (function() {
13
13
  'use strict';
14
14
 
15
- // http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
16
- function clone(obj) {
17
- var copy, i, attr, len;
18
-
19
- // Handle the 3 simple types, and null or undefined
20
- if (null === obj || "object" !== typeof obj) {
21
- return obj;
22
- }
15
+ // helpers
23
16
 
24
- // Handle Date
25
- if (obj instanceof Date) {
26
- copy = new Date();
27
- copy.setTime(obj.getTime());
28
- return copy;
29
- }
17
+ function isArray(variable) {
18
+ return Object.prototype.toString.call(variable) === "[object Array]";
19
+ }
30
20
 
31
- // Handle Array
32
- if (obj instanceof Array) {
33
- copy = [];
34
- for (i = 0, len = obj.length; i < len; i++) {
35
- copy[i] = clone(obj[i]);
36
- }
37
- return copy;
38
- }
21
+ function isPlainObject(variable) {
22
+ return variable instanceof Object;
23
+ }
39
24
 
40
- // Handle Object
41
- if (obj instanceof Object) {
42
- copy = {};
43
- for (attr in obj) {
44
- if (obj.hasOwnProperty(attr)) {
45
- copy[attr] = clone(obj[attr]);
25
+ // https://github.com/madrobby/zepto/blob/master/src/zepto.js
26
+ function extend(target, source) {
27
+ var key;
28
+ for (key in source) {
29
+ if (isPlainObject(source[key]) || isArray(source[key])) {
30
+ if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
31
+ target[key] = {};
32
+ }
33
+ if (isArray(source[key]) && !isArray(target[key])) {
34
+ target[key] = [];
46
35
  }
36
+ extend(target[key], source[key]);
37
+ }
38
+ else if (source[key] !== undefined) {
39
+ target[key] = source[key];
47
40
  }
48
- return copy;
49
41
  }
42
+ }
50
43
 
51
- throw new Error("Unable to copy obj! Its type isn't supported.");
44
+ function merge(obj1, obj2) {
45
+ var target = {};
46
+ extend(target, obj1);
47
+ extend(target, obj2);
48
+ return target;
52
49
  }
53
50
 
54
51
  // https://github.com/Do/iso8601.js
@@ -101,7 +98,7 @@
101
98
 
102
99
  function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax) {
103
100
  return function(series, opts) {
104
- var options = clone(defaultOptions);
101
+ var options = merge({}, defaultOptions);
105
102
 
106
103
  // hide legend
107
104
  // this is *not* an external option!
@@ -122,6 +119,9 @@
122
119
  setMax(options, opts.max);
123
120
  }
124
121
 
122
+ // merge library last
123
+ options = merge(options, opts.library || {});
124
+
125
125
  return options;
126
126
  };
127
127
  }
@@ -196,7 +196,7 @@
196
196
  };
197
197
 
198
198
  renderPieChart = function(element, series, opts) {
199
- var options = clone(defaultOptions);
199
+ var options = merge(defaultOptions, opts.library || {});
200
200
  options.chart = {renderTo: element.id};
201
201
  options.series = [{
202
202
  type: "pie",
@@ -314,10 +314,6 @@
314
314
 
315
315
  var jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax);
316
316
 
317
- var sortByNumber = function(a, b) {
318
- return a[0] - b[0];
319
- };
320
-
321
317
  // cant use object as key
322
318
  var createDataTable = function(series, columnType) {
323
319
  var data = new google.visualization.DataTable();
@@ -345,7 +341,7 @@
345
341
  }
346
342
  }
347
343
  if (columnType === "datetime") {
348
- rows2.sort(sortByNumber);
344
+ rows2.sort(sortByTime);
349
345
  }
350
346
  data.addRows(rows2);
351
347
 
@@ -363,7 +359,7 @@
363
359
 
364
360
  renderPieChart = function(element, series, opts) {
365
361
  waitForLoaded(function() {
366
- var options = clone(defaultOptions);
362
+ var options = merge(defaultOptions, opts.library || {});
367
363
  options.chartArea = {
368
364
  top: "10%",
369
365
  height: "80%"
@@ -437,12 +433,6 @@
437
433
  }
438
434
  }
439
435
 
440
- // helpers
441
-
442
- function isArray(variable) {
443
- return Object.prototype.toString.call(variable) === "[object Array]";
444
- }
445
-
446
436
  // type conversions
447
437
 
448
438
  function toStr(n) {
@@ -535,7 +525,7 @@
535
525
  if (typeof element === "string") {
536
526
  element = document.getElementById(element);
537
527
  }
538
- fetchDataSource(element, data, clone(opts || {}), callback);
528
+ fetchDataSource(element, data, opts || {}, callback);
539
529
  }
540
530
 
541
531
  // define classes
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
23
24
  end
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require "erb"
2
3
 
3
4
  module Chartkick
4
5
  module Helper
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -0,0 +1,24 @@
1
+ require "test_helper"
2
+
3
+ class TestChartkick < Minitest::Test
4
+ include Chartkick::Helper
5
+
6
+ # TODO actual tests
7
+
8
+ def setup
9
+ @data = [[34, 42], [56, 49]]
10
+ end
11
+
12
+ def test_line_chart
13
+ assert line_chart(@data)
14
+ end
15
+
16
+ def test_pie_chart
17
+ assert pie_chart(@data)
18
+ end
19
+
20
+ def test_column_chart
21
+ assert column_chart(@data)
22
+ end
23
+
24
+ end
@@ -0,0 +1,4 @@
1
+ require "bundler/setup"
2
+ Bundler.require(:default)
3
+ require "minitest/autorun"
4
+ require "minitest/pride"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-11 00:00:00.000000000 Z
11
+ date: 2013-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Create beautiful Javascript charts with one line of Ruby
42
56
  email:
43
57
  - acekane1@gmail.com
@@ -59,6 +73,8 @@ files:
59
73
  - lib/chartkick/rails.rb
60
74
  - lib/chartkick/sinatra.rb
61
75
  - lib/chartkick/version.rb
76
+ - test/chartkick_test.rb
77
+ - test/test_helper.rb
62
78
  homepage: ''
63
79
  licenses:
64
80
  - MIT
@@ -83,4 +99,6 @@ rubygems_version: 2.0.0
83
99
  signing_key:
84
100
  specification_version: 4
85
101
  summary: Create beautiful Javascript charts with one line of Ruby
86
- test_files: []
102
+ test_files:
103
+ - test/chartkick_test.rb
104
+ - test/test_helper.rb