物管理前端
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.

100 lines
2.7 KiB

  1. import { getShapeStyleFuction, getTextStyleFunction } from './getShapeStyleUtil.js'
  2. const { CurvedEdge, CurvedEdgeModel } = window
  3. class CurvedEdgeConnection extends CurvedEdge {
  4. getEndArrow() {
  5. const h = window.h
  6. const { model, graphModel } = this.props
  7. const {
  8. id,
  9. properties: { arrowType, borderColor },
  10. } = model
  11. const { stroke, strokeWidth } = model.getArrowStyle()
  12. const pathAttr = {
  13. stroke,
  14. strokeWidth,
  15. }
  16. if (arrowType === 'empty') {
  17. // 空心箭头
  18. return h('path', {
  19. ...pathAttr,
  20. fill: '#FFF',
  21. d: 'M 0 0 -10 -5 -10 5 z',
  22. })
  23. }
  24. else if (arrowType === 'half') {
  25. // 半箭头
  26. return h('path', {
  27. ...pathAttr,
  28. d: 'M 0 0 -10 5',
  29. })
  30. }
  31. else if (arrowType === 'none') {
  32. // 无箭头
  33. return h('path', {
  34. ...pathAttr,
  35. d: '',
  36. })
  37. }
  38. return h('path', {
  39. ...pathAttr,
  40. fill: borderColor,
  41. d: 'M 0 0 -10 -5 -10 5 z',
  42. })
  43. }
  44. }
  45. class Model extends CurvedEdgeModel {
  46. constructor(data, graphModel) {
  47. super(data, graphModel)
  48. this.strokeWidth = 1
  49. }
  50. getEdgeAnimationStyle() {
  51. const animation = super.getEdgeAnimationStyle()
  52. const { borderColor, strokeDashWidth, strokeDashWidth2, strokeDashSpace, animationName, animationDuration, animationReverse } = this.properties
  53. animation.stroke = borderColor
  54. animation.strokeDashoffset = ''
  55. animation.strokeDasharray = `${strokeDashWidth},${strokeDashSpace},${strokeDashWidth2}`
  56. animation.animationName = animationName || 'lf_animate_dash'
  57. animation.animationDuration = animationDuration || '20s'
  58. animation.animationDirection = animationReverse ? 'reverse' : ''
  59. return animation
  60. }
  61. setAttributes() {
  62. this.radius = this.properties.radius || 5
  63. const { defaultValue, min, max } = this.properties
  64. if (defaultValue) {
  65. const realValue = window.resolveScadaNewValue(defaultValue)
  66. const realMin = min < max ? min : max
  67. const realMax = max > min ? max : min
  68. if (realValue >= realMin && realValue <= realMax)
  69. this.isAnimation = true
  70. else
  71. this.isAnimation = false
  72. }
  73. else {
  74. this.isAnimation = this.properties.isAnimation || false
  75. }
  76. }
  77. getTextStyle() {
  78. const style = super.getTextStyle()
  79. return getTextStyleFunction(style, this.properties)
  80. }
  81. getEdgeStyle() {
  82. const attributes = super.getEdgeStyle()
  83. const properties = this.properties
  84. const style = getShapeStyleFuction(attributes, properties)
  85. return { ...style, fill: 'none' }
  86. }
  87. }
  88. export default {
  89. type: 'pro-curved-edge',
  90. view: CurvedEdgeConnection,
  91. model: Model,
  92. }