From 2bddccaaf08af2807803fc751b155fe745d6ea6f Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Mon, 8 Jun 2015 19:03:47 -0400 Subject: [PATCH] Use the correct base for linear scales. This gives the correct fill for lines and animations start at the correct point --- src/Chart.Line.js | 11 ++++++++++- src/Chart.Radar.js | 12 +++++++++++- src/Chart.Scatter.js | 11 ++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Chart.Line.js b/src/Chart.Line.js index 6598d8d13..c715855ed 100644 --- a/src/Chart.Line.js +++ b/src/Chart.Line.js @@ -232,6 +232,15 @@ // Update the lines this.eachDataset(function(dataset, datasetIndex) { var yScale = this.scales[dataset.yAxisID]; + var scaleBase; + + if (yScale.min < 0 && yScale.max < 0) { + scaleBase = yScale.getPixelForValue(yScale.max); + } else if (yScale.min > 0 && yScale.max > 0) { + scaleBase = yScale.getPixelForValue(yScale.min); + } else { + scaleBase = yScale.getPixelForValue(0); + } helpers.extend(dataset.metaDataset, { // Utility @@ -252,7 +261,7 @@ // Scale scaleTop: yScale.top, scaleBottom: yScale.bottom, - scaleZero: yScale.getPixelForValue(0), + scaleZero: scaleBase, }, }); diff --git a/src/Chart.Radar.js b/src/Chart.Radar.js index 5f58cce7e..cb2d81991 100644 --- a/src/Chart.Radar.js +++ b/src/Chart.Radar.js @@ -192,6 +192,16 @@ // Update the lines this.eachDataset(function(dataset, datasetIndex) { + var scaleBase; + + if (this.scale.min < 0 && this.scale.max < 0) { + scaleBase = this.scale.getPointPosition(0, this.scale.max); + } else if (this.scale.min > 0 && this.scale.max > 0) { + scaleBase = this.scale.getPointPosition(0, this.scale.min); + } else { + scaleBase = this.scale.getPointPosition(0, 0); + } + helpers.extend(dataset.metaDataset, { // Utility _datasetIndex: datasetIndex, @@ -213,7 +223,7 @@ // Scale scaleTop: this.scale.top, scaleBottom: this.scale.bottom, - scaleZero: this.scale.getPointPosition(0), + scaleZero: scaleBase, }, }); diff --git a/src/Chart.Scatter.js b/src/Chart.Scatter.js index 09f2b643f..c32b876a4 100644 --- a/src/Chart.Scatter.js +++ b/src/Chart.Scatter.js @@ -241,6 +241,15 @@ // Update the lines this.eachDataset(function(dataset, datasetIndex) { var yScale = this.scales[dataset.yAxisID]; + var scaleBase; + + if (yScale.min < 0 && yScale.max < 0) { + scaleBase = yScale.getPixelForValue(yScale.max); + } else if (yScale.min > 0 && yScale.max > 0) { + scaleBase = yScale.getPixelForValue(yScale.min); + } else { + scaleBase = yScale.getPixelForValue(0); + } helpers.extend(dataset.metaDataset, { // Utility @@ -261,7 +270,7 @@ // Scale scaleTop: yScale.top, scaleBottom: yScale.bottom, - scaleZero: yScale.getPixelForValue(0), + scaleZero: scaleBase, }, }); -- 2.47.3