chartkick 3.2.1 → 3.2.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.

@@ -2,7 +2,7 @@
2
2
  * Chartkick.js
3
3
  * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
- * v3.1.1
5
+ * v3.1.3
6
6
  * MIT License
7
7
  */
8
8
 
@@ -486,7 +486,7 @@
486
486
 
487
487
  var jsOptions = jsOptionsFunc(merge(baseOptions, defaultOptions), hideLegend, setTitle, setMin, setMax, setStacked, setXtitle, setYtitle);
488
488
 
489
- var createDataTable = function (chart, options, chartType) {
489
+ var createDataTable = function (chart, options, chartType, library) {
490
490
  var datasets = [];
491
491
  var labels = [];
492
492
 
@@ -631,11 +631,15 @@
631
631
  var xmax = chart.options.xmax;
632
632
 
633
633
  if (chart.xtype === "datetime") {
634
+ // hacky check for Chart.js >= 2.9.0
635
+ // https://github.com/chartjs/Chart.js/compare/v2.8.0...v2.9.0
636
+ var gte29 = "math" in library.helpers;
637
+ var ticksKey = gte29 ? "ticks" : "time";
634
638
  if (notnull(xmin)) {
635
- options.scales.xAxes[0].time.min = toDate(xmin).getTime();
639
+ options.scales.xAxes[0][ticksKey].min = toDate(xmin).getTime();
636
640
  }
637
641
  if (notnull(xmax)) {
638
- options.scales.xAxes[0].time.max = toDate(xmax).getTime();
642
+ options.scales.xAxes[0][ticksKey].max = toDate(xmax).getTime();
639
643
  }
640
644
  } else if (chart.xtype === "number") {
641
645
  if (notnull(xmin)) {
@@ -726,7 +730,7 @@
726
730
  var options = jsOptions(chart, merge(chartOptions, chart.options));
727
731
  setFormatOptions(chart, options, chartType);
728
732
 
729
- var data = createDataTable(chart, options, chartType || "line");
733
+ var data = createDataTable(chart, options, chartType || "line", this.library);
730
734
 
731
735
  if (chart.xtype === "number") {
732
736
  options.scales.xAxes[0].type = "linear";
@@ -787,7 +791,7 @@
787
791
  options = jsOptions(chart, chart.options);
788
792
  }
789
793
  setFormatOptions(chart, options, chartType);
790
- var data = createDataTable(chart, options, "column");
794
+ var data = createDataTable(chart, options, "column", this.library);
791
795
  if (chartType !== "bar") {
792
796
  setLabelSize(chart, data, options);
793
797
  }
@@ -812,7 +816,7 @@
812
816
  options.showLines = false;
813
817
  }
814
818
 
815
- var data = createDataTable(chart, options, chartType);
819
+ var data = createDataTable(chart, options, chartType, this.library);
816
820
 
817
821
  options.scales.xAxes[0].type = "linear";
818
822
  options.scales.xAxes[0].position = "bottom";
@@ -886,6 +890,7 @@
886
890
  },
887
891
  plotOptions: {
888
892
  areaspline: {},
893
+ area: {},
889
894
  series: {
890
895
  marker: {}
891
896
  }
@@ -922,7 +927,10 @@
922
927
  };
923
928
 
924
929
  var setStacked$1 = function (options, stacked) {
925
- options.plotOptions.series.stacking = stacked ? (stacked === true ? "normal" : stacked) : null;
930
+ var stackedValue = stacked ? (stacked === true ? "normal" : stacked) : null;
931
+ options.plotOptions.series.stacking = stackedValue;
932
+ options.plotOptions.area.stacking = stackedValue;
933
+ options.plotOptions.areaspline.stacking = stackedValue;
926
934
  };
927
935
 
928
936
  var setXtitle$1 = function (options, title) {
@@ -1568,7 +1576,7 @@
1568
1576
  function ajaxCall(url, success, error) {
1569
1577
  var $ = window.jQuery || window.Zepto || window.$;
1570
1578
 
1571
- if ($) {
1579
+ if ($ && $.ajax) {
1572
1580
  $.ajax({
1573
1581
  dataType: "json",
1574
1582
  url: url,
@@ -1605,8 +1613,12 @@
1605
1613
  }
1606
1614
  }
1607
1615
 
1608
- function chartError(element, message) {
1609
- setText(element, "Error Loading Chart: " + message);
1616
+ // TODO remove prefix for all messages
1617
+ function chartError(element, message, noPrefix) {
1618
+ if (!noPrefix) {
1619
+ message = "Error Loading Chart: " + message;
1620
+ }
1621
+ setText(element, message);
1610
1622
  element.style.color = "#ff0000";
1611
1623
  }
1612
1624
 
@@ -1627,6 +1639,17 @@
1627
1639
  }, function (message) {
1628
1640
  chartError(chart.element, message);
1629
1641
  });
1642
+ } else if (typeof dataSource === "function") {
1643
+ try {
1644
+ dataSource(function (data) {
1645
+ chart.rawData = data;
1646
+ errorCatcher(chart);
1647
+ }, function (message) {
1648
+ chartError(chart.element, message, true);
1649
+ });
1650
+ } catch (err) {
1651
+ chartError(chart.element, err, true);
1652
+ }
1630
1653
  } else {
1631
1654
  chart.rawData = dataSource;
1632
1655
  errorCatcher(chart);
@@ -1972,6 +1995,8 @@
1972
1995
  var sep = this.dataSource.indexOf("?") === -1 ? "?" : "&";
1973
1996
  var url = this.dataSource + sep + "_=" + (new Date()).getTime();
1974
1997
  fetchDataSource(this, url);
1998
+ } else if (typeof this.dataSource === "function") {
1999
+ fetchDataSource(this, this.dataSource);
1975
2000
  }
1976
2001
  };
1977
2002
 
@@ -1980,8 +2005,8 @@
1980
2005
 
1981
2006
  var refresh = this.options.refresh;
1982
2007
 
1983
- if (refresh && typeof this.dataSource !== "string") {
1984
- throw new Error("Data source must be a URL for refresh");
2008
+ if (refresh && typeof this.dataSource !== "string" && typeof this.dataSource !== "function") {
2009
+ throw new Error("Data source must be a URL or callback for refresh");
1985
2010
  }
1986
2011
 
1987
2012
  if (!this.intervalId) {
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: 3.2.1
4
+ version: 3.2.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: 2019-07-15 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.0.4
91
+ rubygems_version: 3.0.3
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Create beautiful JavaScript charts with one line of Ruby