@@ -20,7 +20,6 @@ function xyToPos(x, y, scrollX = 0, scrollY = 0, zoomScale = 1.0) {
2020 let roundedY = Math . floor ( focusY * 2 + 0.5 ) / 2 ;
2121 let centerX = roundedX * pitch ;
2222 let centerY = roundedY * pitch ;
23- //TODO: shall we updated rad here?
2423 let scaledRad = rad * zoomScale ;
2524 if ( Math . abs ( centerX - x ) <= scaledRad && Math . abs ( centerY - y ) <= scaledRad && roundedX % 1 === roundedY % 1 ) {
2625 return [ roundedX , roundedY ] ;
@@ -200,6 +199,7 @@ function defensiveDraw(ctx, body) {
200199 */
201200function draw ( ctx , snap ) {
202201 let circuit = snap . circuit ;
202+ let zoom = snap . zoomScale || 1.0 ;
203203
204204 let numPropagatedLayers = 0 ;
205205 for ( let layer of circuit . layers ) {
@@ -217,6 +217,16 @@ function draw(ctx, snap) {
217217 let y = circuit . qubitCoordData [ 2 * q + 1 ] ;
218218 return c2dCoordTransform ( x , y ) ;
219219 } ;
220+ let pixelCoords = q => {
221+ let x = circuit . qubitCoordData [ 2 * q ] ;
222+ let y = circuit . qubitCoordData [ 2 * q + 1 ] ;
223+ return [ x * pitch * zoom - OFFSET_X + snap . scrollX , y * pitch * zoom - OFFSET_Y + snap . scrollY ] ;
224+ }
225+ let logicCoords = q => {
226+ let x = circuit . qubitCoordData [ 2 * q ] ;
227+ let y = circuit . qubitCoordData [ 2 * q + 1 ] ;
228+ return [ x * pitch , y * pitch ] ;
229+ }
220230 let propagatedMarkerLayers = /** @type {!Map<!int, !PropagatedPauliFrames> } */ new Map ( ) ;
221231 for ( let mi = 0 ; mi < numPropagatedLayers ; mi ++ ) {
222232 propagatedMarkerLayers . set ( mi , PropagatedPauliFrames . fromCircuit ( circuit , mi ) ) ;
@@ -256,13 +266,6 @@ function draw(ctx, snap) {
256266 }
257267
258268 let scaledRad = rad * snap . zoomScale ;
259- //TODO: which font-size shall I use?
260- //console.log("ctx font", ctx.font);
261- // if (scaledRad < 2) {
262- // ctx.font = '10px sans-serif';
263- // } else {
264- // ctx.font = `${scaledRad}px sans-serif`;
265- // }
266269
267270 defensiveDraw ( ctx , ( ) => {
268271 ctx . fillStyle = 'white' ;
@@ -279,13 +282,21 @@ function draw(ctx, snap) {
279282 }
280283 }
281284 }
285+
286+
287+
288+ ctx . save ( ) ;
289+ ctx . translate ( - OFFSET_X + snap . scrollX , - OFFSET_Y + snap . scrollY ) ;
290+ ctx . scale ( zoom , zoom ) ;
291+
282292 let polygonMarkers = [ ...circuit . layers [ lastPolygonLayer ] . markers ] ;
283293 polygonMarkers . sort ( ( a , b ) => b . id_targets . length - a . id_targets . length ) ;
284294 for ( let op of polygonMarkers ) {
285295 if ( op . gate . name === 'POLYGON' ) {
286- op . id_draw ( qubitDrawCoords , ctx ) ;
296+ op . id_draw ( logicCoords , ctx ) ;
287297 }
288298 }
299+ ctx . restore ( ) ;
289300
290301 // Draw the grid of qubits.
291302 defensiveDraw ( ctx , ( ) => {
@@ -311,12 +322,8 @@ function draw(ctx, snap) {
311322 }
312323
313324 ctx . strokeStyle = 'black' ;
314- for ( let qx = 0 ; qx < 100 ; qx += qStep ) {
315- let [ x , _ ] = c2dCoordTransform ( qx , 0 ) ;
316- let s = `${ qx } ` ;
317- ctx . fillStyle = 'black' ;
318- ctx . fillText ( s , x - ctx . measureText ( s ) . width / 2 , 15 ) ;
319- for ( let qy = qx % 1 ; qy < 100 ; qy += qStep * 2 ) {
325+ for ( let qx = 0 ; qx < 100 ; qx += 0.5 ) {
326+ for ( let qy = qx % 1 ; qy < 100 ; qy += 1 ) {
320327 let [ x , y ] = c2dCoordTransform ( qx , qy ) ;
321328 ctx . fillStyle = 'white' ;
322329 let isUnused = ! usedQubitCoordSet . has ( `${ qx } ,${ qy } ` ) ;
@@ -338,18 +345,21 @@ function draw(ctx, snap) {
338345 }
339346 }
340347 } ) ;
341-
342- ctx . font = `${ Math . max ( 6 , scaledRad ) } px sans-serif` ;
348+
349+ ctx . save ( ) ;
350+ ctx . translate ( - OFFSET_X + snap . scrollX , - OFFSET_Y + snap . scrollY ) ;
351+ ctx . scale ( zoom , zoom ) ;
352+
343353 for ( let [ mi , p ] of propagatedMarkerLayers . entries ( ) ) {
344- drawCrossMarkers ( ctx , snap , qubitDrawCoords , p , mi ) ;
354+ drawCrossMarkers ( ctx , snap , logicCoords , p , mi ) ;
345355 }
346356
347357 for ( let op of circuit . layers [ snap . curLayer ] . iter_gates_and_markers ( ) ) {
348358 if ( op . gate . name !== 'POLYGON' ) {
349- op . id_draw ( qubitDrawCoords , ctx ) ;
359+ op . id_draw ( logicCoords , ctx ) ;
350360 }
351361 }
352-
362+
353363 defensiveDraw ( ctx , ( ) => {
354364 ctx . globalAlpha *= 0.25
355365 for ( let [ qx , qy ] of snap . timelineSet . values ( ) ) {
@@ -359,6 +369,10 @@ function draw(ctx, snap) {
359369 }
360370 } ) ;
361371
372+ drawMarkers ( ctx , snap , logicCoords , propagatedMarkerLayers ) ;
373+
374+ ctx . restore ( ) ;
375+
362376 defensiveDraw ( ctx , ( ) => {
363377 ctx . globalAlpha *= 0.5
364378 for ( let [ qx , qy ] of snap . focusedSet . values ( ) ) {
@@ -368,8 +382,6 @@ function draw(ctx, snap) {
368382 }
369383 } ) ;
370384
371- drawMarkers ( ctx , snap , qubitDrawCoords , propagatedMarkerLayers ) ;
372-
373385 if ( focusX !== undefined ) {
374386 ctx . save ( ) ;
375387 ctx . globalAlpha *= 0.5 ;
@@ -402,7 +414,7 @@ function draw(ctx, snap) {
402414 ctx . fillRect ( x - scaledRad , y - scaledRad , 2 * scaledRad , 2 * scaledRad ) ;
403415 }
404416 } ) ;
405-
417+
406418 ctx . font = `10px sans-serif` ;
407419 } ) ;
408420
0 commit comments