help.tsx 8.8 KB

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