Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions mpop_dataviz/barchartlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void BarChartLayout::setStartPosition(const QPointF &pos)

void BarChartLayout::moveObjectsToLayout(qint64 currentTime) {
// TODO: never ever iterate over size of line vector
// TODO: if (_isLogarithmicY) {}
const qreal DISTANCE_BETWEEN_BARS = _barsHeight / 3.7;
const qreal WIDTH_OF_EACH_COLUMN = DISTANCE_BETWEEN_BARS * 3;
const qreal DISTANCE_BETWEEN_COLUMN = DISTANCE_BETWEEN_BARS / 2;
Expand All @@ -73,15 +74,17 @@ void BarChartLayout::moveObjectsToLayout(qint64 currentTime) {
int biggestRow = *std::max_element(_rowsValues.begin(), _rowsValues.end());
qreal columnSize = biggestRow / 5;

qreal offsetX = ((WIDTH_OF_EACH_COLUMN * columnSize) + ((DISTANCE_BETWEEN_BARS * 2) +
DISTANCE_BETWEEN_COLUMN) * (int(columnSize) - 1)) / 2;
qreal offsetY = ((_barsHeight * (_rowsValues.size() - 1)) +
(DISTANCE_BETWEEN_ROW * (_rowsValues.size() - 1))) / 2;
qreal offsetX = (
(WIDTH_OF_EACH_COLUMN * columnSize) +
((DISTANCE_BETWEEN_BARS * 2) + DISTANCE_BETWEEN_COLUMN) *
(int(columnSize) - 1)
) / 2;
qreal offsetY = (
(_barsHeight * (_rowsValues.size() - 1)) +
(DISTANCE_BETWEEN_ROW * (_rowsValues.size() - 1))) / 2;

for (int rowIndex = 0; rowIndex < _rowsValues.size(); rowIndex++) {

int columnIndex = 0;

// Each bar in the bar chart is a column
// We group lines by groups of 5
for (int barIndex = 0; barIndex < _rowsValues.at(rowIndex); barIndex++) {
Expand All @@ -101,9 +104,8 @@ void BarChartLayout::moveObjectsToLayout(qint64 currentTime) {
if (moduloFive == 4) {
x = ((barIndex - 2) * DISTANCE_BETWEEN_BARS) - (DISTANCE_BETWEEN_BARS / 2) + columnOffset;
rotation = -73;
// Increase the size of the fifth bar to fit to user story proportion
// Increase the size of every fifth bar
line->setSize(_barsWidth, _barsHeight * 1.25);

columnIndex += 1;
}

Expand Down
3 changes: 2 additions & 1 deletion mpop_dataviz/barchartlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class BarChartLayout : public Layout
_rowsValues.end(), 0);
}


void updateBarsPosition(qint64 currentTime) override;

void showSceneObject(qint64 currentTime) override;
Expand All @@ -40,13 +39,15 @@ class BarChartLayout : public Layout
void setStartPosition(const QPointF &pos);
void setDistanceBetweenRows(qreal rowSpace) { _spaceBetweenRows = rowSpace; }

void setLogarithmicY(bool isLogarithmicY);
private:
QList<int> _rowsValues;
QSharedPointer<GroupTweenAnimator> _groupTweenAnimator;

QVector<PrisonerLine::ptr> _horizontalLines;

bool _centered = false;
bool _isLogarithmicY = false;

qreal _x, _y = 0.0;
qreal _spaceBetweenRows = 0.018;
Expand Down
4 changes: 2 additions & 2 deletions mpop_dataviz/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Layout
virtual ~Layout();

/**
* @brief Adds some prisoner lines to this layour.
* @brief Adds some prisoner lines to this layout.
* @param prisonerLines
*/
void addBarObjects(QSharedPointer<QVector<PrisonerLine::ptr>> barObjects);

/**
* @brief Move the objects managed by this layout into their desired position.
* @brief Moves the objects managed by this layout into their desired position.
*/
virtual void moveObjectsToLayout(qint64 currentTime) = 0;

Expand Down
1 change: 1 addition & 0 deletions mpop_dataviz/viewmodemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ void ViewModeManager::moveBarsToAnswerByAgeLayout()
_agesAnswerBarChart.moveObjectsToLayout(currentTime());

_userAgeAnswer.addBarObjects(myAgeVect);
_userAgeAnswer.setLogarithmicY(true);
_userAgeAnswer.setBarsSize(sizeFromPixel(3.5, barHeight));
_userAgeAnswer.setBarsColor("#80E2A7");
_userAgeAnswer.setStartPosition(
Expand Down