Skip to content

Commit a63a8e4

Browse files
committed
Show milestones on timeline. Add repo public milestone.
1 parent 5e4e6b6 commit a63a8e4

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

lib/constants.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import 'package:flutter_web/material.dart';
12
import 'package:flutter_web_ui/ui.dart';
23

34
class Constants {
45
static final Color backgroundColor = const Color(0xFF000020);
6+
static final Color timelineLineColor = Colors.white;
7+
static final Color milestoneColor = new Color(0x40FFFFFF);
58
}

lib/layered_chart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ChartPainter extends CustomPainter {
172172
textPaint = new Paint();
173173
textPaint.color = new Color(0xFFFFFFFF);
174174
milestonePaint = new Paint();
175-
milestonePaint.color = new Color(0x40FFFFFF);
175+
milestonePaint.color = Constants.milestoneColor;
176176
milestonePaint.style = PaintingStyle.stroke;
177177
milestonePaint.strokeWidth = 2;
178178
linePaint = new Paint();

lib/main.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,20 @@ class _MainLayoutState extends State<MainLayout>
5252
_animation.addListener(() {
5353
setState(() {
5454
animationValue = _animation.value;
55-
interpolatedAnimationValue = interpolator.get(animationValue);
55+
// interpolatedAnimationValue = interpolator.get(animationValue);
5656
});
5757
// print("New anim value ${value}");
5858
});
5959

6060
weekLabels = new List();
6161
weekLabels.add(WeekLabel.forDate(new DateTime(2019, 2, 26), "v1.2"));
6262
weekLabels.add(WeekLabel.forDate(new DateTime(2018, 12, 4), "v1.0"));
63-
weekLabels.add(WeekLabel.forDate(new DateTime(2018, 9, 19), "Preview 2"));
64-
// weekLabels.add(WeekLabel.forDate(new DateTime(2018, 6, 21), "Preview 1"));
63+
// weekLabels.add(WeekLabel.forDate(new DateTime(2018, 9, 19), "Preview 2"));
64+
weekLabels.add(WeekLabel.forDate(new DateTime(2018, 6, 21), "Preview 1"));
6565
// weekLabels.add(WeekLabel.forDate(new DateTime(2018, 5, 7), "Beta 3"));
6666
weekLabels.add(WeekLabel.forDate(new DateTime(2018, 2, 27), "Beta 1"));
6767
weekLabels.add(WeekLabel.forDate(new DateTime(2017, 5, 1), "Alpha"));
68+
weekLabels.add(new WeekLabel(48, "Repo Made Public"));
6869

6970
loadGitHubData();
7071
}
@@ -110,7 +111,7 @@ class _MainLayoutState extends State<MainLayout>
110111

111112
LayeredChart layeredChart = new LayeredChart(dataToPlot, weekLabels, interpolatedAnimationValue);
112113

113-
Timeline timeline = new Timeline(dataToPlot != null && dataToPlot.length > 0 ? dataToPlot.last.series.length : 0, interpolatedAnimationValue);
114+
Timeline timeline = new Timeline(dataToPlot != null && dataToPlot.length > 0 ? dataToPlot.last.series.length : 0, interpolatedAnimationValue, weekLabels);
114115

