@@ -38,6 +38,7 @@ export interface FunnelChartLabelsProps {
3838 trends ?: FunnelChartMetaData [ 'trends' ] ;
3939 xScale : ScaleBand < string > ;
4040 shouldApplyScaling : boolean ;
41+ showPercentages ?: boolean ;
4142 renderScaleIconTooltipContent ?: ( ) => ReactNode ;
4243}
4344
@@ -56,6 +57,7 @@ export function FunnelChartLabels({
5657 trends,
5758 xScale,
5859 shouldApplyScaling,
60+ showPercentages = true ,
5961 renderScaleIconTooltipContent,
6062} : FunnelChartLabelsProps ) {
6163 const { characterWidths, containerBounds} = useChartContext ( ) ;
@@ -76,11 +78,13 @@ export function FunnelChartLabels({
7678 const currentTargetWidth = isLast
7779 ? barWidth - GROUP_OFFSET * 2
7880 : labelWidth - GROUP_OFFSET * 2 ;
79- const currentPercentWidth = estimateStringWidthWithOffset (
80- percentages [ i ] ,
81- VALUE_FONT_SIZE ,
82- VALUE_FONT_WEIGHT ,
83- ) ;
81+ const currentPercentWidth = showPercentages
82+ ? estimateStringWidthWithOffset (
83+ percentages [ i ] ,
84+ VALUE_FONT_SIZE ,
85+ VALUE_FONT_WEIGHT ,
86+ )
87+ : 0 ;
8488 const currentCountStringWidth = estimateStringWidthWithOffset (
8589 formattedValues [ i ] ,
8690 VALUE_FONT_SIZE ,
@@ -151,6 +155,7 @@ export function FunnelChartLabels({
151155 labelWidth ,
152156 barWidth ,
153157 chartContainerWidth ,
158+ showPercentages ,
154159 ] ) ;
155160
156161 function displayChartLabels (
@@ -161,22 +166,25 @@ export function FunnelChartLabels({
161166 countStringWidth : number ,
162167 trendIndicatorProps : any ,
163168 trendIndicatorWidth : number ,
169+ showPercentages : boolean ,
164170 ) {
165171 if ( layoutStrategy === LAYOUT_STRATEGY . ONE_LINE_ALL ) {
166172 return (
167173 < Fragment >
168- < SingleTextLine
169- color = { TEXT_COLOR }
170- text = { percentages [ index ] }
171- targetWidth = { percentWidth }
172- textAnchor = "start"
173- fontSize = { VALUE_FONT_SIZE }
174- fontWeight = { VALUE_FONT_WEIGHT }
175- />
174+ { showPercentages ? (
175+ < SingleTextLine
176+ color = { TEXT_COLOR }
177+ text = { percentages [ index ] }
178+ targetWidth = { percentWidth }
179+ textAnchor = "start"
180+ fontSize = { VALUE_FONT_SIZE }
181+ fontWeight = { VALUE_FONT_WEIGHT }
182+ />
183+ ) : null }
176184 < SingleTextLine
177185 color = { TEXT_COLOR }
178186 text = { formattedValues [ index ] }
179- x = { percentWidth + LINE_PADDING }
187+ x = { showPercentages ? percentWidth + LINE_PADDING : 0 }
180188 targetWidth = {
181189 currentTargetWidth -
182190 ( percentWidth + LINE_PADDING ) -
@@ -202,19 +210,22 @@ export function FunnelChartLabels({
202210 }
203211
204212 if ( layoutStrategy === LAYOUT_STRATEGY . ONE_LINE_COUNTS_AND_TRENDS ) {
213+ const formattedValueTransformY = showPercentages
214+ ? LINE_HEIGHT + VERTICAL_STACK_SPACING
215+ : 0 ;
205216 return (
206217 < Fragment >
207- < SingleTextLine
208- color = { TEXT_COLOR }
209- text = { percentages [ index ] }
210- targetWidth = { currentTargetWidth }
211- textAnchor = "start"
212- fontSize = { VALUE_FONT_SIZE }
213- fontWeight = { VALUE_FONT_WEIGHT }
214- />
215- < g
216- transform = { `translate(0, ${ LINE_HEIGHT + VERTICAL_STACK_SPACING } )` }
217- >
218+ { showPercentages ? (
219+ < SingleTextLine
220+ color = { TEXT_COLOR }
221+ text = { percentages [ index ] }
222+ targetWidth = { currentTargetWidth }
223+ textAnchor = "start"
224+ fontSize = { VALUE_FONT_SIZE }
225+ fontWeight = { VALUE_FONT_WEIGHT }
226+ />
227+ ) : null }
228+ < g transform = { `translate(0, ${ formattedValueTransformY } )` } >
218229 < SingleTextLine
219230 color = { TEXT_COLOR }
220231 text = { formattedValues [ index ] }
@@ -240,19 +251,25 @@ export function FunnelChartLabels({
240251 }
241252
242253 if ( layoutStrategy === LAYOUT_STRATEGY . VERTICAL_STACKING ) {
254+ const formattedValueTransformY = showPercentages
255+ ? LINE_HEIGHT + VERTICAL_STACK_SPACING
256+ : 0 ;
257+ const trendIndicatorTransformY = showPercentages
258+ ? LINE_HEIGHT * 2 + VERTICAL_STACK_SPACING * 2
259+ : LINE_HEIGHT + VERTICAL_STACK_SPACING * 2 ;
243260 return (
244261 < Fragment >
245- < SingleTextLine
246- color = { TEXT_COLOR }
247- text = { percentages [ index ] }
248- targetWidth = { currentTargetWidth }
249- textAnchor = "start"
250- fontSize = { VALUE_FONT_SIZE }
251- fontWeight = { VALUE_FONT_WEIGHT }
252- />
253- < g
254- transform = { `translate(0, ${ LINE_HEIGHT + VERTICAL_STACK_SPACING } )` }
255- >
262+ { showPercentages ? (
263+ < SingleTextLine
264+ color = { TEXT_COLOR }
265+ text = { percentages [ index ] }
266+ targetWidth = { currentTargetWidth }
267+ textAnchor = "start"
268+ fontSize = { VALUE_FONT_SIZE }
269+ fontWeight = { VALUE_FONT_WEIGHT }
270+ />
271+ ) : null }
272+ < g transform = { `translate(0, ${ formattedValueTransformY } )` } >
256273 < SingleTextLine
257274 color = { TEXT_COLOR }
258275 text = { formattedValues [ index ] }
@@ -264,11 +281,7 @@ export function FunnelChartLabels({
264281 />
265282 </ g >
266283 { trendIndicatorProps && (
267- < g
268- transform = { `translate(0, ${
269- LINE_HEIGHT * 2 + VERTICAL_STACK_SPACING * 2
270- } )`}
271- >
284+ < g transform = { `translate(0, ${ trendIndicatorTransformY } )` } >
272285 < g transform = { `translate(0, ${ - LABEL_VERTICAL_OFFSET } )` } >
273286 < TrendIndicator { ...trendIndicatorProps } />
274287 </ g >
@@ -307,6 +320,8 @@ export function FunnelChartLabels({
307320 const { trendIndicatorProps, trendIndicatorWidth} =
308321 getTrendIndicatorData ( trends ?. [ index ] ?. reached ) ;
309322
323+ const updatedPercentWidth = showPercentages ? percentWidth : 0 ;
324+
310325 return (
311326 < g
312327 transform = { `translate(${
@@ -344,10 +359,11 @@ export function FunnelChartLabels({
344359 layoutStrategy ,
345360 index ,
346361 currentTargetWidth ,
347- percentWidth ,
362+ updatedPercentWidth ,
348363 countStringWidth ,
349364 trendIndicatorProps ,
350365 trendIndicatorWidth ,
366+ showPercentages ,
351367 ) }
352368 </ g >
353369 </ g >
0 commit comments