|
183 | 183 | const arrowLength = 20;
|
184 | 184 | const arrowY = 100;
|
185 | 185 | // Line 1: Horizontal line
|
186 |
| - this.circleContainer.append('line') |
| 186 | + const line1 = this.circleContainer.append('line') |
187 | 187 | .attr('x1', arrowX - arrowLength - 20)
|
188 | 188 | .attr('y1', arrowY)
|
189 | 189 | .attr('x2', arrowX)
|
|
192 | 192 | .attr('stroke-width', 2);
|
193 | 193 |
|
194 | 194 | // Line 2: Diagonal line (left)
|
195 |
| - this.circleContainer.append('line') |
| 195 | + const line2 = this.circleContainer.append('line') |
196 | 196 | .attr('x1', arrowX - 10)
|
197 | 197 | .attr('y1', arrowY - 5)
|
198 | 198 | .attr('x2', arrowX - arrowLength + 20)
|
|
201 | 201 | .attr('stroke-width', 2);
|
202 | 202 |
|
203 | 203 | // Line 3: Diagonal line (right)
|
204 |
| - this.circleContainer.append('line') |
| 204 | + const line3 = this.circleContainer.append('line') |
205 | 205 | .attr('x1', arrowX - 10)
|
206 | 206 | .attr('y1', arrowY + 5)
|
207 | 207 | .attr('x2', arrowX - arrowLength + 20)
|
208 | 208 | .attr('y2', arrowY)
|
209 | 209 | .attr('stroke', 'black')
|
210 | 210 | .attr('stroke-width', 2);
|
| 211 | +
|
| 212 | + return [line1, line2, line3]; |
211 | 213 | },
|
212 | 214 |
|
213 | 215 | appendIntoLinkedList(num, pos) {
|
214 | 216 | if (!pos) {
|
215 |
| - const ele = this.createCircle(num); |
216 |
| - this.createArrow((this.xAxis - this.circleRadius * 20) + 70); |
217 |
| - this.linkedList.append(num, ele); |
| 217 | + const circle = this.createCircle(num); |
| 218 | + const line = this.createArrow((this.xAxis - this.circleRadius * 20) + 70); |
| 219 | + this.linkedList.append(num, {circle: circle, lines: line}); |
218 | 220 | }
|
219 | 221 | },
|
220 | 222 |
|
|
228 | 230 | let pos = 1;
|
229 | 231 | while (current) {
|
230 | 232 | found = current.data == this.targetValue;
|
231 |
| - current.element.transition() |
| 233 | + current.element.circle.transition() |
232 | 234 | .duration(1000).attr('fill', "pink");
|
| 235 | + await new Promise(resolve => setTimeout(resolve, 1200)); |
| 236 | + for(const line of current.element.lines){ |
| 237 | + line.transition().duration(300).attr('stroke', "pink"); |
| 238 | + } |
233 | 239 | await new Promise(resolve => setTimeout(resolve, 1000));
|
234 | 240 | if (found) {
|
235 |
| - current.element.transition() |
| 241 | + current.element.circle.transition() |
236 | 242 | .duration(1000).attr('fill', "green");
|
237 | 243 | break;
|
238 | 244 | }
|
|
0 commit comments