help.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import * as React from 'react';
  7. import { Binding } from '../../../mol-util/binding';
  8. import { PluginUIComponent } from '../base';
  9. import { StateTransformer, StateSelection } from '../../../mol-state';
  10. import { SelectLoci } from '../../behavior/dynamic/representation';
  11. import { StructureRepresentationInteraction } from '../../behavior/dynamic/selection/structure-representation-interaction';
  12. import { Icon } from '../controls/common';
  13. function getBindingsList(bindings: { [k: string]: Binding }) {
  14. return Object.keys(bindings).map(k => [k, bindings[k]] as [string, Binding])
  15. }
  16. class BindingsHelp extends React.Component<{ bindings: { [k: string]: Binding } }, { isExpanded: boolean }> {
  17. getBindingComponents() {
  18. const bindingsList = getBindingsList(this.props.bindings)
  19. return <ul style={{ paddingLeft: '20px' }}>
  20. {bindingsList.map(value => {
  21. const [name, binding] = value
  22. return !Binding.isEmpty(binding)
  23. ? <li key={name}>{Binding.format(binding, name)}</li>
  24. : null
  25. })}
  26. </ul>
  27. }
  28. render() {
  29. return <HelpText>{this.getBindingComponents()}</HelpText>
  30. }
  31. }
  32. class HelpText extends React.PureComponent {
  33. render() {
  34. return <div className='msp-control-row msp-help-text'>
  35. <div>{this.props.children}</div>
  36. </div>
  37. }
  38. }
  39. class HelpGroup extends React.Component<{ header: string, initiallyExpanded?: boolean }, { isExpanded: boolean }> {
  40. state = {
  41. header: this.props.header,
  42. isExpanded: !!this.props.initiallyExpanded
  43. }
  44. toggleExpanded = () => this.setState({ isExpanded: !this.state.isExpanded });
  45. render() {
  46. return <div className='msp-control-group-wrapper'>
  47. <div className='msp-control-group-header'>
  48. <button className='msp-btn msp-btn-block' onClick={this.toggleExpanded}>
  49. <span className={`msp-icon msp-icon-${this.state.isExpanded ? 'collapse' : 'expand'}`} />
  50. {this.props.header}
  51. </button>
  52. </div>
  53. {this.state.isExpanded && <div className='msp-control-offset' style={{ display: this.state.isExpanded ? 'block' : 'none' }}>
  54. {this.props.children}
  55. </div>}
  56. </div>
  57. }
  58. }
  59. function HelpSection(props: { header: string }) {
  60. return <div className='msp-simple-help-section'>{props.header}</div>;
  61. }
  62. export class HelpContent extends PluginUIComponent {
  63. componentDidMount() {
  64. this.subscribe(this.plugin.events.canvas3d.settingsUpdated, () => this.forceUpdate());
  65. }
  66. private getMouseBindingComponents() {
  67. const interactionBindings: { [k: string]: Binding } = {}
  68. this.plugin.spec.behaviors.forEach(b => {
  69. const { bindings } = b.defaultParams
  70. if (bindings) Object.assign(interactionBindings, bindings)
  71. })
  72. return <>
  73. {this.plugin.canvas3d && <HelpGroup key='trackball' header='Moving in 3D'>
  74. <BindingsHelp bindings={this.plugin.canvas3d.props.trackball.bindings} />
  75. </HelpGroup>}
  76. <HelpGroup key='interactions' header='Select, Highlight, Focus'>
  77. <BindingsHelp bindings={interactionBindings} />
  78. </HelpGroup>
  79. </>
  80. }
  81. private formatTriggers(binding: Binding) {
  82. return binding.triggers.map(t => Binding.Trigger.format(t)).join(' or ')
  83. }
  84. private getTriggerFor(transformer: StateTransformer, name: string) {
  85. const state = this.plugin.state.behaviorState
  86. const selections = state.select(StateSelection.Generators.ofTransformer(transformer))
  87. const params = selections.length === 1 ? selections[0].params : undefined
  88. const bindings = params ? params.values.bindings : {}
  89. const binding: Binding = name in bindings ? bindings[name] : Binding.Empty
  90. return this.formatTriggers(binding)
  91. }
  92. render() {
  93. const selectToggleTriggers = this.getTriggerFor(SelectLoci, 'clickSelectToggle')
  94. const structureInteractionTriggers = this.getTriggerFor(StructureRepresentationInteraction, 'clickInteractionAroundOnly')
  95. // const volumeAroundTriggers = this.getTriggerFor(StructureRepresentationInteraction, 'clickInteractionAroundOnly') // TODO get from correct behavior transform
  96. // TODO: interactive help, for example for density
  97. return <div>
  98. <HelpSection header='Interface Controls' />
  99. <HelpGroup header='Inline Help'>
  100. <HelpText>Many user interface elements show a little questionmark icon when hovered over. Clicking the icon toggles the display of an inline help text.</HelpText>
  101. <HelpText>Tooltips may provide additional information on a user interface element and are shown when hovering over it with the mouse.</HelpText>
  102. </HelpGroup>
  103. <HelpGroup header='Selections'>
  104. <HelpText>
  105. The viewer allows changing colors and representations for selections of atoms, residues or chains. Selections can be created by
  106. <ul style={{ paddingLeft: '20px' }}>
  107. <li>picking elements on the 3D canvas or the sequence view using the mouse, e.g. toggle selection using {selectToggleTriggers} (for more see help section on <i>Mouse Controls</i>)</li>
  108. <li>using the <i>Add</i>, <i>Remove</i> and <i>Only</i> dropdown buttons in the <i>Manage Selection</i> panel which allow modifing the current selection by predefined sets</li>
  109. </ul>
  110. </HelpText>
  111. </HelpGroup>
  112. <HelpGroup header='Coloring'>
  113. <HelpText>
  114. There are two ways to color structures. Every representation (e.g. cartoon or spacefill) has a color theme which can be changed using the dropdown for each representation in the <i>Structure Settings</i> panel. Additionally any selection atoms, residues or chains can by given a custom color. For that, first select the parts of the structure to be colored (see help section on <i>Selections</i>) and, second, choose a color from the color dropdown botton in the <i>Selection</i> row of the <i>Change Representation</i> panel. The theme color can be seen as a base color that is overpainted by the custom color. Custom colors can be removed for a selection with the 'Clear' option in the color dropdown.
  115. </HelpText>
  116. </HelpGroup>
  117. <HelpGroup header='Representations'>
  118. <HelpText>
  119. Structures can be shown with many different representations (e.g. cartoon or spacefill). The <i>Change Representation</i> panel offers a collection of predefined styles which can be applied using the <i>Preset</i> dropdown button. Additionally any selection atoms, residues or chains can by shown with a custom representation. For that, first select the parts of the structure to be mofified (see help section on <i>Selections</i>) and, second, choose a representation to hide or show from the <i>Show</i> and <i>Hide</i> dropdown bottons in the <i>Selection</i> row of the <i>Change Representation</i> panel. The <i>Everything</i> row applies the action to the whole structure instead of the current selection.
  120. </HelpText>
  121. </HelpGroup>
  122. <HelpGroup header='Surroundings'>
  123. <HelpText>
  124. To show the surroundings of a residue or ligand, click it in the 3D scene or in the sequence widget using {structureInteractionTriggers}.
  125. </HelpText>
  126. </HelpGroup>
  127. {/* <HelpGroup header='Densities'>
  128. <HelpText>
  129. Densities can be shown for both X-ray and cryo-EM structures. By default the density around an element/atom can be shown by clicking using {volumeAroundTriggers}. The <i>Density Controls</i> panel offers a variety of options to adjust the display of density maps. The absence of the <i>Density Controls</i> panel indicates that no density is available for the loaded entry which is the case for e.g. NMR structures or very old X-ray structures.
  130. </HelpText>
  131. </HelpGroup> */}
  132. <HelpSection header='How-to Guides' />
  133. {/* <HelpGroup header='RCSB Molecule of the Month Style'>
  134. <HelpText>
  135. <ol style={{ paddingLeft: '20px' }}>
  136. <li>First, hide everything, then show everything with the spacefill representation using the <i>Representation</i> panel.</li>
  137. <li>Change color theme of the spacefill representation to <i>illustrative</i> using the <i>Structure Settings</i> panel.</li>
  138. <li>Set render style to <i>toon</i> and activate <i>occlusion</i> in the <i>General Settings</i> panel.</li>
  139. </ol>
  140. </HelpText>
  141. </HelpGroup> */}
  142. <HelpGroup header='Create an Image'>
  143. <HelpText>
  144. <p>Use the <Icon name='screenshot' /> icon in the viewport or go to the <i>Create Image</i> panel and click <i>download</i> to get the same image you see on the 3D canvas.</p>
  145. <p>To adjust the size of the image, select <i>Custom</i> from the <i>Size</i> dropdown in the <i>Create Image</i> panel. Adjust the <i>Width</i> and <i>Height</i> using the sliders. To see an image preview with the correct aspect ratio, activate the preview by expanding the <i>Preview</i> panel.</p>
  146. </HelpText>
  147. </HelpGroup>
  148. <HelpSection header='Mouse Controls' />
  149. {this.getMouseBindingComponents()}
  150. </div>
  151. }
  152. }