Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Bliss
bliss
Commits
3863f5ab
Commit
3863f5ab
authored
May 18, 2022
by
Valentin Valls
Browse files
Split xduration and ttl duration with 2 different widgets
parent
702b6b59
Changes
6
Hide whitespace changes
Inline
Side-by-side
bliss/flint/client/plots.py
View file @
3863f5ab
...
...
@@ -585,6 +585,23 @@ class TimeCurvePlot(BasePlot):
"""
self
.
submit
(
"setXDuration"
,
second
)
@
property
def
ttl
(
self
):
return
self
.
submit
(
"ttl"
)
@
ttl
.
setter
def
ttl
(
self
,
second
:
int
):
"""
Set the time to live of the data.
After this period of time, a received data is not anymore displayable
in Flint.
Arguments:
second: Amount of seconds a data will live
"""
self
.
submit
(
"setTtl"
,
second
)
def
add_time_curve_item
(
self
,
yname
,
**
kwargs
):
"""
Select a dedicated data to be displayed against the time.
...
...
bliss/flint/custom_plots/time_curve_plot.py
View file @
3863f5ab
...
...
@@ -14,6 +14,7 @@ from silx.gui import qt
from
silx.gui.plot
import
Plot1D
from
silx.gui.plot.items
import
axis
as
axis_mdl
from
bliss.flint.widgets.utils.duration_action
import
DurationAction
from
bliss.flint.widgets.utils.static_icon
import
StaticIcon
_logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -35,20 +36,33 @@ class TimeCurvePlot(qt.QWidget):
layout
=
qt
.
QVBoxLayout
(
self
)
layout
.
addWidget
(
self
.
__plot
)
self
.
__duration
=
60
*
2
self
.
__durationAction
=
DurationAction
()
self
.
__durationAction
.
setCheckable
(
True
)
self
.
__durationAction
.
setChecked
(
True
)
self
.
__durationAction
.
addDuration
(
"1h"
,
60
*
60
)
self
.
__durationAction
.
addDuration
(
"30m"
,
30
*
60
)
self
.
__durationAction
.
addDuration
(
"10m"
,
10
*
60
)
self
.
__durationAction
.
addDuration
(
"5m"
,
5
*
60
)
self
.
__durationAction
.
addDuration
(
"2m"
,
2
*
60
)
self
.
__durationAction
.
addDuration
(
"1m"
,
1
*
60
)
self
.
__durationAction
.
addDuration
(
"30s"
,
30
)
self
.
__durationAction
.
setDuration
(
self
.
__duration
)
self
.
__durationAction
.
valueChanged
.
connect
(
self
.
__durationChanged
)
self
.
__xduration
=
60
*
2
self
.
__ttl
=
60
*
5
self
.
__xdurationAction
=
DurationAction
(
self
)
self
.
__xdurationAction
.
setCheckable
(
True
)
self
.
__xdurationAction
.
setChecked
(
True
)
self
.
__xdurationAction
.
addDuration
(
"1h"
,
60
*
60
)
self
.
__xdurationAction
.
addDuration
(
"30m"
,
30
*
60
)
self
.
__xdurationAction
.
addDuration
(
"10m"
,
10
*
60
)
self
.
__xdurationAction
.
addDuration
(
"5m"
,
5
*
60
)
self
.
__xdurationAction
.
addDuration
(
"2m"
,
2
*
60
)
self
.
__xdurationAction
.
addDuration
(
"1m"
,
1
*
60
)
self
.
__xdurationAction
.
addDuration
(
"30s"
,
30
)
self
.
__xdurationAction
.
setDuration
(
self
.
__xduration
)
self
.
__xdurationAction
.
valueChanged
.
connect
(
self
.
__xdurationChanged
)
# time to live widget
self
.
__ttlAction
=
DurationAction
(
self
)
self
.
__ttlAction
.
addDuration
(
"1h"
,
60
*
60
)
self
.
__ttlAction
.
addDuration
(
"30m"
,
30
*
60
)
self
.
__ttlAction
.
addDuration
(
"10m"
,
10
*
60
)
self
.
__ttlAction
.
addDuration
(
"5m"
,
5
*
60
)
self
.
__ttlAction
.
addDuration
(
"2m"
,
2
*
60
)
self
.
__ttlAction
.
addDuration
(
"1m"
,
1
*
60
)
self
.
__ttlAction
.
addDuration
(
"30s"
,
30
)
self
.
__ttlAction
.
setDuration
(
self
.
__ttl
)
self
.
__ttlAction
.
valueChanged
.
connect
(
self
.
__ttlChanged
)
self
.
__plot
.
setGraphXLabel
(
"Time"
)
xAxis
=
self
.
__plot
.
getXAxis
()
...
...
@@ -62,22 +76,45 @@ class TimeCurvePlot(qt.QWidget):
# FIXME: The toolbar have to be recreated, not updated
toolbar
=
self
.
__plot
.
toolBar
()
xAutoAction
=
self
.
__plot
.
getXAxisAutoScaleAction
()
toolbar
.
insertAction
(
xAutoAction
,
self
.
__durationAction
)
toolbar
.
insertAction
(
xAutoAction
,
self
.
__
x
durationAction
)
xAutoAction
.
setVisible
(
False
)
xLogAction
=
self
.
__plot
.
getXAxisLogarithmicAction
()
xLogAction
.
setVisible
(
False
)
timeToolbar
=
qt
.
QToolBar
(
self
)
ttlIconWidget
=
StaticIcon
(
self
)
ttlIconWidget
.
setIcon
(
"flint:icons/ttl-static"
)
ttlIconWidget
.
setToolTip
(
"Define the time to live of the data"
)
ttlIconWidget
.
redirectClickTo
(
self
.
__ttlAction
)
timeToolbar
.
addWidget
(
ttlIconWidget
)
timeToolbar
.
addAction
(
self
.
__ttlAction
)
self
.
_timeToolbar
=
timeToolbar
self
.
__plot
.
addToolBar
(
timeToolbar
)
self
.
clear
()
def
__durationChanged
(
self
,
duration
):
def
__
x
durationChanged
(
self
,
duration
):
self
.
setXDuration
(
duration
)
def
setXDuration
(
self
,
duration
):
self
.
__durationAction
.
setDuration
(
duration
)
self
.
__duration
=
duration
self
.
__xdurationAction
.
setDuration
(
duration
)
self
.
__xduration
=
duration
if
self
.
__ttl
<
duration
:
self
.
setTtl
(
duration
)
self
.
__safeUpdatePlot
()
def
ttl
(
self
):
return
self
.
__ttl
def
setTtl
(
self
,
duration
):
self
.
__ttlAction
.
setDuration
(
duration
)
self
.
__ttl
=
duration
self
.
__dropOldData
()
self
.
__safeUpdatePlot
()
def
__ttlChanged
(
self
,
duration
):
self
.
setTtl
(
duration
)
def
__dropOldData
(
self
):
xData
=
self
.
__data
.
get
(
self
.
__xAxisName
)
if
xData
is
None
:
...
...
@@ -85,14 +122,12 @@ class TimeCurvePlot(qt.QWidget):
if
len
(
xData
)
==
0
:
return
duration
=
xData
[
-
1
]
-
xData
[
0
]
if
duration
<=
self
.
__
duration
:
if
duration
<=
self
.
__
ttl
:
return
# FIXME: most of the time only last items with be removed
# There is maybe no need to recompute the whole array
distFromLastValueOfView
=
self
.
__duration
-
numpy
.
abs
(
xData
[
-
1
]
-
self
.
__duration
-
xData
)
distFromLastValueOfView
=
self
.
__ttl
-
numpy
.
abs
(
xData
[
-
1
]
-
self
.
__ttl
-
xData
)
index
=
numpy
.
argmax
(
distFromLastValueOfView
)
if
index
>=
1
:
index
=
index
-
1
...
...
@@ -158,12 +193,12 @@ class TimeCurvePlot(qt.QWidget):
self
.
__safeUpdatePlot
()
def
resetZoom
(
self
):
if
self
.
__durationAction
.
isChecked
():
if
self
.
__
x
durationAction
.
isChecked
():
self
.
__plot
.
resetZoom
()
xData
=
self
.
__data
.
get
(
self
.
__xAxisName
)
if
xData
is
not
None
and
len
(
xData
)
>
0
:
xmax
=
xData
[
-
1
]
xmin
=
xmax
-
self
.
__duration
xmin
=
xmax
-
self
.
__
x
duration
xAxis
=
self
.
__plot
.
getXAxis
()
xAxis
.
setLimits
(
xmin
,
xmax
)
...
...
bliss/flint/resources/icons/ttl-static.png
0 → 100644
View file @
3863f5ab
1.03 KB
bliss/flint/resources/icons/ttl-static.svg
0 → 100644
View file @
3863f5ab
<?xml version="1.0" encoding="UTF-8"?>
<svg
id=
"svg39"
version=
"1.1"
viewBox=
"0 0 32 32"
xml:space=
"preserve"
xmlns=
"http://www.w3.org/2000/svg"
xmlns:cc=
"http://creativecommons.org/ns#"
xmlns:dc=
"http://purl.org/dc/elements/1.1/"
xmlns:rdf=
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
><metadata
id=
"metadata43"
><rdf:RDF><cc:Work
rdf:about=
""
><dc:format>
image/svg+xml
</dc:format><dc:type
rdf:resource=
"http://purl.org/dc/dcmitype/StillImage"
/></cc:Work></rdf:RDF></metadata><path
id=
"path822-9"
d=
"m4.9221 6.5357c0.042943 6.4507-0.11128 13.016 0 19.404 0.41254 1.5614 5.2398 2.7715 11.057 2.7715 5.8123-0.0017 10.68-1.2113 11.092-2.7715 0.09522-6.3604 0-12.96 0-19.404"
fill=
"none"
stroke=
"#8e8e8e"
stroke-linecap=
"round"
stroke-miterlimit=
"10"
stroke-width=
"2.5"
/><ellipse
id=
"path822"
cx=
"16.003"
cy=
"6.2716"
rx=
"11.115"
ry=
"2.9817"
fill=
"none"
stroke=
"#8e8e8e"
stroke-linecap=
"round"
stroke-miterlimit=
"10"
stroke-width=
"2.5"
style=
"font-variant-east_asian:normal"
/><g
id=
"text863"
stroke-width=
".1998"
aria-label=
"TTL"
><path
id=
"path817"
d=
"m8.0413 14.812h5.3696v1.1356h-1.9316v4.6906h-1.5024v-4.6906h-1.9355z"
/><path
id=
"path819"
d=
"m13.676 14.812h5.3696v1.1356h-1.9316v4.6906h-1.5024v-4.6906h-1.9355z"
/><path
id=
"path821"
d=
"m19.818 14.812h1.5024v4.6906h2.638v1.1356h-4.1403z"
/></g>
</svg>
tests/flint_client/test_custom_plots.py
View file @
3863f5ab
...
...
@@ -537,8 +537,8 @@ def test_time_curve_plot(flint_session):
assert
vrange
[
0
]
==
[
0
,
3
]
assert
vrange
[
1
]
==
[
0
,
6
]
# when a fixed duration is used, the data disappear
on one side
p
.
select_x_duration
(
second
=
5
)
# when a fixed duration is used, the
oldest
data disappear
p
.
ttl
=
5
p
.
append_data
(
time
=
[
10
],
diode1
=
[
2
],
diode2
=
[
6
])
vrange
=
p
.
get_data_range
()
assert
vrange
[
0
][
0
]
>
1
...
...
tests/qt/flint/custom_plots/test_time_curve_plot.py
View file @
3863f5ab
...
...
@@ -76,7 +76,7 @@ def test_time_curve_plot__drop_data(time_curve_plot_widget):
on the other side.
"""
w
=
time_curve_plot_widget
w
.
set
XDuration
(
5
)
w
.
set
Ttl
(
5
)
w
.
addTimeCurveItem
(
"value1"
)
w
.
addTimeCurveItem
(
"value2"
)
w
.
appendData
(
time
=
[
0
,
1
,
2
],
value1
=
[
0
,
1
,
2
],
value2
=
[
0
,
1
,
2
])
...
...
@@ -87,3 +87,26 @@ def test_time_curve_plot__drop_data(time_curve_plot_widget):
assert
len
(
curve
.
getXData
())
<=
5
+
2
assert
curve
.
getXData
()[
0
]
>
0
assert
curve
.
getXData
()[
-
1
]
==
8
def
test_time_curve_plot__limited_view
(
time_curve_plot_widget
):
"""Create a plot with limited x-axis duration and feed it with data
We expect the plot to contain more items data than what it is displayed.
"""
w
=
time_curve_plot_widget
w
.
setXDuration
(
5
)
w
.
setTtl
(
10
)
w
.
addTimeCurveItem
(
"value1"
)
w
.
addTimeCurveItem
(
"value2"
)
w
.
appendData
(
time
=
[
0
,
1
,
2
],
value1
=
[
0
,
1
,
2
],
value2
=
[
0
,
1
,
2
])
w
.
appendData
(
time
=
[
3
,
4
,
5
],
value1
=
[
0
,
1
,
2
],
value2
=
[
0
,
1
,
2
])
w
.
appendData
(
time
=
[
6
,
7
,
8
],
value1
=
[
0
,
1
,
2
],
value2
=
[
0
,
1
,
2
])
plot
=
w
.
getPlotWidget
()
xAxis
=
plot
.
getXAxis
()
assert
xAxis
.
getLimits
()[
0
]
>
0
assert
xAxis
.
getLimits
()[
1
]
==
8.0
curve
=
plot
.
getAllCurves
()[
0
]
assert
len
(
curve
.
getXData
())
==
9
assert
curve
.
getXData
()[
0
]
==
0
assert
curve
.
getXData
()[
-
1
]
==
8
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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