@@ -7,7 +7,7 @@ import Callout from "../../../../../../components/callout";
77import ChartWrapper from "../../../../../../components/chart-wrapper" ;
88import { getCssColor } from "../../../../../../utils/colors" ;
99import { type OutcomesFilterField , type OutcomesFluxLink , useOutcomesFlux } from "../../../../api" ;
10- import { createSankeyOptions } from "./options" ;
10+ import { createSankeyOptions , SITUATION_ORDER } from "./options" ;
1111
1212interface SankeyChartProps {
1313 exportMetadata ?: {
@@ -192,11 +192,32 @@ function SankeyChartView({
192192 } ;
193193 } , [ exportMetadata ?. filtersText , links , totalStudents ] ) ;
194194
195+ const presentSituations = useMemo ( ( ) => {
196+ const set = new Set < string > ( ) ;
197+ links . forEach ( ( l ) => {
198+ if ( l . source_situation ) set . add ( l . source_situation ) ;
199+ if ( l . target_situation ) set . add ( l . target_situation ) ;
200+ } ) ;
201+ return [ ...set ] . sort ( ( a , b ) => ( SITUATION_ORDER [ a ] ?? 99 ) - ( SITUATION_ORDER [ b ] ?? 99 ) ) ;
202+ } , [ links ] ) ;
203+
195204 if ( ! options ) return null ;
196205
206+ const legend = (
207+ < div className = "outcomes-flux-sankey__legend" >
208+ { presentSituations . map ( ( sit ) => (
209+ < span key = { sit } className = "outcomes-flux-sankey__legend-item" >
210+ < span className = { `outcomes-flux-sankey__legend-color outcomes-flux-sankey__legend-color--${ sit } ` } />
211+ { SITUATION_LABELS [ sit ] || sit }
212+ </ span >
213+ ) ) }
214+ </ div >
215+ ) ;
216+
197217 return (
198218 < ChartWrapper
199219 hideTitle = { hideTitle }
220+ legend = { legend }
200221 config = { {
201222 id : "outcomes-flux-sankey" ,
202223 integrationURL : `/integration?chart_id=outcomesFluxSankey&${ searchParams . toString ( ) } ` ,
0 commit comments