chartkick 1.2.5 → 1.3.0

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: d0dba34a7302ee5f73cba7e55be0014c639431d6
4
- data.tar.gz: f72f4d80febb09fd928abdf75c3967bbdeeb6d21
3
+ metadata.gz: 00b03d10b24d6e36edf3061bdd594b83b831776f
4
+ data.tar.gz: eb2175cda000c9ed560f9b28dc08fd3eb9fd5b19
5
5
  SHA512:
6
- metadata.gz: 73351da6753359cb7af17028059d3077788c2f8a6912f79f96243923a58bf0ab64911004661352efaceff634ceff5742eafa98b27a45d7a9e97365933d8b8ab2
7
- data.tar.gz: 4cadd3bf93432e26968faf47c822c228ed184e228324cffbaa8b7e4188ec5140647ffd9d87e84f67bf3b2c56376bab7ed0548d7ce076e4954fb2773d13f54e13
6
+ metadata.gz: 133267fc6a6a015495905656bac3be481ad205ed6aa81a5b7bdd68523617b798a72f3e2aac5f62834f62382c63d0462a28f1b1b934239db955cf6abfbd5f3999
7
+ data.tar.gz: c7ebf3c44d41a69f099e5a46cd81f21ae501b99c7a5660d4e3a082ef87f01d7cbc9efd7fe393a8f1499b85458197ce4d76d2d1b7b52b9084bcebe4f3be96d718
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.3.0
2
+
3
+ - Added timelines
4
+
1
5
  ## 1.2.5
2
6
 
3
7
  - Added support for multiple groups
data/README.md CHANGED
@@ -48,6 +48,12 @@ Geo chart
48
48
  <%= geo_chart Medal.group(:country).count %>
49
49
  ```
50
50
 
51
+ Timeline
52
+
53
+ ```erb
54
+ <%= timeline [["Washington", "1789-04-29", "1797-03-03"], ["Adams", "1797-03-03", "1801-03-03"]] %>
55
+ ```
56
+
51
57
  Multiple series
52
58
 
53
59
  ```erb
@@ -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.2.1
5
+ * v1.2.2
6
6
  * MIT License
7
7
  */
8
8
 
@@ -13,8 +13,6 @@
13
13
 
14
14
  var Chartkick, ISO8601_PATTERN, DECIMAL_SEPARATOR, adapters = [];
15
15
 
16
- var $ = window.jQuery || window.Zepto || window.$;
17
-
18
16
  // helpers
19
17
 
20
18
  function isArray(variable) {
@@ -154,6 +152,7 @@
154
152
  }
155
153
 
156
154
  function getJSON(element, url, success) {
155
+ var $ = window.jQuery || window.Zepto || window.$;
157
156
  $.ajax({
158
157
  dataType: "json",
159
158
  url: url,
@@ -401,17 +400,37 @@
401
400
  var GoogleChartsAdapter = new function () {
402
401
  var google = window.google;
403
402
 
404
- // load from google
405
- var loaded = false;
406
- google.setOnLoadCallback(function () {
407
- loaded = true;
408
- });
409
- google.load("visualization", "1.0", {"packages": ["corechart"]});
403
+ var loaded = {};
404
+ var callbacks = [];
405
+
406
+ var runCallbacks = function() {
407
+ var cb, call;
408
+ for (var i = 0; i < callbacks.length; i++) {
409
+ cb = callbacks[i];
410
+ call = (cb.pack == "corechart" && isFunction(google.visualization.LineChart)) || (cb.pack == "timeline" && isFunction(google.visualization.Timeline))
411
+ if (call) {
412
+ cb.callback();
413
+ callbacks.splice(i, 1);
414
+ i--;
415
+ }
416
+ }
417
+ };
418
+
419
+ google.setOnLoadCallback(runCallbacks);
420
+
421
+ var waitForLoaded = function (pack, callback) {
422
+ if (!callback) {
423
+ callback = pack;
424
+ pack = "corechart";
425
+ }
426
+
427
+ callbacks.push({pack: pack, callback: callback});
410
428
 
411
- var waitForLoaded = function (callback) {
412
- google.setOnLoadCallback(callback); // always do this to prevent race conditions (watch out for other issues due to this)
413
- if (loaded) {
414
- callback();
429
+ if (loaded[pack]) {
430
+ runCallbacks();
431
+ } else {
432
+ loaded[pack] = true;
433
+ google.load("visualization", "1.0", {"packages": [pack]});
415
434
  }
416
435
  };
417
436
 
@@ -627,7 +646,33 @@
627
646
  });
628
647
  });
629
648
  };
649
+
650
+ this.renderTimeline = function (chart) {
651
+ waitForLoaded("timeline", function () {
652
+ var chartOptions = {
653
+ legend: "none"
654
+ };
655
+
656
+ if (chart.options.colors) {
657
+ chartOptions.colorAxis.colors = chart.options.colors;
658
+ }
659
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
660
+
661
+ var data = new google.visualization.DataTable();
662
+ data.addColumn({type: "string", id: "Name"});
663
+ data.addColumn({type: "date", id: "Start"});
664
+ data.addColumn({type: "date", id: "End"});
665
+ data.addRows(chart.data);
666
+
667
+ chart.chart = new google.visualization.Timeline(chart.element);
668
+
669
+ resize(function () {
670
+ chart.chart.draw(data, options);
671
+ });
672
+ });
673
+ };
630
674
  };
