#pragma once #include #include #include #include #include class GraphView; struct GraphSeries { std::vector* data; double minX, maxX; double minY, maxY; QString name; QColor color; int lineWidth = 2; double circleRadius = 1.0; enum class SeriesType{ Line, Dot, LineDot}; SeriesType type; std::pair::iterator, std::vector::iterator> getFirstLastIndexInSeriesThatsInBound(int minX, int maxX); }; struct Bound { double minX = 0, minY = 0, maxX = 0, maxY = 0; enum class Change{MoveLeft, MoveRight, MoveUp, MoveDown, ZoomOut, ZoomIn, Reset}; Bound() {} Bound(double minX, double maxX, double minY, double maxY):minX(minX), maxX(maxX), minY(minY), maxY(maxY){} void move(GraphView* widget,const Change& type, const double changePercentage = 0.1); }; class GraphView :public QWidget { Q_OBJECT public: GraphView(QWidget* parent, QString title, Bound fixedBound); ~GraphView(); QString title; Bound fixedBound; private: bool useFixedBound; void paintEvent(QPaintEvent* event) override; //Data std::vector graphSeriesVec; Bound totalBound; Bound actualBound = totalBound; double rangeGraphX = 0, rangeGraphY = 0; //Visualization QString xAxisNumbers[11]; QString yAxisNumbers[11]; double hueoffset; QPen linePen, rectPen, axisPen; public: void setUseFixedBound(bool value); void generateAndAddRandomLine(); void addLine(std::vector& line); void addLine(std::vector& line, QColor color); void addDots(std::vector& dots); void addDots(std::vector& dots, QColor color); void calculateRangeXY(); void generateAxisNumberStrings(); private: void calculateTotalGraphBound(); void GraphView::calculateMinMaxXY(GraphSeries& lgs); void addSeries(std::vector& line, QColor color, GraphSeries::SeriesType type); QColor generateNextColorForGraph(); QPointF transformPoint(QPointF& point, double stregth_factorX, double stregth_factorY) const; bool inBoundX(QPointF& point); void keyPressEvent(QKeyEvent* event) override; void wheelEvent(QWheelEvent* event) override; };