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
be330b6a
Commit
be330b6a
authored
Jan 05, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring and more unit tests for graphite functions
parent
7a2011d9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
22 deletions
+74
-22
src/app/controllers/graphiteTarget.js
+5
-5
src/app/services/graphite/gfunc.js
+8
-16
src/test/karma.conf.js
+1
-0
src/test/specs/gfunc-specs.js
+46
-0
src/test/test-main.js
+14
-1
No files found.
src/app/controllers/graphiteTarget.js
View file @
be330b6a
...
...
@@ -2,10 +2,10 @@ define([
'angular'
,
'underscore'
,
'config'
,
'../services/graphite/g
raphiteFuncs
'
,
'../services/graphite/g
func
'
,
'../services/graphite/parser'
],
function
(
angular
,
_
,
config
,
g
raphiteFuncs
,
Parser
)
{
function
(
angular
,
_
,
config
,
g
func
,
Parser
)
{
'use strict'
;
var
module
=
angular
.
module
(
'kibana.controllers'
);
...
...
@@ -13,7 +13,7 @@ function (angular, _, config, graphiteFuncs, Parser) {
module
.
controller
(
'GraphiteTargetCtrl'
,
function
(
$scope
,
$http
,
filterSrv
,
graphiteSrv
)
{
$scope
.
init
=
function
()
{
$scope
.
funcCategories
=
g
raphiteFuncs
.
getCategories
();
$scope
.
funcCategories
=
g
func
.
getCategories
();
parseTarget
();
};
...
...
@@ -56,7 +56,7 @@ function (angular, _, config, graphiteFuncs, Parser) {
switch
(
astNode
.
type
)
{
case
'function'
:
var
innerFunc
=
g
raphiteFuncs
.
createFuncInstance
(
astNode
.
name
);
var
innerFunc
=
g
func
.
createFuncInstance
(
astNode
.
name
);
_
.
each
(
astNode
.
params
,
function
(
param
,
index
)
{
parseTargeRecursive
(
param
,
innerFunc
,
index
);
...
...
@@ -226,7 +226,7 @@ function (angular, _, config, graphiteFuncs, Parser) {
};
$scope
.
addFunction
=
function
(
funcDef
)
{
$scope
.
functions
.
push
(
g
raphiteFuncs
.
createFuncInstance
(
funcDef
));
$scope
.
functions
.
push
(
g
func
.
createFuncInstance
(
funcDef
));
$scope
.
targetChanged
();
};
...
...
src/app/services/graphite/g
raphiteFuncs
.js
→
src/app/services/graphite/g
func
.js
View file @
be330b6a
...
...
@@ -14,6 +14,9 @@ function (_) {
};
function
addFuncDef
(
funcDef
)
{
funcDef
.
params
=
funcDef
.
params
||
[];
funcDef
.
defaultParams
=
funcDef
.
defaultParams
||
[];
if
(
funcDef
.
category
)
{
funcDef
.
category
.
push
(
funcDef
);
}
...
...
@@ -38,8 +41,6 @@ function (_) {
addFuncDef
({
name
:
"holtWintersForecast"
,
category
:
categories
.
Calculate
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
...
...
@@ -60,16 +61,12 @@ function (_) {
name
:
'sumSeries'
,
shortName
:
'sum'
,
category
:
categories
.
Combine
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
name
:
'averageSeries'
,
shortName
:
'avg'
,
category
:
categories
.
Combine
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
...
...
@@ -106,15 +103,11 @@ function (_) {
addFuncDef
({
name
:
'integral'
,
category
:
categories
.
Transform
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
name
:
'derivate'
,
category
:
categories
.
Transform
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
...
...
@@ -150,15 +143,14 @@ function (_) {
};
return
{
createFuncInstance
:
function
(
name
)
{
if
(
_
.
isString
(
name
))
{
var
funcDef
=
index
[
name
];
if
(
!
funcDef
)
{
createFuncInstance
:
function
(
funcDef
)
{
if
(
_
.
isString
(
funcDef
))
{
if
(
!
index
[
funcDef
])
{
throw
{
message
:
'Method not found '
+
name
};
}
name
=
funcDef
;
funcDef
=
index
[
funcDef
]
;
}
return
new
FuncInstance
(
name
);
return
new
FuncInstance
(
funcDef
);
},
getCategories
:
function
()
{
...
...
src/test/karma.conf.js
View file @
be330b6a
...
...
@@ -8,6 +8,7 @@ module.exports = function(config) {
files
:
[
'test/test-main.js'
,
{
pattern
:
'app/**/*.js'
,
included
:
false
},
{
pattern
:
'vendor/**/*.js'
,
included
:
false
},
{
pattern
:
'test/**/*.js'
,
included
:
false
}
],
...
...
src/test/specs/gfunc-specs.js
0 → 100644
View file @
be330b6a
define
([
'app/services/graphite/gfunc'
],
function
(
gfunc
)
{
describe
(
'when creating func instance from func namae'
,
function
()
{
it
(
'should return func instance'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'sumSeries'
);
expect
(
func
).
to
.
be
.
ok
();
expect
(
func
.
def
.
name
).
to
.
equal
(
'sumSeries'
);
expect
(
func
.
def
.
params
.
length
).
to
.
equal
(
0
);
expect
(
func
.
def
.
defaultParams
.
length
).
to
.
equal
(
0
);
expect
(
func
.
def
.
defaultParams
.
length
).
to
.
equal
(
0
);
});
it
(
'should return func instance with shortName'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'sum'
);
expect
(
func
).
to
.
be
.
ok
();
});
it
(
'should return func instance from funcDef'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'sum'
);
var
func
=
gfunc
.
createFuncInstance
(
func
.
def
);
expect
(
func
).
to
.
be
.
ok
();
});
it
(
'func instance should have text representation'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'groupByNode'
);
func
.
params
[
0
]
=
5
;
func
.
params
[
1
]
=
'avg'
;
func
.
updateText
();
expect
(
func
.
text
).
to
.
equal
(
"groupByNode(5, avg)"
);
});
});
describe
(
'when requesting function categories'
,
function
()
{
it
(
'should return function categories'
,
function
()
{
var
catIndex
=
gfunc
.
getCategories
();
expect
(
catIndex
.
Special
.
length
).
to
.
equal
(
3
);
});
});
});
src/test/test-main.js
View file @
be330b6a
require
.
config
({
baseUrl
:
'base'
baseUrl
:
'base'
,
paths
:
{
underscore
:
'app/components/underscore.extended'
,
'underscore-src'
:
'vendor/underscore'
,
},
shim
:
{
underscore
:
{
exports
:
'_'
},
}
});
require
([
'test/specs/lexer-specs'
,
'test/specs/parser-specs'
,
'test/specs/gfunc-specs'
,
],
function
()
{
window
.
__karma__
.
start
();
});
\ No newline at end of file
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