Skip to content

Commit 676ed00

Browse files
committed
updates
1 parent 953bd3d commit 676ed00

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

app/lib/frontend/templates/views/pkg/labeled_scores.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,46 @@ d.Node labeledScoresNode({
2121
children: [
2222
d.div(
2323
classes: ['packages-score', 'packages-score-like'],
24-
child: _labeledScore('likes', likeCount, sign: ''),
24+
child: _labeledScore('likes', likeCount.toString(), sign: ''),
2525
),
2626
d.div(
2727
classes: ['packages-score', 'packages-score-health'],
28-
child: _labeledScore('pub points', grantedPubPoints, sign: ''),
28+
child:
29+
_labeledScore('pub points', grantedPubPoints?.toString(), sign: ''),
2930
),
3031
requestContext.experimentalFlags.showDownloadCounts
3132
? d.div(
3233
classes: ['packages-score', 'packages-score-downloads'],
3334
child: _labeledScore(
3435
'downloads',
3536
thirtyDaysDownloads != null
36-
? computeValueWithSuffix(thirtyDaysDownloads).value
37+
? formatWith3SignificantDigits(thirtyDaysDownloads).value
3738
: null,
3839
sign: thirtyDaysDownloads != null
39-
? computeValueWithSuffix(thirtyDaysDownloads).suffix
40+
? formatWith3SignificantDigits(thirtyDaysDownloads).suffix
4041
: '',
4142
),
4243
)
4344
: d.div(
4445
classes: ['packages-score', 'packages-score-popularity'],
4546
child: _labeledScore(
4647
'popularity',
47-
popularityStorage.isInvalid ? null : popularity,
48+
popularityStorage.isInvalid ? null : popularity.toString(),
4849
sign: popularityStorage.isInvalid ? '' : '%',
4950
),
5051
),
5152
],
5253
);
5354
}
5455

55-
d.Node _labeledScore(String label, num? value, {required String sign}) {
56+
d.Node _labeledScore(String label, String? value, {required String sign}) {
5657
return d.fragment([
5758
d.div(
5859
classes: ['packages-score-value', if (value != null) '-has-value'],
5960
children: [
6061
d.span(
6162
classes: ['packages-score-value-number'],
62-
text: value?.toString() ?? '--',
63+
text: value ?? '--',
6364
),
6465
d.span(classes: ['packages-score-value-sign'], text: sign),
6566
],

app/test/service/download_counts/compute_total_download_counts_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:pub_dev/shared/configuration.dart';
1111
import 'package:test/test.dart';
1212

1313
import '../../shared/test_services.dart';
14-
import 'fake_download_counts.dart';
14+
import '../../../lib/fake/backend/fake_download_counts.dart';
1515

1616
void main() {
1717
group('', () {

app/test/service/download_counts/download_counts_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:pub_dev/service/download_counts/sync_download_counts.dart';
1212
import 'package:test/test.dart';
1313

1414
import '../../shared/test_services.dart';
15-
import 'fake_download_counts.dart';
15+
import '../../../lib/fake/backend/fake_download_counts.dart';
1616

1717
void main() {
1818
group('', () {

pkg/_pub_shared/lib/format/number_format.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,17 @@
66
/// The chunk will have a single digit precision, and will be
77
/// rounded down, in order to prevent exaggerated counts.
88
String formatWithSuffix(int value) {
9-
final f = computeValueWithSuffix(value);
10-
return '${_toFixed(f.value)}${f.suffix}';
11-
}
12-
13-
({num value, String suffix}) computeValueWithSuffix(int value) {
149
if (value >= 1000000) {
15-
return (value: _singleDigitDivision(value, 1000000), suffix: 'm');
10+
return '${_toFixed(value, 1000000)}m';
1611
} else if (value >= 1000) {
17-
return (value: _singleDigitDivision(value, 1000), suffix: 'k');
12+
return '${_toFixed(value, 1000)}k';
1813
} else {
19-
return (value: value, suffix: '');
14+
return value.toString();
2015
}
2116
}
2217

23-
num _singleDigitDivision(int value, int d) {
24-
return (((value * 10) ~/ d) / 10);
25-
}
26-
27-
String _toFixed(num value) {
28-
return value < 1000 ? '$value' : value.toStringAsFixed(1);
18+
String _toFixed(int value, int d) {
19+
return (((value * 10) ~/ d) / 10).toStringAsFixed(1);
2920
}
3021

3122
/// Formats an int [value] to human readable chunk and suffix with at most 3

0 commit comments

Comments
 (0)