From 5a24bfa500a35000de8eddce2ebdcb4efd6c1d41 Mon Sep 17 00:00:00 2001 From: SAiTO TOSHiKi Date: Sun, 4 Dec 2016 05:09:45 +0800 Subject: [PATCH] Implement clipping (#3658) Implements clipping of items outside the chart area. Resolves #3506 #3491 #2873 --- src/controllers/controller.bar.js | 2 ++ src/controllers/controller.line.js | 4 +++- src/core/core.canvasHelpers.js | 12 ++++++++++++ src/elements/element.point.js | 24 +++++++++++++++++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index e5070542e88..bf1fb693793 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -229,12 +229,14 @@ module.exports = function(Chart) { var dataset = me.getDataset(); var i, len; + Chart.canvasHelpers.clipArea(me.chart.chart.ctx, me.chart.chartArea); for (i = 0, len = metaData.length; i < len; ++i) { var d = dataset.data[i]; if (d !== null && d !== undefined && !isNaN(d)) { metaData[i].transition(easingDecimal).draw(); } } + Chart.canvasHelpers.unclipArea(me.chart.chart.ctx); }, setHoverStyle: function(rectangle) { diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 23d4eedc402..806ab4f3f58 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -292,14 +292,16 @@ module.exports = function(Chart) { points[i].transition(easingDecimal); } + Chart.canvasHelpers.clipArea(me.chart.chart.ctx, me.chart.chartArea); // Transition and Draw the line if (lineEnabled(me.getDataset(), me.chart.options)) { meta.dataset.transition(easingDecimal).draw(); } + Chart.canvasHelpers.unclipArea(me.chart.chart.ctx); // Draw the points for (i=0, ilen=points.length; i