Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1bc55a2d
Commit
1bc55a2d
authored
Jan 15, 2017
by
Ryuichi Sakai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable image rendering to use browser time offset
parent
e5a6c523
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
11 deletions
+62
-11
pkg/api/render.go
+6
-5
pkg/components/renderer/renderer.go
+38
-5
public/app/features/dashboard/partials/shareModal.html
+10
-0
public/app/features/dashboard/shareModalCtrl.js
+8
-1
No files found.
pkg/api/render.go
View file @
1bc55a2d
...
...
@@ -14,11 +14,12 @@ func RenderToPng(c *middleware.Context) {
queryParams
:=
fmt
.
Sprintf
(
"?%s"
,
c
.
Req
.
URL
.
RawQuery
)
renderOpts
:=
&
renderer
.
RenderOpts
{
Path
:
c
.
Params
(
"*"
)
+
queryParams
,
Width
:
queryReader
.
Get
(
"width"
,
"800"
),
Height
:
queryReader
.
Get
(
"height"
,
"400"
),
OrgId
:
c
.
OrgId
,
Timeout
:
queryReader
.
Get
(
"timeout"
,
"30"
),
Path
:
c
.
Params
(
"*"
)
+
queryParams
,
Width
:
queryReader
.
Get
(
"width"
,
"800"
),
Height
:
queryReader
.
Get
(
"height"
,
"400"
),
OrgId
:
c
.
OrgId
,
Timeout
:
queryReader
.
Get
(
"timeout"
,
"30"
),
TimeOffset
:
queryReader
.
Get
(
"timeOffset"
,
""
),
}
pngPath
,
err
:=
renderer
.
RenderToPng
(
renderOpts
)
...
...
pkg/components/renderer/renderer.go
View file @
1bc55a2d
...
...
@@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"time"
...
...
@@ -15,18 +16,44 @@ import (
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
"strings"
)
type
RenderOpts
struct
{
Path
string
Width
string
Height
string
Timeout
string
OrgId
int64
Path
string
Width
string
Height
string
Timeout
string
OrgId
int64
TimeOffset
string
}
var
rendererLog
log
.
Logger
=
log
.
New
(
"png-renderer"
)
func
isoTimeOffsetToPosixTz
(
isoOffset
string
)
string
{
re
:=
regexp
.
MustCompile
(
`^([+-])([0-1][0-9]|2[0-4])([0-5][0-9])$`
)
results
:=
re
.
FindStringSubmatch
(
isoOffset
)
if
results
==
nil
{
return
""
}
sign
:=
"+"
if
results
[
1
]
==
"+"
{
sign
=
"-"
// "+" is west and "-" is east in POSIX TZ
}
return
fmt
.
Sprintf
(
"SOMEWHERE%s%s:%s"
,
sign
,
results
[
2
],
results
[
3
])
}
func
appendEnviron
(
baseEnviron
[]
string
,
name
string
,
value
string
)
[]
string
{
results
:=
make
([]
string
,
0
)
prefix
:=
fmt
.
Sprintf
(
"%s="
,
name
)
for
_
,
v
:=
range
baseEnviron
{
if
!
strings
.
HasPrefix
(
v
,
prefix
)
{
results
=
append
(
results
,
v
)
}
}
return
append
(
results
,
fmt
.
Sprintf
(
"%s=%s"
,
name
,
value
))
}
func
RenderToPng
(
params
*
RenderOpts
)
(
string
,
error
)
{
rendererLog
.
Info
(
"Rendering"
,
"path"
,
params
.
Path
)
...
...
@@ -73,6 +100,12 @@ func RenderToPng(params *RenderOpts) (string, error) {
return
""
,
err
}
tz
:=
isoTimeOffsetToPosixTz
(
params
.
TimeOffset
)
if
tz
!=
""
{
baseEnviron
:=
os
.
Environ
()
cmd
.
Env
=
appendEnviron
(
baseEnviron
,
"TZ"
,
tz
)
}
err
=
cmd
.
Start
()
if
err
!=
nil
{
return
""
,
err
...
...
public/app/features/dashboard/partials/shareModal.html
View file @
1bc55a2d
...
...
@@ -69,6 +69,15 @@
<
/div
>
</script>
<script
type=
"text/ng-template"
id=
"renderImageOptions.html"
>
<
div
class
=
"gf-form-group"
>
<
gf
-
form
-
switch
class
=
"gf-form"
label
=
"Use browser time offset in image"
label
-
class
=
"width-18"
switch
-
class
=
"max-width-6"
checked
=
"options.browserTimeOffset"
on
-
change
=
"buildUrl()"
>
<
/gf-form-switch
>
<
/div
>
</script>
<script
type=
"text/ng-template"
id=
"shareLink.html"
>
<
div
class
=
"share-modal-header"
>
<
div
class
=
"share-modal-big-icon"
>
...
...
@@ -91,6 +100,7 @@
<
/div
>
<
/div
>
<
/div
>
<
div
ng
-
include
src
=
"'renderImageOptions.html'"
><
/div
>
<
div
class
=
"gf-form"
ng
-
show
=
"modeSharePanel"
>
<
a
href
=
"{{imageUrl}}"
target
=
"_blank"
><
i
class
=
"fa fa-camera"
><
/i> Direct link rendered image</
a
>
<
/div
>
...
...
public/app/features/dashboard/shareModalCtrl.js
View file @
1bc55a2d
...
...
@@ -10,7 +10,7 @@ function (angular, _, require, config) {
module
.
controller
(
'ShareModalCtrl'
,
function
(
$scope
,
$rootScope
,
$location
,
$timeout
,
timeSrv
,
templateSrv
,
linkSrv
)
{
$scope
.
options
=
{
forCurrent
:
true
,
includeTemplateVars
:
true
,
theme
:
'current'
};
$scope
.
options
=
{
forCurrent
:
true
,
includeTemplateVars
:
true
,
browserTimeOffset
:
false
,
theme
:
'current'
};
$scope
.
editor
=
{
index
:
$scope
.
tabIndex
||
0
};
$scope
.
init
=
function
()
{
...
...
@@ -82,6 +82,13 @@ function (angular, _, require, config) {
$scope
.
imageUrl
=
soloUrl
.
replace
(
config
.
appSubUrl
+
'/dashboard-solo/'
,
config
.
appSubUrl
+
'/render/dashboard-solo/'
);
$scope
.
imageUrl
+=
'&width=1000'
;
$scope
.
imageUrl
+=
'&height=500'
;
if
(
$scope
.
options
.
browserTimeOffset
)
{
var
offsetMinutes
=
new
Date
().
getTimezoneOffset
();
// Negative if ahead of UTC
var
sign
=
offsetMinutes
<
0
?
'+'
:
'-'
;
var
hours
=
(
'0'
+
Math
.
abs
(
offsetMinutes
)
/
60
).
slice
(
-
2
);
var
minutes
=
(
'0'
+
Math
.
abs
(
offsetMinutes
)
%
60
).
slice
(
-
2
);
$scope
.
imageUrl
+=
'&timeOffset='
+
encodeURIComponent
(
sign
+
hours
+
minutes
);
}
};
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment