File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -444,19 +444,37 @@ export const generateRuntimeLegend = (
444444 let number = row [ columns . primary . name ]
445445 let assigned = false
446446
447- // Find the correct range for this value - ranges don't overlap anymore
447+ // Find the correct range for this value - check both boundaries
448448 for ( let itemIndex = 0 ; itemIndex < result . items . length ; itemIndex ++ ) {
449449 const item = result . items [ itemIndex ]
450450
451451 if ( item . min === undefined || item . max === undefined ) continue
452452
453- // Simple range check since ranges don't overlap
453+ // Check if value falls within range (inclusive of both min and max)
454454 if ( number >= item . min && number <= item . max ) {
455455 newLegendMemo . set ( hashObj ( row ) , itemIndex )
456456 assigned = true
457457 break
458458 }
459459 }
460+
461+ // Fallback: if still not assigned, assign to closest range
462+ if ( ! assigned ) {
463+ console . warn ( 'Value not assigned to any range:' , number , 'assigning to closest range' )
464+ let closestIndex = 0
465+ let minDistance = Math . abs ( number - ( ( result . items [ 0 ] . min + result . items [ 0 ] . max ) / 2 ) )
466+
467+ for ( let i = 1 ; i < result . items . length ; i ++ ) {
468+ const midpoint = ( result . items [ i ] . min + result . items [ i ] . max ) / 2
469+ const distance = Math . abs ( number - midpoint )
470+ if ( distance < minDistance ) {
471+ minDistance = distance
472+ closestIndex = i
473+ }
474+ }
475+
476+ newLegendMemo . set ( hashObj ( row ) , closestIndex )
477+ }
460478 }
461479 } )
462480 }
You can’t perform that action at this time.
0 commit comments