color-theme.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright (c) 2018 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 { ColorTheme } from '../../mol-theme/color';
  8. import { Color } from '../../mol-util/color';
  9. export interface ColorThemeComponentProps {
  10. colorTheme: ColorTheme<any>
  11. }
  12. export interface ColorThemeComponentState {
  13. }
  14. export class ColorThemeComponent extends React.Component<ColorThemeComponentProps, ColorThemeComponentState> {
  15. state = {
  16. }
  17. render() {
  18. const ct = this.props.colorTheme
  19. return <div>
  20. <span>Color Theme Info </span>
  21. {ct.description ? <div><i>{ct.description}</i></div> : ''}
  22. {
  23. ct.legend && ct.legend.kind === 'scale-legend'
  24. ? <div
  25. style={{
  26. width: '100%',
  27. height: '30px',
  28. background: `linear-gradient(to right, ${ct.legend.colors.map(c => Color.toStyle(c)).join(', ')})`
  29. }}
  30. >
  31. <span style={{float: 'left', padding: '6px', color: 'white', fontWeight: 'bold', backgroundColor: 'rgba(0, 0, 0, 0.2)'}}>{ct.legend.minLabel}</span>
  32. <span style={{float: 'right', padding: '6px', color: 'white', fontWeight: 'bold', backgroundColor: 'rgba(0, 0, 0, 0.2)'}}>{ct.legend.maxLabel}</span>
  33. </div>
  34. : ct.legend && ct.legend.kind === 'table-legend'
  35. ? <div>
  36. {ct.legend.table.map((value, i) => {
  37. const [name, color] = value
  38. return <div key={i} style={{minWidth: '60px', marginRight: '5px', display: 'inline-block'}}>
  39. <div style={{width: '30px', height: '20px', backgroundColor: Color.toStyle(color), display: 'inline-block'}}></div>
  40. {name}
  41. </div>
  42. })}
  43. </div>
  44. : ''
  45. }
  46. </div>;
  47. }
  48. }