@@ -56,11 +56,13 @@ return /******/ (function(modules) { // webpackBootstrap
56
56
57
57
module . exports = {
58
58
Bar : __webpack_require__ ( 1 ) ,
59
- Doughnut : __webpack_require__ ( 6 ) ,
60
- Line : __webpack_require__ ( 7 ) ,
61
- Pie : __webpack_require__ ( 8 ) ,
62
- PolarArea : __webpack_require__ ( 9 ) ,
63
- Radar : __webpack_require__ ( 10 ) ,
59
+ Bubble : __webpack_require__ ( 6 ) ,
60
+ Doughnut : __webpack_require__ ( 7 ) ,
61
+ Line : __webpack_require__ ( 8 ) ,
62
+ Pie : __webpack_require__ ( 9 ) ,
63
+ PolarArea : __webpack_require__ ( 10 ) ,
64
+ Radar : __webpack_require__ ( 11 ) ,
65
+ Scatter : __webpack_require__ ( 12 ) ,
64
66
createClass : __webpack_require__ ( 2 ) . createClass
65
67
} ;
66
68
@@ -78,6 +80,13 @@ return /******/ (function(modules) { // webpackBootstrap
78
80
/* 2 */
79
81
/***/ function ( module , exports , __webpack_require__ ) {
80
82
83
+ // Designed to be used with the current v2.0-dev version of Chart.js
84
+ // It's not on NPM, but if you'd like to use it you can, install it
85
+ // by setting the chart.js version in your package.json to:
86
+ // "chart.js": "git://github.com./danmolitor/Chart.js.git#v2.0-dev"
87
+
88
+ // I'll try to rework this for their 2.0.0 beta as well.
89
+
81
90
var React = __webpack_require__ ( 3 ) ;
82
91
var ReactDOM = __webpack_require__ ( 4 ) ;
83
92
@@ -112,35 +121,63 @@ return /******/ (function(modules) { // webpackBootstrap
112
121
this . initializeChart ( this . props ) ;
113
122
} ;
114
123
124
+
115
125
classData . componentWillUnmount = function ( ) {
116
126
var chart = this . state . chart ;
117
127
chart . destroy ( ) ;
118
128
} ;
119
129
120
130
classData . componentWillReceiveProps = function ( nextProps ) {
121
131
var chart = this . state . chart ;
122
- if ( nextProps . redraw ) {
123
- chart . destroy ( ) ;
124
- this . initializeChart ( nextProps ) ;
125
- } else {
126
- dataKey = dataKey || dataKeys [ chart . name ] ;
127
- updatePoints ( nextProps , chart , dataKey ) ;
128
- if ( chart . scale ) {
129
- chart . scale . xLabels = nextProps . data . labels ;
130
- chart . scale . calculateXLabelRotation ( ) ;
131
- }
132
- chart . update ( ) ;
133
- }
134
- } ;
132
+
133
+ // // Reset the array of datasets
134
+ chart . data . datasets . forEach ( function ( set , setIndex ) {
135
+ set . data . forEach ( function ( val , pointIndex ) {
136
+ set . data = [ ] ;
137
+ } ) ;
138
+ } ) ;
139
+
140
+ // // Reset the array of labels
141
+ chart . data . labels = [ ] ;
142
+
143
+ // Adds the datapoints from nextProps
144
+ nextProps . data . datasets . forEach ( function ( set , setIndex ) {
145
+ set . data . forEach ( function ( val , pointIndex ) {
146
+ chart . data . datasets [ setIndex ] . data [ pointIndex ] = nextProps . data . datasets [ setIndex ] . data [ pointIndex ] ;
147
+ } ) ;
148
+ } ) ;
149
+
150
+ // Sets the labels from nextProps
151
+ nextProps . data . labels . forEach ( function ( val , labelIndex ) {
152
+ chart . data . labels [ labelIndex ] = nextProps . data . labels [ labelIndex ] ;
153
+ } ) ;
154
+
155
+ // Updates Chart with new data
156
+ chart . update ( ) ;
157
+ } ;
135
158
136
159
classData . initializeChart = function ( nextProps ) {
137
160
var Chart = __webpack_require__ ( 5 ) ;
138
161
var el = ReactDOM . findDOMNode ( this ) ;
139
162
var ctx = el . getContext ( "2d" ) ;
140
- var chart = new Chart ( ctx ) [ chartType ] ( nextProps . data , nextProps . options || { } ) ;
163
+
164
+ if ( chartType === 'PolarArea' ) {
165
+ var chart = new Chart ( ctx , {
166
+ type : 'polarArea' ,
167
+ data : nextProps . data ,
168
+ options : nextProps . options
169
+ } ) ;
170
+ } else {
171
+ var chart = new Chart ( ctx , {
172
+ type : chartType . toLowerCase ( ) ,
173
+ data : nextProps . data ,
174
+ options : nextProps . options
175
+ } ) ;
176
+ }
141
177
this . state . chart = chart ;
142
178
} ;
143
179
180
+
144
181
// return the chartjs instance
145
182
classData . getChart = function ( ) {
146
183
return this . state . chart ;
@@ -165,50 +202,6 @@ return /******/ (function(modules) { // webpackBootstrap
165
202
}
166
203
} ;
167
204
168
- var dataKeys = {
169
- 'Line' : 'points' ,
170
- 'Radar' : 'points' ,
171
- 'Bar' : 'bars'
172
- } ;
173
-
174
- var updatePoints = function ( nextProps , chart , dataKey ) {
175
- var name = chart . name ;
176
-
177
- if ( name === 'PolarArea' || name === 'Pie' || name === 'Doughnut' ) {
178
- nextProps . data . forEach ( function ( segment , segmentIndex ) {
179
- if ( ! chart . segments [ segmentIndex ] ) {
180
- chart . addData ( segment ) ;
181
- } else {
182
- Object . keys ( segment ) . forEach ( function ( key ) {
183
- chart . segments [ segmentIndex ] [ key ] = segment [ key ] ;
184
- } ) ;
185
- }
186
- } ) ;
187
- } else {
188
- while ( chart . scale . xLabels . length > nextProps . data . labels . length ) {
189
- chart . removeData ( ) ;
190
- }
191
- nextProps . data . datasets . forEach ( function ( set , setIndex ) {
192
- set . data . forEach ( function ( val , pointIndex ) {
193
- if ( typeof ( chart . datasets [ setIndex ] [ dataKey ] [ pointIndex ] ) == "undefined" ) {
194
- addData ( nextProps , chart , setIndex , pointIndex ) ;
195
- } else {
196
- chart . datasets [ setIndex ] [ dataKey ] [ pointIndex ] . value = val ;
197
- }
198
- } ) ;
199
- } ) ;
200
- }
201
- } ;
202
-
203
- var addData = function ( nextProps , chart , setIndex , pointIndex ) {
204
- var values = [ ] ;
205
- nextProps . data . datasets . forEach ( function ( set ) {
206
- values . push ( set . data [ pointIndex ] ) ;
207
- } ) ;
208
- chart . addData ( values , nextProps . data . labels [ setIndex ] ) ;
209
- } ;
210
-
211
-
212
205
/***/ } ,
213
206
/* 3 */
214
207
/***/ function ( module , exports ) {
@@ -233,7 +226,7 @@ return /******/ (function(modules) { // webpackBootstrap
233
226
234
227
var vars = __webpack_require__ ( 2 ) ;
235
228
236
- module . exports = vars . createClass ( 'Doughnut ' , [ 'getSegmentsAtEvent ' ] ) ;
229
+ module . exports = vars . createClass ( 'Bubble ' , [ 'getPointsAtEvent ' ] ) ;
237
230
238
231
239
232
/***/ } ,
@@ -242,7 +235,7 @@ return /******/ (function(modules) { // webpackBootstrap
242
235
243
236
var vars = __webpack_require__ ( 2 ) ;
244
237
245
- module . exports = vars . createClass ( 'Line ' , [ 'getPointsAtEvent ' ] ) ;
238
+ module . exports = vars . createClass ( 'Doughnut ' , [ 'getSegmentsAtEvent ' ] ) ;
246
239
247
240
248
241
/***/ } ,
@@ -251,7 +244,7 @@ return /******/ (function(modules) { // webpackBootstrap
251
244
252
245
var vars = __webpack_require__ ( 2 ) ;
253
246
254
- module . exports = vars . createClass ( 'Pie ' , [ 'getSegmentsAtEvent ' ] ) ;
247
+ module . exports = vars . createClass ( 'Line ' , [ 'getPointsAtEvent ' ] ) ;
255
248
256
249
257
250
/***/ } ,
@@ -260,7 +253,7 @@ return /******/ (function(modules) { // webpackBootstrap
260
253
261
254
var vars = __webpack_require__ ( 2 ) ;
262
255
263
- module . exports = vars . createClass ( 'PolarArea ' , [ 'getSegmentsAtEvent' ] ) ;
256
+ module . exports = vars . createClass ( 'Pie ' , [ 'getSegmentsAtEvent' ] ) ;
264
257
265
258
266
259
/***/ } ,
@@ -269,9 +262,27 @@ return /******/ (function(modules) { // webpackBootstrap
269
262
270
263
var vars = __webpack_require__ ( 2 ) ;
271
264
265
+ module . exports = vars . createClass ( 'PolarArea' , [ 'getSegmentsAtEvent' ] ) ;
266
+
267
+
268
+ /***/ } ,
269
+ /* 11 */
270
+ /***/ function ( module , exports , __webpack_require__ ) {
271
+
272
+ var vars = __webpack_require__ ( 2 ) ;
273
+
272
274
module . exports = vars . createClass ( 'Radar' , [ 'getPointsAtEvent' ] ) ;
273
275
274
276
277
+ /***/ } ,
278
+ /* 12 */
279
+ /***/ function ( module , exports , __webpack_require__ ) {
280
+
281
+ var vars = __webpack_require__ ( 2 ) ;
282
+
283
+ module . exports = vars . createClass ( 'Scatter' , [ 'getPointsAtEvent' ] ) ;
284
+
285
+
275
286
/***/ }
276
287
/******/ ] )
277
288
} ) ;
0 commit comments