@@ -22,12 +22,14 @@ export default function PriceRangeChart({
2222 dateLabels,
2323 availableDates,
2424 loading = false ,
25- enableItemNavigation = true
25+ enableItemNavigation = true ,
26+ onSelectedDatePosition
2627} ) {
2728 const chartRef = useRef ( null ) ;
2829 const chartInstance = useRef ( null ) ;
2930 const labelsContainerRef = useRef ( null ) ;
3031 const dateLabelsContainerRef = useRef ( null ) ;
32+ const chartContainerRef = useRef ( null ) ;
3133 const [ dotSizeMode , setDotSizeMode ] = useState ( 'stock' ) ;
3234 const [ showItemLabels , setShowItemLabels ] = useState ( ( ) => {
3335 if ( typeof window === 'undefined' ) {
@@ -758,6 +760,22 @@ export default function PriceRangeChart({
758760 const xScale = chart . scales . x ;
759761 const yScale = chart . scales . y ;
760762
763+ // Find and report selected date position first
764+ if ( selectedDate && onSelectedDatePosition && chartRef . current ) {
765+ const selectedIndex = dates . findIndex ( ( date , index ) => {
766+ const grouped = datasets [ 0 ] ?. groupedDatesSeries ?. [ index ] || [ date ] ;
767+ return date === selectedDate || grouped . includes ( selectedDate ) ;
768+ } ) ;
769+
770+ if ( selectedIndex >= 0 ) {
771+ const xPos = xScale . getPixelForValue ( selectedIndex ) ;
772+ const canvas = chartRef . current ;
773+ const canvasRect = canvas . getBoundingClientRect ( ) ;
774+ const viewportX = canvasRect . left + xPos ;
775+ onSelectedDatePosition ( viewportX ) ;
776+ }
777+ }
778+
761779 const clickableDates = dates . filter ( ( date , index ) => {
762780 const axisLabel = formatAxisLabel ( index ) ;
763781 if ( ! axisLabel ) {
@@ -800,6 +818,8 @@ export default function PriceRangeChart({
800818
801819 if ( isSelected && hasData ) {
802820 linkEl . classList . add ( 'selected' ) ;
821+ // This position reporting is now done earlier in the afterDatasetsDraw hook
822+ // to ensure it happens on every chart render
803823 }
804824 if ( ! hasData ) {
805825 linkEl . classList . add ( 'disabled' ) ;
@@ -819,13 +839,7 @@ export default function PriceRangeChart({
819839 const textSpan = document . createElement ( 'span' ) ;
820840 textSpan . textContent = axisLabel ;
821841
822- const chevron = document . createElement ( 'span' ) ;
823- chevron . textContent = '›' ;
824- chevron . style . fontSize = '12px' ;
825- chevron . style . opacity = '0.6' ;
826-
827842 linkEl . appendChild ( textSpan ) ;
828- linkEl . appendChild ( chevron ) ;
829843
830844 if ( hasData ) {
831845 linkEl . style . cursor = 'pointer' ;
@@ -974,7 +988,7 @@ export default function PriceRangeChart({
974988 } ) }
975989 </ div >
976990 ) }
977- < div className = "chart-container" >
991+ < div className = "chart-container" ref = { chartContainerRef } >
978992 { loading && ( ! datasets || datasets . length === 0 ) && (
979993 < div className = "chart-loading" > Loading price data...</ div >
980994 ) }
0 commit comments