-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScopePy_graphs.py
More file actions
7564 lines (4973 loc) · 224 KB
/
ScopePy_graphs.py
File metadata and controls
7564 lines (4973 loc) · 224 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 16 20:19:52 2014
@author: john
ScopePy Graph library
=========================
Graph plotting and asscociated widgets are defined here
Version
==============================================================================
$Revision:: 177 $
$Date:: 2016-07-31 21:09:08 -0400 (Sun, 3#$
$Author:: $
==============================================================================
"""
#==============================================================================
#%% License
#==============================================================================
"""
Copyright 2015 John Bainbridge
This file is part of ScopePy.
ScopePy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScopePy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ScopePy. If not, see <http://www.gnu.org/licenses/>.
"""
#=============================================================================
#%% TODO list:
#=============================================================================
"""
* GraphSeries - implement transparency
* GraphSeries - Change marker colours
* Chunk handling
* Log scale
* Marker lines : horiz and vertical [done]
- Delta positions with respect to other markers
* Context menus :
- Turning on/off axes
- setting lin/log scale
* Manually editing axis scales
"""
#=============================================================================
#%% Imports
#=============================================================================
import sys
import logging
import copy
from collections import OrderedDict
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
# ScopePy libraries
import ScopePy_channel as ch
import ScopePy_utilities as util
import csslib
import ScopePy_colours_and_shapes as col_shapes
#==============================================================================
#%% Logger
#==============================================================================
# create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# Add do nothing handler
logger.addHandler(logging.NullHandler())
# create console handler and set level to debug
con = logging.StreamHandler()
con.setLevel(logging.ERROR)
# create formatter
formatter = logging.Formatter('[%(asctime)s:%(name)s:%(levelname)s]: %(message)s')
# add formatter to ch
con.setFormatter(formatter)
# add ch to logger
logger.addHandler(con)
#=============================================================================
#%% Constants
#=============================================================================
global KEYBOARD
PLOT_HORIZ_SIZE = 350
PLOT_VERT_SIZE = 400
# Size of scene, must be 500 or greater to give the range in
# text sizes
SCENESIZE = 500
DEFAULT_AXIS_MIN = -10.0
DEFAULT_AXIS_RANGE = 20.0
DEFAULT_GRID = np.arange(-10.0,10.0,2)
# Maximum number of markers
MAX_MARKERS = 4
DEBUG = False
# Debug printout
dbg = util.DebugPrint(['all','brief','verbose','HorizMarkerLine'])
"""
Note: QGraphicsItems for this application need to be drawn using
floating point coordinates such as QPointF(), QRectF()
"""
#=============================================================================
#%% Graph widget class definition
#=============================================================================
class GraphWidget(QGraphicsView):
"""
Basic 2D plot widget for ScopePy
Features:
* Autoscaling, X,Y or both
* Panning & zooming with mouse or keyboard
* Horiz & vertical markers
* On screen editable axis limits
"""
def __init__(self,preferences, parent=None):
super(GraphWidget, self).__init__(parent)
# Link to preferences
# ---------------------
self.preferences = preferences
# Setup Scene
# -------------------------
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(-SCENESIZE/2, -SCENESIZE/2, SCENESIZE, SCENESIZE)
self.scene.setItemIndexMethod(QGraphicsScene.NoIndex)
#self.setRenderHint(QPainter.Antialiasing) # Has a big effect on performance, turn off by default
self.setScene(self.scene)
self.setFocusPolicy(Qt.StrongFocus)
self.fitInView(self.scene.sceneRect())
self.setSizePolicy(QSizePolicy.Minimum,QSizePolicy.Minimum)
self.setMouseTracking(True)
# Turn off scroll bars
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
# add coordinate manager
# ----------------------------
self.coordinateManager = CoordinateManager(self.scene,self)
# Set default axis range
self.coordinateManager.x_min_DC = DEFAULT_AXIS_MIN
self.coordinateManager.x_max_DC = DEFAULT_AXIS_MIN + DEFAULT_AXIS_RANGE
self.coordinateManager.y_min_DC = DEFAULT_AXIS_MIN
self.coordinateManager.y_max_DC = DEFAULT_AXIS_MIN + DEFAULT_AXIS_RANGE
self.coordinateManager.x_grid_major_DC = DEFAULT_GRID
self.coordinateManager.y_grid_major_DC = DEFAULT_GRID
# Colours
# ----------------
self.backgroundColor = QColor(69,65,65)
#self.backgroundColor.darker(600)
self.vertMarkerColor = '#FFFF00'
self.horizMarkerColor = '#81F781'
# Data series traceability
# ------------------------------
# Dictionaries for keeping a record of the data series
# items that are on the graph.
# Used for re-drawing
# One list for graph series
self.graphSeries = OrderedDict()
# Separate list of ScopePy channels
self.channelSeries = OrderedDict()
# Markers
# -----------
# dictionary for recording any markers added to the plot
self.horizontalMarkers = {}
self.verticalMarkers = {}
# Axis scales
# -------------------
# Used for autoscaling the graph
# # These are updated every time a series is added
# self.xmin = DEFAULT_AXIS_MIN
# self.xmax = DEFAULT_AXIS_MIN + DEFAULT_AXIS_RANGE
#
# self.ymin = DEFAULT_AXIS_MIN
# self.ymax = DEFAULT_AXIS_MIN + DEFAULT_AXIS_RANGE
# draw the widget
self.draw()
# Minimum sizes
self.horiz_size = PLOT_HORIZ_SIZE
self.vert_size = PLOT_VERT_SIZE
# Debug dot
# self.dot = Dot(Qt.red,QPointF(0,0))
# self.scene.addItem(self.dot)
#
# self.scene.addLine(-200,0,200,0,QPen(Qt.red))
# self.scene.addLine(0,-200,0,200,QPen(Qt.red))
#
def minimumSizeHint(self):
"""
Set the minimum size
"""
return QSize(self.horiz_size,self.vert_size)
def sizeHint(self):
"""
Minimum is the size hint
"""
return self.minimumSizeHint()
def draw(self):
"""
Initial drawing of widget
"""
# Background
self.background = Background(self.backgroundColor,self.coordinateManager)
self.scene.addItem(self.background)
# Plot box
self.plotBox = PlotBox(self.coordinateManager)
self.scene.addItem(self.plotBox)
if DEBUG:
print("PlotBox:",self.plotBox.pos())
# Axes
# -----------------
# Centre axes
self.xCentreAxis = Axis('origin y',self.coordinateManager)
self.xCentreAxis.tickLabelsEnabled = True
#self.xCentreAxis.minorTicksEnabled = False
self.xCentreAxis.axisTitle_position = "middle"
self.yCentreAxis = Axis('origin x',self.coordinateManager)
self.yCentreAxis.tickLabelsEnabled = True
#self.yCentreAxis.minorTicksEnabled = False
self.yCentreAxis.axisTitle_position = "middle"
self.yCentreAxis.axisTitle_end_offset_NC = 0.10
self.scene.addItem(self.xCentreAxis)
#print("self.xCentreAxis:",self.xCentreAxis.pos())
self.scene.addItem(self.yCentreAxis)
# Box axes
self.xBottomAxis = Axis('bottom',self.coordinateManager)
self.xBottomAxis.tickLabelsEnabled = True
self.xBottomAxis.axisTitle_position = "middle"
self.xBottomAxis.setMinorTickPosition("above")
self.scene.addItem(self.xBottomAxis)
self.xTopAxis = Axis('top',self.coordinateManager)
self.xTopAxis.tickLabelsEnabled = False
self.xTopAxis.setMinorTickPosition("below")
self.xTopAxis.showAxisTitle = False
self.scene.addItem(self.xTopAxis)
self.yLeftAxis = Axis('left',self.coordinateManager)
self.yLeftAxis.tickLabelsEnabled = True
self.yLeftAxis.setMinorTickPosition("right")
self.scene.addItem(self.yLeftAxis)
self.yRightAxis = Axis('right',self.coordinateManager)
self.yRightAxis.tickLabelsEnabled = False
self.yRightAxis.setMinorTickPosition("left")
self.scene.addItem(self.yRightAxis)
# Add legend but hide it first
self.addLegend()
self.hideLegend()
# Axis limits
# ================
# TODO: These need to update the plot
# x axis
# ---------------
@property
def xmin(self):
return self.coordinateManager.x_data_min_DC
@xmin.setter
def xmin(self,value):
if value != self.coordinateManager.x_data_min_DC:
self.coordinateManager.x_data_min_DC = value
self.coordinateManager.autoscale(axis='x')
@property
def xmax(self):
return self.coordinateManager.x_data_max_DC
@xmax.setter
def xmax(self,value):
if value != self.coordinateManager.x_data_max_DC:
self.coordinateManager.x_data_max_DC = value
self.coordinateManager.autoscale(axis='x')
# y axis
# ---------------
@property
def ymin(self):
return self.coordinateManager.y_data_min_DC
@ymin.setter
def ymin(self,value):
if value != self.coordinateManager.y_data_min_DC:
self.coordinateManager.y_data_min_DC = value
self.coordinateManager.autoscale(axis='y')
@property
def ymax(self):
return self.coordinateManager.y_data_max_DC
@ymax.setter
def ymax(self,value):
if value != self.coordinateManager.y_data_max_DC:
self.coordinateManager.y_data_max_DC = value
self.coordinateManager.autoscale(axis='y')
@property
def xlabel(self):
"""
Return x axis title
"""
return self.xBottomAxis.getAxisTitle()
@xlabel.setter
def xlabel(self,axis_label):
"""
Set the text in axis label
Input
--------
axis_label : str
"""
# Change all the x axis labels
#self.xCentreAxis.setAxisTitle(axis_label)
self.xTopAxis.setAxisTitle(axis_label)
self.xBottomAxis.setAxisTitle(axis_label)
self.update()
@property
def ylabel(self):
"""
Return x axis title
"""
return self.yLeftAxis.getAxisTitle()
@ylabel.setter
def ylabel(self,axis_label):
"""
Set the text in axis label
Input
--------
axis_label : str
"""
# Change all the y axis labels
#self.yCentreAxis.setAxisTitle(axis_label)
self.yLeftAxis.setAxisTitle(axis_label)
self.yRightAxis.setAxisTitle(axis_label)
self.update()
def addSeries(self,graph_series):
"""
Add graph series to plot
Input
-----------
graph_series : GraphSeries object
"""
# TODO need to add data as x & y plus marker specs
# can't add series externally because they need coordinate manager
# Add to graph series list
self.graphSeries[graph_series.name] = graph_series
# Add to scene
self.scene.addItem(self.graphSeries[graph_series.name] )
# Update scaling
self.updateScaling(graph_series.x_DC,graph_series.y_DC)
# Update legend
self.legend.updateLegend()
def addChannel(self,channel,chunkMode='all'):
"""
Add ScopePy channel to graph
Inputs:
--------------
channel : ScopePy_channel
chunkMode : str
Output
---------
channel_series: ChannelGraphSeries object
"""
# Add channel to the list
self.channelSeries[channel.name] = ChannelGraphSeries(channel,self.coordinateManager,chunkMode=chunkMode)
# Add channel series object to the scene
self.scene.addItem(self.channelSeries[channel.name])
#self.channelSeries[channel.name].drawMarkers = False
# Update scaling
data = channel.data(chunkMode=chunkMode)
if not channel.isEmpty:
self.updateScaling(data[channel.x_axis],data[channel.y_axis])
# Update legend
self.legend.updateLegend()
# Return pointer to the ChannelGraphSeries
return self.channelSeries[channel.name]
def deleteChannel(self,channel_name):
"""
Remove channel from plot
"""
if channel_name not in self.channelSeries:
return
# Remove ChannelGraphSeries object from plot
self.scene.removeItem(self.channelSeries[channel_name])
# Remove channel from internal dictionary
self.channelSeries.pop(channel_name)
# Update the scaling values with the remaining channels
self.clearScaling()
for ch_series in self.channelSeries.values():
channel = ch_series.channel
data = channel.data(chunkMode=ch_series.chunkMode)
self.updateScaling(data[channel.x_axis],data[channel.y_axis])
def addHorizMarker(self):
"""
Add a horizontal marker to the plot
Marker is named automatically: H1, H2 ...
"""
marker_name = "H%d" % (len(self.horizontalMarkers)+1)
horiz_marker = HorizMarkerLine(self.coordinateManager,
name=marker_name,
markerDict=self.horizontalMarkers)
horiz_marker.lineColour = self.horizMarkerColor
self.scene.addItem(horiz_marker)
# Add marker to the list
self.horizontalMarkers[marker_name] = horiz_marker
logger.debug('Adding new horizontal marker [%s] at y = %.3f' % (marker_name,horiz_marker.position_DC))
self.update()
def addVertMarker(self):
"""
Add a Vertical marker to the plot
Marker is named automatically: V1, V2 ...
"""
marker_name = "V%d" % (len(self.verticalMarkers)+1)
vert_marker = VertMarkerLine(self.coordinateManager,
name=marker_name,
markerDict=self.verticalMarkers)
vert_marker.lineColour = self.vertMarkerColor
self.scene.addItem(vert_marker)
# Add marker to the list
self.verticalMarkers[marker_name] = vert_marker
logger.debug('Adding new vertical marker [%s] at x = %.3f' % (marker_name,vert_marker.position_DC))
self.update()
def deleteHorizMarker(self,marker_name):
"""
Remove horiz marker
"""
# Extract from dictionary
marker = self.horizontalMarkers.pop(marker_name,None)
if marker:
self.scene.removeItem(marker)
def deleteVertMarker(self,marker_name):
"""
Remove vert marker
"""
# Extract from dictionary
marker = self.verticalMarkers.pop(marker_name,None)
if marker:
self.scene.removeItem(marker)
def updateScaling(self,xdata,ydata):
"""
Update the min and max axis values.
Check the min and max x and y values, if they are outside the
range of the internal values then update them.
Inputs
-----------
xdata, ydata : numpy array or list
x and y data of a new series
"""
# Update x
# ----------------
update_x = False
# Get min and max for x
xdata_min = min(xdata)
xdata_max = max(xdata)
if xdata_min < self.coordinateManager.x_data_min_DC:
self.coordinateManager.x_data_min_DC = xdata_min
update_x = True
if xdata_max > self.coordinateManager.x_data_max_DC:
self.coordinateManager.x_data_max_DC = xdata_max
update_x = True
if update_x:
self.coordinateManager.autoscale('x')
# Update y
# ----------------
update_y = False
# Get min and max for x
ydata_min = min(ydata)
ydata_max = max(ydata)
if ydata_min < self.coordinateManager.y_data_min_DC:
self.coordinateManager.y_data_min_DC = ydata_min
update_y = True
if ydata_max > self.coordinateManager.y_data_max_DC:
self.coordinateManager.y_data_max_DC = ydata_max
update_y = True
# Trigger updates
if update_y:
self.coordinateManager.autoscale('y')
def clearScaling(self):
"""
Reset the graph scaling min and max values
"""
self.coordinateManager.reset_data_min_max()
def update(self):
"""
Reimplement update function to check if any plots are on screen
but not visible
"""
# Check GraphSeries
# -------------------------
for name in self.graphSeries:
self.graphSeries[name].recalculate = True
self.graphSeries[name].update()
# Check channels
# -------------------------
for name in self.channelSeries:
self.channelSeries[name].recalculate = True
self.channelSeries[name].updateFromChannel()
self.channelSeries[name].forceUpdate()
# Update legend
# -------------------
if hasattr(self,'legend'):
self.legend.updateLegend()
# Check Horizontal marker lines
# -------------------------------
for line in self.horizontalMarkers.values():
line.update()
# Check Vertical marker lines
# -------------------------------
for line in self.verticalMarkers.values():
line.update()
# Axis limit editors
# --------------------
#self.xMinEditor.update(self.coordinateManager.plotBox2scene())
# Run normal update
super().update()
def updateChannel(self,channel_name):
"""
Force a channel to re-draw
This is normally connected to a signal from the ScopePy_channel class
Input
-------
channel_name: str
"""
if not channel_name in self.channelSeries:
return
self.channelSeries[channel_name].updateFromChannel()
self.channelSeries[channel_name].forceUpdate()
def recalculate_graphs(self):
"""
Tell all GraphSeries and derivatives to recalculate their coordinates.
This is called by Coordinate manager when the axis limits change
"""
# Check GraphSeries
# -------------------------
for name in self.graphSeries:
self.graphSeries[name].recalculate = True
# Check channels
# -------------------------
for name in self.channelSeries:
self.channelSeries[name].recalculate = True
def plot2image(self):
"""
Copy plot to an image
Output
-------
image : QImage()
"""
#imageRect = self.coordinateManager.plotBox2scene()
imageRect = self.coordinateManager.viewport2sceneRect()
coords = (imageRect.x(),imageRect.y(),imageRect.width(),imageRect.height())
logger.debug("plot2image: x = %d, y = %d, w = %d, h = %d" % coords)
image_size = QSize(imageRect.width(),imageRect.height())
image = QImage(image_size,QImage.Format_RGB16)
logger.debug("Image dimensions:")
#print(image.rect())
self.scene.render(QPainter(image),target=QRectF(image.rect()),
source=imageRect,mode=Qt.KeepAspectRatio)
return image
def plot2clipboard(self):
"""
Copy plot to clipboard
"""
image = self.plot2image()
clipboard = QApplication.clipboard()
clipboard.setImage(image)
def focusOnPlot(self):
"""
Put keyboard focus on the plot area. This allows panning and zooming
with the keyboard.
"""
self.setFocus()
self.plotBox.setFocus()
self.plotBox.grabKeyboard()
# Autoscaling functions:
# ---------------------------------
def autoscale(self):
logger.debug("Autoscale selected")
self.coordinateManager.autoscale()
def autoscaleX(self):
logger.debug("Autoscale X selected")
self.coordinateManager.autoscale('x')
def autoscaleY(self):
logger.debug("Autoscale Y selected")
self.coordinateManager.autoscale('y')
# StyleSheet functions
# ---------------------------------------
def setStyleSheet(self,css_str):
"""
Set the style of the graphs using a CSS stylesheet.
Input
----------
css_str : str
CSS stylesheet which has the following entries (others are ignored):
standard_plot{
plot-background-color: #000000;
grid-color: #003400;
axis-color: #444444;
axis-label-color: #444444;
axis-title-color:#666666;
axis-limits-color: #666666;
axis-limits-background:#303030;
horiz-marker-color: #88a02f;
vert-marker-color: #18a02f;
border-color: #212121;
border-grid:1;
border-grid-color: #a00000;
vert-marker-color:#FFFF00;
horiz-marker-color:#81F781;
legend-outlineColor:
legend-outlineWidth: 3
legend-outlineMargin: 4
legend-cellBorderColor:
legend-cellBackgroundColor:
legend-cellBorderWidth: 1
legend-backgroundColor:
legend-textColor:
legend-fontsize: 8;
}
TODO: selected
"""
# Convert CSS to dictionary
# --------------------------------
styles = csslib.getCss(css_str)
# Check for the 'standard_plot' key
if 'standard_plot' not in styles:
return
# Extraction Function
def getColor(key,default_colour):
return QColor(styles['standard_plot'].get(key,default_colour))
# Set styles
# -----------------------
# Background/border colour
self.background.color = getColor('border-color',QColor(Qt.darkGray).name())
self.background.gridEnabled = styles['standard_plot'].get('border-grid',0)==1
self.background.gridColor = getColor('border-grid-color',QColor(Qt.red).name())
# actual plot background
self.plotBox.borderColor = getColor('grid-color',QColor(Qt.green).name())
self.plotBox.gridColor = getColor('grid-color',QColor(Qt.green).name())
self.plotBox.backgroundColor = getColor('plot-background-color',QColor(Qt.black).name())
# Change axis colours
for axis in [self.xCentreAxis,self.xBottomAxis,self.xTopAxis,
self.yCentreAxis,self.yLeftAxis,self.yRightAxis]:
axis.axisColor = getColor('axis-color',QColor(Qt.gray).name())
axis.tickLabelColor = getColor('axis-label-color',QColor(Qt.gray).name())
axis.axisTitle_color = getColor('axis-title-color',QColor(Qt.gray).name())
# Markers
# TODO: Not consistent with other colours - Fix this
self.vertMarkerColor = styles['standard_plot'].get('vert-marker-color','#FFFF00')
self.horizMarkerColor = styles['standard_plot'].get('horiz-marker-color','#81F781')
# Legend
self.legend.outlineColour = getColor('legend-outlineColor',QColor(Qt.darkGray).name())
self.legend.outlineWidth = int(styles['standard_plot'].get('legend-outlineWidth',2))
self.legend.outlineMargin = int(styles['standard_plot'].get('legend-outlineMargin',3))
self.legend.cellBorderColour = getColor('legend-cellBorderColor',QColor(Qt.black).name())
self.legend.cellBackgroundColour = getColor('legend-cellBackgroundColor',QColor(Qt.black).name())
self.legend.cellWidth = int(styles['standard_plot'].get('legend-cellBorderWidth',1))
self.legend.backgroundColour = getColor('legend-backgroundColor',QColor(Qt.black).name())
self.legend.textColour = getColor('legend-textColor',QColor(Qt.lightGray).name())
self.legend.fontsize = int(styles['standard_plot'].get('legend-fontsize',8))
def addLegend(self):
"""
Add legend to plot
"""
self.legend = GraphLegend(self.coordinateManager,self.channelSeries)
self.scene.addItem(self.legend)
# Set default position
self.legend.upper_right()
def hideLegend(self):
"""
Hide legend
"""
if hasattr(self,'legend'):
self.legend.hide()
def showLegend(self):
"""
show legend
"""
if hasattr(self,'legend'):
self.legend.show()
self.legend.upper_left()
#=============================================================================
#%% Graphics items
#=============================================================================
# QGraphicsItems need the following methods