chartkick 5.0.0 → 5.0.1

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
  SHA256:
3
- metadata.gz: 0e3e26d84662ff0821322864aa4481daefc1c8a33c90210cf69fa3e2641122c1
4
- data.tar.gz: 65098ca753ee49fa221f93dc24cd630bc007a0bfbe81885143287c3640f1f221
3
+ metadata.gz: 9ac4b71bb9edbf35b307e350adf2fc5ebfed0e23618ca5e079f37e3ce548f68c
4
+ data.tar.gz: b5a6a2499a5e9835d3dcc7b002a881d60d85a66efc45c79931cc9897cdeca6de
5
5
  SHA512:
6
- metadata.gz: 781b9376d0f979e0fee356b5f872bbe339d2975c1fd46833262bc16476f83e0e2dc0149452616915a4c5eab323022db901b416722146dc7982fdc1a71bdc7240
7
- data.tar.gz: ff8d09974073e3b09555654770c6d42534d0dffd87271b5f79d6bc15b58a5cec6d9695d23541e69ac32cafb428790ddf0fb6f697f5631bf1a3dca5aa5d1da44b
6
+ metadata.gz: 709e242eff3d7c82c2c78dee8f0693f055819e3a0e24db1d5d58fe4d3564d1309a2477d45fc2b261685a6d60f81d6a2b6ace5a7c03dce48db1fea4cdb7bce4ae
7
+ data.tar.gz: c866cf49a27a03a16fdaa276b5b002b5eb36378b8f16ce062a3d2a08a56c67b47d286035f5e47cea8bf549e33174d6581a0024f4c8e96ca32849ef236c91e24d
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## 5.0.0 (2022-01-18)
1
+ ## 5.0.1 (2023-01-19)
2
+
3
+ - Updated Chartkick.js to 5.0.1
4
+
5
+ ## 5.0.0 (2023-01-18)
2
6
 
3
7
  - Added support for Chart.js 4
4
8
  - Changed `chart_json` to be defined on `Hash` and `Array` instead of `Enumerable`
data/README.md CHANGED
@@ -22,10 +22,10 @@ gem "chartkick"
22
22
 
23
23
  Then follow the instructions for your JavaScript setup:
24
24
 
