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
81cb4a74
Commit
81cb4a74
authored
Sep 26, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(graph): progress on graph panel work
parent
40e6317b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
83 deletions
+10
-83
public/app/plugins/panel/graph/graph.ts
+10
-83
No files found.
public/app/plugins/panel/graph/graph.ts
View file @
81cb4a74
...
...
@@ -23,7 +23,7 @@ var labelWidthCache = {};
module
.
directive
(
'grafanaGraph'
,
function
(
$rootScope
,
timeSrv
)
{
return
{
restrict
:
'A'
,
template
:
'
<div> </div>
'
,
template
:
''
,
link
:
function
(
scope
,
elem
)
{
var
ctrl
=
scope
.
ctrl
;
var
dashboard
=
ctrl
.
dashboard
;
...
...
@@ -164,10 +164,15 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
var
right
=
panel
.
yaxes
[
1
];
if
(
left
.
show
&&
left
.
label
)
{
gridMargin
.
left
=
20
;
}
if
(
right
.
show
&&
right
.
label
)
{
gridMargin
.
right
=
20
;
}
}
function
processDatapoints
(
plot
)
{
console
.
log
(
'processDatapoints'
);
// apply y-axis min/max options
var
yaxis
=
plot
.
getYAxes
();
for
(
var
i
=
0
;
i
<
yaxis
.
length
;
i
++
)
{
var
axis
=
yaxis
[
i
];
var
panelOptions
=
panel
.
yaxes
[
i
];
axis
.
options
.
max
=
panelOptions
.
max
;
axis
.
options
.
min
=
panelOptions
.
min
;
}
}
// Function for rendering panel
...
...
@@ -188,7 +193,6 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
hooks
:
{
draw
:
[
drawHook
],
processOffset
:
[
processOffsetHook
],
processDatapoints
:
[
processDatapoints
],
},
legend
:
{
show
:
false
},
series
:
{
...
...
@@ -401,87 +405,15 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
};
}
//Override min/max to provide more flexible autoscaling
function
autoscaleSpanOverride
(
yaxis
,
data
,
options
)
{
var
expr
;
if
(
yaxis
.
min
!=
null
&&
data
!=
null
)
{
expr
=
parseThresholdExpr
(
yaxis
.
min
);
options
.
min
=
autoscaleYAxisMin
(
expr
,
data
.
stats
);
}
if
(
yaxis
.
max
!=
null
&&
data
!=
null
)
{
expr
=
parseThresholdExpr
(
yaxis
.
max
);
options
.
max
=
autoscaleYAxisMax
(
expr
,
data
.
stats
);
}
}
function
parseThresholdExpr
(
expr
)
{
var
match
,
operator
,
value
,
precision
;
expr
=
String
(
expr
);
match
=
expr
.
match
(
/
\s
*
([
<=>~
]
*
)\s
*
(\-?\d
+
(\.\d
+
)?)
/
);
if
(
match
)
{
operator
=
match
[
1
];
value
=
parseFloat
(
match
[
2
]);
//Precision based on input
precision
=
match
[
3
]
?
match
[
3
].
length
-
1
:
0
;
return
{
operator
:
operator
,
value
:
value
,
precision
:
precision
};
}
else
{
return
undefined
;
}
}
function
autoscaleYAxisMax
(
expr
,
dataStats
)
{
var
operator
=
expr
.
operator
,
value
=
expr
.
value
,
precision
=
expr
.
precision
;
if
(
operator
===
">"
)
{
return
dataStats
.
max
<
value
?
value
:
null
;
}
else
if
(
operator
===
"<"
)
{
return
dataStats
.
max
>
value
?
value
:
null
;
}
else
if
(
operator
===
"~"
)
{
return
kbn
.
roundValue
(
dataStats
.
avg
+
value
,
precision
);
}
else
if
(
operator
===
"="
)
{
return
kbn
.
roundValue
(
dataStats
.
current
+
value
,
precision
);
}
else
if
(
!
operator
&&
!
isNaN
(
value
))
{
return
kbn
.
roundValue
(
value
,
precision
);
}
else
{
return
null
;
}
}
function
autoscaleYAxisMin
(
expr
,
dataStats
)
{
var
operator
=
expr
.
operator
,
value
=
expr
.
value
,
precision
=
expr
.
precision
;
if
(
operator
===
">"
)
{
return
dataStats
.
min
<
value
?
value
:
null
;
}
else
if
(
operator
===
"<"
)
{
return
dataStats
.
min
>
value
?
value
:
null
;
}
else
if
(
operator
===
"~"
)
{
return
kbn
.
roundValue
(
dataStats
.
avg
-
value
,
precision
);
}
else
if
(
operator
===
"="
)
{
return
kbn
.
roundValue
(
dataStats
.
current
-
value
,
precision
);
}
else
if
(
!
operator
&&
!
isNaN
(
value
))
{
return
kbn
.
roundValue
(
value
,
precision
);
}
else
{
return
null
;
}
}
function
configureAxisOptions
(
data
,
options
)
{
var
defaults
=
{
position
:
'left'
,
show
:
panel
.
yaxes
[
0
].
show
,
min
:
panel
.
yaxes
[
0
].
min
,
index
:
1
,
logBase
:
panel
.
yaxes
[
0
].
logBase
||
1
,
max
:
panel
.
percentage
&&
panel
.
stack
?
100
:
panel
.
yaxes
[
0
].
max
,
max
:
100
,
// correct later
};
// autoscaleSpanOverride(panel.yaxes[0], data[0], defaults);
options
.
yaxes
.
push
(
defaults
);
if
(
_
.
find
(
data
,
{
yaxis
:
2
}))
{
...
...
@@ -490,12 +422,7 @@ module.directive('grafanaGraph', function($rootScope, timeSrv) {
secondY
.
show
=
panel
.
yaxes
[
1
].
show
;
secondY
.
logBase
=
panel
.
yaxes
[
1
].
logBase
||
1
;
secondY
.
position
=
'right'
;
secondY
.
min
=
panel
.
yaxes
[
1
].
min
;
secondY
.
max
=
panel
.
percentage
&&
panel
.
stack
?
100
:
panel
.
yaxes
[
1
].
max
;
// autoscaleSpanOverride(panel.yaxes[1], data[1], secondY);
options
.
yaxes
.
push
(
secondY
);
applyLogScale
(
options
.
yaxes
[
1
],
data
);
configureAxisMode
(
options
.
yaxes
[
1
],
panel
.
percentage
&&
panel
.
stack
?
"percent"
:
panel
.
yaxes
[
1
].
format
);
}
...
...
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