Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b0714d86

Přidáno uživatelem Jan Rach před téměř 4 roky(ů)

Re: #8854 - Graphs update

Zobrazit rozdíly:

aswi2021vochomurka/view/main_view.py
53 53

  
54 54
    def onMessage(self, message: Message):
55 55
        self.newMessage.emit(message.topic)
56
        self.window.plot()
56
        self.window.plot(message)
57 57

  
58 58
    def onCloseTopic(self, topic: str):
59 59
        pass
60 60

  
61 61

  
62
#class MainView(QMainWindow):
63 62
class MainView(QDialog):
64 63
    worker: Worker = None
65 64
    workerThread: QThread = None
66 65

  
67 66
    def __init__(self):
68
        #QMainWindow.__init__(self)
69 67
        super(MainView, self).__init__()
70 68

  
71 69
        self.chartsNum = 0
72 70
        self.arrayData = []
73 71

  
72
        self.dataIndex = 0
73
        self.dataDict = {}
74

  
74 75
        self.figure = plt.figure(figsize=([500,500]))
75 76

  
76 77
        self.canvas = FigureCanvas(self.figure)
......
79 80
        self.setMinimumSize(QSize(440, 240))
80 81
        self.setWindowTitle("MQTT demo")
81 82

  
82
        # Add text field
83 83
        self.b = QPlainTextEdit(self)
84 84
        self.b.insertPlainText("App started...\n")
85
        # self.b.move(10, 50)
86
        # self.b.resize(200, 100)
87 85

  
88 86
        layout = QVBoxLayout()
89 87
        layout.addWidget(self.b)
......
92 90

  
93 91
        self.setLayout(layout)
94 92

  
95
        # self.plot()
96

  
97 93
        self.initSubscriber()
98 94

  
99
    # action called by thte push button
100
    def plot(self):
101

  
102
        self.chartsNum += 1
103
        rows = math.ceil(self.chartsNum / 2)
104

  
95
    def plot(self, message: Message):
105 96
        self.figure.clear()
106 97

  
107
        data = [random.random() for i in range(10)]
108
        self.arrayData.append(data)
98
        if message.topic in self.dataDict:
99
            self.dataDict[message.topic].append(message.value)
100
        else:
101
            self.dataDict[message.topic] = [message.value]
102
            self.chartsNum += 1
103

  
104
        rows = math.ceil(self.chartsNum / 2)
109 105

  
110
        for x in range(self.chartsNum):
111
            self.figure.add_subplot(rows,2,x+1)
112
            plt.plot(self.arrayData[x])
106
        b = 0
107
        for a in self.dataDict.values():
108
            self.figure.add_subplot(rows, 2, b + 1)
109
            b += 1
110
            plt.plot(a)
113 111

  
114 112
        self.canvas.draw()
115 113

  

Také k dispozici: Unified diff