File tree Expand file tree Collapse file tree
src/web/components/chart/donut Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ interface LabelsProps<TData extends LabelData> {
2626}
2727
2828const LABEL_RADIUS_OFFSET = 10 ;
29- const LABEL_X = 85 ;
29+ const LABEL_EDGE_OFFSET = 15 ;
3030const LABEL_GAP = 16 ;
3131
3232interface LabelPosition {
@@ -115,7 +115,8 @@ const Labels = <TData extends LabelData = LabelData>({
115115 const arcPoint = arc . centroid ( currentArc ) ;
116116 const outerArcPoint = outerArc . centroid ( currentArc ) ;
117117 const { isRightSide, y} = labelPositions [ index ] ;
118- const labelPoint = [ isRightSide ? LABEL_X : - LABEL_X , y ] ;
118+ const labelX = outerRadiusX + LABEL_EDGE_OFFSET ;
119+ const labelPoint = [ isRightSide ? labelX : - labelX , y ] ;
119120 const points = [ arcPoint , outerArcPoint , labelPoint ]
120121 . map ( point => point . join ( ',' ) )
121122 . join ( ' ' ) ;
Original file line number Diff line number Diff line change @@ -45,12 +45,32 @@ describe('Labels', () => {
4545 expect ( document . querySelectorAll ( '.pie-label' ) ) . toHaveLength ( 2 ) ;
4646 } ) ;
4747
48- test ( 'should keep external labels inside the chart edge' , ( ) => {
48+ test ( 'should keep external labels outside the donut edge' , ( ) => {
4949 renderLabels ( [ { toolTip : 'Single slice' , value : 100 } ] ) ;
5050
5151 expect ( screen . getByText ( '100' ) ) . toHaveAttribute (
5252 'transform' ,
53- 'translate(-85,110)' ,
53+ 'translate(-115,110)' ,
54+ ) ;
55+ } ) ;
56+
57+ test ( 'should move labels outside the donut when it grows' , ( ) => {
58+ const { render} = rendererWith ( ) ;
59+ render (
60+ < Labels
61+ centerX = { 150 }
62+ centerY = { 150 }
63+ data = { [ { toolTip : 'Single slice' , value : 100 } ] }
64+ innerRadiusX = { 191 }
65+ innerRadiusY = { 191 }
66+ outerRadiusX = { 294 }
67+ outerRadiusY = { 294 }
68+ /> ,
69+ ) ;
70+
71+ expect ( screen . getByText ( '100' ) ) . toHaveAttribute (
72+ 'transform' ,
73+ 'translate(-309,304)' ,
5474 ) ;
5575 } ) ;
5676
You can’t perform that action at this time.
0 commit comments