@@ -23,6 +23,7 @@ import { Entity, SegmentedBarChartProps } from './types'
2323import './styles.scss'
2424
2525const SegmentedBarChart : React . FC < SegmentedBarChartProps > = ( {
26+ hideLegend,
2627 entities : userEntities = [ FALLBACK_ENTITY ] ,
2728 rootClassName,
2829 countClassName,
@@ -36,7 +37,7 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
3637 const total = entities . reduce ( ( sum , entity ) => entity . value + sum , 0 )
3738 const filteredEntities = entities . filter ( ( entity ) => ! ! entity . value )
3839
39- const calcSegmentWidth = ( entity : Entity ) => `${ ( entity . value / total ) * 100 } %`
40+ const calcSegmentWidth = ( entityValue : Entity [ 'value' ] ) => `${ ( entityValue / total ) * 100 } %`
4041
4142 const renderLabel = ( label : Entity [ 'label' ] ) =>
4243 isLoading ? (
@@ -88,11 +89,17 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
8889 ) )
8990 }
9091
91- const renderLegend = ( ) => (
92- < div className = { `flexbox flex-wrap dc__row-gap-4 ${ isProportional ? 'dc__gap-24' : 'dc__gap-16' } ` } >
93- { renderContent ( ) }
94- </ div >
95- )
92+ const renderLegend = ( ) => {
93+ if ( hideLegend ) {
94+ return null
95+ }
96+
97+ return (
98+ < div className = { `flexbox flex-wrap dc__row-gap-4 ${ isProportional ? 'dc__gap-24' : 'dc__gap-16' } ` } >
99+ { renderContent ( ) }
100+ </ div >
101+ )
102+ }
96103
97104 const renderBar = ( ) => (
98105 < motion . div
@@ -112,7 +119,7 @@ const SegmentedBarChart: React.FC<SegmentedBarChartProps> = ({
112119 className = { `h-8 ${ index === 0 ? 'dc__left-radius-4' : '' } ${
113120 index === map . length - 1 ? 'dc__right-radius-4' : ''
114121 } ${ isLoading ? 'shimmer' : '' } `}
115- style = { { backgroundColor : entity . color , width : calcSegmentWidth ( entity ) } }
122+ style = { { backgroundColor : entity . color , width : calcSegmentWidth ( entity . value ) } }
116123 />
117124 ) ) }
118125 </ motion . div >
0 commit comments