Skip to content

Commit

Permalink
Optimize the charts of empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
wzshiming committed Aug 27, 2021
1 parent 5f56300 commit 2a6e231
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions generator/charts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/wzshiming/profile_stats"
"github.com/wzshiming/profile_stats/generator/charts/render"
placeholder_render "github.com/wzshiming/profile_stats/generator/placeholder/render"
"github.com/wzshiming/profile_stats/source"
"github.com/wzshiming/profile_stats/utils"
)
Expand Down Expand Up @@ -197,5 +198,12 @@ func (a *Charts) Get(ctx context.Context, w io.Writer, title string, usernames [
})
}

if len(data.Series) == 0 {
return placeholder_render.PlaceHolderRender(w, placeholder_render.PlaceHolderData{
Width: len(title) * 9,
Height: 30,
Text: title,
})
}
return render.ChartRender(w, data)
}
2 changes: 1 addition & 1 deletion generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewHandler(src *source.Source) *Handler {

r.register("now", now.NewNow())
r.register("updatedat", now.NewNow())
r.register("stats", placeholder.NewPlaceHolder())
r.register("placeholder", placeholder.NewPlaceHolder())
r.register("activities", activities.NewActivities(src))
r.register("stats", stats.NewStats(src))
r.register("charts", charts.NewCharts(src))
Expand Down

0 comments on commit 2a6e231

Please sign in to comment.