mc-react-structure-visualizer 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,10 +16,16 @@
16
16
  }
17
17
 
18
18
  .supercell-input {
19
- width: 40px;
19
+ width: 45px;
20
20
  height: 25px;
21
21
  }
22
22
 
23
+ /* Always show the small arrows (needed for Chrome) */
24
+ .supercell-input::-webkit-inner-spin-button,
25
+ .supercell-input::-webkit-outer-spin-button {
26
+ opacity: 1;
27
+ }
28
+
23
29
  .control-box-row {
24
30
  margin: 5px 5px;
25
31
  line-height: inherit;
@@ -54,6 +54,7 @@ var ControlBox = /*#__PURE__*/function (_React$Component) {
54
54
  key: index,
55
55
  className: "supercell-input",
56
56
  type: "number",
57
+ min: "1",
57
58
  value: _this2.props.viewerParams.supercell[index],
58
59
  onChange: function onChange(e) {
59
60
  return _this2.handleSupercellChange(index, e.target.value);
@@ -48,6 +48,13 @@ var Visualizer3dmol = /*#__PURE__*/function (_React$Component) {
48
48
  this.viewer = $3Dmol.createViewer(this.divId, config);
49
49
  this.updateView();
50
50
  }
51
+ }, {
52
+ key: "componentDidUpdate",
53
+ value: function componentDidUpdate(prevProps) {
54
+ if (prevProps.viewerParams != this.props.viewerParams || prevProps.cifText != this.props.cifText) {
55
+ this.updateView();
56
+ }
57
+ }
51
58
  }, {
52
59
  key: "updateView",
53
60
  value: function updateView() {
@@ -73,10 +80,6 @@ var Visualizer3dmol = /*#__PURE__*/function (_React$Component) {
73
80
  var sc = this.props.viewerParams.supercell;
74
81
  this.viewer.replicateUnitCell(sc[0], sc[1], sc[2], this.model);
75
82
  this.model.assignBonds();
76
-
77
- // console.log(this.viewer.getView());
78
- // this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
79
-
80
83
  this.viewer.zoomTo();
81
84
  this.viewer.render();
82
85
  }
@@ -100,9 +103,6 @@ var Visualizer3dmol = /*#__PURE__*/function (_React$Component) {
100
103
  }, {
101
104
  key: "render",
102
105
  value: function render() {
103
- if (this.viewer && this.model) {
104
- this.updateView();
105
- }
106
106
  return /*#__PURE__*/_react.default.createElement("div", {
107
107
  id: this.divId,
108
108
  className: "gldiv"
@@ -0,0 +1,33 @@
1
+ .structure-window-outer {
2
+ position: relative;
3
+ }
4
+
5
+ .structure-window {
6
+ position: relative;
7
+ z-index: 2;
8
+ height: 370px;
9
+ width: 450px;
10
+ background: #f5fffa;
11
+ text-align: center;
12
+ border: 1px solid #999;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ border-radius: 5px;
17
+ }
18
+
19
+ .disable-mouse {
20
+ pointer-events: none;
21
+ }
22
+
23
+ .mouse-disabled-note {
24
+ background-color: #fafafa;
25
+ border: 1px solid black;
26
+ color: #353434;
27
+ padding: 5px;
28
+ border-radius: 5px;
29
+ position: absolute;
30
+ top: 15px;
31
+ left: 170px;
32
+ z-index: 3;
33
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _Visualizer3dmol = _interopRequireDefault(require("./3dmol/Visualizer3dmol"));
10
+ require("./index.css");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+ 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); } }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ 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); }
17
+ 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); }
18
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
19
+ 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); }; }
20
+ 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); }
21
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
22
+ 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; } }
23
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
+ var StructureWindow = /*#__PURE__*/function (_React$Component) {
25
+ _inherits(StructureWindow, _React$Component);
26
+ var _super = _createSuper(StructureWindow);
27
+ function StructureWindow(props) {
28
+ _classCallCheck(this, StructureWindow);
29
+ return _super.call(this, props);
30
+ }
31
+ _createClass(StructureWindow, [{
32
+ key: "render",
33
+ value: function render() {
34
+ var _this = this;
35
+ var swClassName = "structure-window";
36
+ if (!this.props.mouseEnabled) swClassName += " disable-mouse";
37
+ return /*#__PURE__*/_react.default.createElement("div", {
38
+ className: "structure-window-outer",
39
+ onClick: function onClick() {
40
+ return _this.props.setMouseEnabled();
41
+ }
42
+ }, /*#__PURE__*/_react.default.createElement("div", {
43
+ className: swClassName
44
+ }, /*#__PURE__*/_react.default.createElement(_Visualizer3dmol.default, {
45
+ ref: this.props.visualizerRef,
46
+ viewerParams: this.props.viewerParams,
47
+ cifText: this.props.cifText
48
+ })), !this.props.mouseEnabled && /*#__PURE__*/_react.default.createElement("div", {
49
+ className: "mouse-disabled-note"
50
+ }, "Click to interact!"));
51
+ }
52
+ }]);
53
+ return StructureWindow;
54
+ }(_react.default.Component);
55
+ var _default = StructureWindow;
56
+ exports.default = _default;
package/dist/index.css CHANGED
@@ -1,13 +1,3 @@
1
- .structure-window {
2
- position: relative;
3
- z-index: 2;
4
- height: 370px;
1
+ .structure-visualizer {
5
2
  width: 450px;
6
- background: #f5fffa;
7
- text-align: center;
8
- border: 1px solid #999;
9
- display: flex;
10
- justify-content: center;
11
- align-items: center;
12
- border-radius: 5px;
13
3
  }
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _ControlBox = _interopRequireDefault(require("./ControlBox"));
10
- var _Visualizer3dmol = _interopRequireDefault(require("./3dmol/Visualizer3dmol"));
10
+ var _StructureWindow = _interopRequireDefault(require("./StructureWindow"));
11
11
  require("./index.css");
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -35,21 +35,52 @@ var StructureVisualizer = /*#__PURE__*/function (_React$Component) {
35
35
  _this.state = {
36
36
  viewerParams: {
37
37
  supercell: [2, 2, 2],
38
- orientation: "x",
39
38
  bonds: true,
40
39
  atomLabels: false,
41
40
  packedCell: false,
42
41
  vdwRadius: false
43
- }
42
+ },
43
+ mouseEnabled: false
44
44
  };
45
45
 
46
46
  // use Ref to send events to the visualizer backend
47
47
  _this.visualizerRef = /*#__PURE__*/_react.default.createRef();
48
+
49
+ // Ref to detect click outside
50
+ _this.wrapperRef = /*#__PURE__*/_react.default.createRef();
51
+ _this.handleClickOutside = _this.handleClickOutside.bind(_assertThisInitialized(_this));
48
52
  _this.handleViewerParamChange = _this.handleViewerParamChange.bind(_assertThisInitialized(_this));
49
53
  _this.handleViewerEvent = _this.handleViewerEvent.bind(_assertThisInitialized(_this));
54
+ _this.setMouseEnabled = _this.setMouseEnabled.bind(_assertThisInitialized(_this));
50
55
  return _this;
51
56
  }
