Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/card theme #33

Merged
merged 23 commits into from
May 13, 2024
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
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
)

func main() {

svg, err := api.MountainHandler()
if err != nil {
fmt.Printf("Error calling MountainHandler: %v\n", err)
return
}

// ファイルパスを設定
directory := "./output"
filePath := "./output/output.svg"
directory := "./mountain-output"
filePath := "./mountain-output/mountain.svg"

// ディレクトリが存在しない場合は作成
if _, err := os.Stat(directory); os.IsNotExist(err) {
Expand Down
1 change: 1 addition & 0 deletions mountain-output/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Output folder
1 change: 0 additions & 1 deletion output/README.md

This file was deleted.

60 changes: 31 additions & 29 deletions ui/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,74 @@ package ui

import (
"fmt"
"os"
)

func startSVG(width, height int, viewBox string) string {
return fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="%d" viewBox="%s" >`, width, height, viewBox)
func startSVG() string {
return fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="340" height="200" viewBox="0 0 340 200" >`)
suba327777 marked this conversation as resolved.
Show resolved Hide resolved
}

func rect(width, height int, bgColor string) string {
return fmt.Sprintf(`<rect width="%d" height="%d" fill="%s" rx="5" ry="5" stroke="white" stroke-width="1"/>`, width, height, bgColor)
func rect(bgColor, borderColor string) string {
return fmt.Sprintf(`<rect width="340" height="200" fill="%s" rx="5" ry="5" stroke="%s" stroke-width="1"/>`, bgColor, borderColor)
suba327777 marked this conversation as resolved.
Show resolved Hide resolved
}

func title(username string, mountain string) string {
func title(mountainIcon, textColor, username string) string {
return fmt.Sprintf(`
<g>
<g transform="translate(5,8)">%s</g>
<text x="45" y="26" font-size="16" dominant-baseline="middle" text-anchor="start" fill="white">%s</text>
<text x="45" y="26" font-size="16" dominant-baseline="middle" text-anchor="start" fill="%s">%s</text>
</g>
`, mountain, username)
`, mountainIcon, textColor, username)
}

func leftInfo(dailyCommitsMonthCount, endOfMonth, commitsYearCount int, tree, climber string) string {
func leftInfo(dailyCommitsMonthCount, endOfMonth, commitsYearCount int, treeIcon, climberIcon, textColor string) string {
suba327777 marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Sprintf(`
<g>
<g>
<g transform="translate(5,75)">%s</g>
<text x="48" y="85" font-size="11" dominant-baseline="middle" text-anchor="start" fill="white">commit day</text>
<text x="50" y="100" font-size="11" dominant-baseline="middle" text-anchor="start" fill="white">per month</text>
<text x="125" y="90" font-size="10" dominant-baseline="middle" text-anchor="start" fill="white">%d/%d</text>
<text x="48" y="85" font-size="11" dominant-baseline="middle" text-anchor="start" fill="%s">commit day</text>
<text x="50" y="100" font-size="11" dominant-baseline="middle" text-anchor="start" fill="%s">per month</text>
<text x="125" y="90" font-size="10" dominant-baseline="middle" text-anchor="start" fill="%s">%d/%d</text>
</g>
<g>
<g transform="translate(5,140)">%s</g>
<text x="40" y="150" font-size="11" dominant-baseline="middle" text-anchor="start" fill="white">Total Commits</text>
<text x="60" y="165" font-size="11" dominant-baseline="middle" text-anchor="start" fill="white">(2024)</text>
<text x="130" y="155" font-size="10" dominant-baseline="middle" text-anchor="start" fill="white">%d</text>
<g transform="translate(5,140)">%s</g> <text x="40" y="150" font-size="11" dominant-baseline="middle" text-anchor="start" fill="%s">Total Commits</text>
suba327777 marked this conversation as resolved.
Show resolved Hide resolved
<text x="60" y="165" font-size="11" dominant-baseline="middle" text-anchor="start" fill="%s">(2024)</text>
<text x="130" y="155" font-size="10" dominant-baseline="middle" text-anchor="start" fill="%s">%d</text>

</g>
</g>
`, tree, dailyCommitsMonthCount, endOfMonth, climber, commitsYearCount)
`, treeIcon, textColor, textColor, textColor, dailyCommitsMonthCount, endOfMonth, climberIcon, textColor, textColor, textColor, commitsYearCount)
suba327777 marked this conversation as resolved.
Show resolved Hide resolved
}

func rightInfo(grass string) string {
func rightInfo(bgColor, borderColor, grass string) string {
return fmt.Sprintf(`
<g>
<rect x="175" y="55" width="150" height="130" fill="#141321" rx="5" ry="5" stroke="white" stroke-width="1"/>
<rect x="175" y="55" width="150" height="130" fill="%s" rx="5" ry="5" stroke="%s" stroke-width="1"/>
<g transform="translate(158 167)">
<g>%s</g>
</g>
</g>
`, grass)
`, bgColor, borderColor, grass)
}

func endSVG() string {
return `</svg>`
}

func GenerateCard(username string, dailyCommitsSince1MonthCount, dailyCommitsMonthCount, endOfMonth, commitsYearCount int) string {
width := 340
height := 200
viewBox := fmt.Sprintf("0 0 %d %d", width, height)
bgColor := "#141321"
grassMountain := generateMountain(dailyCommitsSince1MonthCount)
svg := startSVG(width, height, viewBox)
svg += rect(width, height, bgColor)
svg += title(username, Mountain)
svg += leftInfo(dailyCommitsMonthCount, endOfMonth, commitsYearCount, Tree, Climber)
svg += rightInfo(grassMountain)
themeName := os.Getenv("THEME")
theme := getTheme(themeName)

mountainIcon := changeIconColor(Mountain, theme.MountainIconColor)
climberIcon := changeIconColor(Climber, theme.IconColor)
treeIcon := changeIconColor(Tree, theme.IconColor)
grassMountain := generateMountain(dailyCommitsSince1MonthCount, theme.Name, theme.TriangleMountainColor)

svg := startSVG()
svg += rect(theme.BgColor, theme.BorderColor)
svg += title(mountainIcon, theme.TitleColor, username)
svg += leftInfo(dailyCommitsMonthCount, endOfMonth, commitsYearCount, treeIcon, climberIcon, theme.TextColor)
svg += rightInfo(theme.BgColor, theme.BorderColor, grassMountain)
svg += endSVG()

return svg
Expand Down
Loading
Loading