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
a49ef90a
Commit
a49ef90a
authored
Apr 21, 2017
by
Daniel Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
singlestat: value mapping for table data
Adds support for value mapping for table data in the single stat panel.
parent
8874be4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
110 additions
and
52 deletions
+110
-52
public/app/plugins/panel/singlestat/module.ts
+5
-0
public/app/plugins/panel/singlestat/specs/singlestat_specs.ts
+105
-52
No files found.
public/app/plugins/panel/singlestat/module.ts
View file @
a49ef90a
...
...
@@ -178,6 +178,8 @@ class SingleStatCtrl extends MetricsPanelCtrl {
var
formatFunc
=
kbn
.
valueFormats
[
this
.
panel
.
format
];
data
.
valueFormatted
=
formatFunc
(
datapoint
[
this
.
panel
.
tableColumn
],
decimalInfo
.
decimals
,
decimalInfo
.
scaledDecimals
);
data
.
valueRounded
=
kbn
.
roundValue
(
data
.
value
,
this
.
panel
.
decimals
||
0
);
this
.
setValueMapping
(
data
);
}
setColoring
(
options
)
{
...
...
@@ -274,7 +276,10 @@ class SingleStatCtrl extends MetricsPanelCtrl {
data
.
scopedVars
=
_
.
extend
({},
this
.
panel
.
scopedVars
);
data
.
scopedVars
[
"__name"
]
=
{
value
:
this
.
series
[
0
].
label
};
}
this
.
setValueMapping
(
data
);
}
setValueMapping
(
data
)
{
// check value to text mappings if its enabled
if
(
this
.
panel
.
mappingType
===
1
)
{
for
(
let
i
=
0
;
i
<
this
.
panel
.
valueMaps
.
length
;
i
++
)
{
...
...
public/app/plugins/panel/singlestat/specs/singlestat_specs.ts
View file @
a49ef90a
...
...
@@ -136,60 +136,113 @@ describe('SingleStatCtrl', function() {
});
});
const
tableData
=
[{
"columns"
:
[
{
"text"
:
"Time"
,
"type"
:
"time"
},
{
"text"
:
"test1"
},
{
"text"
:
"mean"
},
{
"text"
:
"test2"
}
],
"rows"
:
[
[
1492759673649
,
'ignore1'
,
15
,
'ignore2'
]
],
"type"
:
"table"
}];
singleStatScenario
(
'When table data'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should use series avg as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
15
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'15'
);
});
});
singleStatScenario
(
'When table data has multiple columns'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
''
;
});
it
(
'Should set column to first column that is not time'
,
function
()
{
expect
(
ctx
.
ctrl
.
panel
.
tableColumn
).
to
.
be
(
'test1'
);
describe
(
'When table data'
,
function
()
{
const
tableData
=
[{
"columns"
:
[
{
"text"
:
"Time"
,
"type"
:
"time"
},
{
"text"
:
"test1"
},
{
"text"
:
"mean"
},
{
"text"
:
"test2"
}
],
"rows"
:
[
[
1492759673649
,
'ignore1'
,
15
,
'ignore2'
]
],
"type"
:
"table"
}];
singleStatScenario
(
'with default values'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should use first rows value as default main value'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
15
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
15
);
});
it
(
'should set formatted value'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'15'
);
});
});
singleStatScenario
(
'When table data has multiple columns'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
ctrl
.
panel
.
tableColumn
=
''
;
});
it
(
'Should set column to first column that is not time'
,
function
()
{
expect
(
ctx
.
ctrl
.
panel
.
tableColumn
).
to
.
be
(
'test1'
);
});
});
singleStatScenario
(
'MainValue should use same number for decimals as displayed when checking thresholds'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
99.99999
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
});
it
(
'Should be rounded'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
99.99999
);
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
100
);
});
it
(
'should set formatted falue'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'100'
);
});
});
singleStatScenario
(
'When value to text mapping is specified'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
9.9
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
valueMaps
=
[{
value
:
'10'
,
text
:
'OK'
}];
});
it
(
'value should remain'
,
function
()
{
expect
(
ctx
.
data
.
value
).
to
.
be
(
9.9
);
});
it
(
'round should be rounded up'
,
function
()
{
expect
(
ctx
.
data
.
valueRounded
).
to
.
be
(
10
);
});
it
(
'Should replace value with text'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for first range'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
41
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'OK'
);
});
});
singleStatScenario
(
'When range to text mapping is specified for other ranges'
,
function
(
ctx
)
{
ctx
.
setup
(
function
()
{
ctx
.
data
=
tableData
;
ctx
.
data
[
0
].
rows
[
0
]
=
[
1492759673649
,
'ignore1'
,
65
,
'ignore2'
];
ctx
.
ctrl
.
panel
.
tableColumn
=
'mean'
;
ctx
.
ctrl
.
panel
.
mappingType
=
2
;
ctx
.
ctrl
.
panel
.
rangeMaps
=
[{
from
:
'10'
,
to
:
'50'
,
text
:
'OK'
},{
from
:
'51'
,
to
:
'100'
,
text
:
'NOT OK'
}];
});
it
(
'Should replace value with text NOT OK'
,
function
()
{
expect
(
ctx
.
data
.
valueFormatted
).
to
.
be
(
'NOT OK'
);
});
});
});
});
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