Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ node_modules
/storage
tmp
/.idea
.opencode

*.log
*.enc
Expand Down
6 changes: 3 additions & 3 deletions pkg/avatar/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type info struct {

func extractInfo(name string) info {
initials := strings.ToUpper(getInitials(name))
colorHash := getInitialsColorHash(name)
colorHash := getInitialsColorHash(initials)
color := getColorFromHash(colorHash)
return info{initials: initials, colorHash: colorHash, color: color}
}
Expand All @@ -139,8 +139,8 @@ func getInitials(name string) string {

func getInitialsColorHash(name string) int {
sum := 0
for i := 0; i < len(name); i++ {
sum += int(name[i])
for _, r := range name {
sum += int(r)
}
return sum
}
Expand Down
36 changes: 13 additions & 23 deletions pkg/avatar/svg_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"sort"
"strings"
)

Expand Down Expand Up @@ -50,18 +49,18 @@ type avatarInfo struct {
}

// grep linear-gradient path-to/cozy-ui/react/Avatar/helpers.js
var cozyUIAvatarColorSchemes = map[string]*linearGradient{
"sunrise": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#F8D280"}, {OffsetPerc: 96.03, Color: "#F2AC69"}}},
"downy": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#81EAD4"}, {OffsetPerc: 96.03, Color: "#62C6B7"}}},
"sugarCoral": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#F19E86"}, {OffsetPerc: 96.03, Color: "#F95967"}}},
"pinkBonnet": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#E4ABF0"}, {OffsetPerc: 96.03, Color: "#D96EED"}}},
"blueMana": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#85D9FD"}, {OffsetPerc: 96.03, Color: "#2A9EFC"}}},
"nightBlue": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 39.32, Color: "#80AEFF"}, {OffsetPerc: 96.03, Color: "#883DFE"}}},
"snowPea": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#BDF4A1"}, {OffsetPerc: 96.03, Color: "#52CE64"}}},
"pluviophile": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#A1D6F4"}, {OffsetPerc: 96.03, Color: "#52CEC2"}}},
"cornflower": {CSSAngleDeg: 135, Stops: []linearGradientStop{{OffsetPerc: 00.00, Color: "#86D9D3"}, {OffsetPerc: 100.0, Color: "#1CCFB4"}}},
"paleGreen": {CSSAngleDeg: 135, Stops: []linearGradientStop{{OffsetPerc: 00.00, Color: "#E2FA17"}, {OffsetPerc: 100.0, Color: "#75D8CB"}}},
"moonBlue": {CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#6DCFFF"}, {OffsetPerc: 96.03, Color: "#3D88F8"}}},
var cozyUIAvatarColorSchemes = []*linearGradient{
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#F8D280"}, {OffsetPerc: 96.03, Color: "#F2AC69"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#81EAD4"}, {OffsetPerc: 96.03, Color: "#62C6B7"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#F19E86"}, {OffsetPerc: 96.03, Color: "#F95967"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#E4ABF0"}, {OffsetPerc: 96.03, Color: "#D96EED"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#85D9FD"}, {OffsetPerc: 96.03, Color: "#2A9EFC"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 39.32, Color: "#80AEFF"}, {OffsetPerc: 96.03, Color: "#883DFE"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#BDF4A1"}, {OffsetPerc: 96.03, Color: "#52CE64"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#A1D6F4"}, {OffsetPerc: 96.03, Color: "#52CEC2"}}},
{CSSAngleDeg: 135, Stops: []linearGradientStop{{OffsetPerc: 00.00, Color: "#86D9D3"}, {OffsetPerc: 100.0, Color: "#1CCFB4"}}},
{CSSAngleDeg: 135, Stops: []linearGradientStop{{OffsetPerc: 00.00, Color: "#E2FA17"}, {OffsetPerc: 100.0, Color: "#75D8CB"}}},
{CSSAngleDeg: 136, Stops: []linearGradientStop{{OffsetPerc: 14.84, Color: "#6DCFFF"}, {OffsetPerc: 96.03, Color: "#3D88F8"}}},
}

// Encode an unclosed XML tag with the provided attributes
Expand Down Expand Up @@ -132,21 +131,12 @@ func encodeLinearGradient(encoder *xml.Encoder, gradient *linearGradient) error
)
}

var cozyUIAvatarColorSchemes_sortedKeys []string

// Deterministically pick one of the `cozyUIAvatarColorSchemes` for a given `gradientHash` number
func getGradientByHash(gradientHash int) *linearGradient {
if len(cozyUIAvatarColorSchemes_sortedKeys) == 0 {
cozyUIAvatarColorSchemes_sortedKeys = make([]string, 0, len(cozyUIAvatarColorSchemes))
for k := range cozyUIAvatarColorSchemes {
cozyUIAvatarColorSchemes_sortedKeys = append(cozyUIAvatarColorSchemes_sortedKeys, k)
}
sort.Strings(cozyUIAvatarColorSchemes_sortedKeys)
}
if gradientHash < 0 {
gradientHash = -gradientHash
}
return cozyUIAvatarColorSchemes[cozyUIAvatarColorSchemes_sortedKeys[gradientHash%len(cozyUIAvatarColorSchemes_sortedKeys)]]
return cozyUIAvatarColorSchemes[gradientHash%len(cozyUIAvatarColorSchemes)]
}

var fontMap = make(map[fontDescriptor]string)
Expand Down
2 changes: 1 addition & 1 deletion pkg/avatar/testdata/anonymous.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pkg/avatar/testdata/ww.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading