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
3ec053be
Commit
3ec053be
authored
Aug 20, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved series override code to TimeSeries
parent
b2f9f81e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
156 additions
and
122 deletions
+156
-122
src/app/components/timeSeries.js
+40
-0
src/app/directives/grafanaGraph.js
+2
-38
src/app/panels/graph/legend.html
+2
-2
src/test/specs/grafanaGraph-specs.js
+0
-82
src/test/specs/timeSeries-specs.js
+111
-0
src/test/test-main.js
+1
-0
No files found.
src/app/components/timeSeries.js
View file @
3ec053be
...
...
@@ -11,6 +11,46 @@ function (_, kbn) {
this
.
label
=
opts
.
info
.
alias
;
}
function
matchSeriesOverride
(
aliasOrRegex
,
seriesAlias
)
{
if
(
aliasOrRegex
[
0
]
===
'/'
)
{
var
match
=
aliasOrRegex
.
match
(
new
RegExp
(
'^/(.*?)/(g?i?m?y?)$'
));
var
regex
=
new
RegExp
(
match
[
1
],
match
[
2
]);
return
seriesAlias
.
match
(
regex
)
!=
null
;
}
return
aliasOrRegex
===
seriesAlias
;
}
function
translateFillOption
(
fill
)
{
return
fill
===
0
?
0.001
:
fill
/
10
;
}
TimeSeries
.
prototype
.
applySeriesOverrides
=
function
(
overrides
)
{
this
.
lines
=
{};
this
.
points
=
{};
this
.
bars
=
{};
this
.
info
.
yaxis
=
1
;
delete
this
.
stack
;
for
(
var
i
=
0
;
i
<
overrides
.
length
;
i
++
)
{
var
override
=
overrides
[
i
];
if
(
!
matchSeriesOverride
(
override
.
alias
,
this
.
info
.
alias
))
{
continue
;
}
if
(
override
.
lines
!==
void
0
)
{
this
.
lines
.
show
=
override
.
lines
;
}
if
(
override
.
points
!==
void
0
)
{
this
.
points
.
show
=
override
.
points
;
}
if
(
override
.
bars
!==
void
0
)
{
this
.
bars
.
show
=
override
.
bars
;
}
if
(
override
.
fill
!==
void
0
)
{
this
.
lines
.
fill
=
translateFillOption
(
override
.
fill
);
}
if
(
override
.
stack
!==
void
0
)
{
this
.
stack
=
override
.
stack
;
}
if
(
override
.
linewidth
!==
void
0
)
{
this
.
lines
.
lineWidth
=
override
.
linewidth
;
}
if
(
override
.
pointradius
!==
void
0
)
{
this
.
points
.
radius
=
override
.
pointradius
;
}
if
(
override
.
steppedLine
!==
void
0
)
{
this
.
lines
.
steps
=
override
.
steppedLine
;
}
if
(
override
.
yaxis
!==
void
0
)
{
this
.
info
.
yaxis
=
override
.
yaxis
;
}
}
};
TimeSeries
.
prototype
.
getFlotPairs
=
function
(
fillStyle
,
yFormats
)
{
var
result
=
[];
...
...
src/app/directives/grafanaGraph.js
View file @
3ec053be
...
...
@@ -118,7 +118,7 @@ function (angular, $, kbn, moment, _) {
lines
:
{
show
:
panel
.
lines
,
zero
:
false
,
fill
:
panel
.
fill
===
0
?
0.001
:
panel
.
fill
/
10
,
fill
:
translateFillOption
(
panel
.
fill
)
,
lineWidth
:
panel
.
linewidth
,
steps
:
panel
.
steppedLine
},
...
...
@@ -155,8 +155,8 @@ function (angular, $, kbn, moment, _) {
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
var
series
=
data
[
i
];
series
.
applySeriesOverrides
(
panel
.
seriesOverrides
);
series
.
data
=
series
.
getFlotPairs
(
panel
.
nullPointMode
,
panel
.
y_formats
);
applySeriesOverrideOptions
(
series
);
}
if
(
data
.
length
&&
data
[
0
].
info
.
timeStep
)
{
...
...
@@ -183,42 +183,6 @@ function (angular, $, kbn, moment, _) {
}
}
function
matchSeriesOverride
(
aliasOrRegex
,
seriesAlias
)
{
if
(
aliasOrRegex
[
0
]
===
'/'
)
{
var
match
=
aliasOrRegex
.
match
(
new
RegExp
(
'^/(.*?)/(g?i?m?y?)$'
));
var
regex
=
new
RegExp
(
match
[
1
],
match
[
2
]);
return
seriesAlias
.
match
(
regex
)
!=
null
;
}
return
aliasOrRegex
===
seriesAlias
;
}
function
applySeriesOverrideOptions
(
series
)
{
series
.
lines
=
{};
series
.
points
=
{};
series
.
bars
=
{};
delete
series
.
stack
;
for
(
var
i
=
0
;
i
<
scope
.
panel
.
seriesOverrides
.
length
;
i
++
)
{
var
override
=
scope
.
panel
.
seriesOverrides
[
i
];
if
(
!
matchSeriesOverride
(
override
.
alias
,
series
.
info
.
alias
))
{
continue
;
}
if
(
override
.
lines
!==
void
0
)
{
series
.
lines
.
show
=
override
.
lines
;
}
if
(
override
.
points
!==
void
0
)
{
series
.
points
.
show
=
override
.
points
;
}
if
(
override
.
bars
!==
void
0
)
{
series
.
bars
.
show
=
override
.
bars
;
}
if
(
override
.
fill
!==
void
0
)
{
series
.
lines
.
fill
=
translateFillOption
(
override
.
fill
);
}
if
(
override
.
stack
!==
void
0
)
{
series
.
stack
=
override
.
stack
;
}
if
(
override
.
linewidth
!==
void
0
)
{
series
.
lines
.
lineWidth
=
override
.
linewidth
;
}
if
(
override
.
pointradius
!==
void
0
)
{
series
.
points
.
radius
=
override
.
pointradius
;
}
if
(
override
.
steppedLine
!==
void
0
)
{
series
.
lines
.
steps
=
override
.
steppedLine
;
}
if
(
override
.
yaxis
!==
void
0
)
{
series
.
yaxis
=
override
.
yaxis
;
series
.
info
.
yaxis
=
override
.
yaxis
;
}
}
}
function
translateFillOption
(
fill
)
{
return
fill
===
0
?
0.001
:
fill
/
10
;
}
...
...
src/app/panels/graph/legend.html
View file @
3ec053be
...
...
@@ -34,12 +34,12 @@
<
div
class
=
"editor-row small"
style
=
"padding-bottom: 0;"
>
<
label
>
Axis
:
<
/label
>
<
button
ng
-
click
=
"toggleYAxis(series)"
<
button
ng
-
click
=
"toggleYAxis(series)
;dismiss();
"
class
=
"btn btn-mini"
ng
-
class
=
"{'btn-success': series.yaxis === 1 }"
>
Left
<
/button
>
<
button
ng
-
click
=
"toggleYAxis(series)"
<
button
ng
-
click
=
"toggleYAxis(series)
;dismiss();
"
class
=
"btn btn-mini"
ng
-
class
=
"{'btn-success': series.yaxis === 2 }"
>
Right
...
...
src/test/specs/grafanaGraph-specs.js
View file @
3ec053be
...
...
@@ -92,88 +92,6 @@ define([
});
});
graphScenario
(
'series option overrides, bars, true & lines false'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
scope
,
data
)
{
scope
.
panel
.
lines
=
true
;
scope
.
panel
.
seriesOverrides
=
[
{
alias
:
'test'
,
bars
:
true
,
lines
:
false
}
];
data
[
1
].
info
.
alias
=
'test'
;
});
it
(
'should match second series and disable lines, and enable bars'
,
function
()
{
expect
(
ctx
.
plotOptions
.
series
.
lines
.
show
).
to
.
be
(
true
);
expect
(
ctx
.
plotData
[
1
].
lines
.
show
).
to
.
be
(
false
);
expect
(
ctx
.
plotData
[
1
].
bars
.
show
).
to
.
be
(
true
);
});
});
graphScenario
(
'series option overrides, linewidth, stack'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
scope
,
data
)
{
scope
.
panel
.
lines
=
true
;
scope
.
panel
.
stack
=
true
;
scope
.
panel
.
linewidth
=
2
;
scope
.
panel
.
seriesOverrides
=
[
{
alias
:
'test'
,
linewidth
:
5
,
stack
:
false
}
];
data
[
1
].
info
.
alias
=
'test'
;
});
it
(
'should match second series and disable stack, and set lineWidth'
,
function
()
{
expect
(
ctx
.
plotOptions
.
series
.
stack
).
to
.
be
(
true
);
expect
(
ctx
.
plotData
[
1
].
stack
).
to
.
be
(
false
);
expect
(
ctx
.
plotData
[
1
].
lines
.
lineWidth
).
to
.
be
(
5
);
});
});
graphScenario
(
'series option overrides, pointradius, steppedLine'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
scope
,
data
)
{
scope
.
panel
.
seriesOverrides
=
[
{
alias
:
'test'
,
pointradius
:
5
,
steppedLine
:
true
}
];
data
[
1
].
info
.
alias
=
'test'
;
});
it
(
'should match second series and set pointradius, and set steppedLine'
,
function
()
{
expect
(
ctx
.
plotData
[
1
].
points
.
radius
).
to
.
be
(
5
);
expect
(
ctx
.
plotData
[
1
].
lines
.
steps
).
to
.
be
(
true
);
});
});
graphScenario
(
'override match on regex'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
scope
,
data
)
{
scope
.
panel
.
lines
=
true
;
scope
.
panel
.
seriesOverrides
=
[
{
alias
:
'/.*01/'
,
lines
:
false
}
];
data
[
1
].
info
.
alias
=
'test_01'
;
});
it
(
'should match second series'
,
function
()
{
expect
(
ctx
.
plotData
[
0
].
lines
.
show
).
to
.
be
(
undefined
);
expect
(
ctx
.
plotData
[
1
].
lines
.
show
).
to
.
be
(
false
);
});
});
graphScenario
(
'override series y-axis'
,
function
(
ctx
)
{
ctx
.
setup
(
function
(
scope
,
data
)
{
scope
.
panel
.
lines
=
true
;
scope
.
panel
.
seriesOverrides
=
[
{
alias
:
'test'
,
yaxis
:
2
}
];
data
[
1
].
info
.
alias
=
'test'
;
});
it
(
'should match second series and set yaxis'
,
function
()
{
expect
(
ctx
.
plotData
[
1
].
yaxis
).
to
.
be
(
2
);
});
});
});
});
src/test/specs/timeSeries-specs.js
0 → 100644
View file @
3ec053be
define
([
'components/timeSeries'
],
function
(
TimeSeries
)
{
'use strict'
;
describe
(
"TimeSeries"
,
function
()
{
var
points
,
series
;
var
yAxisFormats
=
[
'short'
,
'ms'
];
var
testData
=
{
info
:
{
alias
:
'test'
},
datapoints
:
[
[
1
,
2
],[
null
,
3
],[
10
,
4
],[
8
,
5
]
]
};
describe
(
'when getting flot pairs'
,
function
()
{
it
(
'with connected style, should ignore nulls'
,
function
()
{
series
=
new
TimeSeries
(
testData
);
points
=
series
.
getFlotPairs
(
'connected'
,
yAxisFormats
);
expect
(
points
.
length
).
to
.
be
(
3
);
});
it
(
'with null as zero style, should replace nulls with zero'
,
function
()
{
series
=
new
TimeSeries
(
testData
);
points
=
series
.
getFlotPairs
(
'null as zero'
,
yAxisFormats
);
expect
(
points
.
length
).
to
.
be
(
4
);
expect
(
points
[
1
][
1
]).
to
.
be
(
0
);
});
});
describe
(
'series overrides'
,
function
()
{
var
series
;
beforeEach
(
function
()
{
series
=
new
TimeSeries
(
testData
);
});
describe
(
'fill & points'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test'
;
series
.
applySeriesOverrides
([{
alias
:
'test'
,
fill
:
0
,
points
:
true
}]);
});
it
(
'should set fill zero, and enable points'
,
function
()
{
expect
(
series
.
lines
.
fill
).
to
.
be
(
0.001
);
expect
(
series
.
points
.
show
).
to
.
be
(
true
);
});
});
describe
(
'series option overrides, bars, true & lines false'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test'
;
series
.
applySeriesOverrides
([{
alias
:
'test'
,
bars
:
true
,
lines
:
false
}]);
});
it
(
'should disable lines, and enable bars'
,
function
()
{
expect
(
series
.
lines
.
show
).
to
.
be
(
false
);
expect
(
series
.
bars
.
show
).
to
.
be
(
true
);
});
});
describe
(
'series option overrides, linewidth, stack'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test'
;
series
.
applySeriesOverrides
([{
alias
:
'test'
,
linewidth
:
5
,
stack
:
false
}]);
});
it
(
'should disable stack, and set lineWidth'
,
function
()
{
expect
(
series
.
stack
).
to
.
be
(
false
);
expect
(
series
.
lines
.
lineWidth
).
to
.
be
(
5
);
});
});
describe
(
'series option overrides, pointradius, steppedLine'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test'
;
series
.
applySeriesOverrides
([{
alias
:
'test'
,
pointradius
:
5
,
steppedLine
:
true
}]);
});
it
(
'should set pointradius, and set steppedLine'
,
function
()
{
expect
(
series
.
points
.
radius
).
to
.
be
(
5
);
expect
(
series
.
lines
.
steps
).
to
.
be
(
true
);
});
});
describe
(
'override match on regex'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test_01'
;
series
.
applySeriesOverrides
([{
alias
:
'/.*01/'
,
lines
:
false
}]);
});
it
(
'should match second series'
,
function
()
{
expect
(
series
.
lines
.
show
).
to
.
be
(
false
);
});
});
describe
(
'override series y-axis'
,
function
()
{
beforeEach
(
function
()
{
series
.
info
.
alias
=
'test'
;
series
.
applySeriesOverrides
([{
alias
:
'test'
,
yaxis
:
2
}]);
});
it
(
'should set yaxis'
,
function
()
{
expect
(
series
.
info
.
yaxis
).
to
.
be
(
2
);
});
});
});
});
});
src/test/test-main.js
View file @
3ec053be
...
...
@@ -118,6 +118,7 @@ require([
'specs/lexer-specs'
,
'specs/parser-specs'
,
'specs/gfunc-specs'
,
'specs/timeSeries-specs'
,
'specs/row-ctrl-specs'
,
'specs/graphiteTargetCtrl-specs'
,
'specs/influxdb-datasource-specs'
,
...
...
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