675
+
631
676
  adapters.push(GoogleChartsAdapter);
632
677
  }
633
678
 
@@ -636,7 +681,7 @@
636
681
  // to get the name of the chart class
637
682
  function renderChart(chartType, chart) {
638
683
  var i, adapter, fnName;
639
- fnName = "render" + chartType + "Chart";
684
+ fnName = "render" + chartType;
640
685
 
641
686
  for (i = 0; i < adapters.length; i++) {
642
687
  adapter = adapters[i];
@@ -689,34 +734,49 @@
689
734
  return perfectData;
690
735
  }
691
736
 
737
+ function processTime(data)
738
+ {
739
+ var i;
740
+ for (i = 0; i < data.length; i++) {
741
+ data[i][1] = toDate(data[i][1]);
742
+ data[i][2] = toDate(data[i][2]);
743
+ }
744
+ return data;
745
+ }
746
+
692
747
  function processLineData(chart) {
693
748
  chart.data = processSeries(chart.data, chart.options, true);
694
- renderChart("Line", chart);
749
+ renderChart("LineChart", chart);
695
750
  }
696
751
 
697
752
  function processColumnData(chart) {
698
753
  chart.data = processSeries(chart.data, chart.options, false);
699
- renderChart("Column", chart);
754
+ renderChart("ColumnChart", chart);
700
755
  }
701
756
 
702
757
  function processPieData(chart) {
703
758
  chart.data = processSimple(chart.data);
704
- renderChart("Pie", chart);
759
+ renderChart("PieChart", chart);
705
760
  }
706
761
 
707
762
  function processBarData(chart) {
708
763
  chart.data = processSeries(chart.data, chart.options, false);
709
- renderChart("Bar", chart);
764
+ renderChart("BarChart", chart);
710
765
  }
711
766
 
712
767
  function processAreaData(chart) {
713
768
  chart.data = processSeries(chart.data, chart.options, true);
714
- renderChart("Area", chart);
769
+ renderChart("AreaChart", chart);
715
770
  }
716
771
 
717
772
  function processGeoData(chart) {
718
773
  chart.data = processSimple(chart.data);
719
- renderChart("Geo", chart);
774
+ renderChart("GeoChart", chart);
775
+ }
776
+
777
+ function processTimelineData(chart) {
778
+ chart.data = processTime(chart.data);
779
+ renderChart("Timeline", chart);
720
780
  }
721
781
 
722
782
  function setElement(chart, element, dataSource, opts, callback) {
@@ -751,6 +811,9 @@
751
811
  GeoChart: function (element, dataSource, opts) {
752
812
  setElement(this, element, dataSource, opts, processGeoData);
753
813
  },
814
+ Timeline: function (element, dataSource, opts) {
815
+ setElement(this, element, dataSource, opts, processTimelineData);
816
+ },
754
817
  charts: {}
755
818
  };
756
819
 
@@ -28,6 +28,10 @@ module Chartkick
28
28
  chartkick_chart "GeoChart", data_source, options
29
29
  end
30
30
 
31
+ def timeline(data_source, options = {})
32
+ chartkick_chart "Timeline", data_source, options
33
+ end
34
+
31
35
  private
32
36
 
33
37
  def chartkick_chart(klass, data_source, options, &block)
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "1.2.5"
2
+ VERSION = "1.3.0"
3
3
  end
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.2.5
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-13 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler