fixedpoint.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {CADElement, ElementProps} from './element'
  2. import {SVGURI} from '../constant/Element'
  3. import Renderer from '../base/renderer'
  4. export interface SeftProps {
  5. r?: number,
  6. r1?: number,
  7. strokeWidth?: number,
  8. fillColor?: string,
  9. storkeColor?: string
  10. }
  11. export interface point extends SeftProps {
  12. x: number,
  13. y: number
  14. }
  15. let a = 1;
  16. export interface PointProps extends point, ElementProps { }
  17. class Point extends CADElement<PointProps, Point> {
  18. init: SeftProps
  19. real: SVGEllipseElement
  20. static fillColor = 'rgb(0, 200, 175)'
  21. static storkeColor = 'green'
  22. static Setting = new Map<Renderer, SeftProps>()
  23. constructor({strokeWidth = 0, r = 4, r1 = 4, fillColor, storkeColor, ...args}: PointProps) {
  24. fillColor = fillColor || Point.Setting.get(args.renderer).fillColor
  25. storkeColor = storkeColor || Point.Setting.get(args.renderer).storkeColor
  26. super({storkeColor, fillColor, r, r1, strokeWidth, ...args})
  27. this.init = { strokeWidth, r, r1, fillColor, storkeColor }
  28. this.update()
  29. }
  30. grentNode() {
  31. let point = document.createElementNS(SVGURI, 'ellipse')
  32. point.setAttribute('_id', (a++).toString())
  33. return point
  34. }
  35. update() {
  36. let r1 = this.r * this.multiple
  37. let r2 = this.r1 * this.multiple
  38. let strokeWidth = this.strokeWidth * this.multiple
  39. // console.log(this)
  40. try {
  41. this.real.setAttribute('cx', this.x.toString())
  42. this.real.setAttribute('cy', this.y.toString())
  43. this.real.setAttribute('fill', this.fillColor)
  44. this.real.setAttribute('rx', r1.toString())
  45. this.real.setAttribute('ry', r2.toString())
  46. this.real.setAttribute('stroke-width', strokeWidth.toString())
  47. this.real.setAttribute('stroke', this.storkeColor)
  48. } catch (e) {
  49. console.error(this.x)
  50. }
  51. }
  52. destroy() {
  53. super.destroy()
  54. }
  55. }
  56. export default Point