UNPKG

@metacell/geppetto-meta-ui

Version:

React components from geppetto-meta to create neuroscience applications and visualize data.

223 lines (221 loc) 10.7 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } import React, { Component } from 'react'; import OpenSeaDragon from 'openseadragon'; import { PropTypes } from 'prop-types'; import * as util from '../utilities'; import { faHome, faSearchPlus, faSearchMinus } from '@fortawesome/free-solid-svg-icons'; import CustomToolbar from '../common/CustomToolbar'; var styles = { bigImageViewerContainer: { display: 'flex', padding: "2rem", alignItems: 'stretch', flex: 1 }, bigImageViewerContent: { display: 'flex', alignItems: 'stretch', paddingLeft: "0.5rem", flex: 1 } }; var ZOOM_OUT_TOOLTIP = 'Zoom Out'; var ZOOM_IN_TOOLTIP = 'Zoom In'; var CENTER_IMAGE_TOOLTIP = 'Center Image'; var BigImageViewer = /*#__PURE__*/function (_Component) { function BigImageViewer(props) { var _this; _classCallCheck(this, BigImageViewer); _this = _callSuper(this, BigImageViewer, [props]); var settings = { id: _this.props.id + '_component', zoomInButton: 'zoom-in', zoomOutButton: 'zoom-out', homeButton: 'home', fullPageButton: 'full-page' }; _this.state = { settings: util.extend(settings, _this.props.settings), file: _this.extractFilePath(_this.props.data) }; // this.download = this.download.bind(this); _this.goHome = _this.goHome.bind(_this); _this.zoomIn = _this.zoomIn.bind(_this); _this.zoomOut = _this.zoomOut.bind(_this); _this.fullPage = _this.fullPage.bind(_this); return _this; } _inherits(BigImageViewer, _Component); return _createClass(BigImageViewer, [{ key: "componentDidUpdate", value: function componentDidUpdate(prevProps, prevState, snapshot) { this.loadViewer(); } }, { key: "componentDidMount", value: function componentDidMount() { this.loadViewer(); } }, { key: "extractFilePath", value: function extractFilePath(data) { var file; if (data !== undefined) { if (data.getMetaType === undefined) { file = data; } else if (data.getMetaType() === 'Instance' && data.getVariable().getInitialValues()[0].value.format === 'DZI') { file = data.getVariable().getInitialValues()[0].value.data; } } return file; } }, { key: "loadViewer", value: function loadViewer() { if (this.state.file !== undefined) { if (this.viewer !== undefined) { this.viewer.destroy(); } this.state.settings.tileSources = this.state.file; this.viewer = OpenSeaDragon(this.state.settings); } } // These four methods are not exposed by OpenSeaDragon }, { key: "goHome", value: function goHome() { this.viewer.viewport.goHome(); } }, { key: "zoomIn", value: function zoomIn() { this.viewer.viewport.zoomBy(this.viewer.zoomPerClick / 1.0); this.viewer.viewport.applyConstraints(); } }, { key: "zoomOut", value: function zoomOut() { this.viewer.viewport.zoomBy(1.0 / this.viewer.zoomPerClick); this.viewer.viewport.applyConstraints(); } }, { key: "fullPage", value: function fullPage() { this.viewer.setFullScreen(true); this.viewer.fullPageButton.element.focus(); this.viewer.viewport.applyConstraints(); } }, { key: "getCustomButtons", value: function getCustomButtons() { var customButtons = []; customButtons.push({ icon: faSearchMinus, id: 'zoom-out', tooltip: ZOOM_OUT_TOOLTIP, action: this.zoomOut }); customButtons.push({ icon: faSearchPlus, id: 'zoom-in', tooltip: ZOOM_IN_TOOLTIP, action: this.zoomIn }); customButtons.push({ icon: faHome, id: 'home', tooltip: CENTER_IMAGE_TOOLTIP, action: this.goHome }); return customButtons; } }, { key: "render", value: function render() { var _this$props$styles$bi, _this$props; var toolbarOptions = this.props.toolbarOptions; var customButtons = this.getCustomButtons(); var toolbar = toolbarOptions && toolbarOptions.instance ? /*#__PURE__*/React.createElement(toolbarOptions.instance, _extends({ buttons: customButtons }, toolbarOptions.props)) : /*#__PURE__*/React.createElement(CustomToolbar, { buttons: customButtons, containerStyles: toolbarOptions === null || toolbarOptions === void 0 ? void 0 : toolbarOptions.containerStyles, toolBarClassName: toolbarOptions === null || toolbarOptions === void 0 ? void 0 : toolbarOptions.toolBarClassName, innerDivStyles: toolbarOptions === null || toolbarOptions === void 0 ? void 0 : toolbarOptions.innerDivStyles, buttonStyles: toolbarOptions === null || toolbarOptions === void 0 ? void 0 : toolbarOptions.buttonStyles }); return /*#__PURE__*/React.createElement("div", { className: "big-image-viewer-wrapper", style: _objectSpread(_objectSpread({}, styles.bigImageViewerContainer), (_this$props$styles$bi = (_this$props = this.props) === null || _this$props === void 0 || (_this$props = _this$props.styles) === null || _this$props === void 0 ? void 0 : _this$props.bigImageViewerContainer) !== null && _this$props$styles$bi !== void 0 ? _this$props$styles$bi : {}) }, toolbar, /*#__PURE__*/React.createElement("div", { id: this.props.id + '_component', className: "big-image-viewer", style: styles.bigImageViewerContent })); } }]); }(Component); BigImageViewer.defaultProps = { settings: [], toolbarOptions: null }; BigImageViewer.propTypes = { /** * Component identifier */ id: PropTypes.string.isRequired, /** * Path/URL to image file (f.e. "/path/to/my/image.dzi") */ data: PropTypes.string.isRequired, /** * All required and optional settings for instantiating a new instance of an OpenSeadragon image viewer */ settings: PropTypes.array, /** * Options to customize the toolbar */ toolbarOptions: PropTypes.shape({ /** * Reference to toolbar component */ instance: PropTypes.elementType, /** * Custom toolbar props */ props: PropTypes.shape({}), /** * Styles to be applied to the toolbar container */ containerStyles: PropTypes.shape({}), /** * Styles to be applied to the toolbar */ toolBarClassName: PropTypes.shape({}), /** * Styles to be applied to the inner div */ innerDivStyles: PropTypes.shape({}), /** * Styles to be applied to the buttons */ buttonStyles: PropTypes.shape({}) }) }; export default BigImageViewer;