RcsbFv3DComponent.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import * as React from "react";
  2. import * as classes from '../styles/RcsbFvStyle.module.scss';
  3. import {MolstarPlugin} from '../RcsbFvStructure/StructurePlugins/MolstarPlugin';
  4. import {SaguaroPluginInterface} from '../RcsbFvStructure/StructurePlugins/SaguaroPluginInterface';
  5. import '../styles/RcsbFvMolstarStyle.module.scss';
  6. import {RcsbFvSequence, SequenceViewInterface} from "../RcsbFvSequence/RcsbFvSequence";
  7. import {RcsbFvStructure, StructureViewInterface} from "../RcsbFvStructure/RcsbFvStructure";
  8. import {
  9. EventType,
  10. RcsbFvContextManager,
  11. RcsbFvContextManagerInterface,
  12. UpdateConfigInterface
  13. } from "../RcsbFvContextManager/RcsbFvContextManager";
  14. import {Subscription} from "rxjs";
  15. import {PluginContext} from "molstar/lib/mol-plugin/context";
  16. import {RcsbFvSelection} from "../RcsbFvSelection/RcsbFvSelection";
  17. import {CSSProperties} from "react";
  18. export interface RcsbFv3DComponentInterface {
  19. structurePanelConfig:StructureViewInterface;
  20. sequencePanelConfig: SequenceViewInterface;
  21. id: string;
  22. ctxManager: RcsbFvContextManager;
  23. cssConfig?:{
  24. rootPanel?: CSSProperties,
  25. structurePanel?: CSSProperties,
  26. sequencePanel?: CSSProperties
  27. }
  28. unmount:(flag:boolean)=>void;
  29. fullScreen: boolean;
  30. }
  31. export class RcsbFv3DComponent extends React.Component <RcsbFv3DComponentInterface, {structurePanelConfig:StructureViewInterface, sequencePanelConfig:SequenceViewInterface}> {
  32. private readonly pfvScreenFraction = 0.55;
  33. private readonly plugin: SaguaroPluginInterface;
  34. private readonly selection: RcsbFvSelection = new RcsbFvSelection();
  35. private subscription: Subscription;
  36. readonly state: {structurePanelConfig:StructureViewInterface, sequencePanelConfig:SequenceViewInterface} = {
  37. structurePanelConfig: this.props.structurePanelConfig,
  38. sequencePanelConfig: this.props.sequencePanelConfig
  39. }
  40. constructor(props: RcsbFv3DComponentInterface) {
  41. super(props);
  42. this.plugin = new MolstarPlugin(this.selection);
  43. }
  44. render(): JSX.Element {
  45. return (
  46. <div style={RcsbFv3DComponent.mainDivCssConfig(this.props.cssConfig?.rootPanel)} className={ this.props.fullScreen ? classes.fullScreen+" "+classes.rcsbFvMain : classes.rcsbFvMain} >
  47. <div>
  48. <div style={this.structureCssConfig(this.props.cssConfig?.structurePanel)} className={classes.rcsbFvCell}>
  49. <RcsbFvStructure
  50. {...this.state.structurePanelConfig}
  51. componentId={this.props.id}
  52. plugin={this.plugin}
  53. selection={this.selection}
  54. />
  55. </div>
  56. <div style={this.sequenceCssConfig(this.props.cssConfig?.sequencePanel)} className={classes.rcsbFvCell} >
  57. <RcsbFvSequence
  58. type={this.state.sequencePanelConfig.type}
  59. config={this.state.sequencePanelConfig.config}
  60. componentId={this.props.id}
  61. plugin={this.plugin}
  62. selection={this.selection}
  63. title={this.state.sequencePanelConfig.title}
  64. subtitle={this.state.sequencePanelConfig.subtitle}
  65. unmount={this.props.unmount}
  66. />
  67. </div>
  68. </div>
  69. </div>
  70. );
  71. }
  72. componentDidMount() {
  73. this.subscription = this.subscribe();
  74. }
  75. componentWillUnmount() {
  76. this.unsubscribe();
  77. }
  78. private structureCssConfig(css: CSSProperties | undefined): CSSProperties{
  79. return {...{width:Math.round((1-this.pfvScreenFraction)*100).toString()+"%", height:"100%", zIndex:1}, ...css };
  80. }
  81. private sequenceCssConfig(css: CSSProperties | undefined): CSSProperties{
  82. return {...{width:Math.round((this.pfvScreenFraction)*100).toString()+"%", height:"100%", overflow:"auto", paddingBottom:5}, ...css };
  83. }
  84. private static mainDivCssConfig(css: CSSProperties | undefined): CSSProperties{
  85. return {...{
  86. }, ...css}
  87. }
  88. private subscribe(): Subscription{
  89. return this.props.ctxManager.subscribe((obj:RcsbFvContextManagerInterface)=>{
  90. if(obj.eventType == EventType.UPDATE_CONFIG){
  91. this.updateConfig(obj.eventData as UpdateConfigInterface)
  92. }else if(obj.eventType == EventType.PLUGIN_CALL){
  93. this.plugin.pluginCall(obj.eventData as ((f:PluginContext)=>void));
  94. }
  95. });
  96. }
  97. /**Unsubscribe className to rxjs events. Useful if many panels are created an destroyed.*/
  98. private unsubscribe(): void{
  99. this.subscription.unsubscribe();
  100. }
  101. private updateConfig(config:UpdateConfigInterface){
  102. const structureConfig: StructureViewInterface | undefined = config.structurePanelConfig;
  103. const sequenceConfig: SequenceViewInterface | undefined = config.sequencePanelConfig;
  104. if(structureConfig != null && sequenceConfig != null){
  105. this.setState({structurePanelConfig:structureConfig, sequencePanelConfig:sequenceConfig});
  106. }else if(structureConfig != null){
  107. this.setState({structurePanelConfig:structureConfig});
  108. }else if(sequenceConfig != null){
  109. this.setState({sequencePanelConfig: sequenceConfig});
  110. }
  111. }
  112. }