Skip to content

Commit 4a04f79

Browse files
authored
Adjust edges of weekly sparkline downloads chart (#8281)
1 parent 397d4df commit 4a04f79

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
4444
List<({DateTime date, int downloads})> data) {
4545
final height = 80;
4646
final width = 190;
47-
final drawingHeight = 75;
47+
final padding = 4;
48+
final drawingHeight = height - padding;
49+
final drawingWidth = width - 2 * padding;
50+
4851
final lastDay = data.last.date;
4952
final firstDay = data.first.date;
5053
final xAxisSpan = lastDay.difference(firstDay);
@@ -54,7 +57,8 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
5457

5558
(double, double) computeCoordinates(DateTime date, int downloads) {
5659
final duration = date.difference(firstDay);
57-
final x = width * duration.inMilliseconds / xAxisSpan.inMilliseconds;
60+
final x = padding +
61+
drawingWidth * duration.inMilliseconds / xAxisSpan.inMilliseconds;
5862
final y = height - drawingHeight * (downloads / maxDownloads);
5963
return (x, y);
6064
}
@@ -114,7 +118,8 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
114118

115119
final area = SVGPathElement();
116120
area.setAttribute('class', 'weekly-sparkline-area');
117-
area.setAttribute('d', '$line L$width $height L0 $height Z');
121+
area.setAttribute(
122+
'd', '$line L${drawingWidth + padding} $height L$padding $height Z');
118123

119124
chart.append(sparkline);
120125
chart.append(area);
@@ -131,7 +136,8 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
131136
'top:${e.y + toolTipOffsetFromMouse + document.scrollingElement!.scrollTop}px;'
132137
'left:${e.x}px;');
133138

134-
final s = (e.x - chart.getBoundingClientRect().x) / width;
139+
final s =
140+
(e.x - (chart.getBoundingClientRect().x + padding)) / drawingWidth;
135141
final selectedDayIndex =
136142
lowerBoundBy<({DateTime date, int downloads}), double>(
137143
data,

pkg/web_css/lib/src/_detail_page.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ $detail-tabs-tablet-width: calc(100% - 240px);
247247
font-family: monospace;
248248
font-size: 13px;
249249
color: var(--pub-weekly-chart-main-color);
250+
text-align: center;
250251
}
251252

252253
.weekly-downloads-sparkline-tooltip {

0 commit comments

Comments
 (0)