shape-group.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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> = {
  34. label: 'Shape Group',
  35. factory: ShapeGroupColorTheme,
  36. getParams: getShapeGroupColorThemeParams,
  37. defaultValues: PD.getDefaultValues(ShapeGroupColorThemeParams),
  38. isApplicable: (ctx: ThemeDataContext) => !!ctx.shape
  39. }