/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose */ import * as React from 'react' import { StructureRepresentation, StructureProps } from 'mol-geo/representation/structure'; import Viewer from 'mol-view/viewer'; import { VisualQuality, VisualQualityNames } from 'mol-geo/representation/util'; import { ColorThemeProps, ColorThemeName, ColorThemeNames, ColorTheme } from 'mol-view/theme/color'; import { Color } from 'mol-util/color'; export interface StructureRepresentationComponentProps { viewer: Viewer representation: StructureRepresentation } export interface StructureRepresentationComponentState { label: string visible: boolean alpha: number quality: VisualQuality colorTheme: ColorThemeProps } export class StructureRepresentationComponent extends React.Component { state = { label: this.props.representation.label, visible: this.props.representation.props.visible, alpha: this.props.representation.props.alpha, quality: this.props.representation.props.quality, colorTheme: this.props.representation.props.colorTheme, } componentWillMount() { const repr = this.props.representation this.setState({ ...this.state, label: repr.label, visible: repr.props.visible, alpha: repr.props.alpha, quality: repr.props.quality, colorTheme: repr.props.colorTheme, }) } async update(state: Partial) { const repr = this.props.representation const props: Partial = {} if (state.visible !== undefined) props.visible = state.visible if (state.quality !== undefined) props.quality = state.quality if (state.alpha !== undefined) props.alpha = state.alpha if (state.colorTheme !== undefined) props.colorTheme = state.colorTheme await repr.createOrUpdate(props).run() this.props.viewer.add(repr) this.props.viewer.requestDraw(true) console.log(this.props.viewer.stats) const newState = { ...this.state, visible: repr.props.visible, quality: repr.props.quality, alpha: repr.props.alpha, colorTheme: repr.props.colorTheme, } this.setState(newState) } render() { const { label, visible, quality, alpha, colorTheme } = this.state const ct = ColorTheme(colorTheme) if (ct.legend && ct.legend.kind === 'scale-legend') { // console.log(`linear-gradient(to right, ${ct.legend.colors.map(c => Color.toStyle(c)).join(', ')})`) } return

{label}

Visible
Quality
Opacity this.update({ alpha: parseFloat(e.currentTarget.value) })} >
Color Theme {ct.description ?
{ct.description}
: ''} { ct.legend && ct.legend.kind === 'scale-legend' ?
Color.toStyle(c)).join(', ')})` }} > {ct.legend.min} {ct.legend.max}
: ct.legend && ct.legend.kind === 'table-legend' ?
{ct.legend.table.map((value, i) => { const [name, color] = value return
{name}
})}
: '' }
; } }