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
e78c4862
Commit
e78c4862
authored
Sep 19, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Trying to improve yaxis precision
parent
563dd898
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
81 deletions
+33
-81
src/app/components/kbn.js
+9
-67
src/app/components/timeSeries.js
+8
-8
src/app/directives/grafanaGraph.js
+16
-6
No files found.
src/app/components/kbn.js
View file @
e78c4862
...
@@ -7,6 +7,7 @@ function($, _, moment) {
...
@@ -7,6 +7,7 @@ function($, _, moment) {
'use strict'
;
'use strict'
;
var
kbn
=
{};
var
kbn
=
{};
kbn
.
formatFunctions
=
{};
kbn
.
round_interval
=
function
(
interval
)
{
kbn
.
round_interval
=
function
(
interval
)
{
switch
(
true
)
{
switch
(
true
)
{
...
@@ -497,52 +498,7 @@ function($, _, moment) {
...
@@ -497,52 +498,7 @@ function($, _, moment) {
return
(
size
.
toFixed
(
decimals
)
+
ext
);
return
(
size
.
toFixed
(
decimals
)
+
ext
);
};
};
kbn
.
getFormatFunction
=
function
(
formatName
,
decimals
)
{
kbn
.
toFixed
=
function
(
value
,
decimals
)
{
switch
(
formatName
)
{
case
'short'
:
return
function
(
val
)
{
return
kbn
.
shortFormat
(
val
,
decimals
);
};
case
'bytes'
:
return
function
(
val
)
{
return
kbn
.
byteFormat
(
val
,
decimals
);
};
case
'bits'
:
return
function
(
val
)
{
return
kbn
.
bitFormat
(
val
,
decimals
);
};
case
'bps'
:
return
function
(
val
)
{
return
kbn
.
bpsFormat
(
val
,
decimals
);
};
case
's'
:
return
function
(
val
)
{
return
kbn
.
sFormat
(
val
,
decimals
);
};
case
'ms'
:
return
function
(
val
)
{
return
kbn
.
msFormat
(
val
,
decimals
);
};
case
'µs'
:
return
function
(
val
)
{
return
kbn
.
microsFormat
(
val
,
decimals
);
};
case
'ns'
:
return
function
(
val
)
{
return
kbn
.
nanosFormat
(
val
,
decimals
);
};
case
'percent'
:
return
function
(
val
,
axis
)
{
return
kbn
.
noneFormat
(
val
,
axis
?
axis
.
tickDecimals
:
null
)
+
' %'
;
};
default
:
return
function
(
val
,
axis
)
{
return
kbn
.
noneFormat
(
val
,
axis
?
axis
.
tickDecimals
:
null
);
};
}
};
kbn
.
noneFormat
=
function
(
value
,
decimals
)
{
var
factor
=
decimals
?
Math
.
pow
(
10
,
decimals
)
:
1
;
var
factor
=
decimals
?
Math
.
pow
(
10
,
decimals
)
:
1
;
var
formatted
=
String
(
Math
.
round
(
value
*
factor
)
/
factor
);
var
formatted
=
String
(
Math
.
round
(
value
*
factor
)
/
factor
);
...
@@ -553,7 +509,6 @@ function($, _, moment) {
...
@@ -553,7 +509,6 @@ function($, _, moment) {
// If tickDecimals was specified, ensure that we have exactly that
// If tickDecimals was specified, ensure that we have exactly that
// much precision; otherwise default to the value's own precision.
// much precision; otherwise default to the value's own precision.
if
(
decimals
!=
null
)
{
if
(
decimals
!=
null
)
{
var
decimalPos
=
formatted
.
indexOf
(
"."
);
var
decimalPos
=
formatted
.
indexOf
(
"."
);
var
precision
=
decimalPos
===
-
1
?
0
:
formatted
.
length
-
decimalPos
-
1
;
var
precision
=
decimalPos
===
-
1
?
0
:
formatted
.
length
-
decimalPos
-
1
;
...
@@ -565,17 +520,13 @@ function($, _, moment) {
...
@@ -565,17 +520,13 @@ function($, _, moment) {
return
formatted
;
return
formatted
;
};
};
kbn
.
msFormat
=
function
(
size
,
decimals
)
{
kbn
.
formatFunctions
.
ms
=
function
(
size
,
decimals
)
{
// Less than 1 milli, downscale to micro
if
(
Math
.
abs
(
size
)
<
1000
)
{
if
(
size
!==
0
&&
Math
.
abs
(
size
)
<
1
)
{
return
kbn
.
toFixed
(
size
,
decimals
)
+
" ms"
;
return
kbn
.
microsFormat
(
size
*
1000
,
decimals
);
}
else
if
(
Math
.
abs
(
size
)
<
1000
)
{
return
size
.
toFixed
(
decimals
)
+
" ms"
;
}
}
// Less than 1 min
// Less than 1 min
else
if
(
Math
.
abs
(
size
)
<
60000
)
{
else
if
(
Math
.
abs
(
size
)
<
60000
)
{
return
(
size
/
1000
).
toFixed
(
decimals
)
+
" s"
;
return
kbn
.
toFixed
(
size
/
1000
,
decimals
)
+
" s"
;
}
}
// Less than 1 hour, devide in minutes
// Less than 1 hour, devide in minutes
else
if
(
Math
.
abs
(
size
)
<
3600000
)
{
else
if
(
Math
.
abs
(
size
)
<
3600000
)
{
...
@@ -594,12 +545,7 @@ function($, _, moment) {
...
@@ -594,12 +545,7 @@ function($, _, moment) {
};
};
kbn
.
sFormat
=
function
(
size
,
decimals
)
{
kbn
.
sFormat
=
function
(
size
,
decimals
)
{
// Less than 1 sec, downscale to milli
if
(
Math
.
abs
(
size
)
<
600
)
{
if
(
size
!==
0
&&
Math
.
abs
(
size
)
<
1
)
{
return
kbn
.
msFormat
(
size
*
1000
,
decimals
);
}
// Less than 10 min, use seconds
else
if
(
Math
.
abs
(
size
)
<
600
)
{
return
size
.
toFixed
(
decimals
)
+
" s"
;
return
size
.
toFixed
(
decimals
)
+
" s"
;
}
}
// Less than 1 hour, devide in minutes
// Less than 1 hour, devide in minutes
...
@@ -623,12 +569,8 @@ function($, _, moment) {
...
@@ -623,12 +569,8 @@ function($, _, moment) {
};
};
kbn
.
microsFormat
=
function
(
size
,
decimals
)
{
kbn
.
microsFormat
=
function
(
size
,
decimals
)
{
// Less than 1 micro, downscale to nano
if
(
Math
.
abs
(
size
)
<
1000
)
{
if
(
size
!==
0
&&
Math
.
abs
(
size
)
<
1
)
{
return
kbn
.
toFixed
(
size
,
decimals
)
+
" µs"
;
return
kbn
.
nanosFormat
(
size
*
1000
,
decimals
);
}
else
if
(
Math
.
abs
(
size
)
<
1000
)
{
return
size
.
toFixed
(
decimals
)
+
" µs"
;
}
}
else
if
(
Math
.
abs
(
size
)
<
1000000
)
{
else
if
(
Math
.
abs
(
size
)
<
1000000
)
{
return
(
size
/
1000
).
toFixed
(
decimals
)
+
" ms"
;
return
(
size
/
1000
).
toFixed
(
decimals
)
+
" ms"
;
...
...
src/app/components/timeSeries.js
View file @
e78c4862
...
@@ -100,21 +100,21 @@ function (_, kbn) {
...
@@ -100,21 +100,21 @@ function (_, kbn) {
}
}
if
(
result
.
length
)
{
if
(
result
.
length
)
{
this
.
info
.
avg
=
(
this
.
info
.
total
/
result
.
length
);
this
.
info
.
avg
=
(
this
.
info
.
total
/
result
.
length
);
this
.
info
.
current
=
result
[
result
.
length
-
1
][
1
];
this
.
info
.
current
=
result
[
result
.
length
-
1
][
1
];
var
formater
=
kbn
.
getFormatFunction
(
yFormats
[
this
.
yaxis
-
1
],
2
);
this
.
info
.
avg
=
this
.
info
.
avg
!=
null
?
formater
(
this
.
info
.
avg
)
:
null
;
this
.
info
.
current
=
this
.
info
.
current
!=
null
?
formater
(
this
.
info
.
current
)
:
null
;
this
.
info
.
min
=
this
.
info
.
min
!=
null
?
formater
(
this
.
info
.
min
)
:
null
;
this
.
info
.
max
=
this
.
info
.
max
!=
null
?
formater
(
this
.
info
.
max
)
:
null
;
this
.
info
.
total
=
this
.
info
.
total
!=
null
?
formater
(
this
.
info
.
total
)
:
null
;
}
}
return
result
;
return
result
;
};
};
TimeSeries
.
prototype
.
updateLegendValues
=
function
(
formater
,
decimals
)
{
this
.
info
.
avg
=
this
.
info
.
avg
!=
null
?
formater
(
this
.
info
.
avg
,
decimals
)
:
null
;
this
.
info
.
current
=
this
.
info
.
current
!=
null
?
formater
(
this
.
info
.
current
,
decimals
)
:
null
;
this
.
info
.
min
=
this
.
info
.
min
!=
null
?
formater
(
this
.
info
.
min
,
decimals
)
:
null
;
this
.
info
.
max
=
this
.
info
.
max
!=
null
?
formater
(
this
.
info
.
max
,
decimals
)
:
null
;
this
.
info
.
total
=
this
.
info
.
total
!=
null
?
formater
(
this
.
info
.
total
,
decimals
)
:
null
;
};
return
TimeSeries
;
return
TimeSeries
;
});
});
src/app/directives/grafanaGraph.js
View file @
e78c4862
...
@@ -88,6 +88,18 @@ function (angular, $, kbn, moment, _) {
...
@@ -88,6 +88,18 @@ function (angular, $, kbn, moment, _) {
}
}
}
}
function
updateLegendValues
(
plot
)
{
var
yaxis
=
plot
.
getYAxes
();
console
.
log
(
'drawSeries'
,
yaxis
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
var
formater
=
kbn
.
formatFunctions
[
scope
.
panel
.
y_formats
[
series
.
yaxis
-
1
]];
series
.
updateLegendValues
(
formater
,
yaxis
[
series
.
yaxis
-
1
].
tickDecimals
);
}
}
// Function for rendering panel
// Function for rendering panel
function
render_panel
()
{
function
render_panel
()
{
if
(
shouldAbortRender
())
{
if
(
shouldAbortRender
())
{
...
@@ -110,11 +122,7 @@ function (angular, $, kbn, moment, _) {
...
@@ -110,11 +122,7 @@ function (angular, $, kbn, moment, _) {
// Populate element
// Populate element
var
options
=
{
var
options
=
{
hooks
:
{
hooks
:
{
draw
:
[
updateLegendValues
]
},
drawSeries
:
[
function
()
{
console
.
log
(
'drawSeries'
,
arguments
);
}]
},
legend
:
{
show
:
false
},
legend
:
{
show
:
false
},
series
:
{
series
:
{
stackpercent
:
panel
.
stack
?
panel
.
percentage
:
false
,
stackpercent
:
panel
.
stack
?
panel
.
percentage
:
false
,
...
@@ -318,7 +326,9 @@ function (angular, $, kbn, moment, _) {
...
@@ -318,7 +326,9 @@ function (angular, $, kbn, moment, _) {
}
}
function
configureAxisMode
(
axis
,
format
)
{
function
configureAxisMode
(
axis
,
format
)
{
axis
.
tickFormatter
=
kbn
.
getFormatFunction
(
format
,
1
);
axis
.
tickFormatter
=
function
(
val
,
axis
)
{
return
kbn
.
formatFunctions
[
format
](
val
,
axis
.
tickDecimals
);
};
}
}
function
time_format
(
interval
,
ticks
,
min
,
max
)
{
function
time_format
(
interval
,
ticks
,
min
,
max
)
{
...
...
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