UNPKG

nuke-biz-custom-chart

Version:

custom-chart

79 lines (58 loc) 3.42 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; 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 _rax = require('rax'); var _weexNuke = require('weex-nuke'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(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; } function _inherits(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 isWeex = _weexNuke.Env.isWeex; var canvasWeex = null; if (isWeex) { canvasWeex = require('./canvas-weex'); } var Canvas = function (_Component) { _inherits(Canvas, _Component); function Canvas() { _classCallCheck(this, Canvas); var _this = _possibleConstructorReturn(this, (Canvas.__proto__ || Object.getPrototypeOf(Canvas)).call(this)); _this.getContext = _this.getContext.bind(_this); return _this; } _createClass(Canvas, [{ key: 'getContext', value: function getContext() { var canvas = (0, _rax.findDOMNode)(this.refs.canvas); if (isWeex) { return new Promise(function (resolve) { requestAnimationFrame(function () { resolve(canvasWeex.init(canvas)); }); }); } return new Promise(function (resolve) { if (canvas && canvas.getContext) { var context = canvas.getContext('2d'); context.render = function () {}; resolve(context); } }); } }, { key: 'render', value: function render() { var _props$style = this.props.style, style = _props$style === undefined ? {} : _props$style; if (isWeex) { return (0, _rax.createElement)('gcanvas', _extends({}, this.props, { ref: 'canvas' })); } return (0, _rax.createElement)('canvas', _extends({}, this.props, { width: style.width, height: style.height, ref: 'canvas' })); } }]); return Canvas; }(_rax.Component); exports.default = Canvas; module.exports = exports['default'];