shape-group.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 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: 'group',
  23. color: (location: Location): Color => {
  24. if (Shape.isLocation(location)) {
  25. return location.shape.colors.ref.value[location.group]
  26. }
  27. return DefaultColor
  28. },
  29. props,
  30. description: Description
  31. }
  32. }
  33. export const ShapeGroupColorThemeProvider: ColorTheme.Provider<ShapeGroupColorThemeParams> = {
  34. label: 'Shape Group',
  35. factory: ShapeGroupColorTheme,
  36. getParams: getShapeGroupColorThemeParams,
  37. defaultValues: PD.getDefaultValues(ShapeGroupColorThemeParams)
  38. }