|
| 1 | +import { Text } from '@antv/g'; |
| 2 | + |
| 3 | +export async function textDecoration(context) { |
| 4 | + const { canvas } = context; |
| 5 | + await canvas.ready; |
| 6 | + |
| 7 | + // Test underline |
| 8 | + const text1 = new Text({ |
| 9 | + style: { |
| 10 | + x: 50, |
| 11 | + y: 50, |
| 12 | + text: 'Underline Text', |
| 13 | + fontSize: 20, |
| 14 | + fill: 'black', |
| 15 | + textDecorationLine: 'underline', |
| 16 | + textDecorationColor: 'red', |
| 17 | + textDecorationStyle: 'solid', |
| 18 | + }, |
| 19 | + }); |
| 20 | + canvas.appendChild(text1); |
| 21 | + |
| 22 | + // Test overline |
| 23 | + const text2 = new Text({ |
| 24 | + style: { |
| 25 | + x: 50, |
| 26 | + y: 100, |
| 27 | + text: 'Overline Text', |
| 28 | + fontSize: 20, |
| 29 | + fill: 'black', |
| 30 | + textDecorationLine: 'overline', |
| 31 | + textDecorationColor: 'blue', |
| 32 | + textDecorationStyle: 'solid', |
| 33 | + }, |
| 34 | + }); |
| 35 | + canvas.appendChild(text2); |
| 36 | + |
| 37 | + // Test line-through |
| 38 | + const text3 = new Text({ |
| 39 | + style: { |
| 40 | + x: 50, |
| 41 | + y: 150, |
| 42 | + text: 'Line-through Text', |
| 43 | + fontSize: 20, |
| 44 | + fill: 'black', |
| 45 | + textDecorationLine: 'line-through', |
| 46 | + textDecorationColor: 'green', |
| 47 | + textDecorationStyle: 'solid', |
| 48 | + }, |
| 49 | + }); |
| 50 | + canvas.appendChild(text3); |
| 51 | + |
| 52 | + // Test multiple decorations |
| 53 | + const text4 = new Text({ |
| 54 | + style: { |
| 55 | + x: 50, |
| 56 | + y: 200, |
| 57 | + text: 'Underline and Overline', |
| 58 | + fontSize: 20, |
| 59 | + fill: 'black', |
| 60 | + textDecorationLine: 'underline overline', |
| 61 | + textDecorationColor: 'purple', |
| 62 | + textDecorationStyle: 'solid', |
| 63 | + }, |
| 64 | + }); |
| 65 | + canvas.appendChild(text4); |
| 66 | + |
| 67 | + // Test dashed underline |
| 68 | + const text5 = new Text({ |
| 69 | + style: { |
| 70 | + x: 50, |
| 71 | + y: 250, |
| 72 | + text: 'Dashed Underline', |
| 73 | + fontSize: 20, |
| 74 | + fill: 'black', |
| 75 | + textDecorationLine: 'underline', |
| 76 | + textDecorationColor: 'orange', |
| 77 | + textDecorationStyle: 'dashed', |
| 78 | + }, |
| 79 | + }); |
| 80 | + canvas.appendChild(text5); |
| 81 | + |
| 82 | + // Test dotted underline |
| 83 | + const text6 = new Text({ |
| 84 | + style: { |
| 85 | + x: 50, |
| 86 | + y: 300, |
| 87 | + text: 'Dotted Underline', |
| 88 | + fontSize: 20, |
| 89 | + fill: 'black', |
| 90 | + textDecorationLine: 'underline', |
| 91 | + textDecorationColor: 'brown', |
| 92 | + textDecorationStyle: 'dotted', |
| 93 | + }, |
| 94 | + }); |
| 95 | + canvas.appendChild(text6); |
| 96 | + |
| 97 | + // Test wavy underline |
| 98 | + const text7 = new Text({ |
| 99 | + style: { |
| 100 | + x: 50, |
| 101 | + y: 350, |
| 102 | + text: 'Wavy Underline', |
| 103 | + fontSize: 20, |
| 104 | + fill: 'black', |
| 105 | + textDecorationLine: 'underline', |
| 106 | + textDecorationColor: 'pink', |
| 107 | + textDecorationStyle: 'wavy', |
| 108 | + }, |
| 109 | + }); |
| 110 | + canvas.appendChild(text7); |
| 111 | + |
| 112 | + // Test none (should remove any decoration) |
| 113 | + const text8 = new Text({ |
| 114 | + style: { |
| 115 | + x: 50, |
| 116 | + y: 400, |
| 117 | + text: 'No Decoration', |
| 118 | + fontSize: 20, |
| 119 | + fill: 'black', |
| 120 | + textDecorationLine: 'none', |
| 121 | + }, |
| 122 | + }); |
| 123 | + canvas.appendChild(text8); |
| 124 | + |
| 125 | + // Test textDecorationThickness |
| 126 | + const text9 = new Text({ |
| 127 | + style: { |
| 128 | + x: 50, |
| 129 | + y: 450, |
| 130 | + text: 'Thick Underline', |
| 131 | + fontSize: 20, |
| 132 | + fill: 'black', |
| 133 | + textDecorationLine: 'underline', |
| 134 | + textDecorationColor: 'red', |
| 135 | + textDecorationStyle: 'solid', |
| 136 | + textDecorationThickness: 3, |
| 137 | + }, |
| 138 | + }); |
| 139 | + canvas.appendChild(text9); |
| 140 | + |
| 141 | + // Test textDecorationThickness with dashed style |
| 142 | + const text10 = new Text({ |
| 143 | + style: { |
| 144 | + x: 50, |
| 145 | + y: 500, |
| 146 | + text: 'Thick Dashed', |
| 147 | + fontSize: 20, |
| 148 | + fill: 'black', |
| 149 | + textDecorationLine: 'underline', |
| 150 | + textDecorationColor: 'blue', |
| 151 | + textDecorationStyle: 'dashed', |
| 152 | + textDecorationThickness: 4, |
| 153 | + }, |
| 154 | + }); |
| 155 | + canvas.appendChild(text10); |
| 156 | +} |
0 commit comments