@ibm-sterling/charts-react
Version:
Sterling charting components for React
323 lines (274 loc) • 8.54 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = _interopDefault(require('react'));
var charts = require('@ibm-sterling/charts');
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var BaseChart = function (_React$Component) {
inherits(BaseChart, _React$Component);
function BaseChart(props) {
classCallCheck(this, BaseChart);
var _this = possibleConstructorReturn(this, (BaseChart.__proto__ || Object.getPrototypeOf(BaseChart)).call(this, props));
var options = props.options,
data = props.data;
if (!options) {
console.error("Missing options!");
}
if (!data) {
console.error("Missing data!");
}
_this.data = props.data || {};
_this.options = props.options || {};
Object.assign(_this, _this.chart);
return _this;
}
createClass(BaseChart, [{
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.chart.model.setData(this.props.data);
this.chart.model.setOptions(this.props.options);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.chart.destroy();
}
}]);
return BaseChart;
}(React.Component);
var PieChart = function (_BaseChart) {
inherits(PieChart, _BaseChart);
function PieChart() {
classCallCheck(this, PieChart);
return possibleConstructorReturn(this, (PieChart.__proto__ || Object.getPrototypeOf(PieChart)).apply(this, arguments));
}
createClass(PieChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.PieChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return PieChart;
}(BaseChart);
var DonutChart = function (_BaseChart) {
inherits(DonutChart, _BaseChart);
function DonutChart() {
classCallCheck(this, DonutChart);
return possibleConstructorReturn(this, (DonutChart.__proto__ || Object.getPrototypeOf(DonutChart)).apply(this, arguments));
}
createClass(DonutChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.DonutChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return DonutChart;
}(BaseChart);
var LineChart = function (_BaseChart) {
inherits(LineChart, _BaseChart);
function LineChart() {
classCallCheck(this, LineChart);
return possibleConstructorReturn(this, (LineChart.__proto__ || Object.getPrototypeOf(LineChart)).apply(this, arguments));
}
createClass(LineChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.LineChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return LineChart;
}(BaseChart);
var ScatterChart = function (_BaseChart) {
inherits(ScatterChart, _BaseChart);
function ScatterChart() {
classCallCheck(this, ScatterChart);
return possibleConstructorReturn(this, (ScatterChart.__proto__ || Object.getPrototypeOf(ScatterChart)).apply(this, arguments));
}
createClass(ScatterChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.ScatterChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return ScatterChart;
}(BaseChart);
var GroupedBarChart = function (_BaseChart) {
inherits(GroupedBarChart, _BaseChart);
function GroupedBarChart() {
classCallCheck(this, GroupedBarChart);
return possibleConstructorReturn(this, (GroupedBarChart.__proto__ || Object.getPrototypeOf(GroupedBarChart)).apply(this, arguments));
}
createClass(GroupedBarChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.GroupedBarChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return GroupedBarChart;
}(BaseChart);
var SimpleBarChart = function (_BaseChart) {
inherits(SimpleBarChart, _BaseChart);
function SimpleBarChart() {
classCallCheck(this, SimpleBarChart);
return possibleConstructorReturn(this, (SimpleBarChart.__proto__ || Object.getPrototypeOf(SimpleBarChart)).apply(this, arguments));
}
createClass(SimpleBarChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.SimpleBarChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return SimpleBarChart;
}(BaseChart);
var StackedBarChart = function (_BaseChart) {
inherits(StackedBarChart, _BaseChart);
function StackedBarChart() {
classCallCheck(this, StackedBarChart);
return possibleConstructorReturn(this, (StackedBarChart.__proto__ || Object.getPrototypeOf(StackedBarChart)).apply(this, arguments));
}
createClass(StackedBarChart, [{
key: "componentDidMount",
value: function componentDidMount() {
this.chart = new charts.StackedBarChart(this.chartRef, {
data: this.props.data,
options: this.props.options
});
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
ref: function ref(chartRef) {
return _this2.chartRef = chartRef;
},
className: "chart-holder" });
}
}]);
return StackedBarChart;
}(BaseChart);
exports.PieChart = PieChart;
exports.DonutChart = DonutChart;
exports.LineChart = LineChart;
exports.ScatterChart = ScatterChart;
exports.GroupedBarChart = GroupedBarChart;
exports.SimpleBarChart = SimpleBarChart;
exports.StackedBarChart = StackedBarChart;