From 2a6e231cb0741d078cc072e8a8fa283f2f179f20 Mon Sep 17 00:00:00 2001 From: Shiming Zhang Date: Fri, 27 Aug 2021 13:18:46 +0800 Subject: [PATCH] Optimize the charts of empty data --- generator/charts/charts.go | 8 ++++++++ generator/generator.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/generator/charts/charts.go b/generator/charts/charts.go index 031976d..995957d 100644 --- a/generator/charts/charts.go +++ b/generator/charts/charts.go @@ -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" ) @@ -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) } diff --git a/generator/generator.go b/generator/generator.go index e6467a3..28afc2e 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -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))