diff --git a/lib/core.js b/lib/core.js index b39d67b..c0ec668 100644 --- a/lib/core.js +++ b/lib/core.js @@ -2,91 +2,100 @@ var React = require('react'); var ReactDOM = require('react-dom'); module.exports = { - createClass: function(chartType, methodNames, dataKey) { - var excludedProps = ['data', 'options', 'redraw']; - var classData = { - displayName: chartType + 'Chart', - getInitialState: function() { return {}; }, - render: function() { - var _props = { - ref: 'canvass' - }; - for (var name in this.props) { - if (this.props.hasOwnProperty(name)) { - if (excludedProps.indexOf(name) === -1) { - _props[name] = this.props[name]; + createClass: function(chartType, methodNames, dataKey) { + var excludedProps = ['data', 'options', 'redraw']; + + class ChartComponent extends React.Component { + constructor(props) { + super(props); + this.displayName = chartType + 'Chart'; + this.chart = {}; + this.canvas = null; } - } - } - return React.createElement('canvas', _props); - } - }; - var extras = ['clear', 'stop', 'resize', 'toBase64Image', 'generateLegend', 'update', 'addData', 'removeData']; - function extra(type) { - classData[type] = function() { - return this.state.chart[type].apply(this.state.chart, arguments); - }; - } + componentDidMount() { + this.initializeChart(); + + this.canvas = ReactDOM.findDOMNode(this); + + var extras = ['clear', 'stop', 'resize', 'toBase64Image', 'generateLegend', 'update', 'addData', 'removeData'], + i; + for (i=0; i