11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import ReactDOM from 'react-dom' ;
43import Chart from 'chart.js' ;
54import isEqual from 'lodash.isequal' ;
65
6+
7+ //Taken from MDN
8+ if ( ! Array . prototype . find ) {
9+ Object . defineProperty ( Array . prototype , 'find' , {
10+ value : function ( predicate ) {
11+ // 1. Let O be ? ToObject(this value).
12+ if ( this == null ) {
13+ throw new TypeError ( '"this" is null or not defined' ) ;
14+ }
15+
16+ var o = Object ( this ) ;
17+
18+ // 2. Let len be ? ToLength(? Get(O, "length")).
19+ var len = o . length >>> 0 ;
20+
21+ // 3. If IsCallable(predicate) is false, throw a TypeError exception.
22+ if ( typeof predicate !== 'function' ) {
23+ throw new TypeError ( 'predicate must be a function' ) ;
24+ }
25+
26+ // 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
27+ var thisArg = arguments [ 1 ] ;
28+
29+ // 5. Let k be 0.
30+ var k = 0 ;
31+
32+ // 6. Repeat, while k < len
33+ while ( k < len ) {
34+ // a. Let Pk be ! ToString(k).
35+ // b. Let kValue be ? Get(O, Pk).
36+ // c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
37+ // d. If testResult is true, return kValue.
38+ var kValue = o [ k ] ;
39+ if ( predicate . call ( thisArg , kValue , k , o ) ) {
40+ return kValue ;
41+ }
42+ // e. Increase k by 1.
43+ k ++ ;
44+ }
45+
46+ // 7. Return undefined.
47+ return undefined ;
48+ }
49+ } ) ;
50+ }
51+
52+
753class ChartComponent extends React . Component {
854 static getLabelAsKey = d => d . label ;
955
@@ -22,6 +68,7 @@ class ChartComponent extends React.Component {
2268 plugins : PropTypes . arrayOf ( PropTypes . object ) ,
2369 redraw : PropTypes . bool ,
2470 type : function ( props , propName , componentName ) {
71+
2572 if ( ! Object . keys ( Chart . controllers ) . find ( ( chartType ) => chartType === props [ propName ] ) ) {
2673 return new Error (
2774 'Invalid chart type `' + props [ propName ] + '` supplied to' +
@@ -203,6 +250,7 @@ class ChartComponent extends React.Component {
203250 const { options, legend, type, redraw, plugins} = this . props ;
204251 const node = this . element ;
205252 const data = this . memoizeDataProps ( ) ;
253+ options . legend = legend ;
206254
207255 this . chart_instance = new Chart ( node , {
208256 type,
0 commit comments