@@ -32,15 +32,14 @@ export const transformCartesianSeries = (
3232 }
3333 }
3434 // The threshold series require data points to enable keyboard navigation and hover effects.
35- // For y-threshold we find all defined x values from other series and use it those to create an array of
36- // data points. As result, the y-threshold series becomes properly navigable.
37- const xs = getAllX ( originalSeries , visibleSeries ) ;
38- // For x-threshold the point-based navigation is disabled as irrelevant. However, we still need at least
39- // one data point for core chart to work correctly, so we find the first visible y value from other series.
40- const ys = getFirstY ( originalSeries , visibleSeries ) ;
35+ const thresholdX = getThresholdX ( originalSeries , visibleSeries ) ;
36+ const thresholdY = getThresholdY ( originalSeries , visibleSeries ) ;
4137 function transformSeriesToHighcharts ( s : CartesianChartProps . SeriesOptions ) : Highcharts . SeriesOptionsType {
4238 if ( s . type === "x-threshold" || s . type === "y-threshold" ) {
43- const data = s . type === "x-threshold" ? ys . map ( ( y ) => ( { x : s . value , y } ) ) : xs . map ( ( x ) => ( { x, y : s . value } ) ) ;
39+ const data =
40+ s . type === "x-threshold"
41+ ? thresholdY . map ( ( y ) => ( { x : s . value , y } ) )
42+ : thresholdX . map ( ( x ) => ( { x, y : s . value } ) ) ;
4443 const { custom } = createThresholdMetadata ( s . type , s . value ) ;
4544 const enableMouseTracking = s . type === "y-threshold" ;
4645 const style = { ...Styles . thresholdSeries , color : s . color ?? Styles . thresholdSeries . color } ;
@@ -62,7 +61,9 @@ export const transformCartesianSeries = (
6261 return { series, xPlotLines, yPlotLines } ;
6362} ;
6463
65- function getFirstY ( series : readonly CartesianChartProps . SeriesOptions [ ] , visibleSeries : readonly string [ ] ) {
64+ // For x-threshold the point-based navigation is disabled as irrelevant. However, we still need at least
65+ // one data point for core chart to work correctly, so we find the first visible y value from other series.
66+ function getThresholdY ( series : readonly CartesianChartProps . SeriesOptions [ ] , visibleSeries : readonly string [ ] ) {
6667 for ( const s of getVisibleDataSeries ( series , visibleSeries ) ) {
6768 for ( const d of s . data ) {
6869 const y = d === null ? null : typeof d === "number" ? d : d . y ;
@@ -74,7 +75,9 @@ function getFirstY(series: readonly CartesianChartProps.SeriesOptions[], visible
7475 return [ ] ;
7576}
7677
77- function getAllX ( series : readonly CartesianChartProps . SeriesOptions [ ] , visibleSeries : readonly string [ ] ) {
78+ // For y-threshold we find all defined x values from other series and use it those to create an array of
79+ // data points. As result, the y-threshold series becomes properly navigable.
80+ function getThresholdX ( series : readonly CartesianChartProps . SeriesOptions [ ] , visibleSeries : readonly string [ ] ) {
7881 const allX = new Set < number > ( ) ;
7982 for ( const s of getVisibleDataSeries ( series , visibleSeries ) ) {
8083 for ( let i = 0 ; i < s . data . length ; i ++ ) {
0 commit comments