#include "GraphWidget.h" #include GraphWidget::GraphWidget(QWidget *parent) : QWidget(parent) { QVBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); plot = new JKQTPlotter(this); layout->addWidget(plot); // Initialize Graphs graphY1 = new JKQTPXYLineGraph(plot); graphY2 = new JKQTPXYLineGraph(plot); // Styling Y1 (e.g., Blue) graphY1->setColor(QColor("blue")); graphY1->setSymbolColor(QColor("blue")); graphY1->setSymbol(JKQTPCircle); graphY1->setSymbolSize(7); graphY1->setLineWidth(2); // Styling Y2 (e.g., Red) graphY2->setColor(QColor("red")); graphY2->setSymbolColor(QColor("red")); graphY2->setSymbol(JKQTPTriangle); graphY2->setSymbolSize(7); graphY2->setLineWidth(2); plot->addGraph(graphY1); plot->addGraph(graphY2); } void GraphWidget::setupPlot(QString title, QString xLabel, QString y1Label, QString y2Label) { // Basic Settings plot->getPlotter()->setPlotLabel(title); plot->getXAxis()->setAxisLabel(xLabel); // Y-Axis setup plot->getYAxis()->setAxisLabel(y1Label); // Left Axis // If we want a secondary axis for Y2, JKQTPlotter supports it, // but for simplicity here we might plot on the same if scales are similar, // or rely on user interpretation. // For Bode (Ohm vs Degree), scales are vastly different. // Ideally, Y2 should be on the right axis. // Assign Y1 to Left Axis graphY1->setTitle(y1Label); // Assign Y2 to Right Axis (if supported by specific JKQT config, otherwise same axis) // Assuming simple usage for now: graphY2->setTitle(y2Label); // Enable Legend plot->getPlotter()->setShowKey(true); } void GraphWidget::setLogAxis(bool logX, bool logY) { plot->getXAxis()->setLogAxis(logX); plot->getYAxis()->setLogAxis(logY); } void GraphWidget::addData(double x, double y1, double y2) { xData.append(x); y1Data.append(y1); y2Data.append(y2); // Update graph data pointers graphY1->setXColumn(xData); graphY1->setYColumn(y1Data); graphY2->setXColumn(xData); graphY2->setYColumn(y2Data); // Redraw plot->redrawPlot(); } void GraphWidget::clear() { xData.clear(); y1Data.clear(); y2Data.clear(); plot->redrawPlot(); }