Skip to content

Commit

Permalink
showAxes prop
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Mar 3, 2022
1 parent 5e16c1e commit 5a3a3f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ If `true`, the full Molstar interface will be used around the core canvas.

If `true` and `useInterface` is `true`, the controls will be shown around the sides of the interface. Only recommended for large sizes.

#### `showAxes`

If `true`, axes will appear in the bottom left corner.

## Changelog

### Release 0.4.0
Expand Down
26 changes: 23 additions & 3 deletions src/Molstar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "molstar/build/viewer/molstar.css";

const Molstar = props => {

const { useInterface, pdbId, url, file, dimensions, className, showControls } = props;
const { useInterface, pdbId, url, file, dimensions, className, showControls, showAxes } = props;
const parentRef = useRef(null);
const canvasRef = useRef(null);
const plugin = useRef(null);
Expand All @@ -29,6 +29,11 @@ const Molstar = props => {
plugin.current.initViewer(canvasRef.current, parentRef.current);
await plugin.current.init();
}
if (!showAxes) {
plugin.current.canvas3d?.setProps({ camera: { helper: { axes: {
name: "off", params: {}
} } } });
}
await loadStructure(pdbId, url, file, plugin.current);
return () => plugin.current = null;
}, [])
Expand All @@ -37,12 +42,24 @@ const Molstar = props => {
await loadStructure(pdbId, url, file, plugin.current);
}, [pdbId, url, file])

useEffect(() => {
if (plugin.current) {
if (!showAxes) {
plugin.current.canvas3d?.setProps({ camera: { helper: { axes: {
name: "off", params: {}
} } } })
} else {
// TODO
}
}
}, [showAxes])

const loadStructure = async (pdbId, url, file, plugin) => {
if (plugin) {
plugin.clear();
if (file) {
const data = await plugin.builders.data.rawData({
data: file.filestring /* string or number[] */,
data: file.filestring
});
const traj = await plugin.builders.structure.parseTrajectory(data, file.type);
await plugin.builders.structure.hierarchy.applyPreset(traj, "default");
Expand Down Expand Up @@ -85,10 +102,13 @@ const Molstar = props => {
};

Molstar.propTypes = {
interface: PropTypes.bool,
useInterface: PropTypes.bool,
pdbId: PropTypes.string,
url: PropTypes.string,
file: PropTypes.object,
dimensions: PropTypes.array,
showControls: PropTypes.bool,
showAxes: PropTypes.bool,
className: PropTypes.string
};

Expand Down

0 comments on commit 5a3a3f9

Please sign in to comment.