help.tsx 8.2 KB

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