You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dot.tsx 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { uniqueId } from 'utils/utils'
  2. import { DotShape, ShapeType } from 'types'
  3. import { intersectCircleBounds } from 'utils/intersections'
  4. import { boundsContained, translateBounds } from 'utils'
  5. import { defaultStyle } from 'state/shape-styles'
  6. import { registerShapeUtils } from './register'
  7. const dot = registerShapeUtils<DotShape>({
  8. boundsCache: new WeakMap([]),
  9. defaultProps: {
  10. id: uniqueId(),
  11. type: ShapeType.Dot,
  12. isGenerated: false,
  13. name: 'Dot',
  14. parentId: 'page1',
  15. childIndex: 0,
  16. point: [0, 0],
  17. rotation: 0,
  18. isAspectRatioLocked: false,
  19. isLocked: false,
  20. isHidden: false,
  21. style: defaultStyle,
  22. },
  23. render({ id }) {
  24. return <use id={id} href="#dot" fill="black" />
  25. },
  26. getBounds(shape) {
  27. if (!this.boundsCache.has(shape)) {
  28. const bounds = {
  29. minX: 0,
  30. maxX: 1,
  31. minY: 0,
  32. maxY: 1,
  33. width: 1,
  34. height: 1,
  35. }
  36. this.boundsCache.set(shape, bounds)
  37. }
  38. return translateBounds(this.boundsCache.get(shape), shape.point)
  39. },
  40. getRotatedBounds(shape) {
  41. return this.getBounds(shape)
  42. },
  43. getCenter(shape) {
  44. return shape.point
  45. },
  46. hitTest() {
  47. return true
  48. },
  49. hitTestBounds(this, shape, brushBounds) {
  50. const shapeBounds = this.getBounds(shape)
  51. return (
  52. boundsContained(shapeBounds, brushBounds) ||
  53. intersectCircleBounds(shape.point, 4, brushBounds).length > 0
  54. )
  55. },
  56. transform(shape, bounds) {
  57. shape.point = [bounds.minX, bounds.minY]
  58. return this
  59. },
  60. canTransform: false,
  61. canChangeAspectRatio: false,
  62. })
  63. export default dot