|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'package:_pub_shared/format/encoding.dart'; |
5 | 6 | import 'package:pana/pana.dart'; |
| 7 | +import 'package:pub_dev/service/download_counts/download_counts.dart'; |
6 | 8 | import 'package:pubspec_parse/pubspec_parse.dart' as pubspek; |
7 | 9 |
|
8 | 10 | import '../../../../package/models.dart'; |
@@ -69,6 +71,8 @@ d.Node packageInfoBoxNode({ |
69 | 71 | } |
70 | 72 | return d.fragment([ |
71 | 73 | labeledScores, |
| 74 | + if (data.weeklyDownloadCounts != null) |
| 75 | + _downloadsChart(data.weeklyDownloadCounts!), |
72 | 76 | if (thumbnailUrl != null) |
73 | 77 | d.div(classes: [ |
74 | 78 | 'detail-screenshot-thumbnail' |
@@ -105,6 +109,23 @@ d.Node packageInfoBoxNode({ |
105 | 109 | ]); |
106 | 110 | } |
107 | 111 |
|
| 112 | +d.Node _downloadsChart(WeeklyDownloadCounts wdc) { |
| 113 | + final container = d.div( |
| 114 | + classes: ['weekly-downloads-sparkline'], |
| 115 | + id: '-weekly-downloads-sparkline', |
| 116 | + attributes: { |
| 117 | + 'data-widget': 'weekly-sparkline', |
| 118 | + 'data-weekly-sparkline-points': |
| 119 | + _encodeForWeeklySparkline(wdc.weeklyDownloads, wdc.newestDate), |
| 120 | + }); |
| 121 | + return container; |
| 122 | +} |
| 123 | + |
| 124 | +String _encodeForWeeklySparkline(List<int> downloads, DateTime newestDate) { |
| 125 | + final date = newestDate.toUtc().millisecondsSinceEpoch ~/ 1000; |
| 126 | + return encodeIntsAsLittleEndianBase64String([date, ...downloads]); |
| 127 | +} |
| 128 | + |
108 | 129 | d.Node _publisher(String? publisherId) { |
109 | 130 | return _block( |
110 | 131 | 'Publisher', |
|
0 commit comments