(svg: SVGSVGElement, rect: Rect, config: RoughAnnotationConfig, animationGroupDelay: number, animationDuration: number, seed: number)
| 56 | } |
| 57 | |
| 58 | export function renderAnnotation(svg: SVGSVGElement, rect: Rect, config: RoughAnnotationConfig, animationGroupDelay: number, animationDuration: number, seed: number) { |
| 59 | const opList: OpSet[] = []; |
| 60 | let strokeWidth = config.strokeWidth || 2; |
| 61 | const padding = parsePadding(config); |
| 62 | const animate = (config.animate === undefined) ? true : (!!config.animate); |
| 63 | const iterations = config.iterations || 2; |
| 64 | const rtl = config.rtl ? 1 : 0; |
| 65 | const o = getOptions('single', seed); |
| 66 | |
| 67 | switch (config.type) { |
| 68 | case 'underline': { |
| 69 | const y = rect.y + rect.h + padding[2]; |
| 70 | for (let i = rtl; i < iterations + rtl; i++) { |
| 71 | if (i % 2) { |
| 72 | opList.push(line(rect.x + rect.w, y, rect.x, y, o)); |
| 73 | } else { |
| 74 | opList.push(line(rect.x, y, rect.x + rect.w, y, o)); |
| 75 | } |
| 76 | } |
| 77 | break; |
| 78 | } |
| 79 | case 'strike-through': { |
| 80 | const y = rect.y + (rect.h / 2); |
| 81 | for (let i = rtl; i < iterations + rtl; i++) { |
| 82 | if (i % 2) { |
| 83 | opList.push(line(rect.x + rect.w, y, rect.x, y, o)); |
| 84 | } else { |
| 85 | opList.push(line(rect.x, y, rect.x + rect.w, y, o)); |
| 86 | } |
| 87 | } |
| 88 | break; |
| 89 | } |
| 90 | case 'box': { |
| 91 | const x = rect.x - padding[3]; |
| 92 | const y = rect.y - padding[0]; |
| 93 | const width = rect.w + (padding[1] + padding[3]); |
| 94 | const height = rect.h + (padding[0] + padding[2]); |
| 95 | for (let i = 0; i < iterations; i++) { |
| 96 | opList.push(rectangle(x, y, width, height, o)); |
| 97 | } |
| 98 | break; |
| 99 | } |
| 100 | case 'bracket': { |
| 101 | const brackets: BracketType[] = Array.isArray(config.brackets) ? config.brackets : (config.brackets ? [config.brackets] : ['right']); |
| 102 | const lx = rect.x - padding[3] * 2; |
| 103 | const rx = rect.x + rect.w + padding[1] * 2; |
| 104 | const ty = rect.y - padding[0] * 2; |
| 105 | const by = rect.y + rect.h + padding[2] * 2; |
| 106 | for (const br of brackets) { |
| 107 | let points: Point[]; |
| 108 | switch (br) { |
| 109 | case 'bottom': |
| 110 | points = [ |
| 111 | [lx, rect.y + rect.h], |
| 112 | [lx, by], |
| 113 | [rx, by], |
| 114 | [rx, rect.y + rect.h] |
| 115 | ]; |
no test coverage detected
searching dependent graphs…