115116
Column mainColumn = new Column(
116117
mainAxisAlignment: MainAxisAlignment.center,

lib/timeline.dart

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import 'package:flutter_web.examples.github_dataviz/constants.dart';
12
import 'package:flutter_web.examples.github_dataviz/data/contribution_data.dart';
3+
import 'package:flutter_web.examples.github_dataviz/data/week_label.dart';
24
import 'package:flutter_web/material.dart';
35

46
class Timeline extends StatefulWidget {
57
int numWeeks;
68
double animationValue;
7-
8-
Timeline(this.numWeeks, this.animationValue);
9+
List<WeekLabel> weekLabels;
10+
11+
Timeline(this.numWeeks, this.animationValue, this.weekLabels);
912

1013
@override
1114
State<StatefulWidget> createState() {
@@ -17,39 +20,49 @@ class TimelineState extends State<Timeline> {
1720
@override
1821
Widget build(BuildContext context) {
1922
return new Container(
20-
child: new CustomPaint(foregroundPainter: new TimelinePainter(widget.numWeeks, widget.animationValue), child: new Container(height: 200,)));
23+
child: new CustomPaint(
24+
foregroundPainter: new TimelinePainter(widget.numWeeks, widget.animationValue, widget.weekLabels),
25+
child: new Container(height: 200,))
26+
);
2127
}
2228
}
2329

2430
class TimelinePainter extends CustomPainter {
2531

2632
Paint mainLinePaint;
33+
Paint milestoneLinePaint;
2734

2835
Color lineColor = Colors.white;
2936

3037
int numWeeks;
3138
double animationValue;
3239
int weekYearOffset = 9; // Week 0 in our data is 9 weeks before the year boundary (i.e. week 43)
3340

41+
List<WeekLabel> weekLabels;
42+
3443
int yearNumber = 2015;
3544

36-
TimelinePainter(this.numWeeks, this.animationValue) {
45+
TimelinePainter(this.numWeeks, this.animationValue, this.weekLabels) {
3746
mainLinePaint = new Paint();
3847
mainLinePaint.style = PaintingStyle.stroke;
39-
mainLinePaint.color = lineColor;
48+
mainLinePaint.color = Constants.timelineLineColor;
49+
milestoneLinePaint = new Paint();
50+
milestoneLinePaint.style = PaintingStyle.stroke;
51+
milestoneLinePaint.color = Constants.milestoneColor;
4052
}
4153

4254
@override
4355
void paint(Canvas canvas, Size size) {
4456

45-
double yearHeight = 20;
57+
double labelHeight = 20;
58+
double labelHeightDoubled = labelHeight*2;
4659

4760
double mainLineY = size.height/2;
4861
canvas.drawLine(new Offset(0, mainLineY), new Offset(size.width, mainLineY), mainLinePaint);
4962

5063
{
5164
double currWeekX = size.width * animationValue;
52-
canvas.drawLine(new Offset(currWeekX, yearHeight), new Offset(currWeekX, size.height - yearHeight), mainLinePaint);
65+
canvas.drawLine(new Offset(currWeekX, labelHeightDoubled), new Offset(currWeekX, size.height - labelHeightDoubled), mainLinePaint);
5366
}
5467

5568
{
@@ -60,7 +73,7 @@ class TimelinePainter extends CustomPainter {
6073
// Year
6174
isYear = true;
6275
lineHeight = size.height/2;
63-
} else if (week % 4 == 0) {
76+
} else if ((week - 1) % 4 == 0) {
6477
// Month
6578
lineHeight = size.height/8;
6679
}
@@ -75,11 +88,27 @@ class TimelinePainter extends CustomPainter {
7588
TextSpan span = new TextSpan(style: new TextStyle(color: Color.fromARGB(255, 255, 255, 255), fontSize: 12), text: "${yearNumber}");
7689
TextPainter tp = new TextPainter(text: span, textAlign: TextAlign.left, textDirection: TextDirection.ltr);
7790
tp.layout();
78-
tp.paint(canvas, new Offset(currX, size.height - yearHeight));
91+
tp.paint(canvas, new Offset(currX, size.height - labelHeight));
7992
yearNumber++;
8093
}
8194
}
8295
}
96+
97+
{
98+
for (int i = 0; i<weekLabels.length; i++) {
99+
WeekLabel weekLabel = weekLabels[i];
100+
double currX = (weekLabel.weekNum / numWeeks.toDouble()) * size.width;
101+
double lineHeight = size.height/2;
102+
double margin = (size.height - lineHeight) / 2;
103+
canvas.drawLine(new Offset(currX, margin), new Offset(currX, size.height - margin), milestoneLinePaint);
104+
105+
TextSpan span = new TextSpan(style: new TextStyle(color: Constants.milestoneColor, fontSize: 12), text: weekLabel.label);
106+
TextPainter tp = new TextPainter(text: span, textAlign: TextAlign.left, textDirection: TextDirection.ltr);
107+
tp.layout();
108+
tp.paint(canvas, new Offset(currX, size.height - labelHeightDoubled));
109+
110+
}
111+
}
83112
}
84113

85114
@override

0 commit comments

Comments
 (0)