1- import { Circle , DisplayObject , IElement , Line } from '@antv/g' ;
1+ import { Circle , DisplayObject , IElement , Line , Text } from '@antv/g' ;
22import { sort , group , mean , bisector , minIndex } from '@antv/vendor/d3-array' ;
33import { deepMix , lowerFirst , set , throttle , last , isNumber } from '@antv/util' ;
44import { Tooltip as TooltipComponent } from '@antv/component' ;
@@ -347,13 +347,22 @@ function updateRuleX(
347347 polar,
348348 insetLeft,
349349 insetTop,
350+ textXposition = 'start' as const ,
351+ textXoffsetX = 5 ,
352+ textXoffsetY = 0 ,
353+ textX = undefined ,
354+ textY = undefined ,
355+ textFill = undefined ,
350356 ...rest
351357 } ,
352358) {
353359 const defaults = {
354360 lineWidth : 1 ,
355361 stroke : '#1b1e23' ,
356362 strokeOpacity : 0.5 ,
363+ textX,
364+ textY,
365+ textFill,
357366 ...rest ,
358367 } ;
359368
@@ -429,6 +438,31 @@ function updateRuleX(
429438 ruleX . style . y1 = y1 ;
430439 ruleX . style . y2 = y2 ;
431440 root . ruleX = ruleX ;
441+
442+ // Render text if crosshairsLabelX or textX is provided
443+ const labelX = defaults . textX ;
444+ if ( labelX ) {
445+ const createTextX = ( ) => {
446+ const text = new Text ( {
447+ style : {
448+ text : labelX ,
449+ fontSize : 12 ,
450+ fill : defaults . textFill || defaults . stroke ,
451+ textAlign : textXposition ,
452+ textBaseline : 'middle' ,
453+ } ,
454+ } ) ;
455+ root . appendChild ( text ) ;
456+ return text ;
457+ } ;
458+
459+ const textX = root . textX || createTextX ( ) ;
460+ // Position at end of the crosshair line (right side)
461+ textX . style . x = x2 + textXoffsetX ;
462+ textX . style . y = ( y1 + y2 ) / 2 + textXoffsetY ;
463+ textX . style . text = labelX ;
464+ root . textX = textX ;
465+ }
432466 }
433467}
434468
@@ -446,13 +480,20 @@ function updateRuleY(
446480 polar,
447481 insetLeft,
448482 insetTop,
483+ textYposition = 'end' as const ,
484+ textYoffsetX = 5 ,
485+ textYoffsetY = 5 ,
486+ textY = undefined ,
487+ textFill = undefined ,
449488 ...rest
450489 } ,
451490) {
452491 const defaults = {
453492 lineWidth : 1 ,
454493 stroke : '#1b1e23' ,
455494 strokeOpacity : 0.5 ,
495+ textY,
496+ textFill,
456497 ...rest ,
457498 } ;
458499
@@ -498,6 +539,31 @@ function updateRuleY(
498539 ruleY . style . y1 = y1 ;
499540 ruleY . style . y2 = y2 ;
500541 root . ruleY = ruleY ;
542+
543+ // Render text if textY is provided
544+ const labelY = defaults . textY ;
545+ if ( labelY ) {
546+ const createTextY = ( ) => {
547+ const text = new Text ( {
548+ style : {
549+ text : labelY ,
550+ fontSize : 12 ,
551+ fill : defaults . textFill || defaults . stroke ,
552+ textAlign : textYposition ,
553+ textBaseline : 'bottom' ,
554+ } ,
555+ } ) ;
556+ root . appendChild ( text ) ;
557+ return text ;
558+ } ;
559+
560+ const textYObj = root . textY || createTextY ( ) ;
561+ // Position at end of the crosshair line (top)
562+ textYObj . style . x = ( x1 + x2 ) / 2 + textYoffsetX ;
563+ textYObj . style . y = y2 + textYoffsetY ;
564+ textYObj . style . text = labelY ;
565+ root . textY = textYObj ;
566+ }
501567 }
502568}
503569
@@ -506,13 +572,21 @@ function hideRuleY(root) {
506572 root . ruleY . remove ( ) ;
507573 root . ruleY = undefined ;
508574 }
575+ if ( root . textY ) {
576+ root . textY . remove ( ) ;
577+ root . textY = undefined ;
578+ }
509579}
510580
511581function hideRuleX ( root ) {
512582 if ( root . ruleX ) {
513583 root . ruleX . remove ( ) ;
514584 root . ruleX = undefined ;
515585 }
586+ if ( root . textX ) {
587+ root . textX . remove ( ) ;
588+ root . textX = undefined ;
589+ }
516590}
517591
518592function updateMarker ( root , { data, style, theme } ) {
0 commit comments