shape-group.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Location } from 'mol-model/location';
  7. import { Shape } from 'mol-model/shape';
  8. import { ParamDefinition as PD } from 'mol-util/param-definition'
  9. import { ThemeDataContext } from 'mol-theme/theme';
  10. import { SizeTheme } from 'mol-theme/size';
  11. const DefaultSize = 1
  12. const Description = 'Assigns sizes as defined by the shape object.'
  13. export const ShapeGroupSizeThemeParams = {}
  14. export type ShapeGroupSizeThemeParams = typeof ShapeGroupSizeThemeParams
  15. export function getShapeGroupSizeThemeParams(ctx: ThemeDataContext) {
  16. return ShapeGroupSizeThemeParams // TODO return copy
  17. }
  18. export function ShapeGroupSizeTheme(ctx: ThemeDataContext, props: PD.Values<ShapeGroupSizeThemeParams>): SizeTheme<ShapeGroupSizeThemeParams> {
  19. return {
  20. factory: ShapeGroupSizeTheme,
  21. granularity: 'groupInstance',
  22. size: (location: Location): number => {
  23. if (Shape.isLocation(location)) {
  24. return location.shape.getSize(location.group, location.instance)
  25. }
  26. return DefaultSize
  27. },
  28. props,
  29. description: Description
  30. }
  31. }
  32. export const ShapeGroupSizeThemeProvider: SizeTheme.Provider<ShapeGroupSizeThemeParams> = {
  33. label: 'Shape Group',
  34. factory: ShapeGroupSizeTheme,
  35. getParams: getShapeGroupSizeThemeParams,
  36. defaultValues: PD.getDefaultValues(ShapeGroupSizeThemeParams),
  37. isApplicable: (ctx: ThemeDataContext) => !!ctx.shape
  38. }