help.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * Copyright (c) 2019-2020 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 '../../mol-plugin/behavior/dynamic/representation';
  11. import { FocusLoci } from '../../mol-plugin/behavior/dynamic/representation';
  12. import { Icon } from '../controls/icons';
  13. function getBindingsList(bindings: { [k: string]: Binding }) {
  14. return Object.keys(bindings).map(k => [k, bindings[k]] as [string, Binding])
  15. }
  16. export class BindingsHelp extends React.PureComponent<{ bindings: { [k: string]: Binding } }> {
  17. getBindingComponents() {
  18. const bindingsList = getBindingsList(this.props.bindings)
  19. return <>
  20. {bindingsList.map(value => {
  21. const [name, binding] = value
  22. return !Binding.isEmpty(binding)
  23. ? <div key={name} style={{ marginBottom: '6px' }}>
  24. <b>{binding.action}</b><br /><span dangerouslySetInnerHTML={{ __html: Binding.format(binding, name) }} />
  25. </div>
  26. : null
  27. })}
  28. </>
  29. }
  30. render() {
  31. return <HelpText>{this.getBindingComponents()}</HelpText>
  32. }
  33. }
  34. class HelpText extends React.PureComponent {
  35. render() {
  36. return <div className='msp-control-row msp-help-text'>
  37. <div>{this.props.children}</div>
  38. </div>
  39. }
  40. }
  41. class HelpGroup extends React.PureComponent<{ header: string, initiallyExpanded?: boolean }, { isExpanded: boolean }> {
  42. state = {
  43. header: this.props.header,
  44. isExpanded: !!this.props.initiallyExpanded
  45. }
  46. toggleExpanded = () => this.setState({ isExpanded: !this.state.isExpanded });
  47. render() {
  48. return <div className='msp-control-group-wrapper'>
  49. <div className='msp-control-group-header'>
  50. <button className='msp-btn msp-btn-block' onClick={this.toggleExpanded}>
  51. <Icon name={this.state.isExpanded ? 'collapse' : 'expand'} />
  52. {this.props.header}
  53. </button>
  54. </div>
  55. {this.state.isExpanded && <div className='msp-control-offset' style={{ display: this.state.isExpanded ? 'block' : 'none' }}>
  56. {this.props.children}
  57. </div>}
  58. </div>
  59. }
  60. }
  61. function HelpSection(props: { header: string }) {
  62. return <div className='msp-simple-help-section'>{props.header}</div>;
  63. }
  64. export class ViewportHelpContent extends PluginUIComponent {
  65. componentDidMount() {
  66. this.subscribe(this.plugin.events.canvas3d.settingsUpdated, () => this.forceUpdate());
  67. }
  68. render() {
  69. const interactionBindings: { [k: string]: Binding } = {}
  70. this.plugin.spec.behaviors.forEach(b => {
  71. const { bindings } = b.defaultParams
  72. if (bindings) Object.assign(interactionBindings, bindings)
  73. })
  74. return <>
  75. {this.plugin.canvas3d && <HelpGroup key='trackball' header='Moving in 3D'>
  76. <BindingsHelp bindings={this.plugin.canvas3d.props.trackball.bindings} />
  77. </HelpGroup>}
  78. <HelpGroup key='interactions' header='Select, Highlight, Focus'>
  79. <BindingsHelp bindings={interactionBindings} />
  80. </HelpGroup>
  81. </>
  82. }
  83. }
  84. export class HelpContent extends PluginUIComponent {
  85. componentDidMount() {
  86. this.subscribe(this.plugin.events.canvas3d.settingsUpdated, () => this.forceUpdate());
  87. }
  88. private formatTriggers(binding: Binding) {
  89. return binding.triggers.map(t => Binding.Trigger.format(t)).join(' or ')
  90. }
  91. private getTriggerFor(transformer: StateTransformer, name: string) {
  92. const state = this.plugin.state.behaviors
  93. const selections = state.select(StateSelection.Generators.ofTransformer(transformer))
  94. const params = selections.length === 1 ? selections[0].params : undefined
  95. const bindings = params ? params.values.bindings : {}
  96. const binding: Binding = name in bindings ? bindings[name] : Binding.Empty
  97. return this.formatTriggers(binding)
  98. }
  99. render() {
  100. const selectToggleTriggers = this.getTriggerFor(SelectLoci, 'clickSelectToggle')
  101. const focusTriggers = this.getTriggerFor(FocusLoci, 'clickFocus')
  102. // TODO: interactive help, for example for density
  103. return <div>
  104. <HelpSection header='Interface Controls' />
  105. <HelpGroup header='Inline Help'>
  106. <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>
  107. <HelpText>Tooltips may provide additional information on a user interface element and are shown when hovering over it with the mouse.</HelpText>
  108. </HelpGroup>
  109. <HelpGroup header='Selections'>
  110. <HelpText>
  111. The viewer allows changing colors and representations for selections of atoms, residues or chains. Selections can be created by
  112. <ul style={{ paddingLeft: '20px' }}>
  113. <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>
  114. <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>
  115. </ul>
  116. </HelpText>
  117. </HelpGroup>
  118. <HelpGroup header='Coloring'>
  119. <HelpText>
  120. 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.
  121. </HelpText>
  122. </HelpGroup>
  123. <HelpGroup header='Representations'>
  124. <HelpText>
  125. 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.
  126. </HelpText>
  127. </HelpGroup>
  128. <HelpGroup header='Surroundings'>
  129. <HelpText>
  130. To show the surroundings of a residue or ligand, click it in the 3D scene or in the sequence widget using {focusTriggers}.
  131. </HelpText>
  132. </HelpGroup>
  133. <HelpSection header='How-to Guides' />
  134. <HelpGroup header='Create an Image'>
  135. <HelpText>
  136. <p>Use the <Icon name='screenshot' /> icon in the viewport to bring up the screenshot controls.</p>
  137. <p>To adjust the size of the image, use the <i>Resolution</i> dropdown.</p>
  138. </HelpText>
  139. </HelpGroup>
  140. <HelpSection header='Mouse Controls' />
  141. <ViewportHelpContent />
  142. </div>
  143. }
  144. }