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
6062930f
Commit
6062930f
authored
Nov 04, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(tablepanel): added more unit tests for table transforms
parent
867b8380
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
172 additions
and
146 deletions
+172
-146
public/app/panels/table/module.ts
+6
-2
public/app/panels/table/options.html
+9
-2
public/app/panels/table/specs/table_model_specs.ts
+0
-65
public/app/panels/table/specs/transformers_specs.ts
+72
-0
public/app/panels/table/table_model.ts
+1
-77
public/app/panels/table/transformers.ts
+84
-0
No files found.
public/app/panels/table/module.ts
View file @
6062930f
...
...
@@ -6,7 +6,9 @@ import _ = require('lodash');
import
moment
=
require
(
'moment'
);
import
PanelMeta
=
require
(
'app/features/panel/panel_meta'
);
import
TimeSeries
=
require
(
'app/core/time_series'
);
import
{
TableModel
,
transformers
}
from
'./table_model'
;
import
{
TableModel
}
from
'./table_model'
;
import
{
transformers
}
from
'./transformers'
;
export
class
TablePanelCtrl
{
...
...
@@ -26,7 +28,9 @@ export class TablePanelCtrl {
var
panelDefaults
=
{
targets
:
[{}],
transform
:
'timeseries_to_rows'
transform
:
'timeseries_to_rows'
,
pageSize
:
50
,
showHeader
:
true
,
};
_
.
defaults
(
$scope
.
panel
,
panelDefaults
);
...
...
public/app/panels/table/options.html
View file @
6062930f
<div
class=
"editor-row"
>
<div
class=
"tight-form-section"
>
<h5>
Data
Table
</h5>
<h5>
Data
</h5>
<div
class=
"tight-form"
>
<ul
class=
"tight-form-list"
>
<li
class=
"tight-form-item"
style=
"width: 170px"
>
Data t
o Table Transform
T
o Table Transform
</li>
<li>
<select
class=
"input-xlarge tight-form-input"
...
...
@@ -22,6 +22,13 @@
<div
class=
"tight-form-section"
>
<h5>
Table Display
</h5>
</div>
<li
class=
"tight-form-item"
style=
"width: 80px"
>
Pagination (Page size)
</li>
<li>
<input
type=
"pageSize"
class=
"input-small tight-form-input"
placeholder=
"50"
empty-to-null
ng-model=
"panel.pageSize"
ng-change=
"render()"
ng-model-onblur
>
</li>
</div>
<div
class=
"editor-row"
>
...
...
public/app/panels/table/specs/table_model_specs.ts
deleted
100644 → 0
View file @
867b8380
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
{
TableModel
}
from
'../table_model'
;
describe
(
'when getting tableData'
,
()
=>
{
describe
(
'timeseries_to_rows'
,
()
=>
{
var
panel
=
{
transform
:
'timeseries_to_rows'
};
it
(
'should return 2 rows'
,
()
=>
{
var
data
=
TableModel
.
transform
([
{
target
:
'series1'
,
datapoints
:
[[
12.12
,
new
Date
().
getTime
()]],
},
{
target
:
'series2'
,
datapoints
:
[[
12.12
,
new
Date
().
getTime
()]],
}
],
panel
);
expect
(
data
.
columns
.
length
).
to
.
be
(
3
);
expect
(
data
.
rows
.
length
).
to
.
be
(
2
);
expect
(
data
.
columns
[
0
].
text
).
to
.
be
(
'Time'
);
expect
(
data
.
columns
[
1
].
text
).
to
.
be
(
'Series'
);
expect
(
data
.
columns
[
2
].
text
).
to
.
be
(
'Value'
);
expect
(
data
.
rows
[
0
][
1
]).
to
.
be
(
'series1'
);
expect
(
data
.
rows
[
0
][
2
]).
to
.
be
(
'12.12'
);
expect
(
data
.
rows
[
1
][
1
]).
to
.
be
(
'series2'
);
});
});
describe
(
'timeseries_to_rows'
,
()
=>
{
var
panel
=
{
transform
:
'timeseries_to_columns'
};
it
(
'should return 3 columns'
,
()
=>
{
var
data
=
TableModel
.
transform
([
{
target
:
'series1'
,
datapoints
:
[[
12.12
,
new
Date
().
getTime
()]],
},
{
target
:
'series2'
,
datapoints
:
[[
16.12
,
new
Date
().
getTime
()]],
}
],
panel
);
expect
(
data
.
columns
.
length
).
to
.
be
(
3
);
expect
(
data
.
rows
.
length
).
to
.
be
(
1
);
expect
(
data
.
columns
[
0
].
text
).
to
.
be
(
'Time'
);
expect
(
data
.
columns
[
1
].
text
).
to
.
be
(
'series1'
);
expect
(
data
.
columns
[
2
].
text
).
to
.
be
(
'series2'
);
expect
(
data
.
rows
[
0
][
1
]).
to
.
be
(
'12.12'
);
expect
(
data
.
rows
[
0
][
2
]).
to
.
be
(
'16.12'
);
});
});
});
public/app/panels/table/specs/transformers_specs.ts
0 → 100644
View file @
6062930f
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
}
from
'test/lib/common'
;
import
{
TableModel
}
from
'../table_model'
;
describe
(
'when transforming time series table'
,
()
=>
{
var
table
;
describe
(
'given 2 time series'
,
()
=>
{
var
time
=
new
Date
().
getTime
();
var
timeSeries
=
[
{
target
:
'series1'
,
datapoints
:
[[
12.12
,
time
],
[
14.44
,
time
+
1
]],
},
{
target
:
'series2'
,
datapoints
:
[[
16.12
,
time
]],
}
];
describe
(
'timeseries_to_rows'
,
()
=>
{
var
panel
=
{
transform
:
'timeseries_to_rows'
};
beforeEach
(()
=>
{
table
=
TableModel
.
transform
(
timeSeries
,
panel
);
});
it
(
'should return 3 rows'
,
()
=>
{
expect
(
table
.
rows
.
length
).
to
.
be
(
3
);
expect
(
table
.
rows
[
0
][
1
]).
to
.
be
(
'series1'
);
expect
(
table
.
rows
[
1
][
1
]).
to
.
be
(
'series1'
);
expect
(
table
.
rows
[
2
][
1
]).
to
.
be
(
'series2'
);
expect
(
table
.
rows
[
0
][
2
]).
to
.
be
(
'12.12'
);
});
it
(
'should return 3 rows'
,
()
=>
{
expect
(
table
.
columns
.
length
).
to
.
be
(
3
);
expect
(
table
.
columns
[
0
].
text
).
to
.
be
(
'Time'
);
expect
(
table
.
columns
[
1
].
text
).
to
.
be
(
'Series'
);
expect
(
table
.
columns
[
2
].
text
).
to
.
be
(
'Value'
);
});
});
describe
(
'timeseries_to_columns'
,
()
=>
{
var
panel
=
{
transform
:
'timeseries_to_columns'
};
beforeEach
(()
=>
{
table
=
TableModel
.
transform
(
timeSeries
,
panel
);
});
it
(
'should return 3 columns'
,
()
=>
{
expect
(
table
.
columns
.
length
).
to
.
be
(
3
);
expect
(
table
.
columns
[
0
].
text
).
to
.
be
(
'Time'
);
expect
(
table
.
columns
[
1
].
text
).
to
.
be
(
'series1'
);
expect
(
table
.
columns
[
2
].
text
).
to
.
be
(
'series2'
);
});
it
(
'should return 2 rows'
,
()
=>
{
expect
(
table
.
rows
.
length
).
to
.
be
(
2
);
expect
(
table
.
rows
[
0
][
1
]).
to
.
be
(
'12.12'
);
expect
(
table
.
rows
[
0
][
2
]).
to
.
be
(
'16.12'
);
});
it
(
'should show - when no value for timestamp'
,
()
=>
{
expect
(
table
.
rows
[
1
][
2
]).
to
.
be
(
'-'
);
});
});
});
});
public/app/panels/table/table_model.ts
View file @
6062930f
///<reference path="../../headers/common.d.ts" />
import
moment
=
require
(
'moment'
);
import
_
=
require
(
'lodash'
);
var
transformers
=
{};
transformers
[
'timeseries_to_rows'
]
=
{
description
:
'Time series to rows'
,
transform
:
function
(
data
,
panel
,
model
)
{
model
.
columns
=
[
{
text
:
'Time'
},
{
text
:
'Series'
},
{
text
:
'Value'
},
];
model
.
rows
=
[];
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
for
(
var
y
=
0
;
y
<
series
.
datapoints
.
length
;
y
++
)
{
var
dp
=
series
.
datapoints
[
y
];
var
time
=
moment
(
dp
[
1
]).
format
(
'LLL'
);
var
value
=
dp
[
0
];
if
(
value
===
null
)
{
value
=
'null'
;
}
else
if
(
_
.
isNumber
(
value
))
{
value
=
value
.
toFixed
(
2
);
}
model
.
rows
.
push
([
time
,
series
.
target
,
value
]);
}
}
},
};
transformers
[
'timeseries_to_columns'
]
=
{
description
:
'Time series to columns'
,
transform
:
function
(
data
,
panel
,
model
)
{
model
.
columns
=
[{
text
:
'Time'
}];
model
.
rows
=
[];
var
points
=
{};
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
model
.
columns
.
push
({
text
:
series
.
target
});
for
(
var
y
=
0
;
y
<
series
.
datapoints
.
length
;
y
++
)
{
var
dp
=
series
.
datapoints
[
y
];
var
time
=
dp
[
1
];
if
(
!
points
[
time
])
{
points
[
time
]
=
{};
points
[
time
][
i
]
=
[
dp
[
0
]];
}
else
{
points
[
time
][
i
]
=
dp
[
0
];
}
}
}
for
(
var
time
in
points
)
{
var
point
=
points
[
time
];
var
values
=
[
time
];
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
point
[
i
]
!==
undefined
)
{
values
.
push
(
point
[
i
]);
}
}
model
.
rows
.
push
(
values
);
}
}
};
export
{
transformers
}
import
{
transformers
}
from
'./transformers'
;
export
class
TableModel
{
columns
:
any
[];
...
...
public/app/panels/table/transformers.ts
0 → 100644
View file @
6062930f
///<reference path="../../headers/common.d.ts" />
import
moment
=
require
(
'moment'
);
import
_
=
require
(
'lodash'
);
var
transformers
=
{};
transformers
[
'timeseries_to_rows'
]
=
{
description
:
'Time series to rows'
,
transform
:
function
(
data
,
panel
,
model
)
{
model
.
columns
=
[
{
text
:
'Time'
},
{
text
:
'Series'
},
{
text
:
'Value'
},
];
model
.
rows
=
[];
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
for
(
var
y
=
0
;
y
<
series
.
datapoints
.
length
;
y
++
)
{
var
dp
=
series
.
datapoints
[
y
];
var
time
=
moment
(
dp
[
1
]).
format
(
'LLL'
);
var
value
=
dp
[
0
];
if
(
value
===
null
)
{
value
=
'null'
;
}
else
if
(
_
.
isNumber
(
value
))
{
value
=
value
.
toFixed
(
2
);
}
model
.
rows
.
push
([
time
,
series
.
target
,
value
]);
}
}
},
};
transformers
[
'timeseries_to_columns'
]
=
{
description
:
'Time series to columns'
,
transform
:
function
(
data
,
panel
,
model
)
{
model
.
columns
=
[{
text
:
'Time'
}];
model
.
rows
=
[];
// group by time
var
points
=
{};
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
model
.
columns
.
push
({
text
:
series
.
target
});
for
(
var
y
=
0
;
y
<
series
.
datapoints
.
length
;
y
++
)
{
var
dp
=
series
.
datapoints
[
y
];
var
timeKey
=
dp
[
1
].
toString
();
if
(
!
points
[
timeKey
])
{
points
[
timeKey
]
=
{
time
:
dp
[
1
]};
points
[
timeKey
][
i
]
=
dp
[
0
];
}
else
{
points
[
timeKey
][
i
]
=
dp
[
0
];
}
}
}
for
(
var
time
in
points
)
{
var
point
=
points
[
time
];
var
values
=
[
moment
(
point
.
time
).
format
(
'LLL'
)];
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
value
=
point
[
i
];
if
(
_
.
isNumber
(
value
))
{
values
.
push
(
value
.
toFixed
(
2
));
}
else
{
values
.
push
(
'-'
);
}
}
model
.
rows
.
push
(
values
);
}
}
};
export
{
transformers
}
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