diff --git a/rules/helpers.go b/rules/helpers.go index 2f589bf689..9058744e38 100644 --- a/rules/helpers.go +++ b/rules/helpers.go @@ -159,6 +159,6 @@ func TableLinkForExpression(expr string) string { // GraphLinkForExpression creates an escaped relative link to the graph view of // the provided expression. func GraphLinkForExpression(expr string) string { - urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q}]`, expr)) + urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q,"tab":0}]`, expr)) return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1)) } diff --git a/templates/templates_test.go b/templates/templates_test.go index 2d371b6f17..cea9a6c15b 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -135,7 +135,7 @@ func TestTemplateExpansion(t *testing.T) { { // graphLink. text: "{{ graphLink \"up\" }}", - output: "/graph#%5B%7B%22expr%22%3A%22up%22%7D%5D", + output: "/graph#%5B%7B%22expr%22%3A%22up%22%2C%22tab%22%3A0%7D%5D", }, { // tableLink. diff --git a/web/static/js/graph.js b/web/static/js/graph.js index f789b31626..2436745667 100644 --- a/web/static/js/graph.js +++ b/web/static/js/graph.js @@ -58,7 +58,9 @@ Prometheus.Graph.prototype.initialize = function() { self.options["id"] = self.id; self.options["range_input"] = self.options["range_input"] || "1h"; self.options["stacked_checked"] = self.options["stacked"] ? "checked" : ""; - self.options["tab"] = self.options["tab"] || 1; + if (self.options["tab"] === undefined) { + self.options["tab"] = 1; + } // Draw graph controls and container from Handlebars template. @@ -78,13 +80,13 @@ Prometheus.Graph.prototype.initialize = function() { self.consoleTab = graphWrapper.find(".console"); self.graphTab = graphWrapper.find(".graph_container"); self.tabs = graphWrapper.find(".tabs"); - self.tab = $(self.tabs.find("> div")[self.options["tab"]]); // active tab + self.tab = $(self.tabs.find("> div")[self.options["tab"]]); // active tab self.tabs.tabs({ active: self.options["tab"], activate: function(e, ui) { storeGraphOptionsInUrl(); - self.tab = ui.newPanel + self.tab = ui.newPanel; if (self.tab.hasClass("reload")) { // reload if flagged with class "reload" self.submitQuery(); } diff --git a/web/static/js/prom_console.js b/web/static/js/prom_console.js index 154df9e2df..513ca081ce 100644 --- a/web/static/js/prom_console.js +++ b/web/static/js/prom_console.js @@ -577,7 +577,7 @@ PromConsole._chooseNameFunction = function(data) { PromConsole._graphsToSlashGraphURL = function(exprs) { var data = []; for (var i = 0; i < exprs.length; ++i) { - data.push({'expr' : exprs[i]}); + data.push({'expr': exprs[i], 'tab': 0}); } return '/graph#' + encodeURIComponent(JSON.stringify(data));