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
1bec6c2a
Commit
1bec6c2a
authored
Nov 10, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(tablepanel): made annotations transform work
parent
a66825c7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
23 deletions
+76
-23
public/app/panels/table/controller.ts
+9
-6
public/app/panels/table/renderer.ts
+16
-16
public/app/panels/table/specs/renderer_specs.ts
+7
-1
public/app/panels/table/specs/transformers_specs.ts
+29
-0
public/app/panels/table/transformers.ts
+15
-0
No files found.
public/app/panels/table/controller.ts
View file @
1bec6c2a
...
...
@@ -9,7 +9,7 @@ import {TableModel} from './table_model';
export
class
TablePanelCtrl
{
constructor
(
$scope
,
$rootScope
,
$q
,
panelSrv
,
panelHelper
)
{
constructor
(
$scope
,
$rootScope
,
$q
,
panelSrv
,
panelHelper
,
annotationsSrv
)
{
$scope
.
ctrl
=
this
;
$scope
.
pageIndex
=
0
;
...
...
@@ -36,19 +36,22 @@ export class TablePanelCtrl {
$scope
.
init
=
function
()
{
_
.
defaults
(
$scope
.
panel
,
panelDefaults
);
if
(
$scope
.
panel
.
columns
.
length
===
0
)
{
}
panelSrv
.
init
(
$scope
);
};
$scope
.
refreshData
=
function
(
datasource
)
{
panelHelper
.
updateTimeRange
(
$scope
);
if
(
$scope
.
panel
.
transform
===
'annotations'
)
{
return
annotationsSrv
.
getAnnotations
(
$scope
.
dashboard
).
then
(
annotations
=>
{
$scope
.
dataRaw
=
annotations
;
$scope
.
render
();
});
}
return
panelHelper
.
issueMetricQuery
(
$scope
,
datasource
)
.
then
(
$scope
.
dataHandler
,
function
(
err
)
{
$scope
.
seriesList
=
[];
$scope
.
render
([]);
$scope
.
render
();
throw
err
;
});
};
...
...
public/app/panels/table/renderer.ts
View file @
1bec6c2a
...
...
@@ -24,9 +24,22 @@ export class TableRenderer {
return
null
;
}
defaultCellFormater
(
v
)
{
if
(
v
===
null
||
v
===
void
0
)
{
return
''
;
}
if
(
_
.
isArray
(
v
))
{
v
=
v
.
join
(
', '
);
}
return
v
;
}
createColumnFormater
(
style
)
{
if
(
!
style
)
{
return
v
=>
v
;
return
this
.
defaultCellFormater
;
}
if
(
style
.
type
===
'date'
)
{
...
...
@@ -60,17 +73,7 @@ export class TableRenderer {
};
}
return
v
=>
{
if
(
v
===
null
||
v
===
void
0
)
{
return
'-'
;
}
if
(
_
.
isArray
(
v
))
{
v
=
v
.
join
(
', '
);
}
return
v
;
};
return
this
.
defaultCellFormater
;
}
formatColumnValue
(
colIndex
,
value
)
{
...
...
@@ -88,10 +91,7 @@ export class TableRenderer {
}
}
this
.
formaters
[
colIndex
]
=
function
(
v
)
{
return
v
;
};
this
.
formaters
[
colIndex
]
=
this
.
defaultCellFormater
;
return
this
.
formaters
[
colIndex
](
value
);
}
...
...
public/app/panels/table/specs/renderer_specs.ts
View file @
1bec6c2a
...
...
@@ -9,7 +9,8 @@ describe('when rendering table', () => {
table
.
columns
=
[
{
text
:
'Time'
},
{
text
:
'Value'
},
{
text
:
'Colored'
}
{
text
:
'Colored'
},
{
text
:
'Undefined'
},
];
var
panel
=
{
...
...
@@ -59,6 +60,11 @@ describe('when rendering table', () => {
var
html
=
renderer
.
renderCell
(
2
,
55
);
expect
(
html
).
to
.
be
(
'<td style="color:orange">55.0</td>'
);
});
it
(
'unformated undefined should be rendered as -'
,
()
=>
{
var
html
=
renderer
.
renderCell
(
3
,
undefined
);
expect
(
html
).
to
.
be
(
'<td></td>'
);
});
});
});
...
...
public/app/panels/table/specs/transformers_specs.ts
View file @
1bec6c2a
...
...
@@ -103,8 +103,37 @@ describe('when transforming time series table', () => {
expect
(
table
.
rows
[
0
][
0
]).
to
.
be
(
'time'
);
expect
(
table
.
rows
[
0
][
1
]).
to
.
be
(
'message'
);
});
});
describe
(
'Annnotations'
,
()
=>
{
var
panel
=
{
transform
:
'annotations'
};
var
rawData
=
[
{
min
:
1000
,
text
:
'hej'
,
tags
:
[
'tags'
,
'asd'
],
title
:
'title'
,
}
];
beforeEach
(()
=>
{
table
=
TableModel
.
transform
(
rawData
,
panel
);
});
it
(
'should return 4 columns'
,
()
=>
{
expect
(
table
.
columns
.
length
).
to
.
be
(
4
);
expect
(
table
.
columns
[
0
].
text
).
to
.
be
(
'Time'
);
expect
(
table
.
columns
[
1
].
text
).
to
.
be
(
'Title'
);
expect
(
table
.
columns
[
2
].
text
).
to
.
be
(
'Text'
);
expect
(
table
.
columns
[
3
].
text
).
to
.
be
(
'Tags'
);
});
it
(
'should return 1 rows'
,
()
=>
{
expect
(
table
.
rows
.
length
).
to
.
be
(
1
);
expect
(
table
.
rows
[
0
][
0
]).
to
.
be
(
1000
);
});
});
});
});
public/app/panels/table/transformers.ts
View file @
1bec6c2a
...
...
@@ -66,6 +66,21 @@ transformers['timeseries_to_columns'] = {
transformers
[
'annotations'
]
=
{
description
:
'Annotations'
,
transform
:
function
(
data
,
panel
,
model
)
{
model
.
columns
.
push
({
text
:
'Time'
,
type
:
'date'
});
model
.
columns
.
push
({
text
:
'Title'
});
model
.
columns
.
push
({
text
:
'Text'
});
model
.
columns
.
push
({
text
:
'Tags'
});
if
(
!
data
||
data
.
length
===
0
)
{
return
;
}
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
evt
=
data
[
i
];
model
.
rows
.
push
([
evt
.
min
,
evt
.
title
,
evt
.
text
,
evt
.
tags
]);
}
}
};
transformers
[
'json'
]
=
{
...
...
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