Skip to content

Commit

Permalink
godev/cmd/telemetrygodev: further style / content tweaks for charts
Browse files Browse the repository at this point in the history
Make the following changes to style and content of the charts browser:
 - improve the title for aggregate charts
 - share title logic with the individual charts pages
 - "All daily charts" -> "All charts"
 - increase size of chart text
 - use a more subtle color scheme for chart series

For golang/go#68204

Change-Id: I24134cc455ef9b01a45956f766871b0acd06f580
Reviewed-on: https://go-review.googlesource.com/c/telemetry/+/603835
Reviewed-by: Hongxiang Jiang <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
findleyr committed Aug 7, 2024
1 parent b2d1c13 commit aac065f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
24 changes: 15 additions & 9 deletions godev/cmd/telemetrygodev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,7 @@ func handleRoot(render renderer, fsys fs.FS, chartBucket storage.BucketHandle, l
if chartObj == "" {
page.ChartError = "No data."
} else {
start, end, aggregate := strings.Cut(strings.TrimSuffix(chartObj, ".json"), "_")
if aggregate {
page.ChartTitle = fmt.Sprintf("Uploaded data for %s-%s", start, end)
} else {
page.ChartTitle = fmt.Sprintf("Uploaded data for %s", start)
}
page.ChartTitle = chartTitle(chartObj)
charts, err := loadCharts(ctx, chartObj, chartBucket)
if err != nil {
log.ErrorContext(ctx, fmt.Sprintf("error loading index charts: %v", err))
Expand All @@ -185,6 +180,14 @@ func handleRoot(render renderer, fsys fs.FS, chartBucket storage.BucketHandle, l
}
}

func chartTitle(objName string) string {
start, end, aggregate := strings.Cut(strings.TrimSuffix(objName, ".json"), "_")
if aggregate {
return fmt.Sprintf("Aggregate charts for %s to %s", start, end)
}
return fmt.Sprintf("Charts for %s", start)
}

type chartsPage []string

func (chartsPage) Breadcrumbs() []breadcrumb {
Expand Down Expand Up @@ -217,8 +220,9 @@ func handleCharts(render renderer, chartBucket storage.BucketHandle) content.Han
}

type chartPage struct {
Date string
Charts map[string]any
Date string
ChartTitle string
Charts map[string]any
}

func (p chartPage) Breadcrumbs() []breadcrumb {
Expand All @@ -233,7 +237,9 @@ func handleChart(ctx context.Context, w http.ResponseWriter, date string, render
// TODO(rfindley): refactor to return a content.HandlerFunc once we can use Go 1.22 routing.
page := chartPage{Date: date}
var err error
page.Charts, err = loadCharts(ctx, date+".json", chartBucket)
objName := date + ".json"
page.ChartTitle = chartTitle(objName)
page.Charts, err = loadCharts(ctx, objName, chartBucket)
if errors.Is(err, storage.ErrObjectNotExist) {
return content.Status(w, http.StatusNotFound)
} else if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/content/telemetrygodev/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<section>
<div class="Hero">
<div class="Content">
<h1>Daily charts for {{.Date}}</h1>
<h1>{{.ChartTitle}}</h1>
<p>Generated from {{.Charts.NumReports}} reports.</p>
</div>
</div>
Expand Down
13 changes: 10 additions & 3 deletions internal/content/telemetrygodev/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function partition({ Data, Name }: Chart) {

return Plot.plot({
color: {
type: "ordinal",
scheme: "Spectral",
type: "categorical",
scheme: "set2",
},
nice: true,
x: {
Expand All @@ -85,7 +85,14 @@ function partition({ Data, Name }: Chart) {
domain: [0, max + 1], // adjust domain to prevent rendering issues, especially with all-zero data.
},
width: 1024,
style: "overflow:visible;background:transparent;margin-bottom:3rem;",
style: {
overflow: "visible",
background: "transparent",
marginBottom: "3rem",
fontSize: "0.8rem",
marginTop: "1rem",
},
insetTop: 20, // leave enough space between the axis label and marks
marks: [
Plot.barY(Data, {
tip: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/content/telemetrygodev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1>Go Telemetry &#128202;</h1>
<div class="Charts-heading">
<h2>{{.ChartTitle}}</h2>
<ul>
<li><a href="/charts/">All daily charts</a></li>
<li><a href="/charts/">All charts</a></li>
<li><a href="/data/">All raw data</a></li>
</ul>
</div>
Expand Down
Loading

0 comments on commit aac065f

Please sign in to comment.