@@ -9,6 +9,15 @@ import { SatsFlowPeriod } from '../../../../types/bookkeeper.type';
99import { useSelector } from 'react-redux' ;
1010import { selectUIConfigUnit } from '../../../../store/rootSelectors' ;
1111
12+ const ALL_EVENTS_VALUES = [
13+ { name : 'routed' , dataKey : 'routed' , fill : "rgba(201, 222, 83, 1)" } ,
14+ { name : 'invoice_fee' , dataKey : 'invoice_fee' , fill : "rgba(237, 88, 59, 1)" } ,
15+ { name : 'received_invoice' , dataKey : 'received_invoice' , fill : "rgba(121, 203, 96, 1)" } ,
16+ { name : 'paid_invoice' , dataKey : 'paid_invoice' , fill : "rgba(240, 147, 46, 1)" } ,
17+ { name : 'deposit' , dataKey : 'deposit' , fill : "rgba(0, 198, 160, 1)" } ,
18+ { name : 'onchain_fee' , dataKey : 'onchain_fee' , fill : "rgba(242, 207, 32, 1)" } ,
19+ ] ;
20+
1221const SatsFlowGraphTooltip = ( { active, payload, label, unit, periods } : any ) => {
1322 if ( active && payload && payload . length >= 0 ) {
1423 const period = periods . find ( d => d . period_key === label ) ;
@@ -32,41 +41,36 @@ const SatsFlowGraphTooltip = ({ active, payload, label, unit, periods }: any) =>
3241 return null ;
3342 }
3443 } ) }
35- </ div >
44+ </ div >
3645 ) ;
3746 }
3847 return null ;
3948} ;
4049
41- const SatsFlowGraphLegend = ( props : any ) => {
42- const { payload } = props ;
50+ const SatsFlowGraphLegend = ( { eventValues } : { eventValues : typeof ALL_EVENTS_VALUES } ) => {
4351 return (
4452 < Row className = 'gx-3 gy-1 justify-content-center align-items-center' >
45- { payload
46- . filter ( ( entry : any ) => entry . value !== 'net_inflow_msat' )
47- . map ( ( entry : any , index : number ) => (
48- < Col key = { `item-${ index } ` } xs = 'auto' className = 'col-sats-flow-lagend d-flex align-items-center' >
49- < div className = 'sats-flow-lagend-bullet' style = { { backgroundColor : entry . color } } />
50- < span className = 'span-sats-flow-lagend' > { titleCase ( entry . value . replace ( / _ / g, ' ' ) ) } </ span >
51- </ Col >
52- ) )
53- }
53+ { eventValues . map ( ( entry , index ) => (
54+ < Col key = { `item-${ index } ` } xs = 'auto' className = 'col-sats-flow-lagend d-flex align-items-center' >
55+ < div className = 'sats-flow-lagend-bullet' style = { { backgroundColor : entry . fill } } />
56+ < span className = 'span-sats-flow-lagend' > { titleCase ( entry . name . replace ( / _ / g, ' ' ) ) } </ span >
57+ </ Col >
58+ ) ) }
5459 </ Row >
55- )
60+ ) ;
5661} ;
5762
5863const CustomActiveDot = ( props ) => < circle cx = { props . cx } cy = { props . cy } r = { 4 } fill = "var(--bs-body-color)" /> ;
5964
60- function SatsFlowGraph ( { periods} : { periods : SatsFlowPeriod [ ] } ) {
65+ function SatsFlowGraph ( { periods } : { periods : SatsFlowPeriod [ ] } ) {
6166 const uiConfigUnit = useSelector ( selectUIConfigUnit ) ;
62- const barValues = [
63- { name : 'routed' , dataKey : 'routed' , fill : "rgba(201, 222, 83, 1)" } ,
64- { name : 'invoice_fee' , dataKey : 'invoice_fee' , fill : "rgba(237, 88, 59, 1)" } ,
65- { name : 'received_invoice' , dataKey : 'received_invoice' , fill : "rgba(121, 203, 96, 1)" } ,
66- { name : 'paid_invoice' , dataKey : 'paid_invoice' , fill : "rgba(240, 147, 46, 1)" } ,
67- { name : 'deposit' , dataKey : 'deposit' , fill : "rgba(0, 198, 160, 1)" } ,
68- { name : 'onchain_fee' , dataKey : 'onchain_fee' , fill : "rgba(242, 207, 32, 1)" }
69- ] ;
67+ const eventValues = useMemo ( ( ) => {
68+ const presentTags = new Set (
69+ periods . flatMap ( period => period . tag_groups . map ( group => group . tag ) )
70+ ) ;
71+ return ALL_EVENTS_VALUES . filter ( bar => presentTags . has ( bar . name ) ) ;
72+ } , [ periods ] ) ;
73+
7074 const data = useMemo ( ( ) => transformSatsFlowGraphData ( periods ) , [ periods ] ) ;
7175
7276 return (
@@ -79,22 +83,22 @@ function SatsFlowGraph({periods}: {periods: SatsFlowPeriod[]}) {
7983 >
8084 < CartesianGrid strokeDasharray = '3 3' />
8185 < XAxis dataKey = 'name' />
82- < YAxis
86+ < YAxis
8387 tickFormatter = { ( value ) => {
8488 const formatted = formatCurrency ( value , Units . MSATS , uiConfigUnit , false , 0 , 'string' ) ;
8589 return typeof formatted === 'string' ? formatted : String ( formatted ) ;
8690 } }
8791 />
8892 < Tooltip content = { < SatsFlowGraphTooltip unit = { uiConfigUnit } periods = { periods } /> } />
89- < Legend content = { SatsFlowGraphLegend } />
90- { barValues . map ( ( value : any ) => (
93+ < Legend content = { < SatsFlowGraphLegend eventValues = { eventValues } /> } />
94+ { eventValues . map ( ( value : any ) => (
9195 < Bar name = { value . name } key = { value . name } dataKey = { value . dataKey } stackId = 'bar' fill = { value . fill } />
9296 ) ) }
9397 < Line className = 'series-net-inflow' type = 'monotone' dataKey = 'net_inflow_msat' activeDot = { < CustomActiveDot /> } />
9498 </ ComposedChart >
9599 </ ResponsiveContainer >
96100 </ div >
97101 ) ;
98- } ;
102+ }
99103
100104export default memo ( SatsFlowGraph ) ;
0 commit comments