]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Consider all timestamps for bar measuring (#7421)
authorEvert Timberg <evert.timberg+github@gmail.com>
Wed, 27 May 2020 16:22:00 +0000 (12:22 -0400)
committerGitHub <noreply@github.com>
Wed, 27 May 2020 16:22:00 +0000 (12:22 -0400)
* Consider all timestamps for bar measuring
* Fix watched tests for updated file names
* Add test of sparse bar time scales

karma.conf.js
src/scales/scale.time.js
test/fixtures/scale.time/bar-large-gap-between-data.js [new file with mode: 0644]
test/fixtures/scale.time/bar-large-gap-between-data.png [new file with mode: 0644]

index a4ec3cd59eb5a73e3a73d2f702856b119f192b2f..2f5f8d8f308bdb5f6893656c7a617f3805fbdf71 100644 (file)
@@ -14,7 +14,7 @@ module.exports = function(karma) {
        // we will prefer the unminified build which is easier to browse and works
        // better with source mapping. In other cases, pick the minified build to
        // make sure that the minification process (terser) doesn't break anything.
-       const regex = args.watch ? /Chart\.js$/ : /Chart\.min\.js$/;
+       const regex = args.watch ? /chart\.js$/ : /chart\.min\.js$/;
        const build = builds.filter(v => v.output.file.match(regex))[0];
 
        if (args.watch) {
index a6b505c7e13429f4f3da6c5b3c66f4ce9f14464c..ec8d61e7174fde1c068b968bb7574d525f21074a 100644 (file)
@@ -686,7 +686,7 @@ class TimeScale extends Scale {
                me._majorUnit = !tickOpts.major.enabled || me._unit === 'year' ? undefined
                        : determineMajorUnit(me._unit);
                me._table = buildLookupTable(getTimestampsForTable(me), min, max, distribution);
-               me._offsets = computeOffsets(me._table, getDataTimestamps(me), min, max, options);
+               me._offsets = computeOffsets(me._table, timestamps, min, max, options);
 
                if (options.reverse) {
                        ticks.reverse();
diff --git a/test/fixtures/scale.time/bar-large-gap-between-data.js b/test/fixtures/scale.time/bar-large-gap-between-data.js
new file mode 100644 (file)
index 0000000..7b10172
--- /dev/null
@@ -0,0 +1,57 @@
+var date = moment('May 24 2020', 'MMM DD YYYY');
+
+module.exports = {
+       threshold: 0.05,
+       config: {
+               type: 'bar',
+               data: {
+                       datasets: [{
+                               backgroundColor: 'rgba(255, 0, 0, 0.5)',
+                               data: [
+                                       {
+                                               x: date.clone().add(-2, 'day'),
+                                               y: 20,
+                                       },
+                                       {
+                                               x: date.clone().add(-1, 'day'),
+                                               y: 30,
+                                       },
+                                       {
+                                               x: date,
+                                               y: 40,
+                                       },
+                                       {
+                                               x: date.clone().add(1, 'day'),
+                                               y: 50,
+                                       },
+                                       {
+                                               x: date.clone().add(7, 'day'),
+                                               y: 10,
+                                       }
+                               ]
+                       }]
+               },
+               options: {
+                       legend: false,
+                       scales: {
+                               x: {
+                                       display: false,
+                                       type: 'time',
+                                       distribution: 'linear',
+                                       ticks: {
+                                               source: 'auto'
+                                       },
+                                       time: {
+                                               unit: 'day'
+                                       }
+                               },
+                               y: {
+                                       display: false
+                               }
+                       }
+               }
+       },
+       options: {
+               spriteText: true
+       }
+};
diff --git a/test/fixtures/scale.time/bar-large-gap-between-data.png b/test/fixtures/scale.time/bar-large-gap-between-data.png
new file mode 100644 (file)
index 0000000..c228f06
Binary files /dev/null and b/test/fixtures/scale.time/bar-large-gap-between-data.png differ