Skip to content

Commit

Permalink
pkg/html/pages: move HTML code to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
dvyukov committed Nov 8, 2024
1 parent 0571368 commit 70e072b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
40 changes: 4 additions & 36 deletions pkg/html/pages/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package pages

import (
"bytes"
_ "embed"
"fmt"
"html/template"

Expand All @@ -20,40 +21,7 @@ func StatsHTML() (template.HTML, error) {
return template.HTML(buf.String()), nil
}

var statsTemplate = Create(`
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(function() {
{{range $g := .}}
new google.visualization. {{if $g.Stacked}} AreaChart {{else}} LineChart {{end}} (
document.getElementById('div_{{$g.ID}}')).
draw(google.visualization.arrayToDataTable([
["-" {{range $line := $g.Lines}} , '{{$line}}' {{end}}],
{{range $p := $g.Points}} [ {{$p.X}} {{range $y := $p.Y}} , {{$y}} {{end}} ], {{end}}
]), {
title: '{{$g.Title}}',
titlePosition: 'in',
width: "95%",
height: "400",
chartArea: {width: '95%', height: '85%'},
legend: {position: 'in'},
lineWidth: 2,
focusTarget: "category",
{{if $g.Stacked}} isStacked: true, {{end}}
vAxis: {minValue: 1, textPosition: 'in', gridlines: {multiple: 1}, minorGridlines: {multiple: 1}},
hAxis: {minValue: 1, textPosition: 'out', maxAlternation: 1, gridlines: {multiple: 1},
minorGridlines: {multiple: 1}},
})
{{end}}
var statsTemplate = Create(statsHtml)

{{/* Preserve vertical scroll position after page reloads. Otherwise it's random. */}}
window.scroll(0, window.location.hash.substring(1));
document.onscroll = function(e) { window.location.hash = Math.round(window.scrollY); };
});
</script>
{{range $g := .}}
<div id="div_{{$g.ID}}"></div>
{{end}}
`)
//go:embed stats.html
var statsHtml string
40 changes: 40 additions & 0 deletions pkg/html/pages/stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{/*
Copyright 2024 syzkaller project authors. All rights reserved.
Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
*/}}

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(function() {
{{range $g := .}}
new google.visualization. {{if $g.Stacked}} AreaChart {{else}} LineChart {{end}} (
document.getElementById('div_{{$g.ID}}')).
draw(google.visualization.arrayToDataTable([
["-" {{range $line := $g.Lines}} , '{{$line}}' {{end}}],
{{range $p := $g.Points}} [ {{$p.X}} {{range $y := $p.Y}} , {{$y}} {{end}} ], {{end}}
]), {
title: '{{$g.Title}}',
titlePosition: 'in',
width: "95%",
height: "400",
chartArea: {width: '95%', height: '85%'},
legend: {position: 'in'},
lineWidth: 2,
focusTarget: "category",
{{if $g.Stacked}} isStacked: true, {{end}}
vAxis: {minValue: 1, textPosition: 'in', gridlines: {multiple: 1}, minorGridlines: {multiple: 1}},
hAxis: {minValue: 1, textPosition: 'out', maxAlternation: 1, gridlines: {multiple: 1},
minorGridlines: {multiple: 1}},
})
{{end}}

{{/* Preserve vertical scroll position after page reloads. Otherwise it's random. */}}
window.scroll(0, window.location.hash.substring(1));
document.onscroll = function(e) { window.location.hash = Math.round(window.scrollY); };
});
</script>

{{range $g := .}}
<div id="div_{{$g.ID}}"></div>
{{end}}

0 comments on commit 70e072b

Please sign in to comment.