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
37176fa4
Commit
37176fa4
authored
Nov 06, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SingleStatPanel: Finnaly solved automatic decimal precision calculation for singlestat panel, #951
parent
7ff8931d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
9 deletions
+46
-9
src/app/components/kbn.js
+5
-3
src/app/panels/stats/module.js
+41
-6
No files found.
src/app/components/kbn.js
View file @
37176fa4
...
@@ -327,18 +327,20 @@ function($, _, moment) {
...
@@ -327,18 +327,20 @@ function($, _, moment) {
size
/=
factor
;
size
/=
factor
;
}
}
if
(
steps
>
0
)
{
if
(
steps
>
0
)
{
d
ecimals
=
scaledDecimals
+
(
3
*
steps
);
scaledD
ecimals
=
scaledDecimals
+
(
3
*
steps
);
}
}
return
kbn
.
toFixed
(
size
,
decimals
)
+
extArray
[
steps
];
return
kbn
.
toFixed
(
size
,
scaledDecimals
,
decimals
)
+
extArray
[
steps
];
};
};
};
};
kbn
.
toFixed
=
function
(
value
,
decimals
)
{
kbn
.
toFixed
=
function
(
value
,
decimals
,
fallbackDecimals
)
{
if
(
value
===
null
)
{
if
(
value
===
null
)
{
return
""
;
return
""
;
}
}
decimals
=
decimals
||
fallbackDecimals
;
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
);
...
...
src/app/panels/stats/module.js
View file @
37176fa4
...
@@ -65,10 +65,6 @@ function (angular, app, _, TimeSeries, kbn) {
...
@@ -65,10 +65,6 @@ function (angular, app, _, TimeSeries, kbn) {
$scope
.
$on
(
'refresh'
,
$scope
.
get_data
);
$scope
.
$on
(
'refresh'
,
$scope
.
get_data
);
};
};
$scope
.
formatValue
=
function
(
value
)
{
return
kbn
.
valueFormats
[
$scope
.
panel
.
format
](
value
,
0
,
-
7
);
};
$scope
.
updateTimeRange
=
function
()
{
$scope
.
updateTimeRange
=
function
()
{
$scope
.
range
=
timeSrv
.
timeRange
();
$scope
.
range
=
timeSrv
.
timeRange
();
$scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
$scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
...
@@ -132,6 +128,43 @@ function (angular, app, _, TimeSeries, kbn) {
...
@@ -132,6 +128,43 @@ function (angular, app, _, TimeSeries, kbn) {
$scope
.
render
();
$scope
.
render
();
};
};
$scope
.
getDecimalsForValue
=
function
(
value
)
{
var
opts
=
{};
var
delta
=
value
/
2
;
var
dec
=
-
Math
.
floor
(
Math
.
log
(
delta
)
/
Math
.
LN10
);
var
magn
=
Math
.
pow
(
10
,
-
dec
),
norm
=
delta
/
magn
,
// norm is between 1.0 and 10.0
size
;
if
(
norm
<
1.5
)
{
size
=
1
;
}
else
if
(
norm
<
3
)
{
size
=
2
;
// special case for 2.5, requires an extra decimal
if
(
norm
>
2.25
)
{
size
=
2.5
;
++
dec
;
}
}
else
if
(
norm
<
7.5
)
{
size
=
5
;
}
else
{
size
=
10
;
}
size
*=
magn
;
if
(
opts
.
minTickSize
!=
null
&&
size
<
opts
.
minTickSize
)
{
size
=
opts
.
minTickSize
;
}
var
result
=
{};
result
.
decimals
=
Math
.
max
(
0
,
dec
);
result
.
scaledDecimals
=
result
.
decimals
-
Math
.
floor
(
Math
.
log
(
size
)
/
Math
.
LN10
);
return
result
;
};
$scope
.
render
=
function
()
{
$scope
.
render
=
function
()
{
var
data
=
{};
var
data
=
{};
...
@@ -140,9 +173,11 @@ function (angular, app, _, TimeSeries, kbn) {
...
@@ -140,9 +173,11 @@ function (angular, app, _, TimeSeries, kbn) {
}
}
else
{
else
{
var
series
=
$scope
.
series
[
0
];
var
series
=
$scope
.
series
[
0
];
series
.
updateLegendValues
(
kbn
.
valueFormats
[
$scope
.
panel
.
format
],
2
,
-
7
);
data
.
mainValue
=
series
.
stats
[
$scope
.
panel
.
valueName
];
data
.
mainValue
=
series
.
stats
[
$scope
.
panel
.
valueName
];
data
.
mainValueFormated
=
$scope
.
formatValue
(
data
.
mainValue
);
var
decimalInfo
=
$scope
.
getDecimalsForValue
(
data
.
mainValue
);
var
formatFunc
=
kbn
.
valueFormats
[
$scope
.
panel
.
format
];
data
.
mainValueFormated
=
formatFunc
(
data
.
mainValue
,
decimalInfo
.
decimals
,
decimalInfo
.
scaledDecimals
);
data
.
flotpairs
=
series
.
flotpairs
;
data
.
flotpairs
=
series
.
flotpairs
;
}
}
...
...
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