@@ -30,9 +30,11 @@ class LayeredChartState extends State<LayeredChart> {
3030 List <Path > paths;
3131 List <Path > capPaths;
3232 List <double > maxValues;
33+ List <TextPainter > labelPainter;
34+ List <TextPainter > milestonePainter;
3335 Size lastSize = null ;
3436
35- void buildPaths (Size size, List <DataSeries > dataToPlot, int numPoints, double graphHeight, double graphGap, double margin, double theta, double capTheta, double capSize) {
37+ void buildPaths (Size size, List <DataSeries > dataToPlot, List < Milestone > milestones, int numPoints, double graphHeight, double graphGap, double margin, double theta, double capTheta, double capSize) {
3638 int m = dataToPlot.length;
3739 paths = new List <Path >(m);
3840 capPaths = new List <Path >(m);
@@ -110,6 +112,20 @@ class LayeredChartState extends State<LayeredChart> {
110112 capPaths[i].lineTo (startX, startY + 1 );
111113 capPaths[i].close ();
112114 }
115+ labelPainter = new List <TextPainter >();
116+ for (int i = 0 ; i < dataToPlot.length; i++ ) {
117+ TextSpan span = new TextSpan (style: new TextStyle (color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 12 ), text: dataToPlot[i].label.toUpperCase ());
118+ TextPainter tp = new TextPainter (text: span, textAlign: TextAlign .left, textDirection: TextDirection .ltr);
119+ tp.layout ();
120+ labelPainter.add (tp);
121+ }
122+ milestonePainter = new List <TextPainter >();
123+ for (int i = 0 ; i < milestones.length; i++ ) {
124+ TextSpan span = new TextSpan (style: new TextStyle (color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 10 ), text: milestones[i].label.toUpperCase ());
125+ TextPainter tp = new TextPainter (text: span, textAlign: TextAlign .left, textDirection: TextDirection .ltr);
126+ tp.layout ();
127+ milestonePainter.add (tp);
128+ }
113129 lastSize = new Size (size.width, size.height);
114130 }
115131
@@ -142,9 +158,6 @@ class ChartPainter extends CustomPainter {
142158
143159 LayeredChartState state;
144160
145- List <TextPainter > labelPainter;
146- List <TextPainter > milestonePainter;
147-
148161 ChartPainter (this .state, this .dataToPlot, this .milestones, this .margin, this .graphHeight, this .graphGap, double degrees, double capDegrees, this .capSize, this .numPoints, this .amount) {
149162 this .theta = pi * degrees / 180 ;
150163 this .capTheta = pi * capDegrees / 180 ;
@@ -158,20 +171,6 @@ class ChartPainter extends CustomPainter {
158171 milestonePaint.color = new Color (0xAAFFFFFF );
159172 milestonePaint.style = PaintingStyle .stroke;
160173 milestonePaint.strokeWidth = 1 ;
161- labelPainter = new List <TextPainter >();
162- for (int i = 0 ; i < dataToPlot.length; i++ ) {
163- TextSpan span = new TextSpan (style: new TextStyle (color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 12 ), text: dataToPlot[i].label.toUpperCase ());
164- TextPainter tp = new TextPainter (text: span, textAlign: TextAlign .left, textDirection: TextDirection .ltr);
165- tp.layout ();
166- labelPainter.add (tp);
167- }
168- milestonePainter = new List <TextPainter >();
169- for (int i = 0 ; i < milestones.length; i++ ) {
170- TextSpan span = new TextSpan (style: new TextStyle (color: Color .fromARGB (255 , 255 , 255 , 255 ), fontSize: 10 ), text: milestones[i].label.toUpperCase ());
171- TextPainter tp = new TextPainter (text: span, textAlign: TextAlign .left, textDirection: TextDirection .ltr);
172- tp.layout ();
173- milestonePainter.add (tp);
174- }
175174 }
176175
177176 @override
@@ -182,7 +181,7 @@ class ChartPainter extends CustomPainter {
182181 }
183182 if (state.lastSize == null || size.width != state.lastSize.width || size.height != state.lastSize.height) {
184183 print ("Building paths, lastsize = ${state .lastSize }" );
185- state.buildPaths (size, dataToPlot, numPoints, graphHeight, graphGap, margin, theta, capTheta, capSize);
184+ state.buildPaths (size, dataToPlot, milestones, numPoints, graphHeight, graphGap, margin, theta, capTheta, capSize);
186185 }
187186 // Using the 900 version of the Material color for the main color, and the 500 version for the cap
188187 List <Color > colors = [
@@ -230,7 +229,7 @@ class ChartPainter extends CustomPainter {
230229 y1 += graphGap * 0.5 ;
231230 canvas.drawLine (new Offset (x1, y1), new Offset (x2, y2), milestonePaint);
232231 canvas.save ();
233- TextPainter tp = milestonePainter[i];
232+ TextPainter tp = state. milestonePainter[i];
234233 canvas.translate (x1 - tp.width / 2 , y1);
235234 canvas.skew (capTheta * 1.0 , - theta);
236235 tp.paint (canvas, new Offset (0 , 0 ));
@@ -258,14 +257,15 @@ class ChartPainter extends CustomPainter {
258257 // Vertical approach
259258// canvas.translate(startX + 25, startY - 2);
260259// canvas.skew(0 * pi / 180, -theta);
261- TextPainter tp = labelPainter[i];
260+ TextPainter tp = state. labelPainter[i];
262261 tp.paint (canvas, new Offset (0 , 0 ));
263262 canvas.restore ();
264263 }
265264
266265 Paint testPaint = new Paint ();
267266 testPaint.style = PaintingStyle .fill;
268267 testPaint.color = new Color .fromARGB (128 , 255 , 0 , 255 );
268+
269269 Path clipPath = new Path ();
270270 clipPath.moveTo (startX, startY + 1 );
271271 clipPath.lineTo (endX, endY + 1 );
0 commit comments