@@ -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
@@ -110,37 +119,66 @@ return /******/ (function(modules) { // webpackBootstrap
110
119
111
120
classData . componentDidMount = function ( ) {
112
121
this . initializeChart ( this . props ) ;
122
+ console . log ( this . props ) ;
113
123
} ;
114
124
125
+
115
126
classData . componentWillUnmount = function ( ) {
116
127
var chart = this . state . chart ;
117
128
chart . destroy ( ) ;
118
129
} ;
119
130
120
131
classData . componentWillReceiveProps = function ( nextProps ) {
121
132
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
- } ;
133
+
134
+ // // Reset the array of datasets
135
+ chart . data . datasets . forEach ( function ( set , setIndex ) {
136
+ set . data . forEach ( function ( val , pointIndex ) {
137
+ set . data = [ ] ;
138
+ } ) ;
139
+ } ) ;
140
+
141
+ // // Reset the array of labels
142
+ chart . data . labels = [ ] ;
143
+
144
+ // Adds the datapoints from nextProps
145
+ nextProps . data . datasets . forEach ( function ( set , setIndex ) {
146
+ set . data . forEach ( function ( val , pointIndex ) {
147
+ chart . data . datasets [ setIndex ] . data [ pointIndex ] = nextProps . data . datasets [ setIndex ] . data [ pointIndex ] ;
148
+ } ) ;
149
+ } ) ;
150
+
151
+ // Sets the labels from nextProps
152
+ nextProps . data . labels . forEach ( function ( val , labelIndex ) {
153
+ chart . data . labels [ labelIndex ] = nextProps . data . labels [ labelIndex ] ;
154
+ } ) ;
155
+
156
+ // Updates Chart with new data
157
+ chart . update ( ) ;
158
+ } ;
135
159
136
160
classData . initializeChart = function ( nextProps ) {
137
161
var Chart = __webpack_require__ ( 5 ) ;
138
162
var el = ReactDOM . findDOMNode ( this ) ;
139
163
var ctx = el . getContext ( "2d" ) ;
140
- var chart = new Chart ( ctx ) [ chartType ] ( nextProps . data , nextProps . options || { } ) ;
164
+
165
+ if ( chartType === 'PolarArea' ) {
166
+ var chart = new Chart ( ctx , {
167
+ type : 'polarArea' ,
168
+ data : nextProps . data ,
169
+ options : nextProps . options
170
+ } ) ;
171
+ } else {
172
+ var chart = new Chart ( ctx , {
173
+ type : chartType . toLowerCase ( ) ,
174
+ data : nextProps . data ,
175
+ options : nextProps . options
176
+ } ) ;
177
+ }
141
178
this . state . chart = chart ;
142
179
} ;
143
180
181
+
144
182
// return the chartjs instance
145
183
classData . getChart = function ( ) {
146
184
return this . state . chart ;
@@ -165,50 +203,6 @@ return /******/ (function(modules) { // webpackBootstrap
165
203
}
166
204
} ;
167
205
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
206
/***/ } ,
213
207
/* 3 */
214
208
/***/ function ( module , exports ) {
@@ -233,7 +227,7 @@ return /******/ (function(modules) { // webpackBootstrap
233
227
234
228
var vars = __webpack_require__ ( 2 ) ;
235
229
236
- module . exports = vars . createClass ( 'Doughnut ' , [ 'getSegmentsAtEvent ' ] ) ;
230
+ module . exports = vars . createClass ( 'Bubble ' , [ 'getPointsAtEvent ' ] ) ;
237
231
238
232
239
233
/***/ } ,
@@ -242,7 +236,7 @@ return /******/ (function(modules) { // webpackBootstrap
242
236
243
237
var vars = __webpack_require__ ( 2 ) ;
244
238
245
- module . exports = vars . createClass ( 'Line ' , [ 'getPointsAtEvent ' ] ) ;
239
+ module . exports = vars . createClass ( 'Doughnut ' , [ 'getSegmentsAtEvent ' ] ) ;
246
240
247
241
248
242
/***/ } ,
@@ -251,7 +245,7 @@ return /******/ (function(modules) { // webpackBootstrap
251
245
252
246
var vars = __webpack_require__ ( 2 ) ;
253
247
254
- module . exports = vars . createClass ( 'Pie ' , [ 'getSegmentsAtEvent ' ] ) ;
248
+ module . exports = vars . createClass ( 'Line ' , [ 'getPointsAtEvent ' ] ) ;
255
249
256
250
257
251
/***/ } ,
@@ -260,7 +254,7 @@ return /******/ (function(modules) { // webpackBootstrap
260
254
261
255
var vars = __webpack_require__ ( 2 ) ;
262
256
263
- module . exports = vars . createClass ( 'PolarArea ' , [ 'getSegmentsAtEvent' ] ) ;
257
+ module . exports = vars . createClass ( 'Pie ' , [ 'getSegmentsAtEvent' ] ) ;
264
258
265
259
266
260
/***/ } ,
@@ -269,9 +263,27 @@ return /******/ (function(modules) { // webpackBootstrap
269
263
270
264
var vars = __webpack_require__ ( 2 ) ;
271
265
266
+ module . exports = vars . createClass ( 'PolarArea' , [ 'getSegmentsAtEvent' ] ) ;
267
+
268
+
269
+ /***/ } ,
270
+ /* 11 */
271
+ /***/ function ( module , exports , __webpack_require__ ) {
272
+
273
+ var vars = __webpack_require__ ( 2 ) ;
274
+
272
275
module . exports = vars . createClass ( 'Radar' , [ 'getPointsAtEvent' ] ) ;
273
276
274
277
278
+ /***/ } ,
279
+ /* 12 */
280
+ /***/ function ( module , exports , __webpack_require__ ) {
281
+
282
+ var vars = __webpack_require__ ( 2 ) ;
283
+
284
+ module . exports = vars . createClass ( 'Scatter' , [ 'getPointsAtEvent' ] ) ;
285
+
286
+
275
287
/***/ }
276
288
/******/ ] )
277
289
} ) ;
0 commit comments