11import  'package:fl_chart/fl_chart.dart' ;
2+ import  'package:fl_chart/src/chart/base/axis_chart/axis_chart_helper.dart' ;
23import  'package:flutter/material.dart' ;
34import  'package:flutter/scheduler.dart' ;
45
@@ -62,8 +63,6 @@ class _SideTitleWidgetState extends State<SideTitleWidget> {
6263 return  Alignment .centerLeft;
6364 case  AxisSide .bottom: 
6465 return  Alignment .topCenter;
65-  default : 
66-  throw  StateError ('Invalid side' );
6766 }
6867 }
6968
@@ -77,64 +76,12 @@ class _SideTitleWidgetState extends State<SideTitleWidget> {
7776 return  EdgeInsets .only (left:  widget.space);
7877 case  AxisSide .bottom: 
7978 return  EdgeInsets .only (top:  widget.space);
80-  default : 
81-  throw  StateError ('Invalid side' );
82-  }
83-  }
84- 
85-  /// Calculate translate offset to keep child 
86-  /// placed inside its corresponding axis. 
87-  /// The offset will translate the child to the closest edge inside 
88-  /// of the parent 
89-   Offset  _getOffset () {
90-  if  (! widget.fitInside.enabled ||  _childSize ==  null ) return  Offset .zero;
91- 
92-  final  parentAxisSize =  widget.fitInside.parentAxisSize;
93-  final  axisPosition =  widget.fitInside.axisPosition;
94- 
95-  // Find title alignment along its axis 
96-  final  axisMid =  parentAxisSize /  2 ;
97-  final  mainAxisAligment =  (axisPosition -  axisMid).isNegative
98-  ?  MainAxisAlignment .start
99-  :  MainAxisAlignment .end;
100- 
101-  // Find if child widget overflowed outside the chart 
102-  final  childSize =  _childSize! ;
103-  late  bool  isOverflowed;
104-  if  (mainAxisAligment ==  MainAxisAlignment .start) {
105-  isOverflowed =  (axisPosition -  (childSize /  2 )).isNegative;
106-  } else  {
107-  isOverflowed =  (axisPosition +  (childSize /  2 )) >  parentAxisSize;
108-  }
109- 
110-  if  (isOverflowed ==  false ) return  Offset .zero;
111- 
112-  // Calc offset if child overflowed 
113-  late  double  offset;
114-  if  (mainAxisAligment ==  MainAxisAlignment .start) {
115-  offset = 
116-  (childSize /  2 ) -  axisPosition +  widget.fitInside.distanceFromEdge;
117-  } else  {
118-  offset =  - (childSize /  2 ) + 
119-  (parentAxisSize -  axisPosition) - 
120-  widget.fitInside.distanceFromEdge;
121-  }
122- 
123-  switch  (widget.axisSide) {
124-  case  AxisSide .left: 
125-  case  AxisSide .right: 
126-  return  Offset (0 , offset);
127-  case  AxisSide .top: 
128-  case  AxisSide .bottom: 
129-  return  Offset (offset, 0 );
13079 }
13180 }
13281
13382 /// Calculate child width/height 
13483  final  GlobalKey  widgetKey =  GlobalKey ();
135- 
13684 double ?  _childSize;
137- 
13885 void  _getChildSize (_) {
13986 // If fitInside is false, no need to find child size 
14087 if  (! widget.fitInside.enabled) return ;
@@ -179,7 +126,15 @@ class _SideTitleWidgetState extends State<SideTitleWidget> {
179126 @override 
180127 Widget  build (BuildContext  context) {
181128 return  Transform .translate (
182-  offset:  _getOffset (),
129+  offset:  ! widget.fitInside.enabled
130+  ?  Offset .zero
131+  :  AxisChartHelper ().calcFitInsideOffset (
132+  axisSide:  widget.axisSide,
133+  childSize:  _childSize,
134+  parentAxisSize:  widget.fitInside.parentAxisSize,
135+  axisPosition:  widget.fitInside.axisPosition,
136+  distanceFromEdge:  widget.fitInside.distanceFromEdge,
137+  ),
183138 child:  Transform .rotate (
184139 angle:  widget.angle,
185140 child:  Container (
0 commit comments