aboutsummaryrefslogtreecommitdiff
path: root/barchart.h
blob: 947fe2b8230a058c8cb294459560fd3397aeec79 (plain)
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
#ifndef BARCHART_H
#define BARCHART_H

#include <memory>
#include <vector>

#include <armadillo>
#include <glad/gl.h>
#include <nod.hpp>

#include "scale.h"
#include "shader.h"

class BarChart
{
public:
    BarChart();

    size_t width() const { return m_width; }
    size_t height() const { return m_height; }
    GLuint texture() const { return m_outTex; }

    nod::signal<void(const arma::vec &)> valuesChanged;
    nod::signal<void(const std::vector<bool> &)> selectionChanged;
    nod::signal<void(const std::vector<bool> &)> selectionInteractivelyChanged;
    nod::signal<void(int, float)> itemBrushed;
    nod::signal<void(int)> itemInteractivelyBrushed;

    void setSize(size_t, size_t);
    void setValues(const arma::vec &values);
    void updateValues(const arma::vec &values);
    void setColormap(GLuint texture);
    void setSelection(const std::vector<bool> &selection);
    void brushItem(int item);

    void update();
    void draw();

    // protected:
    // QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);

    // void hoverEnterEvent(QHoverEvent *event);
    // void hoverMoveEvent(QHoverEvent *event);
    // void hoverLeaveEvent(QHoverEvent *event);

    // void mousePressEvent(QMouseEvent *event);
    // void mouseMoveEvent(QMouseEvent *event);
    // void mouseReleaseEvent(QMouseEvent *event);

private:
    void updateBars();

    // QSGNode *newSceneGraph() const;
    // QSGNode *newBarNode() const;
    // QSGNode *newSelectionBarNode() const;

    // void updateViewport(QSGNode *root) const;
    // void updateBarNodeGeom(QSGNode *barNode, float x, float width, float height) const;
    // void updateBarNodeColor(QSGNode *barNode, const QColor &color) const;
    // void updateBars(QSGNode *node) const;
    bool m_redraw;
    bool m_shouldUpdateBars;

    // void updatePreSelection(QSGNode *node) const;
    bool m_shouldUpdatePreSelection;
    float m_dragStartPos, m_dragLastPos;

    // void updateSelectionBar(QSGNode *node, float x, float barWidth, const QColor &color) const;
    // void updateSelectionBars(QSGNode *node) const;
    bool m_shouldUpdateSelection;

    void interactiveSelection(float start, float end);
    std::vector<bool> m_selection;

    // void updateBrush(QSGNode *node) const;
    int m_brushedItem;

    int itemAt(float x, bool includeSelectorWidth = false) const;

    size_t m_width, m_height;
    GLuint m_FBO, m_VAO, m_VBO, m_colormapTex, m_outTex;
    std::unique_ptr<Shader> m_shader;

    arma::vec m_values;
    std::vector<int> m_originalIndices, m_currentIndices;
    LinearScale<float> m_scale;
};

#endif // BARCHART_H