From eb8cd139979ecffd9ffe80306dd594b26474a628 Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Wed, 27 May 2020 12:22:00 -0400 Subject: [PATCH] Consider all timestamps for bar measuring (#7421) * Consider all timestamps for bar measuring * Fix watched tests for updated file names * Add test of sparse bar time scales --- karma.conf.js | 2 +- src/scales/scale.time.js | 2 +- .../scale.time/bar-large-gap-between-data.js | 57 ++++++++++++++++++ .../scale.time/bar-large-gap-between-data.png | Bin 0 -> 8928 bytes 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/scale.time/bar-large-gap-between-data.js create mode 100644 test/fixtures/scale.time/bar-large-gap-between-data.png diff --git a/karma.conf.js b/karma.conf.js index a4ec3cd59..2f5f8d8f3 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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) { diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index a6b505c7e..ec8d61e71 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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 index 000000000..7b1017251 --- /dev/null +++ b/test/fixtures/scale.time/bar-large-gap-between-data.js @@ -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 index 0000000000000000000000000000000000000000..c228f066dd4c43bc5d2cff6da003f9f8e3583fee GIT binary patch literal 8928 zcmeHNjZ;%s7C-O$VqZwnhk&rfb)U5hF0#a^3u;lGifdgYU}3RBC8^qqYqi<2rIGOQ zqHCcoG|b{O2o+n4?jJwd%U_+~0nq@N1g9 zRi{gJC3Z|?MzAk%CL9r9 z!3Sg8uvyLt0W{nuiemet-vhmwkm})ws&85&A>##^dpe<4_%Omd>G{Vz4WK>tq9d7M zGk?iJ+R4c=cLTAGWqm7ulCLfh;NF?LMwiM*Fm5f5EdqU;gf{id^2R)spdIsdPBLuc z?|JCH(6!dBBG!_1&LvW|QOU#ef4Sb^UQ4W>z;pCH!hIJYcDx+(9kxs+xa&9IkoT8o-$FG3@_W8x$< zf4Enp`giYja?zbQnBr2|``_FMst`94fh9OLU3bA&8@tl%XtUkSrOET7MM5qXmkLmQV;Nf)swUqYZZ3!*B+7QiQxEk#ZA8Oorh zYz*scQ05AX?7<8pYYao$A^+-CLf^o+Z37bQA*1>}&3uabrmI6HIu?goTwLOI5&`59 zWL{hXs17@V`_{{kj}%yfJ(aEstjH-E?y~LsvK5iJ+HtA55&^z9;z2Dqt_Js6keD;D@6V7BS9H}f-=C|Z*&k2-ZfYbA{RIc1#lGhSgHb%ANn@m z_QksA@T^gmnV1uY03TLay4ep2$b|&tN)2ocK*!&nYA!{`RjB@|o(gyA5%@oP>`uS8 zw@P)3 zU-)|8&+xs-M(duUA%h}sa$EjCdgpGR%7CI_XK-IbQ2IM)B+vS@dk&#f@x{nnH>Q@f z>WYR>cUgL9Q$&~TUj(%FM*`BWrl|Uzzar`)Rgog^e8J?ci}S3Q9TpXciB{*4=Xux+WqN9ZtyLfxU3D$|Q7mD<;! zGO6(%d;Z$yq9grT(9I4<-81%)RQSUSLtz?xq1M@uB!(o8lDL-sPj;NmP<|CZ45;va o3m^i52%A5!&`*Y3l#dG@h^&>)+>*&X4fxxzP8oM