Skip to content

Commit 0b209e2

Browse files
committed
Update canvas.ts
1 parent feb43a1 commit 0b209e2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

packages/scan/src/new-outlines/canvas.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ const TOTAL_FRAMES = 45;
1616
const PRIMARY_COLOR = '115,97,230';
1717
// const SECONDARY_COLOR = '128,128,128';
1818

19+
function sortEntry(prev: [number, string[]], next: [number, string[]]): number {
20+
return next[0] - prev[0];
21+
}
22+
23+
function getSortedEntries(
24+
countByNames: Map<number, string[]>,
25+
): [number, string[]][] {
26+
const entries = [...countByNames.entries()];
27+
return entries.sort(sortEntry);
28+
}
29+
1930
function getLabelTextPart([count, names]: [number, string[]]): string {
2031
let part = `${names.slice(0, MAX_PARTS_LENGTH).join(', ')} ×${count}`;
2132
if (part.length > MAX_LABEL_LENGTH) {
@@ -31,7 +42,7 @@ export const getLabelText = (outlines: ActiveOutline[]): string => {
3142
}
3243

3344
const countByNames = new Map<number, string[]>();
34-
for (const [name, count] of nameByCount.entries()) {
45+
for (const [name, count] of nameByCount) {
3546
const names = countByNames.get(count);
3647
if (names) {
3748
names.push(name);
@@ -41,9 +52,7 @@ export const getLabelText = (outlines: ActiveOutline[]): string => {
4152
}
4253

4354
// TODO(Alexis): Optimize
44-
const partsEntries = Array.from(countByNames.entries()).sort(
45-
([countA], [countB]) => countB - countA,
46-
);
55+
const partsEntries = getSortedEntries(countByNames);
4756
let labelText = getLabelTextPart(partsEntries[0]);
4857
for (let i = 1, len = partsEntries.length; i < len; i++) {
4958
labelText += ', ' + getLabelTextPart(partsEntries[i]);

0 commit comments

Comments
 (0)