Skip to content

Commit 0d08b35

Browse files
committed
Support Chart.js 2.7.0 and 2.7.1
1 parent 5fe8194 commit 0d08b35

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

samples/bar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Indie+Flower">
77
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
88
<script src="https://cdnjs.cloudflare.com/ajax/libs/rough.js/3.0.0/rough.js"></script>
9-
<script src="../dist/chartjs-plugin-rough.min.js"></script>
9+
<script src="../dist/chartjs-plugin-rough.js"></script>
1010
<style>
1111
canvas {
1212
-moz-user-select: none;

src/core/core.controller.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import Chart from 'chart.js';
44

55
var helpers = Chart.helpers;
66

7+
// For Chart.js 2.7.1 backward compatibility
8+
Chart.layouts = Chart.layouts || Chart.layoutService;
9+
710
// For Chart.js 2.7.3 backward compatibility
811
helpers.canvas = helpers.canvas || {};
912
helpers.canvas._isPointInArea = helpers.canvas._isPointInArea || function(point, area) {

src/plugins/plugin.rough.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ var descriptors = plugins.descriptors;
4444
plugins.descriptors = function(chart) {
4545
var rough = chart._rough;
4646

47+
// Replace filler/legend plugins with rough filler/legend plugins
4748
if (rough) {
48-
var cache = chart.$plugins || (chart.$plugins = {});
49+
// chart._plugins for Chart.js 2.7.1 backward compatibility
50+
var cache = chart.$plugins || chart._plugins || (chart.$plugins = chart._plugins = {});
4951
if (cache.id === this._cacheId) {
5052
return cache.descriptors;
5153
}
@@ -81,16 +83,24 @@ export default {
8183
chart.buildOrUpdateControllers = function() {
8284
var result;
8385

86+
// Replace controllers with rough controllers on creation
8487
Chart.controllers = roughControllers;
8588
result = Chart.prototype.buildOrUpdateControllers.apply(this, arguments);
8689
Chart.controllers = controllers;
8790

8891
return result;
8992
};
9093

94+
// Remove the existing legend if exists
9195
if (chart.legend) {
9296
Chart.layouts.removeBox(chart, chart.legend);
9397
delete chart.legend;
9498
}
99+
100+
// Invalidate plugin cache and create new one
101+
delete chart.$plugins;
102+
// For Chart.js 2.7.1 backward compatibility
103+
delete chart._plugins;
104+
plugins.descriptors(chart);
95105
}
96106
};

0 commit comments

Comments
 (0)