@@ -2575,8 +2575,85 @@ useTimeLabelCollision({
2575
2575
2576
2576
const useCustomFormatTimeTag = ref (false );
2577
2577
2578
+ const timeTagEl = ref (null );
2579
+ const timeTagInnerW = ref (200 )
2580
+
2581
+ const activeIndex = computed (() =>
2582
+ (selectedSerieIndex .value ?? selectedMinimapIndex .value ?? 0 )
2583
+ )
2584
+
2585
+ function timeTagMeasuredW () {
2586
+ const w = Math .ceil (timeTagInnerW .value || 200 )
2587
+ return Math .min (Math .max (w, 1 ), 200 )
2588
+ }
2589
+
2590
+ function timeTagX () {
2591
+ const w = timeTagMeasuredW ();
2592
+ const W_FO = 200 ;
2593
+ const sectionsX = Math .max (1 , maxSeries .value );
2594
+ const sectionX = drawingArea .value .width / sectionsX;
2595
+ const centerX = drawingArea .value .left + activeIndex .value * sectionX + sectionX / 2 ;
2596
+ const desiredX = centerX - w / 2 - (W_FO - w) / 2 ;
2597
+ const minX = drawingArea .value .left - (W_FO - w) / 2 ;
2598
+ const maxX = drawingArea .value .right - (W_FO + w) / 2 ;
2599
+ const clamped = Math .max (minX, Math .min (desiredX, maxX));
2600
+ return checkNaN (clamped);
2601
+ }
2602
+
2603
+ onMounted (() => {
2604
+ let observedTimeTagEl = null ;
2605
+ let raf = null ;
2606
+
2607
+ const setW = (w ) => {
2608
+ cancelAnimationFrame (raf)
2609
+ raf = requestAnimationFrame (() => {
2610
+ timeTagInnerW .value = Math .min (Math .max (Math .ceil (w || 0 ), 1 ), 200 );
2611
+ });
2612
+ }
2613
+
2614
+ const ro = new ResizeObserver ((entries ) => {
2615
+ let entry = entries .find (e => e .target === observedTimeTagEl) || entries[0 ];
2616
+ if (! entry) return ;
2617
+ setW (entry .contentRect .width || 200 )
2618
+ });
2619
+
2620
+ const stop = watchEffect ((onInvalidate ) => {
2621
+ const el = timeTagEl .value ;
2622
+ if (observedTimeTagEl && observedTimeTagEl !== el) {
2623
+ ro .unobserve (observedTimeTagEl);
2624
+ observedTimeTagEl = null ;
2625
+ }
2626
+
2627
+ if (el && el !== observedTimeTagEl) {
2628
+ nextTick (() => {
2629
+ if (el .offsetParent === null ) return ;
2630
+ setW (el .offsetWidth || el .getBoundingClientRect ().width || 200 )
2631
+ })
2632
+ ro .observe (el);
2633
+ observedTimeTagEl = el;
2634
+ }
2635
+
2636
+ onInvalidate (() => {
2637
+ if (observedTimeTagEl) {
2638
+ ro .unobserve (observedTimeTagEl);
2639
+ observedTimeTagEl = null ;
2640
+ }
2641
+ });
2642
+ });
2643
+
2644
+ onBeforeUnmount (() => {
2645
+ try {
2646
+ if (observedTimeTagEl) ro .unobserve (observedTimeTagEl);
2647
+ ro .disconnect ();
2648
+ stop ();
2649
+ } catch {
2650
+ // ignore
2651
+ }
2652
+ });
2653
+ });
2654
+
2578
2655
const timeTagContent = computed (() => {
2579
- if ([null , undefined ].includes (selectedSerieIndex .value ) && [null , undefined ].includes (selectedMinimapIndex .value )) return ' '
2656
+ if ([null , undefined ].includes (selectedSerieIndex .value ) && [null , undefined ].includes (selectedMinimapIndex .value )) return ' ' ;
2580
2657
2581
2658
const index = (selectedSerieIndex .value != null ? selectedSerieIndex .value : 0 ) || (selectedMinimapIndex .value != null ? selectedMinimapIndex .value : 0 );
2582
2659
@@ -3698,9 +3775,10 @@ defineExpose({
3698
3775
< g v- if = " FINAL_CONFIG.chart.timeTag.show && (![null, undefined].includes(selectedSerieIndex) || ![null, undefined].includes(selectedMinimapIndex))"
3699
3776
style= " pointer-events:none" >
3700
3777
< foreignObject
3701
- : x= " drawingArea.left + (drawingArea.width / maxSeries) * ((selectedSerieIndex !== null ? selectedSerieIndex : 0) || (selectedMinimapIndex !== null ? selectedMinimapIndex : 0)) - 100 + (drawingArea.width / maxSeries / 2 )"
3778
+ : x= " timeTagX( )"
3702
3779
: y= " drawingArea.bottom" width= " 200" height= " 40" style= " overflow: visible !important;" >
3703
3780
< div
3781
+ ref= " timeTagEl"
3704
3782
data- cy= " time-tag"
3705
3783
class = " vue-ui-xy-time-tag"
3706
3784
: style= " `width: fit-content;margin: 0 auto;text-align:center;padding:3px 12px;background:${FINAL_CONFIG.chart.timeTag.backgroundColor};color:${FINAL_CONFIG.chart.timeTag.color};font-size:${FINAL_CONFIG.chart.timeTag.fontSize}px`"
0 commit comments