color.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 { Color } from 'mol-util/color';
  7. import { Structure } from 'mol-model/structure';
  8. import { Location } from 'mol-model/location';
  9. import { ColorType } from 'mol-geo/geometry/color-data';
  10. import { ElementIndexColorTheme } from './color/element-index';
  11. import { CarbohydrateSymbolColorTheme } from './color/carbohydrate-symbol';
  12. import { ChainIdColorTheme } from './color/chain-id';
  13. import { ElementSymbolColorTheme } from './color/element-symbol';
  14. import { UnitIndexColorTheme } from './color/unit-index';
  15. import { UniformColorTheme } from './color/uniform';
  16. import { CrossLinkColorTheme } from './color/cross-link';
  17. import { ShapeGroupColorTheme } from './color/shape-group';
  18. import { CustomColorTheme } from './color/custom';
  19. import { ResidueNameColorTheme } from './color/residue-name';
  20. import { SequenceIdColorTheme } from './color/sequence-id';
  21. import { SecondaryStructureColorTheme } from './color/secondary-structure';
  22. export type LocationColor = (location: Location, isSecondary: boolean) => Color
  23. export interface ScaleLegend {
  24. kind: 'scale-legend'
  25. minLabel: string,
  26. maxLabel: string,
  27. colors: Color[]
  28. }
  29. export function ScaleLegend(minLabel: string, maxLabel: string, colors: Color[]): ScaleLegend {
  30. return { kind: 'scale-legend', minLabel, maxLabel, colors }
  31. }
  32. export interface TableLegend {
  33. kind: 'table-legend'
  34. table: [ string, Color ][]
  35. }
  36. export function TableLegend(table: [ string, Color ][]): TableLegend {
  37. return { kind: 'table-legend', table }
  38. }
  39. export interface ColorTheme {
  40. granularity: ColorType
  41. color: LocationColor
  42. description?: string
  43. legend?: ScaleLegend | TableLegend
  44. }
  45. export function ColorTheme(props: ColorThemeProps): ColorTheme {
  46. switch (props.name) {
  47. case 'carbohydrate-symbol': return CarbohydrateSymbolColorTheme(props)
  48. case 'chain-id': return ChainIdColorTheme(props)
  49. case 'cross-link': return CrossLinkColorTheme(props)
  50. case 'custom': return CustomColorTheme(props)
  51. case 'element-index': return ElementIndexColorTheme(props)
  52. case 'element-symbol': return ElementSymbolColorTheme(props)
  53. case 'residue-name': return ResidueNameColorTheme(props)
  54. case 'secondary-structure': return SecondaryStructureColorTheme(props)
  55. case 'sequence-id': return SequenceIdColorTheme(props)
  56. case 'shape-group': return ShapeGroupColorTheme(props)
  57. case 'unit-index': return UnitIndexColorTheme(props)
  58. case 'uniform': return UniformColorTheme(props)
  59. }
  60. }
  61. export interface ColorThemeProps {
  62. name: ColorThemeName
  63. domain?: [number, number]
  64. value?: Color
  65. structure?: Structure
  66. color?: LocationColor
  67. granularity?: ColorType,
  68. description?: string,
  69. legend?: ScaleLegend | TableLegend
  70. }
  71. export const ColorThemeInfo = {
  72. 'carbohydrate-symbol': {},
  73. 'chain-id': {},
  74. 'cross-link': {},
  75. 'custom': {},
  76. 'element-index': {},
  77. 'element-symbol': {},
  78. 'residue-name': {},
  79. 'secondary-structure': {},
  80. 'sequence-id': {},
  81. 'shape-group': {},
  82. 'unit-index': {},
  83. 'uniform': {},
  84. }
  85. export type ColorThemeName = keyof typeof ColorThemeInfo
  86. export const ColorThemeNames = Object.keys(ColorThemeInfo)