]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
time type xAxis height crah in line chart 2741/head
authorJack Valuntine <JackValentine@jackarchive.com>
Thu, 9 Jun 2016 04:34:15 +0000 (13:34 +0900)
committerJack Valuntine <JackValentine@jackarchive.com>
Thu, 9 Jun 2016 04:34:15 +0000 (13:34 +0900)
if input only one data in dataset and xAxis type is date make offset crash.
check offset value and don't devide 0 value.
Add xAxis check test case.

src/scales/scale.time.js [changed mode: 0644->0755]
test/scale.time.tests.js [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 1c2ef44..fbb4fbf
@@ -332,7 +332,7 @@ module.exports = function(Chart) {
                        if (labelMoment) {
                                var offset = labelMoment.diff(me.firstTick, me.tickUnit, true);
 
-                               var decimal = offset / me.scaleSizeInUnits;
+                               var decimal = offset !== 0 ? offset / me.scaleSizeInUnits : offset;
 
                                if (me.isHorizontal()) {
                                        var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
old mode 100644 (file)
new mode 100755 (executable)
index 9966f9c..0d1b8b8
@@ -435,4 +435,47 @@ describe('Time scale tests', function() {
                expect(xScale.getLabelForIndex(6, 0)).toBe('2015-01-10T12:00');
 
        });
+       it('should get the correct pixel for only one data in the dataset', function() {
+               var chart = window.acquireChart({
+                       type: 'line',
+                       data: {
+                               labels: ["2016-05-27"],
+                               datasets: [{
+                                       type: "line",
+                                       data: [5]
+                               }]
+                       },
+                       options: {
+                               scales: {
+                                       xAxes: [{
+                                               display: true,
+                                               type: "time",
+                                               time: {
+                                                       displayFormats: {
+                                                               "day": "YYYY-MM-DD"
+                                                       }
+                                               }
+                                       }],
+                                       yAxes: [{
+                                               type: "linear",
+                                               ticks: {
+                                                       reverse: true,
+                                                       min: 0,
+                                                       max: 10
+                                               }
+                                       }]
+                               }
+                       }
+               });
+
+               var xScale = chartInstance.scales.xScale0;
+
+               expect(xScale.getPixelForValue('', 0, 0)).toBeCloseToPixel(78);
+
+               expect(xScale.getValueForPixel(78)).toBeCloseToTime({
+                       value: moment(chartInstance.data.labels[0]),
+                       unit: 'day',
+                       threshold: 0.75
+               });
+       });
 });