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
5a53c2d0
Unverified
Commit
5a53c2d0
authored
Mar 06, 2020
by
Torkel Ödegaard
Committed by
GitHub
Mar 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rendering: Have phantomjs wait a bit before rendering to give fonts a change to load (#22623)
parent
917860c4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
64 deletions
+68
-64
tools/phantomjs/render.js
+68
-64
No files found.
tools/phantomjs/render.js
View file @
5a53c2d0
(
function
()
{
'use strict'
;
'use strict'
;
var
page
=
require
(
'webpage'
).
create
();
var
args
=
require
(
'system'
).
args
;
var
params
=
{};
var
regexp
=
/^
([^
=
]
+
)
=
([^
$
]
+
)
/
;
var
page
=
require
(
'webpage'
).
create
();
var
args
=
require
(
'system'
).
args
;
var
params
=
{};
var
regexp
=
/^
([^
=
]
+
)
=
([^
$
]
+
)
/
;
args
.
forEach
(
function
(
arg
)
{
var
parts
=
arg
.
match
(
regexp
);
if
(
!
parts
)
{
return
;
}
params
[
parts
[
1
]]
=
parts
[
2
];
});
args
.
forEach
(
function
(
arg
)
{
var
parts
=
arg
.
match
(
regexp
);
if
(
!
parts
)
{
return
;
}
params
[
parts
[
1
]]
=
parts
[
2
];
});
var
usage
=
"url=<url> png=<filename> width=<width> height=<height> renderKey=<key>"
;
var
usage
=
'url=<url> png=<filename> width=<width> height=<height> renderKey=<key>'
;
if
(
!
params
.
url
||
!
params
.
png
||
!
params
.
renderKey
||
!
params
.
domain
)
{
console
.
log
(
usage
);
phantom
.
exit
();
}
if
(
!
params
.
url
||
!
params
.
png
||
!
params
.
renderKey
||
!
params
.
domain
)
{
console
.
log
(
usage
);
phantom
.
exit
();
}
phantom
.
addCookie
({
'name'
:
'renderKey'
,
'value'
:
params
.
renderKey
,
'domain'
:
params
.
domain
,
});
phantom
.
addCookie
({
name
:
'renderKey'
,
value
:
params
.
renderKey
,
domain
:
params
.
domain
,
});
page
.
viewportSize
=
{
width
:
params
.
width
||
'800'
,
height
:
params
.
height
||
'400'
};
page
.
viewportSize
=
{
width
:
params
.
width
||
'800'
,
height
:
params
.
height
||
'400'
,
};
var
timeoutMs
=
(
parseInt
(
params
.
timeout
)
||
10
)
*
1000
;
var
waitBetweenReadyCheckMs
=
50
;
var
totalWaitMs
=
0
;
var
timeoutMs
=
(
parseInt
(
params
.
timeout
)
||
10
)
*
1000
;
var
waitBetweenReadyCheckMs
=
50
;
var
totalWaitMs
=
0
;
page
.
open
(
params
.
url
,
function
(
status
)
{
console
.
log
(
'Loading a web page: '
+
params
.
url
+
' status: '
+
status
,
timeoutMs
);
page
.
open
(
params
.
url
,
function
(
status
)
{
console
.
log
(
'Loading a web page: '
+
params
.
url
+
' status: '
+
status
,
timeoutMs
);
page
.
onError
=
function
(
msg
,
trace
)
{
var
msgStack
=
[
'ERROR: '
+
msg
];
if
(
trace
&&
trace
.
length
)
{
msgStack
.
push
(
'TRACE:'
);
trace
.
forEach
(
function
(
t
)
{
msgStack
.
push
(
' -> '
+
t
.
file
+
': '
+
t
.
line
+
(
t
.
function
?
' (in function "'
+
t
.
function
+
'")'
:
''
));
});
}
console
.
error
(
msgStack
.
join
(
'
\
n'
));
};
page
.
onError
=
function
(
msg
,
trace
)
{
var
msgStack
=
[
'ERROR: '
+
msg
];
if
(
trace
&&
trace
.
length
)
{
msgStack
.
push
(
'TRACE:'
);
trace
.
forEach
(
function
(
t
)
{
msgStack
.
push
(
' -> '
+
t
.
file
+
': '
+
t
.
line
+
(
t
.
function
?
' (in function "'
+
t
.
function
+
'")'
:
''
));
});
}
console
.
error
(
msgStack
.
join
(
'
\
n'
));
};
function
checkIsReady
()
{
var
panelsRendered
=
page
.
evaluate
(
function
()
{
var
panelCount
=
document
.
querySelectorAll
(
'plugin-component'
).
length
;
return
window
.
panelsRendered
>=
panelCount
;
});
function
checkIsReady
()
{
var
panelsRendered
=
page
.
evaluate
(
function
()
{
var
panelCount
=
document
.
querySelectorAll
(
'plugin-component'
).
length
;
return
window
.
panelsRendered
>=
panelCount
;
if
(
panelsRendered
||
totalWaitMs
>
timeoutMs
)
{
var
bb
=
page
.
evaluate
(
function
()
{
var
container
=
document
.
getElementsByClassName
(
'dashboard-container'
);
if
(
container
.
length
==
0
)
{
container
=
document
.
getElementsByClassName
(
'panel-container'
);
}
return
container
[
0
].
getBoundingClientRect
();
});
if
(
panelsRendered
||
totalWaitMs
>
timeoutMs
)
{
var
bb
=
page
.
evaluate
(
function
()
{
var
container
=
document
.
getElementsByClassName
(
"dashboard-container"
)
if
(
container
.
length
==
0
)
{
container
=
document
.
getElementsByClassName
(
"panel-container"
)
}
return
container
[
0
].
getBoundingClientRect
();
});
// reset viewport to render full page
page
.
viewportSize
=
{
width
:
bb
.
width
,
height
:
bb
.
height
};
// reset viewport to render full page
page
.
viewportSize
=
{
width
:
bb
.
width
,
height
:
bb
.
height
,
};
setTimeout
(
function
()
{
page
.
render
(
params
.
png
);
phantom
.
exit
();
}
else
{
totalWaitMs
+=
waitBetweenReadyCheckMs
;
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
)
;
}
}
,
5
);
}
else
{
totalWaitMs
+=
waitBetweenReadyCheckMs
;
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
);
}
}
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
);
});
})();
setTimeout
(
checkIsReady
,
waitBetweenReadyCheckMs
);
});
})();
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