Skip to content

Commit

Permalink
Update canvas.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Jan 29, 2025
1 parent a3cc842 commit feb43a1
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions packages/scan/src/new-outlines/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,11 @@ const TOTAL_FRAMES = 45;
const PRIMARY_COLOR = '115,97,230';
// const SECONDARY_COLOR = '128,128,128';

function getLabelTextPart(
partsEntries: [number, string[]][],
partsLength: number,
index: number,
): string {
const [count, names] = partsEntries[index];
function getLabelTextPart([count, names]: [number, string[]]): string {
let part = `${names.slice(0, MAX_PARTS_LENGTH).join(', ')} ×${count}`;
if (part.length > MAX_LABEL_LENGTH) {
part = `${part.slice(0, MAX_LABEL_LENGTH)}…`;
}
if (index !== partsLength - 1) {
part += ', ';
}
return part;
}

Expand All @@ -52,10 +44,9 @@ export const getLabelText = (outlines: ActiveOutline[]): string => {
const partsEntries = Array.from(countByNames.entries()).sort(
([countA], [countB]) => countB - countA,
);
const partsLength = partsEntries.length;
let labelText = getLabelTextPart(partsEntries, partsLength, 0);
for (let i = 1; i < partsLength; i++) {
labelText += getLabelTextPart(partsEntries, partsLength, i);
let labelText = getLabelTextPart(partsEntries[0]);
for (let i = 1, len = partsEntries.length; i < len; i++) {
labelText += ', ' + getLabelTextPart(partsEntries[i]);
}

if (labelText.length > MAX_LABEL_LENGTH) {
Expand Down

0 comments on commit feb43a1

Please sign in to comment.