shape-group.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 { Shape } 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 function getShapeGroupColorThemeParams(ctx: ThemeDataContext) {
  16. return ShapeGroupColorThemeParams // TODO return copy
  17. }
  18. export type ShapeGroupColorThemeProps = PD.DefaultValues<typeof ShapeGroupColorThemeParams>
  19. export function ShapeGroupColorTheme(ctx: ThemeDataContext, props: ShapeGroupColorThemeProps): ColorTheme<ShapeGroupColorThemeProps> {
  20. return {
  21. granularity: 'group',
  22. color: (location: Location): Color => {
  23. if (Shape.isLocation(location)) {
  24. return location.shape.colors.ref.value[location.group]
  25. }
  26. return DefaultColor
  27. },
  28. props,
  29. description: Description
  30. }
  31. }
  32. export const ShapeGroupColorThemeProvider: ColorTheme.Provider<typeof ShapeGroupColorThemeParams> = {
  33. factory: ShapeGroupColorTheme, params: getShapeGroupColorThemeParams
  34. }