"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
exports.__esModule = true;
var React = require("react");
var charts_1 = require("@devinit/charts");
var Chart = (function (_super) {
    __extends(Chart, _super);
    function Chart(props) {
        return _super.call(this, props) || this;
    }
    Chart.prototype.componentDidMount = function () {
        var _this = this;
        var element = this.element;
        var data = this.props.data;
        var config = this.props.config;
        charts_1.draw({ element: element, data: data, config: config }).then(function (chart) {
            _this.chart = chart;
            if (_this.props.callback && element)
                _this.props.callback(element);
        });
    };
    Chart.prototype.componentWillUpdate = function (props) {
        if (this.chart)
            this.chart.update(props.data);
    };
    Chart.prototype.render = function () {
        var _this = this;
        return (React.createElement("div", { ref: function (element) {
                _this.element = element;
            }, style: { width: this.props.width, height: this.props.height } }));
    };
    return Chart;
}(React.Component));
exports["default"] = Chart;
