/** * 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'; import { Progress } from 'mol-task'; export interface StructureRepresentationComponentProps { viewer: Viewer representation: StructureRepresentation } export interface StructureRepresentationComponentState { label: string visible: boolean alpha: number quality: VisualQuality colorTheme: ColorThemeProps resolutionFactor?: number probeRadius?: number isoValue?: number } 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, resolutionFactor: (this.props.representation.props as any).resolutionFactor, probeRadius: (this.props.representation.props as any).probeRadius, isoValue: (this.props.representation.props as any).isoValue, } 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, resolutionFactor: (repr.props as any).resolutionFactor, probeRadius: (repr.props as any).probeRadius, isoValue: (repr.props as any).isoValue, }) } 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 if (state.resolutionFactor !== undefined) (props as any).resolutionFactor = state.resolutionFactor if (state.probeRadius !== undefined) (props as any).probeRadius = state.probeRadius if (state.isoValue !== undefined) (props as any).isoValue = state.isoValue await repr.createOrUpdate(props).run( progress => console.log(Progress.format(progress)), 100 ) this.props.viewer.add(repr) this.props.viewer.draw(true) console.log(this.props.viewer.stats) console.log( 'drawCount', repr.renderObjects[0].values.drawCount.ref.version, repr.renderObjects[0].values.drawCount.ref.value, 'dColorType', repr.renderObjects[0].values.dColorType.ref.version, repr.renderObjects[0].values.dColorType.ref.value ) const newState = { ...this.state, visible: repr.props.visible, quality: repr.props.quality, alpha: repr.props.alpha, colorTheme: repr.props.colorTheme, resolutionFactor: (repr.props as any).resolutionFactor, probeRadius: (repr.props as any).probeRadius, isoValue: (repr.props as any).isoValue, } 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) })} >
{ this.state.resolutionFactor !== undefined ?
Resolution Factor this.update({ resolutionFactor: parseInt(e.currentTarget.value) })} >
: '' } { this.state.isoValue !== undefined ?
Iso Value this.update({ isoValue: parseFloat(e.currentTarget.value) })} >
: '' } { this.state.probeRadius !== undefined ?
Probe Radius this.update({ probeRadius: 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}
})}
: '' }
; } }