File tree Expand file tree Collapse file tree
x-pack/plugins/apm/public
components/shared/TransactionBreakdown/TransactionBreakdownGraph Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 */
66
77import React , { useMemo } from 'react' ;
8- import numeral from '@elastic/numeral' ;
98import { throttle } from 'lodash' ;
109import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n' ;
1110import { Coordinate , TimeSeries } from '../../../../../typings/timeseries' ;
@@ -21,7 +20,7 @@ interface Props {
2120}
2221
2322const tickFormatY = ( y : Maybe < number > ) => {
24- return numeral ( y || 0 ) . format ( '0 %' ) ;
23+ return asPercent ( y ?? 0 , 1 ) ;
2524} ;
2625
2726const formatTooltipValue = ( coordinate : Coordinate ) => {
Original file line number Diff line number Diff line change @@ -8,11 +8,15 @@ import { asPercent } from '../formatters';
88describe ( 'formatters' , ( ) => {
99 describe ( 'asPercent' , ( ) => {
1010 it ( 'should divide and format item as percent' , ( ) => {
11- expect ( asPercent ( 3725 , 10000 , 'n/a' ) ) . toEqual ( '37.3%' ) ;
11+ expect ( asPercent ( 3725 , 10000 , 'n/a' ) ) . toEqual ( '37%' ) ;
12+ } ) ;
13+
14+ it ( 'should add a decimal when value is below 10' , ( ) => {
15+ expect ( asPercent ( 0.092 , 1 ) ) . toEqual ( '9.2%' ) ;
1216 } ) ;
1317
1418 it ( 'should format when numerator is 0' , ( ) => {
15- expect ( asPercent ( 0 , 1 , 'n/a' ) ) . toEqual ( '0.0 %' ) ;
19+ expect ( asPercent ( 0 , 1 , 'n/a' ) ) . toEqual ( '0%' ) ;
1620 } ) ;
1721
1822 it ( 'should return fallback when denominator is undefined' , ( ) => {
Original file line number Diff line number Diff line change @@ -34,5 +34,10 @@ export function asPercent(
3434 }
3535
3636 const decimal = numerator / denominator ;
37+
38+ if ( Math . abs ( decimal ) >= 0.1 || decimal === 0 ) {
39+ return numeral ( decimal ) . format ( '0%' ) ;
40+ }
41+
3742 return numeral ( decimal ) . format ( '0.0%' ) ;
3843}
You can’t perform that action at this time.
0 commit comments