jscharting-react
Version:
JSCharting plugin for react
332 lines (322 loc) • 10.2 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var React = require('react');
var JSC = require('jscharting');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var JSC__namespace = /*#__PURE__*/_interopNamespace(JSC);
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a 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, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var JSCharting = /*#__PURE__*/function (_React$Component) {
_inherits(JSCharting, _React$Component);
var _super = _createSuper(JSCharting);
function JSCharting(props) {
var _this;
_classCallCheck(this, JSCharting);
_this = _super.call(this, props);
_this.instance = undefined;
return _this;
}
_createClass(JSCharting, [{
key: "componentDidMount",
value: function componentDidMount() {
this.applyProperties();
this.renderChart();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.instance) {
this.instance.dispose();
}
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.renderChart();
}
}, {
key: "render",
value: function render() {
var _this2 = this;
return /*#__PURE__*/React__default["default"].createElement("div", {
ref: function ref(node) {
return _this2.container = node;
},
className: this.props.className
});
}
}, {
key: "renderChart",
value: function renderChart() {
var cb = this.props.callback;
var options = this.props.options || this.props;
var ignoreStateUpdate = this.props.ignoreStateUpdate;
var updateExisting = this.instance && this.props.mutable !== false && !this.instance.dirty;
// Skip update if chart exists and ignoreStateUpdate is true
if (!this.instance || !ignoreStateUpdate) {
if (updateExisting) {
this.instance.options(options);
} else {
if (this.instance) {
this.instance.destroy();
}
var containerElement = this.container;
var config = Object.assign({
targetElement: containerElement
}, options);
this.instance = new JSC__namespace.Chart(config, cb);
}
}
}
}, {
key: "applyProperties",
value: function applyProperties() {
var containerElement = this.container;
if (containerElement) {
var options = this.props.options || this.props;
var stringifySize = function stringifySize(size) {
return size && Number(size) === size ? size + 'px' : size;
};
containerElement.style.width = stringifySize(options.width) || '100%';
containerElement.style.height = stringifySize(options.height) || '100%';
}
}
}]);
return JSCharting;
}(React__default["default"].Component);
var JSCLabel = /*#__PURE__*/function (_React$Component2) {
_inherits(JSCLabel, _React$Component2);
var _super2 = _createSuper(JSCLabel);
function JSCLabel(props) {
_classCallCheck(this, JSCLabel);
return _super2.call(this, props);
}
_createClass(JSCLabel, [{
key: "componentDidMount",
value: function componentDidMount() {
this.renderLabel();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.destroy();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.renderLabel();
}
}, {
key: "render",
value: function render() {
var _this3 = this;
return /*#__PURE__*/React__default["default"].createElement("div", {
ref: function ref(node) {
return _this3.container = node;
},
className: this.props.className
});
}
}, {
key: "destroy",
value: function destroy() {
var containerElement = this.container;
if (containerElement) {
containerElement.innerHTML = '';
}
}
}, {
key: "renderLabel",
value: function renderLabel() {
this.destroy();
var containerElement = this.container;
var options = this.props.options;
var textProperty = options && options.text;
JSC__namespace.label(containerElement, textProperty || options, textProperty && options);
}
}]);
return JSCLabel;
}(React__default["default"].Component);
var JSCGrid = /*#__PURE__*/function (_React$Component3) {
_inherits(JSCGrid, _React$Component3);
var _super3 = _createSuper(JSCGrid);
function JSCGrid(props) {
var _this4;
_classCallCheck(this, JSCGrid);
_this4 = _super3.call(this, props);
_this4.instance = undefined;
return _this4;
}
_createClass(JSCGrid, [{
key: "componentDidMount",
value: function componentDidMount() {
this.renderGrid();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.instance && this.instance.destroy();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.renderGrid();
}
}, {
key: "render",
value: function render() {
var _this5 = this;
return /*#__PURE__*/React__default["default"].createElement("div", {
ref: function ref(node) {
return _this5.container = node;
},
className: this.props.className
});
}
}, {
key: "renderGrid",
value: function renderGrid() {
var _this6 = this;
var cb = this.props.callback;
var options = this.props.options || this.props;
var updateExisting = this.instance && this.props.mutable;
if (updateExisting) {
this.instance.options(options);
} else {
this.instance && this.instance.destroy();
var containerElement = this.container;
JSC__namespace.Grid(containerElement, options).then(function (grid) {
_this6.instance = grid;
cb && cb(grid);
});
}
}
}]);
return JSCGrid;
}(React__default["default"].Component);
exports.JSC = JSC__namespace;
exports.JSCGrid = JSCGrid;
exports.JSCLabel = JSCLabel;
exports.JSCharting = JSCharting;
exports["default"] = JSCharting;
//# sourceMappingURL=jscharting-react.js.map