52
57
  _createClass(StructureVisualizer, [{
58
+ key: "componentDidMount",
59
+ value: function componentDidMount() {
60
+ document.addEventListener("mousedown", this.handleClickOutside);
61
+ }
62
+ }, {
63
+ key: "componentWillUnmount",
64
+ value: function componentWillUnmount() {
65
+ document.removeEventListener("mousedown", this.handleClickOutside);
66
+ }
67
+ }, {
68
+ key: "handleClickOutside",
69
+ value: function handleClickOutside(event) {
70
+ if (this.wrapperRef && !this.wrapperRef.current.contains(event.target)) {
71
+ this.setState({
72
+ mouseEnabled: false
73
+ });
74
+ }
75
+ }
76
+ }, {
77
+ key: "setMouseEnabled",
78
+ value: function setMouseEnabled() {
79
+ this.setState({
80
+ mouseEnabled: true
81
+ });
82
+ }
83
+ }, {
53
84
  key: "handleViewerParamChange",
54
85
  value: function handleViewerParamChange(param, value) {
55
86
  this.setState({
@@ -64,16 +95,16 @@ var StructureVisualizer = /*#__PURE__*/function (_React$Component) {
64
95
  }, {
65
96
  key: "render",
66
97
  value: function render() {
67
- // console.log("CIF", this.props.cifText);
68
98
  return /*#__PURE__*/_react.default.createElement("div", {
99
+ ref: this.wrapperRef,
69
100
  className: "structure-visualizer"
70
- }, /*#__PURE__*/_react.default.createElement("div", {
71
- className: "structure-window"
72
- }, /*#__PURE__*/_react.default.createElement(_Visualizer3dmol.default, {
73
- ref: this.visualizerRef,
101
+ }, /*#__PURE__*/_react.default.createElement(_StructureWindow.default, {
102
+ visualizerRef: this.visualizerRef,
74
103
  viewerParams: this.state.viewerParams,
75
- cifText: this.props.cifText
76
- })), /*#__PURE__*/_react.default.createElement(_ControlBox.default, {
104
+ cifText: this.props.cifText,
105
+ mouseEnabled: this.state.mouseEnabled,
106
+ setMouseEnabled: this.setMouseEnabled
107
+ }), /*#__PURE__*/_react.default.createElement(_ControlBox.default, {
77
108
  viewerParams: this.state.viewerParams,
78
109
  onViewerParamChange: this.handleViewerParamChange,
79
110
  onViewerEvent: this.handleViewerEvent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mc-react-structure-visualizer",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "author": "Kristjan Eimre <kristjan.eimre@epfl.ch>",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/App.js CHANGED
@@ -17,8 +17,6 @@ async function fetchCif() {
17
17
  );
18
18
  const jsonAiiDACif = await responseAiiDACif.json();
19
19
 
20
- console.log(jsonAiiDACif);
21
-
22
20
  return jsonAiiDACif.data.download.data;
23
21
  }
24
22
 
@@ -16,10 +16,16 @@
16
16
  }
17
17
 
18
18
  .supercell-input {
19
- width: 40px;
19
+ width: 45px;
20
20
  height: 25px;
21
21
  }
22
22
 
23
+ /* Always show the small arrows (needed for Chrome) */
24
+ .supercell-input::-webkit-inner-spin-button,
25
+ .supercell-input::-webkit-outer-spin-button {
26
+ opacity: 1;
27
+ }
28
+
23
29
  .control-box-row {
24
30
  margin: 5px 5px;
25
31
  line-height: inherit;
@@ -31,6 +31,7 @@ class ControlBox extends React.Component {
31
31
  key={index}
32
32
  className="supercell-input"
33
33
  type="number"
34
+ min="1"
34
35
  value={this.props.viewerParams.supercell[index]}
35
36
  onChange={(e) =>
36
37
  this.handleSupercellChange(index, e.target.value)
@@ -23,6 +23,15 @@ class Visualizer3dmol extends React.Component {
23
23
  this.updateView();
24
24
  }
25
25
 
26
+ componentDidUpdate(prevProps) {
27
+ if (
28
+ prevProps.viewerParams != this.props.viewerParams ||
29
+ prevProps.cifText != this.props.cifText
30
+ ) {
31
+ this.updateView();
32
+ }
33
+ }
34
+
26
35
  updateView() {
27
36
  this.viewer.removeAllModels();
28
37
  this.model = this.viewer.addModel(this.props.cifText, "cif");
@@ -44,9 +53,6 @@ class Visualizer3dmol extends React.Component {
44
53
  this.viewer.replicateUnitCell(sc[0], sc[1], sc[2], this.model);
45
54
  this.model.assignBonds();
46
55
 
47
- // console.log(this.viewer.getView());
48
- // this.viewer.setView([0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5]);
49
-
50
56
  this.viewer.zoomTo();
51
57
  this.viewer.render();
52
58
  }
@@ -68,9 +74,6 @@ class Visualizer3dmol extends React.Component {
68
74
  }
69
75
 
70
76
  render() {
71
- if (this.viewer && this.model) {
72
- this.updateView();
73
- }
74
77
  return (
75
78
  <div id={this.divId} className="gldiv">
76
79
  No data!
@@ -0,0 +1,33 @@
1
+ .structure-window-outer {
2
+ position: relative;
3
+ }
4
+
5
+ .structure-window {
6
+ position: relative;
7
+ z-index: 2;
8
+ height: 370px;
9
+ width: 450px;
10
+ background: #f5fffa;
11
+ text-align: center;
12
+ border: 1px solid #999;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ border-radius: 5px;
17
+ }
18
+
19
+ .disable-mouse {
20
+ pointer-events: none;
21
+ }
22
+
23
+ .mouse-disabled-note {
24
+ background-color: #fafafa;
25
+ border: 1px solid black;
26
+ color: #353434;
27
+ padding: 5px;
28
+ border-radius: 5px;
29
+ position: absolute;
30
+ top: 15px;
31
+ left: 170px;
32
+ z-index: 3;
33
+ }
@@ -0,0 +1,35 @@
1
+ import React from "react";
2
+
3
+ import Visualizer3dmol from "./3dmol/Visualizer3dmol";
4
+
5
+ import "./index.css";
6
+
7
+ class StructureWindow extends React.Component {
8
+ constructor(props) {
9
+ super(props);
10
+ }
11
+
12
+ render() {
13
+ let swClassName = "structure-window";
14
+ if (!this.props.mouseEnabled) swClassName += " disable-mouse";
15
+ return (
16
+ <div
17
+ className="structure-window-outer"
18
+ onClick={() => this.props.setMouseEnabled()}
19
+ >
20
+ <div className={swClassName}>
21
+ <Visualizer3dmol
22
+ ref={this.props.visualizerRef}
23
+ viewerParams={this.props.viewerParams}
24
+ cifText={this.props.cifText}
25
+ />
26
+ </div>
27
+ {!this.props.mouseEnabled && (
28
+ <div className="mouse-disabled-note">Click to interact!</div>
29
+ )}
30
+ </div>
31
+ );
32
+ }
33
+ }
34
+
35
+ export default StructureWindow;
@@ -1,13 +1,3 @@
1
- .structure-window {
2
- position: relative;
3
- z-index: 2;
4
- height: 370px;
1
+ .structure-visualizer {
5
2
  width: 450px;
6
- background: #f5fffa;
7
- text-align: center;
8
- border: 1px solid #999;
9
- display: flex;
10
- justify-content: center;
11
- align-items: center;
12
- border-radius: 5px;
13
3
  }
@@ -2,7 +2,7 @@ import React from "react";
2
2
 
3
3
  import ControlBox from "./ControlBox";
4
4
 
5
- import Visualizer3dmol from "./3dmol/Visualizer3dmol";
5
+ import StructureWindow from "./StructureWindow";
6
6
 
7
7
  import "./index.css";
8
8
 
@@ -13,19 +13,42 @@ class StructureVisualizer extends React.Component {
13
13
  this.state = {
14
14
  viewerParams: {
15
15
  supercell: [2, 2, 2],
16
- orientation: "x",
17
16
  bonds: true,
18
17
  atomLabels: false,
19
18
  packedCell: false,
20
19
  vdwRadius: false,
21
20
  },
21
+ mouseEnabled: false,
22
22
  };
23
23
 
24
24
  // use Ref to send events to the visualizer backend
25
25
  this.visualizerRef = React.createRef();
26
26
 
27
+ // Ref to detect click outside
28
+ this.wrapperRef = React.createRef();
29
+ this.handleClickOutside = this.handleClickOutside.bind(this);
30
+
27
31
  this.handleViewerParamChange = this.handleViewerParamChange.bind(this);
28
32
  this.handleViewerEvent = this.handleViewerEvent.bind(this);
33
+ this.setMouseEnabled = this.setMouseEnabled.bind(this);
34
+ }
35
+
36
+ componentDidMount() {
37
+ document.addEventListener("mousedown", this.handleClickOutside);
38
+ }
39
+
40
+ componentWillUnmount() {
41
+ document.removeEventListener("mousedown", this.handleClickOutside);
42
+ }
43
+
44
+ handleClickOutside(event) {
45
+ if (this.wrapperRef && !this.wrapperRef.current.contains(event.target)) {
46
+ this.setState({ mouseEnabled: false });
47
+ }
48
+ }
49
+
50
+ setMouseEnabled() {
51
+ this.setState({ mouseEnabled: true });
29
52
  }
30
53
 
31
54
  handleViewerParamChange(param, value) {
@@ -42,16 +65,15 @@ class StructureVisualizer extends React.Component {
42
65
  }
43
66
 
44
67
  render() {
45
- // console.log("CIF", this.props.cifText);
46
68
  return (
47
- <div className="structure-visualizer">
48
- <div className="structure-window">
49
- <Visualizer3dmol
50
- ref={this.visualizerRef}
51
- viewerParams={this.state.viewerParams}
52
- cifText={this.props.cifText}
53
- />
54
- </div>
69
+ <div ref={this.wrapperRef} className="structure-visualizer">
70
+ <StructureWindow
71
+ visualizerRef={this.visualizerRef}
72
+ viewerParams={this.state.viewerParams}
73
+ cifText={this.props.cifText}
74
+ mouseEnabled={this.state.mouseEnabled}
75
+ setMouseEnabled={this.setMouseEnabled}
76
+ />
55
77
  <ControlBox
56
78
  viewerParams={this.state.viewerParams}
57
79
  onViewerParamChange={this.handleViewerParamChange}