Skip to content

Commit

Permalink
Adjust edges of weekly sparkly downloads chart
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias committed Nov 13, 2024
1 parent 397d4df commit 3a2a286
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
List<({DateTime date, int downloads})> data) {
final height = 80;
final width = 190;
final drawingHeight = 75;
final padding = 4;
final drawingHeight = height - padding;
final drawingWidth = width - 2 * padding;

final lastDay = data.last.date;
final firstDay = data.first.date;
final xAxisSpan = lastDay.difference(firstDay);
Expand All @@ -54,7 +57,8 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,

(double, double) computeCoordinates(DateTime date, int downloads) {
final duration = date.difference(firstDay);
final x = width * duration.inMilliseconds / xAxisSpan.inMilliseconds;
final x = padding +
drawingWidth * duration.inMilliseconds / xAxisSpan.inMilliseconds;
final y = height - drawingHeight * (downloads / maxDownloads);
return (x, y);
}
Expand Down Expand Up @@ -114,7 +118,8 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,

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

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

final s = (e.x - chart.getBoundingClientRect().x) / width;
final s =
(e.x - (chart.getBoundingClientRect().x + padding)) / drawingWidth;
final selectedDayIndex =
lowerBoundBy<({DateTime date, int downloads}), double>(
data,
Expand Down
1 change: 1 addition & 0 deletions pkg/web_css/lib/src/_detail_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ $detail-tabs-tablet-width: calc(100% - 240px);
font-family: monospace;
font-size: 13px;
color: var(--pub-weekly-chart-main-color);
text-align: center;
}

.weekly-downloads-sparkline-tooltip {
Expand Down

0 comments on commit 3a2a286

Please sign in to comment.