@@ -67,6 +67,28 @@ const SPECIALTY_OPTIONS = [
6767 { value : 'Other' , label : 'Other' }
6868] ;
6969
70+ // Helper function to calculate proper chart domain bounds
71+ const calculateChartDomain = ( data ) => {
72+ if ( ! data || data . length === 0 ) return [ - 0.01 , 0.01 ] ;
73+
74+ const values = data . map ( d => d . value ) . filter ( v => Number . isFinite ( v ) ) ;
75+ if ( values . length === 0 ) return [ - 0.01 , 0.01 ] ;
76+
77+ const min = Math . min ( ...values ) ;
78+ const max = Math . max ( ...values ) ;
79+ const range = max - min ;
80+
81+ // Handle very small ranges to prevent scaling issues
82+ if ( Math . abs ( range ) < 0.001 ) {
83+ return [ - 0.005 , 0.005 ] ;
84+ }
85+
86+ // Add padding to prevent bars from touching the edges
87+ const padding = Math . max ( range * 0.1 , 0.001 ) ;
88+
89+ return [ min - padding , max + padding ] ;
90+ } ;
91+
7092const DashboardPage = ( ) => {
7193 const [ user ] = useAuthState ( auth ) ;
7294
@@ -397,13 +419,21 @@ const DashboardPage = () => {
397419 const selectedResult = results [ selectedIndex ] || null ;
398420 const chartData = useMemo ( ( ) => {
399421 if ( ! selectedResult || ! selectedResult . top_contributions ) return [ ] ;
400- const items = selectedResult . top_contributions . map ( ( c ) => ( {
401- feature : c . feature . split ( '__' ) . slice ( - 1 ) [ 0 ] ,
402- value : c . shap_value ,
403- direction : c . shap_value >= 0 ? 'positive' : 'negative'
404- } ) ) ;
422+
423+ const items = selectedResult . top_contributions
424+ . filter ( c => c && typeof c . shap_value === 'number' && Number . isFinite ( c . shap_value ) )
425+ . map ( ( c ) => ( {
426+ feature : c . feature ? c . feature . split ( '__' ) . slice ( - 1 ) [ 0 ] : 'Unknown' ,
427+ value : parseFloat ( c . shap_value ) || 0 ,
428+ direction : c . shap_value >= 0 ? 'positive' : 'negative'
429+ } ) ) ;
430+
405431 // Sort by absolute impact descending
406432 items . sort ( ( a , b ) => Math . abs ( b . value ) - Math . abs ( a . value ) ) ;
433+
434+ // Ensure we have valid data for chart scaling
435+ if ( items . length === 0 ) return [ ] ;
436+
407437 return items ;
408438 } , [ selectedResult ] ) ;
409439
@@ -708,11 +738,26 @@ const DashboardPage = () => {
708738 < span className = "inline-block w-3 h-3 rounded-sm ml-3" style = { { background : '#10b981' } } > </ span > decreases risk
709739 </ div >
710740 </ div >
711- < div className = "w-full h-96" >
741+ < div className = "w-full h-[500px]" >
742+ { /* Debug info for chart scaling */ }
743+ { chartData . length > 0 && (
744+ < div className = "text-xs text-gray-500 mb-2 text-center" >
745+ Chart range: { calculateChartDomain ( chartData ) [ 0 ] . toFixed ( 6 ) } to { calculateChartDomain ( chartData ) [ 1 ] . toFixed ( 6 ) }
746+ </ div >
747+ ) }
712748 < ResponsiveContainer width = "100%" height = "100%" >
713- < BarChart data = { chartData } layout = "vertical" margin = { { top : 10 , right : 30 , left : 10 , bottom : 10 } } >
749+ < BarChart data = { chartData } layout = "vertical" margin = { { top : 20 , right : 80 , left : 20 , bottom : 20 } } >
714750 < CartesianGrid strokeDasharray = "3 3" />
715- < XAxis type = "number" tickFormatter = { ( v ) => ( Number . isFinite ( v ) ? Number ( v ) . toFixed ( 2 ) : v ) } domain = { [ 'auto' , 'auto' ] } />
751+ < XAxis
752+ type = "number"
753+ tickFormatter = { ( v ) => ( Number . isFinite ( v ) ? Number ( v ) . toFixed ( 4 ) : v ) }
754+ domain = { calculateChartDomain ( chartData ) }
755+ ticks = { chartData . length > 0 ? [
756+ calculateChartDomain ( chartData ) [ 0 ] ,
757+ 0 ,
758+ calculateChartDomain ( chartData ) [ 1 ]
759+ ] : [ ] }
760+ />
716761 < YAxis type = "category" dataKey = "feature" width = { 180 } />
717762 < Tooltip formatter = { ( value , name ) => [ Number ( value ) . toFixed ( 4 ) , 'SHAP' ] } labelFormatter = { ( lbl ) => `Feature: ${ lbl } ` } />
718763 < ReferenceLine x = { 0 } stroke = "#94a3b8" />
@@ -721,7 +766,7 @@ const DashboardPage = () => {
721766 { chartData . map ( ( entry , index ) => (
722767 < Cell key = { `cell-${ index } ` } fill = { colorFor ( entry . value ) } />
723768 ) ) }
724- < LabelList dataKey = "value" position = "right" formatter = { ( v ) => Number ( v ) . toFixed ( 3 ) } className = "text-xs" />
769+ < LabelList dataKey = "value" position = "right" formatter = { ( v ) => Number ( v ) . toFixed ( 4 ) } className = "text-xs" />
725770 </ Bar >
726771 </ BarChart >
727772 </ ResponsiveContainer >
0 commit comments