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
8c82e570
Commit
8c82e570
authored
Mar 12, 2018
by
ilgizar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced array values to variables yLeft and yRight for easy reading code.
parent
11ae9263
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
64 deletions
+70
-64
public/app/plugins/panel/graph/align_yaxes.ts
+70
-64
No files found.
public/app/plugins/panel/graph/align_yaxes.ts
View file @
8c82e570
...
...
@@ -6,112 +6,118 @@ import _ from 'lodash';
* @param align Y level
*/
export
function
alignYLevel
(
yaxis
,
alignLevel
)
{
moveLevelToZero
(
yaxis
,
alignLevel
);
var
[
yLeft
,
yRight
]
=
yaxis
;
moveLevelToZero
(
yLeft
,
yRight
,
alignLevel
);
expandStuckValues
(
y
axis
);
expandStuckValues
(
y
Left
,
yRight
);
// one of graphs on zero
var
zero
=
y
axis
[
0
].
min
===
0
||
yaxis
[
1
].
min
===
0
||
yaxis
[
0
].
max
===
0
||
yaxis
[
1
]
.
max
===
0
;
var
zero
=
y
Left
.
min
===
0
||
yRight
.
min
===
0
||
yLeft
.
max
===
0
||
yRight
.
max
===
0
;
var
oneSide
=
checkOneSide
(
y
axis
);
var
oneSide
=
checkOneSide
(
y
Left
,
yRight
);
if
(
zero
&&
oneSide
)
{
y
axis
[
0
].
min
=
yaxis
[
0
].
max
>
0
?
0
:
yaxis
[
0
]
.
min
;
y
axis
[
0
].
max
=
yaxis
[
0
].
max
>
0
?
yaxis
[
0
]
.
max
:
0
;
y
axis
[
1
].
min
=
yaxis
[
1
].
max
>
0
?
0
:
yaxis
[
1
]
.
min
;
y
axis
[
1
].
max
=
yaxis
[
1
].
max
>
0
?
yaxis
[
1
]
.
max
:
0
;
y
Left
.
min
=
yLeft
.
max
>
0
?
0
:
yLeft
.
min
;
y
Left
.
max
=
yLeft
.
max
>
0
?
yLeft
.
max
:
0
;
y
Right
.
min
=
yRight
.
max
>
0
?
0
:
yRight
.
min
;
y
Right
.
max
=
yRight
.
max
>
0
?
yRight
.
max
:
0
;
}
else
{
// on the opposite sides with respect to zero
if
((
yaxis
[
0
].
min
>=
0
&&
yaxis
[
1
].
max
<=
0
)
||
(
yaxis
[
0
].
max
<=
0
&&
yaxis
[
1
].
min
>=
0
))
{
if
(
yaxis
[
0
].
min
>=
0
)
{
yaxis
[
0
].
min
=
-
yaxis
[
0
].
max
;
yaxis
[
1
].
max
=
-
yaxis
[
1
].
min
;
if
(
checkOppositeSides
(
yLeft
,
yRight
))
{
if
(
yLeft
.
min
>=
0
)
{
yLeft
.
min
=
-
yLeft
.
max
;
yRight
.
max
=
-
yRight
.
min
;
}
else
{
y
axis
[
0
].
max
=
-
yaxis
[
0
]
.
min
;
y
axis
[
1
].
min
=
-
yaxis
[
1
]
.
max
;
y
Left
.
max
=
-
yLeft
.
min
;
y
Right
.
min
=
-
yRight
.
max
;
}
}
else
{
var
rate
=
getRate
(
y
axis
);
var
rate
=
getRate
(
y
Left
,
yRight
);
if
(
oneSide
)
{
if
(
yaxis
[
0
].
min
>
0
)
{
yaxis
[
0
].
min
=
yaxis
[
0
].
max
/
rate
;
yaxis
[
1
].
min
=
yaxis
[
1
].
max
/
rate
;
// all graphs above the Y level
if
(
yLeft
.
min
>
0
)
{
yLeft
.
min
=
yLeft
.
max
/
rate
;
yRight
.
min
=
yRight
.
max
/
rate
;
}
else
{
y
axis
[
0
].
max
=
yaxis
[
0
]
.
min
/
rate
;
y
axis
[
1
].
max
=
yaxis
[
1
]
.
min
/
rate
;
y
Left
.
max
=
yLeft
.
min
/
rate
;
y
Right
.
max
=
yRight
.
min
/
rate
;
}
}
else
{
if
(
checkTwoCross
(
y
axis
))
{
y
axis
[
0
].
min
=
yaxis
[
1
].
min
?
yaxis
[
1
].
min
*
rate
:
yaxis
[
0
]
.
min
;
y
axis
[
1
].
min
=
yaxis
[
0
].
min
?
yaxis
[
0
].
min
/
rate
:
yaxis
[
1
]
.
min
;
y
axis
[
0
].
max
=
yaxis
[
1
].
max
?
yaxis
[
1
].
max
*
rate
:
yaxis
[
0
]
.
max
;
y
axis
[
1
].
max
=
yaxis
[
0
].
max
?
yaxis
[
0
].
max
/
rate
:
yaxis
[
1
]
.
max
;
if
(
checkTwoCross
(
y
Left
,
yRight
))
{
y
Left
.
min
=
yRight
.
min
?
yRight
.
min
*
rate
:
yLeft
.
min
;
y
Right
.
min
=
yLeft
.
min
?
yLeft
.
min
/
rate
:
yRight
.
min
;
y
Left
.
max
=
yRight
.
max
?
yRight
.
max
*
rate
:
yLeft
.
max
;
y
Right
.
max
=
yLeft
.
max
?
yLeft
.
max
/
rate
:
yRight
.
max
;
}
else
{
y
axis
[
0
].
min
=
yaxis
[
0
].
min
>
0
?
yaxis
[
1
].
min
*
rate
:
yaxis
[
0
]
.
min
;
y
axis
[
1
].
min
=
yaxis
[
1
].
min
>
0
?
yaxis
[
0
].
min
/
rate
:
yaxis
[
1
]
.
min
;
y
axis
[
0
].
max
=
yaxis
[
0
].
max
<
0
?
yaxis
[
1
].
max
*
rate
:
yaxis
[
0
]
.
max
;
y
axis
[
1
].
max
=
yaxis
[
1
].
max
<
0
?
yaxis
[
0
].
max
/
rate
:
yaxis
[
1
]
.
max
;
y
Left
.
min
=
yLeft
.
min
>
0
?
yRight
.
min
*
rate
:
yLeft
.
min
;
y
Right
.
min
=
yRight
.
min
>
0
?
yLeft
.
min
/
rate
:
yRight
.
min
;
y
Left
.
max
=
yLeft
.
max
<
0
?
yRight
.
max
*
rate
:
yLeft
.
max
;
y
Right
.
max
=
yRight
.
max
<
0
?
yLeft
.
max
/
rate
:
yRight
.
max
;
}
}
}
}
restoreLevelFromZero
(
y
axis
,
alignLevel
);
restoreLevelFromZero
(
y
Left
,
yRight
,
alignLevel
);
}
function
expandStuckValues
(
y
axis
)
{
function
expandStuckValues
(
y
Left
,
yRight
)
{
// wide Y min and max using increased wideFactor
var
wideFactor
=
0.25
;
if
(
y
axis
[
0
].
max
===
yaxis
[
0
]
.
min
)
{
y
axis
[
0
]
.
min
-=
wideFactor
;
y
axis
[
0
]
.
max
+=
wideFactor
;
if
(
y
Left
.
max
===
yLeft
.
min
)
{
y
Left
.
min
-=
wideFactor
;
y
Left
.
max
+=
wideFactor
;
}
if
(
y
axis
[
1
].
max
===
yaxis
[
1
]
.
min
)
{
y
axis
[
1
]
.
min
-=
wideFactor
;
y
axis
[
1
]
.
max
+=
wideFactor
;
if
(
y
Right
.
max
===
yRight
.
min
)
{
y
Right
.
min
-=
wideFactor
;
y
Right
.
max
+=
wideFactor
;
}
}
function
moveLevelToZero
(
y
axis
,
alignLevel
)
{
function
moveLevelToZero
(
y
Left
,
yRight
,
alignLevel
)
{
if
(
alignLevel
!==
0
)
{
y
axis
[
0
]
.
min
-=
alignLevel
;
y
axis
[
0
]
.
max
-=
alignLevel
;
y
axis
[
1
]
.
min
-=
alignLevel
;
y
axis
[
1
]
.
max
-=
alignLevel
;
y
Left
.
min
-=
alignLevel
;
y
Left
.
max
-=
alignLevel
;
y
Right
.
min
-=
alignLevel
;
y
Right
.
max
-=
alignLevel
;
}
}
function
restoreLevelFromZero
(
y
axis
,
alignLevel
)
{
function
restoreLevelFromZero
(
y
Left
,
yRight
,
alignLevel
)
{
if
(
alignLevel
!==
0
)
{
y
axis
[
0
]
.
min
+=
alignLevel
;
y
axis
[
0
]
.
max
+=
alignLevel
;
y
axis
[
1
]
.
min
+=
alignLevel
;
y
axis
[
1
]
.
max
+=
alignLevel
;
y
Left
.
min
+=
alignLevel
;
y
Left
.
max
+=
alignLevel
;
y
Right
.
min
+=
alignLevel
;
y
Right
.
max
+=
alignLevel
;
}
}
function
checkOneSide
(
y
axis
)
{
function
checkOneSide
(
y
Left
,
yRight
)
{
// on the one hand with respect to zero
return
(
y
axis
[
0
].
min
>=
0
&&
yaxis
[
1
].
min
>=
0
)
||
(
yaxis
[
0
].
max
<=
0
&&
yaxis
[
1
]
.
max
<=
0
);
return
(
y
Left
.
min
>=
0
&&
yRight
.
min
>=
0
)
||
(
yLeft
.
max
<=
0
&&
yRight
.
max
<=
0
);
}
function
checkTwoCross
(
y
axis
)
{
function
checkTwoCross
(
y
Left
,
yRight
)
{
// both across zero
return
y
axis
[
0
].
min
<=
0
&&
yaxis
[
0
].
max
>=
0
&&
yaxis
[
1
].
min
<=
0
&&
yaxis
[
1
]
.
max
>=
0
;
return
y
Left
.
min
<=
0
&&
yLeft
.
max
>=
0
&&
yRight
.
min
<=
0
&&
yRight
.
max
>=
0
;
}
function
getRate
(
yaxis
)
{
function
checkOppositeSides
(
yLeft
,
yRight
)
{
// on the opposite sides with respect to zero
return
(
yLeft
.
min
>=
0
&&
yRight
.
max
<=
0
)
||
(
yLeft
.
max
<=
0
&&
yRight
.
min
>=
0
);
}
function
getRate
(
yLeft
,
yRight
)
{
var
rateLeft
,
rateRight
,
rate
;
if
(
checkTwoCross
(
y
axis
))
{
rateLeft
=
y
axis
[
1
].
min
?
yaxis
[
0
].
min
/
yaxis
[
1
]
.
min
:
0
;
rateRight
=
y
axis
[
1
].
max
?
yaxis
[
0
].
max
/
yaxis
[
1
]
.
max
:
0
;
if
(
checkTwoCross
(
y
Left
,
yRight
))
{
rateLeft
=
y
Right
.
min
?
yLeft
.
min
/
yRight
.
min
:
0
;
rateRight
=
y
Right
.
max
?
yLeft
.
max
/
yRight
.
max
:
0
;
}
else
{
if
(
checkOneSide
(
y
axis
))
{
var
absLeftMin
=
Math
.
abs
(
y
axis
[
0
]
.
min
);
var
absLeftMax
=
Math
.
abs
(
y
axis
[
0
]
.
max
);
var
absRightMin
=
Math
.
abs
(
y
axis
[
1
]
.
min
);
var
absRightMax
=
Math
.
abs
(
y
axis
[
1
]
.
max
);
if
(
checkOneSide
(
y
Left
,
yRight
))
{
var
absLeftMin
=
Math
.
abs
(
y
Left
.
min
);
var
absLeftMax
=
Math
.
abs
(
y
Left
.
max
);
var
absRightMin
=
Math
.
abs
(
y
Right
.
min
);
var
absRightMax
=
Math
.
abs
(
y
Right
.
max
);
var
upLeft
=
_
.
max
([
absLeftMin
,
absLeftMax
]);
var
downLeft
=
_
.
min
([
absLeftMin
,
absLeftMax
]);
var
upRight
=
_
.
max
([
absRightMin
,
absRightMax
]);
...
...
@@ -120,12 +126,12 @@ function getRate(yaxis) {
rateLeft
=
downLeft
?
upLeft
/
downLeft
:
upLeft
;
rateRight
=
downRight
?
upRight
/
downRight
:
upRight
;
}
else
{
if
(
y
axis
[
0
].
min
>
0
||
yaxis
[
1
]
.
min
>
0
)
{
rateLeft
=
y
axis
[
0
].
max
/
yaxis
[
1
]
.
max
;
if
(
y
Left
.
min
>
0
||
yRight
.
min
>
0
)
{
rateLeft
=
y
Left
.
max
/
yRight
.
max
;
rateRight
=
0
;
}
else
{
rateLeft
=
0
;
rateRight
=
y
axis
[
0
].
min
/
yaxis
[
1
]
.
min
;
rateRight
=
y
Left
.
min
/
yRight
.
min
;
}
}
}
...
...
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