Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EO Time Series Viewer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Jakimow
EO Time Series Viewer
Commits
ba31b3d7
Commit
ba31b3d7
authored
11 years ago
by
Luke Campagnola
Browse files
Options
Downloads
Patches
Plain Diff
Legends can be dragged by user
parent
7a7288b6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py
+45
-0
45 additions, 0 deletions
pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py
pyqtgraph/graphicsItems/LegendItem.py
+9
-3
9 additions, 3 deletions
pyqtgraph/graphicsItems/LegendItem.py
with
54 additions
and
3 deletions
pyqtgraph/graphicsItems/GraphicsWidgetAnchor.py
+
45
−
0
View file @
ba31b3d7
...
...
@@ -47,7 +47,52 @@ class GraphicsWidgetAnchor(object):
self
.
__parentAnchor
=
parentPos
self
.
__offset
=
offset
self
.
__geometryChanged
()
def
autoAnchor
(
self
,
pos
,
relative
=
True
):
"""
Set the position of this item relative to its parent by automatically
choosing appropriate anchor settings.
If relative is True, one corner of the item will be anchored to
the appropriate location on the parent with no offset. The anchored
corner will be whichever is closest to the parent
'
s boundary.
If relative is False, one corner of the item will be anchored to the same
corner of the parent, with an absolute offset to achieve the correct
position.
"""
pos
=
Point
(
pos
)
br
=
self
.
mapRectToParent
(
self
.
boundingRect
()).
translated
(
pos
-
self
.
pos
())
pbr
=
self
.
parentItem
().
boundingRect
()
anchorPos
=
[
0
,
0
]
parentPos
=
Point
()
itemPos
=
Point
()
if
abs
(
br
.
left
()
-
pbr
.
left
())
<
abs
(
br
.
right
()
-
pbr
.
right
()):
anchorPos
[
0
]
=
0
parentPos
[
0
]
=
pbr
.
left
()
itemPos
[
0
]
=
br
.
left
()
else
:
anchorPos
[
0
]
=
1
parentPos
[
0
]
=
pbr
.
right
()
itemPos
[
0
]
=
br
.
right
()
if
abs
(
br
.
top
()
-
pbr
.
top
())
<
abs
(
br
.
bottom
()
-
pbr
.
bottom
()):
anchorPos
[
1
]
=
0
parentPos
[
1
]
=
pbr
.
top
()
itemPos
[
1
]
=
br
.
top
()
else
:
anchorPos
[
1
]
=
1
parentPos
[
1
]
=
pbr
.
bottom
()
itemPos
[
1
]
=
br
.
bottom
()
if
relative
:
relPos
=
[(
itemPos
[
0
]
-
pbr
.
left
())
/
pbr
.
width
(),
(
itemPos
[
1
]
-
pbr
.
top
())
/
pbr
.
height
()]
self
.
anchor
(
anchorPos
,
relPos
)
else
:
offset
=
itemPos
-
parentPos
self
.
anchor
(
anchorPos
,
anchorPos
,
offset
)
def
__geometryChanged
(
self
):
if
self
.
__parent
is
None
:
return
...
...
This diff is collapsed.
Click to expand it.
pyqtgraph/graphicsItems/LegendItem.py
+
9
−
3
View file @
ba31b3d7
...
...
@@ -101,7 +101,6 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
label
.
close
()
self
.
updateSize
()
# redraq box
def
updateSize
(
self
):
if
self
.
size
is
not
None
:
return
...
...
@@ -115,15 +114,22 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
#print(width, height)
#print width, height
self
.
setGeometry
(
0
,
0
,
width
+
25
,
height
)
def
boundingRect
(
self
):
return
QtCore
.
QRectF
(
0
,
0
,
self
.
width
(),
self
.
height
())
def
paint
(
self
,
p
,
*
args
):
p
.
setPen
(
fn
.
mkPen
(
255
,
255
,
255
,
100
))
p
.
setBrush
(
fn
.
mkBrush
(
100
,
100
,
100
,
50
))
p
.
drawRect
(
self
.
boundingRect
())
def
hoverEvent
(
self
,
ev
):
ev
.
acceptDrags
(
QtCore
.
Qt
.
LeftButton
)
def
mouseDragEvent
(
self
,
ev
):
if
ev
.
button
()
==
QtCore
.
Qt
.
LeftButton
:
dpos
=
ev
.
pos
()
-
ev
.
lastPos
()
self
.
autoAnchor
(
self
.
pos
()
+
dpos
)
class
ItemSample
(
GraphicsWidget
):
def
__init__
(
self
,
item
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment