Skip to content

Commit 1ea9f04

Browse files
authored
Merge pull request #44 from nrdobie/master
Added support for updating Chart.js defaults. fixes #41
2 parents 1edf4a1 + c15fc5b commit 1ea9f04

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# react-chartjs-2
44

5-
React wrapper for [ChartJs 2](http://www.chartjs.org/docs/#getting-started)
5+
React wrapper for [Chart.js 2](http://www.chartjs.org/docs/#getting-started)
66
Open for PR's and contributions!
77

88

@@ -61,8 +61,8 @@ In order for Chart.js to obey the custom size you need to set `maintainAspectRat
6161
/>
6262
```
6363

64-
### Chart instance
65-
Chart instance can be accessed by placing a ref to the element as:
64+
### Chart.js instance
65+
Chart.js instance can be accessed by placing a ref to the element as:
6666

6767
```
6868
render() {
@@ -75,6 +75,34 @@ render() {
7575
}
7676
```
7777

78+
### Chart.js Defaults
79+
Chart.js defaults can be set by importing the `defaults` object:
80+
81+
```javascript
82+
import { defaults } from 'react-chartjs-2';
83+
84+
// Disable animating charts by default.
85+
defaults.global.animation = false;
86+
```
87+
88+
If you want to bulk set properties, try using the [lodash.merge](https://lodash.com/docs/#merge) function. This function will do a deep recursive merge preserving previously set values that you don't want to update.
89+
90+
```javascript
91+
import { defaults } from 'react-chartjs-2';
92+
import merge from 'lodash.merge';
93+
// or
94+
// import { merge } from 'lodash';
95+
96+
merge(defaults, {
97+
global: {
98+
animation: false,
99+
line: {
100+
borderColor: '#F85F73',
101+
},
102+
},
103+
});
104+
```
105+
78106
### Events
79107

80108
#### onElementsClick (function)

dist/react-chartjs-2.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Object.defineProperty(exports, "__esModule", {
66
value: true
77
});
8-
exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = exports.Bubble = undefined;
8+
exports.defaults = exports.Bubble = exports.Polar = exports.Radar = exports.HorizontalBar = exports.Bar = exports.Line = exports.Pie = exports.Doughnut = undefined;
99

1010
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
1111

@@ -358,6 +358,8 @@ var Bubble = exports.Bubble = function (_React$Component8) {
358358
return Bubble;
359359
}(_react2.default.Component);
360360

361+
var defaults = exports.defaults = _chart2.default.defaults;
362+
361363
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
362364
},{"./utils/deepEqual":2,"chart.js":undefined,"react-dom":undefined}],2:[function(require,module,exports){
363365
'use strict';
@@ -366,7 +368,7 @@ Object.defineProperty(exports, "__esModule", {
366368
value: true
367369
});
368370

369-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
371+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
370372

371373
var hasOwnProperty = Object.prototype.hasOwnProperty;
372374

@@ -392,10 +394,15 @@ var deepEqual = function deepEqual(objA, objB) {
392394
}
393395

394396
var keysA = Object.keys(objA);
397+
var keysB = Object.keys(objB);
398+
var allKeys = keysA.concat(keysB);
395399

396-
// Test for A's keys different from B.
397-
for (var i = 0; i < keysA.length; i++) {
398-
if (!hasOwnProperty.call(objB, keysA[i])) {
400+
// Verify both objects have all the keys
401+
for (var i = 0; i < allKeys.length; i++) {
402+
if (!hasOwnProperty.call(objB, allKeys[i])) {
403+
return false;
404+
}
405+
if (!hasOwnProperty.call(objA, allKeys[i])) {
399406
return false;
400407
}
401408
}

dist/react-chartjs-2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)