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

99 lines
2.6 KiB

  1. import { getShapeStyleFuction, getTextStyleFunction } from './getShapeStyleUtil.js'
  2. const { PolylineEdge, PolylineEdgeModel } = window
  3. // 折线
  4. class PolylineEdgeConnection extends PolylineEdge {
  5. getEndArrow() {
  6. const h = window.h
  7. const { model, graphModel } = this.props
  8. const {
  9. id,
  10. properties: { arrowType, borderColor },
  11. } = model
  12. const { stroke, strokeWidth } = model.getArrowStyle()
  13. const pathAttr = {
  14. stroke,
  15. strokeWidth,
  16. }
  17. if (arrowType === 'empty') {
  18. // 空心箭头
  19. return h('path', {
  20. ...pathAttr,
  21. fill: '#FFF',
  22. d: 'M 0 0 -10 -5 -10 5 z',
  23. })
  24. }
  25. else if (arrowType === 'half') {
  26. // 半箭头
  27. return h('path', {
  28. ...pathAttr,
  29. d: 'M 0 0 -10 5',
  30. })
  31. }
  32. else if (arrowType === 'none') {
  33. // 无箭头
  34. return h('path', {
  35. ...pathAttr,
  36. d: '',
  37. })
  38. }
  39. return h('path', {
  40. ...pathAttr,
  41. fill: borderColor,
  42. d: 'M 0 0 -10 -5 -10 5 z',
  43. })
  44. }
  45. }
  46. class Model extends PolylineEdgeModel {
  47. constructor(data, graphModel) {
  48. super(data, graphModel)
  49. this.strokeWidth = 1
  50. }
  51. getEdgeAnimationStyle() {
  52. const animation = super.getEdgeAnimationStyle()
  53. const { borderColor, strokeDashWidth, strokeDashWidth2, strokeDashSpace, animationName, animationDuration, animationReverse } = this.properties
  54. animation.stroke = borderColor
  55. animation.strokeDashoffset = ''
  56. animation.strokeDasharray = `${strokeDashWidth},${strokeDashSpace},${strokeDashWidth2}`
  57. animation.animationName = animationName || 'lf_animate_dash'
  58. animation.animationDuration = animationDuration || '20s'
  59. animation.animationDirection = animationReverse ? 'reverse' : ''
  60. return animation
  61. }
  62. setAttributes() {
  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-polyline',
  90. view: PolylineEdgeConnection,
  91. model: Model,
  92. }