@@ -29,7 +29,7 @@ const formatInputs = (
29
29
let currY : number = startY ;
30
30
qubits . forEach ( ( { id, numResults } ) => {
31
31
// Add qubit wire to list of qubit wires
32
- qubitWires . push ( _qubitInput ( currY ) ) ;
32
+ qubitWires . push ( _qubitInput ( currY , id . toString ( ) ) ) ;
33
33
34
34
// Create qubit register
35
35
registers [ id ] = { type : RegisterType . Qubit , y : currY } ;
@@ -68,8 +68,39 @@ const formatInputs = (
68
68
*
69
69
* @returns SVG text component for the input register.
70
70
*/
71
- const _qubitInput = ( y : number ) : SVGElement => {
72
- const el : SVGElement = text ( "|𝜓⟩" , leftPadding , y , 16 ) ;
71
+ const _qubitInput = ( y : number , subscript ?: string ) : SVGElement => {
72
+ const el : SVGElement = text ( "" , leftPadding , y , 16 ) ;
73
+
74
+ // Create the main text node
75
+ const mainText = document . createElementNS (
76
+ "http://www.w3.org/2000/svg" ,
77
+ "tspan" ,
78
+ ) ;
79
+ mainText . textContent = "|𝜓" ;
80
+
81
+ // Create the subscript node if provided
82
+ if ( subscript ) {
83
+ const subscriptText = document . createElementNS (
84
+ "http://www.w3.org/2000/svg" ,
85
+ "tspan" ,
86
+ ) ;
87
+ subscriptText . textContent = subscript ;
88
+ subscriptText . setAttribute ( "baseline-shift" , "sub" ) ;
89
+ subscriptText . setAttribute ( "font-size" , "65%" ) ;
90
+ mainText . appendChild ( subscriptText ) ;
91
+ }
92
+
93
+ // Add the closing part of the text
94
+ const closingText = document . createElementNS (
95
+ "http://www.w3.org/2000/svg" ,
96
+ "tspan" ,
97
+ ) ;
98
+ closingText . textContent = "⟩" ;
99
+
100
+ // Append all parts to the main SVG text element
101
+ el . appendChild ( mainText ) ;
102
+ el . appendChild ( closingText ) ;
103
+
73
104
el . setAttribute ( "text-anchor" , "start" ) ;
74
105
el . setAttribute ( "dominant-baseline" , "middle" ) ;
75
106
return el ;
0 commit comments