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
0c3e04ca
Commit
0c3e04ca
authored
Dec 06, 2017
by
Alexander Zobnin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
graph: render legend before graph
parent
ae80a589
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
21 deletions
+27
-21
public/app/plugins/panel/graph/graph.ts
+25
-20
public/app/plugins/panel/graph/legend.ts
+2
-1
No files found.
public/app/plugins/panel/graph/graph.ts
View file @
0c3e04ca
...
@@ -53,18 +53,28 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
...
@@ -53,18 +53,28 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
}
}
});
});
ctrl
.
events
.
on
(
'render'
,
function
(
renderData
)
{
/**
* Split graph rendering into two parts.
* First, calculate series stats in buildFlotPairs() function. Then legend rendering started
* (see ctrl.events.on('render') in legend.ts).
* When legend is rendered it emits 'legend-rendering-complete' and graph rendered.
*/
ctrl
.
events
.
on
(
'render'
,
(
renderData
)
=>
{
data
=
renderData
||
data
;
data
=
renderData
||
data
;
if
(
!
data
)
{
if
(
!
data
)
{
return
;
return
;
}
}
annotations
=
ctrl
.
annotations
||
[];
annotations
=
ctrl
.
annotations
||
[];
buildFlotPairs
(
data
);
buildFlotPairs
(
data
);
ctrl
.
events
.
emit
(
'render-legend'
);
});
ctrl
.
events
.
on
(
'legend-rendering-complete'
,
()
=>
{
render_panel
();
render_panel
();
});
});
// global events
// global events
appEvents
.
on
(
'graph-hover'
,
function
(
evt
)
{
appEvents
.
on
(
'graph-hover'
,
(
evt
)
=>
{
// ignore other graph hover events if shared tooltip is disabled
// ignore other graph hover events if shared tooltip is disabled
if
(
!
dashboard
.
sharedTooltipModeEnabled
())
{
if
(
!
dashboard
.
sharedTooltipModeEnabled
())
{
return
;
return
;
...
@@ -78,7 +88,7 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
...
@@ -78,7 +88,7 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
tooltip
.
show
(
evt
.
pos
);
tooltip
.
show
(
evt
.
pos
);
},
scope
);
},
scope
);
appEvents
.
on
(
'graph-hover-clear'
,
function
(
event
,
info
)
{
appEvents
.
on
(
'graph-hover-clear'
,
(
event
,
info
)
=>
{
if
(
plot
)
{
if
(
plot
)
{
tooltip
.
clear
(
plot
);
tooltip
.
clear
(
plot
);
}
}
...
@@ -86,9 +96,7 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
...
@@ -86,9 +96,7 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
function
getLegendHeight
(
panelHeight
)
{
function
getLegendHeight
(
panelHeight
)
{
const
LEGEND_TABLE_LINE_HEIGHT
=
21
;
const
LEGEND_TABLE_LINE_HEIGHT
=
21
;
const
LEGEND_LINE_HEIGHT
=
17
;
const
LEGEND_PADDING
=
23
;
const
LEGEND_PADDING
=
23
;
const
LEGEND_CHAR_WIDTH
=
5
;
if
(
!
panel
.
legend
.
show
||
panel
.
legend
.
rightSide
)
{
if
(
!
panel
.
legend
.
show
||
panel
.
legend
.
rightSide
)
{
return
0
;
return
0
;
...
@@ -102,25 +110,22 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
...
@@ -102,25 +110,22 @@ function graphDirective($rootScope, timeSrv, popoverSrv, contextSrv) {
let
total
=
LEGEND_PADDING
+
(
LEGEND_TABLE_LINE_HEIGHT
*
legendSeries
.
length
);
let
total
=
LEGEND_PADDING
+
(
LEGEND_TABLE_LINE_HEIGHT
*
legendSeries
.
length
);
return
Math
.
min
(
total
,
Math
.
floor
(
panelHeight
/
2
));
return
Math
.
min
(
total
,
Math
.
floor
(
panelHeight
/
2
));
}
else
{
}
else
{
let
l
inesCount
=
getLegendBoxHeight
(
legendSeries
,
panelWidth
,
LEGEND_CHAR_WIDTH
);
let
l
egendHeight
=
getLegendContainerHeight
(
);
let
total
=
LEGEND_PADDING
+
(
LEGEND_LINE_HEIGHT
*
linesCoun
t
);
let
total
=
LEGEND_PADDING
+
(
legendHeigh
t
);
return
Math
.
min
(
total
,
Math
.
floor
(
panelHeight
/
2
));
return
Math
.
min
(
total
,
Math
.
floor
(
panelHeight
/
2
));
}
}
}
}
function
getLegendBoxHeight
(
legendSeries
,
legendWidth
,
charWidth
)
{
function
getLegendContainerHeight
()
{
let
linesCount
=
1
;
try
{
let
currentLineLength
=
0
;
let
graphWrapperElem
=
elem
.
parent
().
parent
();
let
legendWidthChars
=
Math
.
floor
(
legendWidth
/
charWidth
);
let
legendElem
=
graphWrapperElem
.
find
(
'.graph-legend-wrapper'
);
_
.
each
(
legendSeries
,
(
series
)
=>
{
let
legendHeight
=
legendElem
.
height
();
let
nextLength
=
series
.
aliasEscaped
.
length
+
4
;
return
legendHeight
;
currentLineLength
+=
nextLength
;
}
catch
(
e
)
{
if
(
currentLineLength
>
legendWidthChars
)
{
console
.
log
(
e
);
linesCount
++
;
return
0
;
currentLineLength
=
nextLength
;
}
}
});
return
linesCount
;
}
}
function
setElementHeight
()
{
function
setElementHeight
()
{
...
...
public/app/plugins/panel/graph/legend.ts
View file @
0c3e04ca
...
@@ -18,11 +18,12 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
...
@@ -18,11 +18,12 @@ module.directive('graphLegend', function(popoverSrv, $timeout) {
var
i
;
var
i
;
var
legendScrollbar
;
var
legendScrollbar
;
ctrl
.
events
.
on
(
'render
'
,
function
()
{
ctrl
.
events
.
on
(
'render
-legend'
,
()
=>
{
data
=
ctrl
.
seriesList
;
data
=
ctrl
.
seriesList
;
if
(
data
)
{
if
(
data
)
{
render
();
render
();
}
}
ctrl
.
events
.
emit
(
'legend-rendering-complete'
);
});
});
function
getSeriesIndexForElement
(
el
)
{
function
getSeriesIndexForElement
(
el
)
{
...
...
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