Avatar: getAvatarColor collides on anagrams; add color seed + palette subset
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- react, typescript
Direzione di ricerca
Inizia leggendo components/avatar/utils.tsx e tracciando il percorso del colore automatico di Avatar. Conferma le decisioni dell’API per un seed di colore opzionale e un sottoinsieme della palette, quindi verifica che l’hash distingua i cambiamenti nell’ordine mantenendo il comportamento di fallback. Il lavoro è completo quando i colori automatici supportano seed indipendenti stabili e palette ristrette senza influire sul lavoro sui colori espliciti descritto in #650.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
getAvatarColor picks an avatar color from a name using a char-code sum, which collides on anagrams and clusters on similar strings. There is also no way to seed the color independently of the display name, and no way to restrict the palette to a subset. Consumers with a specific color language end up re-implementing the whole function.
The hashing bug
components/avatar/utils.tsx:
export function getAvatarColor(str: string): AVATAR_COLORS {
const hash = str.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
const index = hash % COLORS.length;
return COLORS[index];
}
Summing char codes is order-insensitive, so any anagram maps to the same color — "Ravi" and "Vira", "Amy Lee" and "Ely Mae" collide. Names that differ by one adjacent-letter swap also collide, and sequences like "User 1" / "User 2" / "User 3" land on adjacent (often visually close) palette entries instead of spreading out.
A small change fixes the distribution — a polynomial (order-sensitive) hash:
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash * 31 + str.charCodeAt(i)) | 0;
}
const index = Math.abs(hash) % COLORS.length;
Two API gaps
1. No color seed. The color is derived from the string passed in — which is the display name — so a rename changes a person's color, and two people with the same name always share one. A separate, stable seed (e.g. an id) would keep colors stable across renames and distinct for namesakes. Suggest an optional colorSeed/seed prop on Avatar (falling back to the name today).
2. No palette subset. COLORS is a fixed 13-entry list including warm tones (orange, crimson, gold) and neutral. A product with a cooler or brand-restricted identity language can't say "only pick from these." Suggest letting getAvatarColor (and Avatar's auto-color) accept an optional palette subset.
Relationship to #650
#650 (item 3) proposes propagating an explicit color prop to Avatar. This issue is about the automatic color path — hash quality and seeding — which is orthogonal: even with an explicit-color prop, the auto-assigned fallback should distribute well and stay stable.
Willing to contribute
Happy to open a PR — the hash change alone is a one-liner, and the seed/palette props are additive.
- Lingua principale
- TypeScript
- Stelle
- 70
- Fork
- 13
- Merge medio
- 4g 6h
- PR unite (30g)
- 10
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di raystack/apsara
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 75/100
-
Docs: hand-duplicated props tables drift risk, missing a11y sections, no per-component changelog Apertaenhancement global
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
bug global
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
Tutte le issue di raystack/apsara
Issue simili
-
bug(cli): hapi doctor inline-media prints a fabricated B:\ helper-script path in packaged installs Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Crush Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
catppuccin/catppuccin#3125 ·
-
Add a SECURITY.md Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
ElementsProject/cln-application#167 · 1 commento · 1 reazione ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Quantco/pnpm-licenses#17 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100