|
| 1 | +import { createRect, createArc, createPolygon } from '@src/vrender'; |
| 2 | + |
| 3 | +import type { Group, IFillType } from '@src/vrender'; |
| 4 | + |
| 5 | +import type { MarkCellStyle, MarkedPropertyDefine } from '../../ts-types'; |
| 6 | +import type { BaseTableAPI } from '../../ts-types/base-table'; |
| 7 | + |
| 8 | +export function createMark(marked: MarkedPropertyDefine, cellGroup: Group, table: BaseTableAPI) { |
| 9 | + if (typeof marked === 'boolean') { |
| 10 | + // 默认是右上角显示个扇形 |
| 11 | + const mark = createArc({ |
| 12 | + x: cellGroup.attribute.width, |
| 13 | + y: 0, |
| 14 | + startAngle: Math.PI / 2, |
| 15 | + endAngle: Math.PI, |
| 16 | + outerRadius: 6, |
| 17 | + fill: '#3073F2', |
| 18 | + pickable: false |
| 19 | + }); |
| 20 | + mark.name = 'mark'; |
| 21 | + |
| 22 | + cellGroup.appendChild(mark); |
| 23 | + } else { |
| 24 | + const { |
| 25 | + bgColor = '#3073F2', |
| 26 | + shape = 'sector', |
| 27 | + position = 'right-top', |
| 28 | + size = 10, |
| 29 | + offset = 0 |
| 30 | + } = marked as MarkCellStyle; |
| 31 | + let x; |
| 32 | + let y; |
| 33 | + let startAngle; |
| 34 | + let endAngle; |
| 35 | + let fill; |
| 36 | + let mark; |
| 37 | + |
| 38 | + if (shape === 'sector') { |
| 39 | + if (position === 'right-top') { |
| 40 | + x = cellGroup.attribute.width - offset; |
| 41 | + y = offset; |
| 42 | + startAngle = Math.PI / 2; |
| 43 | + endAngle = Math.PI; |
| 44 | + } else if (position === 'left-top') { |
| 45 | + x = offset; |
| 46 | + y = offset; |
| 47 | + startAngle = 0; |
| 48 | + endAngle = Math.PI / 2; |
| 49 | + } else if (position === 'right-bottom') { |
| 50 | + x = cellGroup.attribute.width - offset; |
| 51 | + y = cellGroup.attribute.height - offset; |
| 52 | + startAngle = Math.PI; |
| 53 | + endAngle = (Math.PI / 2) * 3; |
| 54 | + } else if (position === 'left-bottom') { |
| 55 | + x = offset; |
| 56 | + y = cellGroup.attribute.height - offset; |
| 57 | + startAngle = (Math.PI / 2) * 3; |
| 58 | + endAngle = Math.PI * 2; |
| 59 | + } |
| 60 | + |
| 61 | + fill = bgColor; |
| 62 | + mark = createArc({ |
| 63 | + x, |
| 64 | + y, |
| 65 | + startAngle, |
| 66 | + endAngle, |
| 67 | + outerRadius: size, |
| 68 | + fill: fill as IFillType, |
| 69 | + pickable: false |
| 70 | + }); |
| 71 | + } else if (shape === 'triangle') { |
| 72 | + let x2; |
| 73 | + let y2; |
| 74 | + let x3; |
| 75 | + let y3; |
| 76 | + if (position === 'right-top') { |
| 77 | + x = cellGroup.attribute.width - offset; |
| 78 | + y = offset; |
| 79 | + x2 = x - size; |
| 80 | + y2 = y; |
| 81 | + x3 = x; |
| 82 | + y3 = y + size; |
| 83 | + } else if (position === 'left-top') { |
| 84 | + x = offset; |
| 85 | + y = offset; |
| 86 | + x2 = x + size; |
| 87 | + y2 = y; |
| 88 | + x3 = x; |
| 89 | + y3 = y + size; |
| 90 | + } else if (position === 'right-bottom') { |
| 91 | + x = cellGroup.attribute.width - offset; |
| 92 | + y = cellGroup.attribute.height - offset; |
| 93 | + x2 = x - size; |
| 94 | + y2 = y; |
| 95 | + x3 = x; |
| 96 | + y3 = y - size; |
| 97 | + } else if (position === 'left-bottom') { |
| 98 | + x = offset; |
| 99 | + y = cellGroup.attribute.height - offset; |
| 100 | + x2 = x + size; |
| 101 | + y2 = y; |
| 102 | + x3 = x; |
| 103 | + y3 = y - size; |
| 104 | + } |
| 105 | + fill = bgColor; |
| 106 | + mark = createPolygon({ |
| 107 | + points: [ |
| 108 | + { x: x, y: y }, |
| 109 | + { x: x2, y: y2 }, |
| 110 | + { x: x3, y: y3 } |
| 111 | + ], |
| 112 | + fill: fill as IFillType, |
| 113 | + pickable: false |
| 114 | + }); |
| 115 | + } else if (shape === 'rect') { |
| 116 | + if (position === 'right-top') { |
| 117 | + x = cellGroup.attribute.width - size - offset; |
| 118 | + y = offset; |
| 119 | + } else if (position === 'left-top') { |
| 120 | + x = offset; |
| 121 | + y = offset; |
| 122 | + } else if (position === 'right-bottom') { |
| 123 | + x = cellGroup.attribute.width - size - offset; |
| 124 | + y = cellGroup.attribute.height - size - offset; |
| 125 | + } else if (position === 'left-bottom') { |
| 126 | + x = offset; |
| 127 | + y = cellGroup.attribute.height - size - offset; |
| 128 | + } |
| 129 | + fill = bgColor; |
| 130 | + mark = createRect({ |
| 131 | + x, |
| 132 | + y, |
| 133 | + width: size, |
| 134 | + height: size, |
| 135 | + fill: fill as IFillType, |
| 136 | + pickable: false |
| 137 | + }); |
| 138 | + } |
| 139 | + mark.name = 'mark'; |
| 140 | + cellGroup.appendChild(mark); |
| 141 | + } |
| 142 | +} |
0 commit comments