@@ -48,15 +48,17 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
48
48
final drawingHeight = height - padding;
49
49
final drawingWidth = width - 2 * padding;
50
50
51
- final lastDay = data.last.date;
52
- final firstDay = data.first.date;
53
- final xAxisSpan = lastDay.difference (firstDay);
51
+ final lastDate = data.last.date;
52
+ final firstDate = data.first.date;
53
+ final firstDay = firstDate.copyWith (day: firstDate.day - 7 );
54
+
55
+ final xAxisSpan = lastDate.difference (firstDate);
54
56
final maxDownloads = data.fold <int >(0 , (a, b) => max <int >(a, b.downloads));
55
57
56
58
final toolTipOffsetFromMouse = 15 ;
57
59
58
60
(double , double ) computeCoordinates (DateTime date, int downloads) {
59
- final duration = date.difference (firstDay );
61
+ final duration = date.difference (firstDate );
60
62
final x = padding +
61
63
drawingWidth * duration.inMilliseconds / xAxisSpan.inMilliseconds;
62
64
final y = height - drawingHeight * (downloads / maxDownloads);
@@ -83,8 +85,7 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
83
85
84
86
// Render chart
85
87
86
- chartSubText.text = '${formatDate (firstDay )} - ${formatDate (lastDay )}' ;
87
-
88
+ chartSubText.text = '${formatDate (firstDay )} - ${formatDate (lastDate )}' ;
88
89
final chart = SVGGElement ();
89
90
final frame = SVGRectElement ();
90
91
frame.setAttribute ('height' , '$height ' );
@@ -142,7 +143,7 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
142
143
lowerBoundBy< ({DateTime date, int downloads}), double > (
143
144
data,
144
145
(e) =>
145
- e.date.difference (firstDay ).inMilliseconds /
146
+ e.date.difference (firstDate ).inMilliseconds /
146
147
xAxisSpan.inMilliseconds,
147
148
(a, b) => a.compareTo (b),
148
149
s);
@@ -154,17 +155,18 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
154
155
sparklineCursor.setAttribute ('transform' , 'translate(${coords .$1 }, 0)' );
155
156
toolTip.text = '${formatWithThousandSeperators (selectedDay .downloads )}' ;
156
157
157
- final startDate = selectedDay.date.subtract (Duration (days: 7 ));
158
+ final startDay = selectedDay.date.subtract (Duration (days: 7 ));
158
159
chartSubText.text =
159
- '${formatDate (startDate )} - ${formatDate (selectedDay .date )}' ;
160
+ '${formatDate (startDay )} - ${formatDate (selectedDay .date )}' ;
160
161
161
162
lastSelectedDay = selectedDay.date;
162
163
});
163
164
164
165
void erase (_) {
165
166
sparklineCursor.setAttribute ('style' , 'opacity:0' );
166
167
toolTip.setAttribute ('style' , 'opacity:0;position:absolute;' );
167
- chartSubText.text = '${formatDate (firstDay )} - ${formatDate (lastDay )}' ;
168
+
169
+ chartSubText.text = '${formatDate (firstDay )} - ${formatDate (lastDate )}' ;
168
170
}
169
171
170
172
erase (1 );
0 commit comments