25
- - [Importmap](#rails-7--importmap) (Rails 7 default)
26
- - [esbuild, rollup.js, or Webpack](#rails-7--esbuild-rollupjs-or-webpack)
27
- - [Webpacker](#rails-6--webpacker) (Rails 6 default)
28
- - [Sprockets](#rails-5--sprockets)
25
+ - [Importmap](#importmap) (Rails 7 default)
26
+ - [esbuild, rollup.js, or Webpack](#esbuild-rollupjs-or-webpack)
27
+ - [Webpacker](#webpacker) (Rails 6 default)
28
+ - [Sprockets](#sprockets)
29
29
 
30
30
  This sets up Chartkick with [Chart.js](https://www.chartjs.org/). For other charting libraries and frameworks, see [detailed instructions](#installation).
31
31
 
@@ -588,7 +588,7 @@ Download [chartkick.js](https://raw.githubusercontent.com/ankane/chartkick/maste
588
588
 
589
589
  Then include the charting library.
590
590
 
591
- Chart.js - download [Chart.js](https://unpkg.com/chart.js@3/dist/chart.js) and the [date-fns adapter bundle](https://unpkg.com/chartjs-adapter-date-fns@2/dist/chartjs-adapter-date-fns.bundle.js)
591
+ Chart.js - download [Chart.js](https://unpkg.com/chart.js@4/dist/chart.umd.js) and the [date-fns adapter bundle](https://unpkg.com/chartjs-adapter-date-fns@3/dist/chartjs-adapter-date-fns.bundle.js)
592
592
 
593
593
  ```html
594
594
  <script src="chart.js"></script>
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "5.0.0"
2
+ VERSION = "5.0.1"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Chartkick.js v5.0.0
2
+ * Chartkick.js v5.0.1
3
3
  * Create beautiful charts with one line of JavaScript
4
4
  * https://github.com/ankane/chartkick.js
5
5
  * MIT License
@@ -211,15 +211,11 @@
211
211
  return "day";
212
212
  }
213
213
 
214
- var dayOfWeek = values[0].getDay();
215
- var week = every(values, function (d) { return d.getDay() === dayOfWeek; });
216
- if (!week) {
217
- return "day";
218
- }
219
-
220
214
  var month = every(values, function (d) { return d.getDate() === 1; });
221
215
  if (!month) {
222
- return "week";
216
+ var dayOfWeek = values[0].getDay();
217
+ var week = every(values, function (d) { return d.getDay() === dayOfWeek; });
218
+ return (week ? "week" : "day");
223
219
  }
224
220
 
225
221
  var year = every(values, function (d) { return d.getMonth() === 0; });
@@ -499,15 +495,20 @@
499
495
  }
500
496
 
501
497
  function setFormatOptions$1(chart, options, chartType) {
502
- var formatOptions = {
498
+ // options to apply to x and r values for scatter and bubble
499
+ var numericOptions = {
500
+ thousands: chart.options.thousands,
501
+ decimal: chart.options.decimal
502
+ };
503
+
504
+ // options to apply to y value
505
+ var formatOptions = merge({
503
506
  prefix: chart.options.prefix,
504
507
  suffix: chart.options.suffix,
505
- thousands: chart.options.thousands,
506
- decimal: chart.options.decimal,
507
508
  precision: chart.options.precision,
508
509
  round: chart.options.round,
509
510
  zeros: chart.options.zeros
510
- };
511
+ }, numericOptions);
511
512
 
512
513
  if (chart.options.bytes) {
513
514
  var series = chart.data;
@@ -539,6 +540,12 @@
539
540
  return formatValue("", value, formatOptions, true);
540
541
  };
541
542
  }
543
+
544
+ if ((chartType === "scatter" || chartType === "bubble") && !options.scales.x.ticks.callback) {
545
+ options.scales.x.ticks.callback = function (value) {
546
+ return formatValue("", value, numericOptions, true);
547
+ };
548
+ }
542
549
  }
543
550
 
544
551
  if (!options.plugins.tooltip.callbacks.label) {
@@ -549,7 +556,8 @@
549
556
  label += ': ';
550
557
  }
551
558
 
552
- return label + context.formattedValue;
559
+ var dataPoint = context.parsed;
560
+ return label + '(' + formatValue('', dataPoint.x, numericOptions) + ', ' + formatValue('', dataPoint.y, formatOptions) + ')';
553
561
  };
554
562
  } else if (chartType === "bubble") {
555
563
  options.plugins.tooltip.callbacks.label = function (context) {
@@ -558,7 +566,7 @@
558
566
  label += ': ';
559
567
  }
560
568
  var dataPoint = context.raw;
561
- return label + '(' + dataPoint.x + ', ' + dataPoint.y + ', ' + dataPoint.v + ')';
569
+ return label + '(' + formatValue('', dataPoint.x, numericOptions) + ', ' + formatValue('', dataPoint.y, formatOptions) + ', ' + formatValue('', dataPoint.v, numericOptions) + ')';
562
570
  };
563
571
  } else if (chartType === "pie") {
564
572
  // need to use separate label for pie charts
@@ -581,6 +589,22 @@
581
589
  };
582
590
  }
583
591
  }
592
+
593
+ // avoid formatting x-axis labels
594
+ // by default, Chart.js applies locale
595
+ if ((chartType === "line" || chartType === "area") && chart.xtype === "number") {
596
+ if (!options.scales.x.ticks.callback) {
597
+ options.scales.x.ticks.callback = function (value) {
598
+ return toStr(value);
599
+ };
600
+ }
601
+
602
+ if (!options.plugins.tooltip.callbacks.title) {
603
+ options.plugins.tooltip.callbacks.title = function (context) {
604
+ return toStr(context[0].parsed.x);
605
+ };
606
+ }
607
+ }
584
608
  }
585
609
 
586
610
  function maxAbsY(series) {
@@ -881,7 +905,11 @@
881
905
  }
882
906
 
883
907
  if (!options.scales.x.time.tooltipFormat) {
884
- if (isDay(timeUnit)) {
908
+ if (timeUnit === "year") {
909
+ options.scales.x.time.tooltipFormat = "yyyy";
910
+ } else if (timeUnit === "month") {
911
+ options.scales.x.time.tooltipFormat = "MMM yyyy";
912
+ } else if (timeUnit === "week" || timeUnit === "day") {
885
913
  options.scales.x.time.tooltipFormat = "PP";
886
914
  } else if (timeUnit === "hour") {
887
915
  options.scales.x.time.tooltipFormat = "MMM d, h a";
@@ -904,12 +932,16 @@
904
932
  };
905
933
 
906
934
  defaultExport$2.prototype.renderLineChart = function renderLineChart (chart, chartType) {
935
+ if (!chartType) {
936
+ chartType = "line";
937
+ }
938
+
907
939
  var chartOptions = {};
908
940
 
909
941
  var options = jsOptions$2(chart, merge(chartOptions, chart.options));
910
942
  setFormatOptions$1(chart, options, chartType);
911
943
 
912
- var data = createDataTable(chart, options, chartType || "line");
944
+ var data = createDataTable(chart, options, chartType);
913
945
 
914
946
  if (chart.xtype === "number") {
915
947
  options.scales.x.type = options.scales.x.type || "linear";
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: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-18 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org