UNPKG

react-chemdoodle-web

Version:
113 lines (95 loc) 4.77 kB
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 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; }; }(); 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 React = require('react'); var PropTypes = require('prop-types'); if (typeof window !== 'undefined') { var jQuery = require('jquery'); window.jQuery = jQuery; var ChemDoodle = require('./vendor/ChemDoodleWeb'); } else { var ChemDoodle = null; } var ChemDoodleCanvas = function (_React$Component) { _inherits(ChemDoodleCanvas, _React$Component); function ChemDoodleCanvas() { _classCallCheck(this, ChemDoodleCanvas); return _possibleConstructorReturn(this, (ChemDoodleCanvas.__proto__ || Object.getPrototypeOf(ChemDoodleCanvas)).apply(this, arguments)); } _createClass(ChemDoodleCanvas, [{ key: 'componendDidMount', value: function componendDidMount() { var rotationMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; //Code var tfcanvas = new ChemDoodle.TransformCanvas3D(this.props.id + '_view'); var cif = ChemDoodle.readCIF(this.props.cifData, this.props.x, this.props.y, this.props.z); tfcanvas.specs.set3DRepresentation('Ball and Stick'); tfcanvas.specs.backgroundColor = this.props.color; tfcanvas.specs.projectionPerspective_3D = true; tfcanvas.specs.atoms_displayLabels_3D = this.props.showLabels; tfcanvas.specs.crystals_unitCellLineWidth = 5; tfcanvas.specs.shapes_color = 'black'; tfcanvas.specs.shapes_lineWidth = 1; tfcanvas.specs.fog_mode_3D = 0; tfcanvas.specs.shadow_3D = false; tfcanvas.specs.atoms_useJMOLColors = true; tfcanvas.specs.compass_display = this.props.showCompass; tfcanvas.loadContent([cif.molecule], [cif.unitCell]); this.tfcanvas = tfcanvas; console.log("ENDOF componentDidMount"); console.log(typeof tfcanvas === 'undefined' ? 'undefined' : _typeof(tfcanvas)); console.log(tfcanvas); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() {} }, { key: 'render', value: function render() { return React.createElement( 'div', null, React.createElement( 'script', null, this.tfcanvas ) ); } }]); return ChemDoodleCanvas; }(React.Component); ChemDoodleCanvas.defaultProps = { height: typeof window === 'undefined' ? 0. : Math.max(Math.min(window.innerWidth * 0.5, 600), 300), width: typeof window === 'undefined' ? 0. : Math.max(Math.min(window.innerWidth * 0.5, 600), 300), color: '#fff', cifData: '', showDownload: true, showCompass: true, showLabels: true, x: 2, y: 2, z: 1, borderWidth: 0.1 }; ChemDoodleCanvas.propTypes = { cifData: PropTypes.string.isRequired, id: PropTypes.string.isRequired, height: PropTypes.number, width: PropTypes.number, color: PropTypes.string, showDownload: PropTypes.bool, showCompass: PropTypes.bool, showLabels: PropTypes.bool, x: PropTypes.number, y: PropTypes.number, z: PropTypes.number, borderWidth: PropTypes.number, classes: PropTypes.object }; module.exports = { ChemDoodleCanvas: ChemDoodleCanvas };