@@ -2469,15 +2469,11 @@ function drawHorizontalAxis(ctx, params, axis) {
2469
2469
}
2470
2470
}
2471
2471
}
2472
- OSD . _drawTopAxis = function ( ctx , params ) {
2473
- drawHorizontalAxis ( ctx , params , "top" ) ;
2474
- } ;
2475
- OSD . _drawBottomAxis = function ( ctx , params ) {
2476
- drawHorizontalAxis ( ctx , params , "bottom" ) ;
2477
- } ;
2478
- OSD . _drawLeftAxis = function ( ctx , params ) {
2479
- const { rowsCount, cy, left, ch, signPad, rows, containerRect, config } = params ;
2480
- ctx . textAlign = "right" ;
2472
+
2473
+ // Shared vertical axis drawing helper for left/right rulers
2474
+ function drawVerticalAxis ( ctx , params , axis ) {
2475
+ const { rowsCount, cy, left, right, ch, cw, signPad, rows, containerRect, config } = params ;
2476
+ ctx . textAlign = axis === "left" ? "right" : "left" ;
2481
2477
for ( let i = 0 ; i < rowsCount ; i ++ ) {
2482
2478
const y = OSD . _rowCenterY ( i , containerRect , rows ) ;
2483
2479
const offset = i - cy ;
@@ -2487,8 +2483,14 @@ OSD._drawLeftAxis = function (ctx, params) {
2487
2483
ctx . strokeStyle = isCenter ? config . colorCenter : isMajor ? config . colorMajor : config . colorMinor ;
2488
2484
ctx . lineWidth = 1 ;
2489
2485
ctx . beginPath ( ) ;
2490
- const x0 = left - 1 ;
2491
- const x1 = Math . max ( 0 , left - tick ) ;
2486
+ let x0 , x1 , labelX ;
2487
+ if ( axis === "left" ) {
2488
+ x0 = left - 1 ;
2489
+ x1 = Math . max ( 0 , left - tick ) ;
2490
+ } else {
2491
+ x0 = Math . min ( cw - 1 , right + 1 ) ;
2492
+ x1 = Math . min ( cw - 1 , right + tick ) ;
2493
+ }
2492
2494
ctx . moveTo ( x0 + 0.5 , y + 0.5 ) ;
2493
2495
ctx . lineTo ( x1 + 0.5 , y + 0.5 ) ;
2494
2496
ctx . stroke ( ) ;
@@ -2497,47 +2499,33 @@ OSD._drawLeftAxis = function (ctx, params) {
2497
2499
const text = offset . toString ( ) ;
2498
2500
const textWidth = ctx . measureText ( text ) . width ;
2499
2501
const extra = text . startsWith ( "-" ) ? signPad : 0 ;
2500
- const desired = x1 - ( isMajor ? config . sideLabelOffsetMajor : config . sideLabelOffset ) - extra ;
2501
- const labelX = Math . max ( config . minEdgePadding + textWidth , desired ) ;
2502
+ if ( axis === "left" ) {
2503
+ const desired = x1 - ( isMajor ? config . sideLabelOffsetMajor : config . sideLabelOffset ) - extra ;
2504
+ labelX = Math . max ( config . minEdgePadding + textWidth , desired ) ;
2505
+ } else {
2506
+ const desired = x1 + ( isMajor ? config . sideLabelOffsetMajor : config . sideLabelOffset ) + extra ;
2507
+ labelX = Math . min ( cw - config . minEdgePadding - textWidth , desired ) ;
2508
+ }
2502
2509
ctx . lineWidth = 3 ;
2503
2510
ctx . strokeStyle = "rgba(0,0,0,0.6)" ;
2504
2511
const yLabel = Math . max ( config . minEdgePadding , Math . min ( ch - config . minEdgePadding , y + 0.5 ) ) ;
2505
2512
ctx . strokeText ( text , labelX , yLabel ) ;
2506
2513
ctx . fillText ( text , labelX , yLabel ) ;
2507
2514
}
2508
2515
}
2516
+ }
2517
+
2518
+ OSD . _drawTopAxis = function ( ctx , params ) {
2519
+ drawHorizontalAxis ( ctx , params , "top" ) ;
2520
+ } ;
2521
+ OSD . _drawBottomAxis = function ( ctx , params ) {
2522
+ drawHorizontalAxis ( ctx , params , "bottom" ) ;
2523
+ } ;
2524
+ OSD . _drawLeftAxis = function ( ctx , params ) {
2525
+ drawVerticalAxis ( ctx , params , "left" ) ;
2509
2526
} ;
2510
2527
OSD . _drawRightAxis = function ( ctx , params ) {
2511
- const { rowsCount, cy, right, cw, signPad, rows, containerRect, config } = params ;
2512
- ctx . textAlign = "left" ;
2513
- for ( let i = 0 ; i < rowsCount ; i ++ ) {
2514
- const y = OSD . _rowCenterY ( i , containerRect , rows ) ;
2515
- const offset = i - cy ;
2516
- const isCenter = i === cy ;
2517
- const isMajor = Math . abs ( offset ) % config . verticalLabelStep === 0 || i === 0 || i === rowsCount - 1 || isCenter ;
2518
- const tick = isMajor ? config . vertTickMajor : config . tickMinor ;
2519
- ctx . strokeStyle = isCenter ? config . colorCenter : isMajor ? config . colorMajor : config . colorMinor ;
2520
- ctx . lineWidth = 1 ;
2521
- ctx . beginPath ( ) ;
2522
- const x0 = Math . min ( cw - 1 , right + 1 ) ;
2523
- const x1 = Math . min ( cw - 1 , right + tick ) ;
2524
- ctx . moveTo ( x0 + 0.5 , y + 0.5 ) ;
2525
- ctx . lineTo ( x1 + 0.5 , y + 0.5 ) ;
2526
- ctx . stroke ( ) ;
2527
- if ( isMajor ) {
2528
- ctx . fillStyle = isCenter ? config . colorCenter : "#ffffff" ;
2529
- const text = offset . toString ( ) ;
2530
- const textWidth = ctx . measureText ( text ) . width ;
2531
- const extra = text . startsWith ( "-" ) ? signPad : 0 ;
2532
- const desired = x1 + ( isMajor ? config . sideLabelOffsetMajor : config . sideLabelOffset ) + extra ;
2533
- const labelX = Math . min ( cw - config . minEdgePadding - textWidth , desired ) ;
2534
- ctx . lineWidth = 3 ;
2535
- ctx . strokeStyle = "rgba(0,0,0,0.6)" ;
2536
- const yLabel = Math . max ( config . minEdgePadding , Math . min ( params . ch - config . minEdgePadding , y + 0.5 ) ) ;
2537
- ctx . strokeText ( text , labelX , yLabel ) ;
2538
- ctx . fillText ( text , labelX , yLabel ) ;
2539
- }
2540
- }
2528
+ drawVerticalAxis ( ctx , params , "right" ) ;
2541
2529
} ;
2542
2530
2543
2531
OSD . drawRulers = function ( ) {
0 commit comments