react-vtk-js
Version:
React based declarative vtk.js visualization pipeline
2 lines (1 loc) • 3.27 kB
JavaScript
import e from"../node_modules/@babel/runtime/helpers/esm/classCallCheck.js";import r from"../node_modules/@babel/runtime/helpers/esm/createClass.js";import t from"../node_modules/@babel/runtime/helpers/esm/inherits.js";import n from"../node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js";import s from"../node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js";import o,{Component as a}from"react";import i from"prop-types";import{ViewContext as p,RepresentationContext as u,DownstreamContext as l}from"./View.js";import d from"../node_modules/@kitware/vtk.js/vtk.js";import m from"../node_modules/@kitware/vtk.js/Common/Core/Base64.js";function c(e){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var t,o=s(e);if(r){var a=s(this).constructor;t=Reflect.construct(o,arguments,a)}else t=o.apply(this,arguments);return n(this,t)}}var f=function(n){t(i,a);var s=c(i);function i(r){var t;return e(this,i),(t=s.call(this,r)).reader=null,t}return r(i,[{key:"render",value:function(){var e=this;return o.createElement(p.Consumer,null,(function(r){return o.createElement(u.Consumer,null,(function(t){return e.representation=t,o.createElement(l.Consumer,null,(function(t){return e.reader||(e.reader=e.createReader(e.props)),e.downstream||(t.setInputConnection(e.reader.getOutputPort(),e.props.port),e.downstream=t),e.view=r,o.createElement(l.Provider,{value:e.reader},o.createElement("div",{key:e.props.id,id:e.props.id},e.props.children))}))}))}))}},{key:"componentDidMount",value:function(){this.update(this.props)}},{key:"componentDidUpdate",value:function(e,r,t){this.update(this.props,e)}},{key:"componentWillUnmount",value:function(){this.reader.delete(),this.reader=null}},{key:"createReader",value:function(e){var r=e.vtkClass,t=e.options;return d({vtkClass:r,progressCallback:t.progressCallback})}},{key:"update",value:function(e,r){var t=this,n=e.vtkClass,s=e.url,o=e.parseAsText,a=e.parseAsArrayBuffer,i=e.options;!n||r&&n===r.vtkClass||(this.reader=this.createReader(e),this.downstream.setInputConnection(this.reader.getOutputPort(),this.props.port)),!s||r&&s===r.url||this.reader.setUrl(s,i).then((function(){t.reader&&(t.representation&&t.representation.dataAvailable(),t.view&&(t.props.resetCameraOnUpdate&&t.view.resetCamera(),t.props.renderOnUpdate&&t.view.renderView()))})),!o||r&&o===r.parseAsText||(this.reader.parseAsText(o),this.representation&&this.representation.dataAvailable()),!a||r&&a===r.parseAsArrayBuffer||(this.reader.parseAsArrayBuffer(m.toArrayBuffer(a)),this.representation&&this.representation.dataAvailable()),this.view&&(this.props.resetCameraOnUpdate&&this.view.resetCamera(),this.props.renderOnUpdate&&this.view.renderView())}}]),i}();f.defaultProps={port:0,vtkClass:"",renderOnUpdate:!0,resetCameraOnUpdate:!0,options:{binary:!0}},f.propTypes={id:i.string,port:i.number,vtkClass:i.string,url:i.string,parseAsText:i.string,parseAsArrayBuffer:i.string,renderOnUpdate:i.bool,resetCameraOnUpdate:i.bool,options:i.object,children:i.oneOfType([i.arrayOf(i.node),i.node])};export{f as default};