From 29043f152bc51d3cb41412749b2936d729725536 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 zc-rk+jZ;%s7C-O$VqZwnhk&rfb)U5hF0#a^3u;lGifdgYU}3RBO;WWL*V<;smPW(J zi>`(3Lc=UhgHQqcp+Kvm)Gi80+O>(ZsC4YI1B#Fq@dMH#@{t5cvL|ahvore#Y=iJOW=l3RmOi`})_j|$*0Q@&RlkhA60pDV#LUi#9E&pw$Jp&1Bz{OExr%MK~^%+Z*_T20+~?r*tlRG9huH!w=;Mop_5gZF#Nk;@& z@c!5~bjvv*fR@`tQEY$gyI`;oQa$`o{dH?Js9unHrW1OFA0xb-nSadN0J>u@I#U@o z>*pL~oSYox-oy(B*QlT zmWS>OU28pRVk=qaS|Vi|l{`HEm+K9lwZ!&uu4^~$tVf%Mw)x%&V!M3K^*-+KXj6Zw z)GH&l+uyowO4(&wczCzDMdrz-w4cp#hcN82XL*=&{!_gti_*47yOVJz5pB+$9`s~T z+FQSI7vN3;+MKP)^lqfIgD<&T8CLf?MLie@yD&8r2qt-Fz7Y(jU>4*}<#Y4PFr1y< zL_({Qd1&rYX1Ldp>W&NUol;ge58c+Z-E*Gs<;9U7&f9`%+Pv`PW5c~1JR$GRKM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