Skip to content

Commit

Permalink
feat: display stats this year with month names
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Jan 9, 2024
1 parent 7602ecb commit 0d6b31e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/graphs.templ
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ templ Graph(data []types.Bar, title string) {
x={ strconv.FormatFloat(bar.LabelX, 'f', 2, 64) }
y={ strconv.FormatFloat(bar.LabelY, 'f', 2, 64) }
>
{ strconv.Itoa(bar.Label) }
{ bar.Label }
</text>
<text
class="fill-neutral-400 dark:fill-neutral-500 opacity-0 transition-opacity text-sm tabular-nums"
Expand Down
2 changes: 1 addition & 1 deletion components/graphs_templ.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ WITH months (
SELECT
generate_series(DATE_TRUNC('year', CURRENT_DATE), DATE_TRUNC('year', CURRENT_DATE) + INTERVAL '1 year' - INTERVAL '1 day', INTERVAL '1 month'))
SELECT
EXTRACT(MONTH FROM months.month)::integer AS label,
TO_CHAR(months.month, 'Mon') AS label,
COALESCE(count(seen.id), 0) AS value
FROM
months
Expand Down
2 changes: 1 addition & 1 deletion handlers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func constructGraphFromData(data []types.GraphData) ([]types.Bar, error) {
// Position centered on the bar. Subtract 3.4 which is half the width of the text.
charWidth := 8.67 // Uses tabular nums so all characters are the same width
numberOfCharsInCount := len(strconv.Itoa(row.Value))
numberOfCharsInRating := len(strconv.Itoa(row.Label))
numberOfCharsInRating := len(row.Label)

halfWidthOfCount := charWidth * float64(numberOfCharsInCount) / 2
halfWidthOfRating := charWidth * float64(numberOfCharsInRating) / 2
Expand Down
6 changes: 3 additions & 3 deletions types/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type PersonStats struct {
}

type GraphData struct {
Label int `db:"label"`
Value int `db:"value"`
Label string `db:"label"`
Value int `db:"value"`
}

type Bar struct {
Label int
Label string
Value int
BarHeight int
BarWidth int
Expand Down

0 comments on commit 0d6b31e

Please sign in to comment.