shape-group.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 { ColorTheme } from '../color';
  7. import { Color } from '../../mol-util/color';
  8. import { Location } from '../../mol-model/location';
  9. import { ShapeGroup } from '../../mol-model/shape';
  10. import { ParamDefinition as PD } from '../../mol-util/param-definition'
  11. import { ThemeDataContext } from '../../mol-theme/theme';
  12. const DefaultColor = Color(0xCCCCCC)
  13. const Description = 'Assigns colors as defined by the shape object.'
  14. export const ShapeGroupColorThemeParams = {}
  15. export type ShapeGroupColorThemeParams = typeof ShapeGroupColorThemeParams
  16. export function getShapeGroupColorThemeParams(ctx: ThemeDataContext) {
  17. return ShapeGroupColorThemeParams // TODO return copy
  18. }
  19. export function ShapeGroupColorTheme(ctx: ThemeDataContext, props: PD.Values<ShapeGroupColorThemeParams>): ColorTheme<ShapeGroupColorThemeParams> {
  20. return {
  21. factory: ShapeGroupColorTheme,
  22. granularity: 'groupInstance',
  23. color: (location: Location): Color => {
  24. if (ShapeGroup.isLocation(location)) {
  25. return location.shape.getColor(location.group, location.instance)
  26. }
  27. return DefaultColor
  28. },
  29. props,
  30. description: Description
  31. }
  32. }
  33. export const ShapeGroupColorThemeProvider: ColorTheme.Provider<ShapeGroupColorThemeParams, 'shape-group'> = {
  34. name: 'shape-group',
  35. label: 'Shape Group',
  36. category: ColorTheme.Category.Misc,
  37. factory: ShapeGroupColorTheme,
  38. getParams: getShapeGroupColorThemeParams,
  39. defaultValues: PD.getDefaultValues(ShapeGroupColorThemeParams),
  40. isApplicable: (ctx: ThemeDataContext) => !!ctx.shape
  41. }