From 6e3da3dfcd61c0dc5b48ad1a6ee43269cceb5346 Mon Sep 17 00:00:00 2001 From: cklotte Date: Fri, 12 Jul 2019 11:28:10 -0500 Subject: [PATCH 1/5] Axis labels have been added --- interface/slice_diagram.cpp | 171 ++++++++++++++++++++++++++++++++++-- interface/slice_diagram.h | 21 +++-- 2 files changed, 180 insertions(+), 12 deletions(-) diff --git a/interface/slice_diagram.cpp b/interface/slice_diagram.cpp index 17fb193b..5cac91d1 100644 --- a/interface/slice_diagram.cpp +++ b/interface/slice_diagram.cpp @@ -1,19 +1,15 @@ /********************************************************************** Copyright 2014-2016 The RIVET Developers. See the COPYRIGHT file at the top-level directory of this distribution. - This file is part of RIVET. - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . **********************************************************************/ @@ -122,6 +118,26 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do x_label_text = x_text; y_label_text = y_text; + //xgrades text and line items + for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem; + textlistx.push_back(text); + QGraphicsLineItem* line = new QGraphicsLineItem; + linelistx.push_back(line); + + datalistx.push_back(x_grades[i]); + } + + //ygrades text and line items + for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem; + textlisty.push_back(text); + QGraphicsLineItem* line = new QGraphicsLineItem; + linelisty.push_back(line); + + datalisty.push_back(y_grades[i]); + } + //pens and brushes QPen blackPen(Qt::black); blackPen.setWidth(2); @@ -193,6 +209,29 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do x_label->setZValue(BigZValue + 1); y_label->setZValue(BigZValue + 1); + //Draw labels for the labels in between min and max + std::ostringstream stream; + + for (unsigned int i = 0; i < x_grades.size() - 2; i++) { // for x_grade labels + stream.precision(4); + + stream << datalistx[i]; + textlistx[i] = addSimpleText(QString(stream.str().data())); + textlistx[i]->setFlag(QGraphicsItem::ItemIgnoresTransformations); + textlistx[i]->setFont(config_params->diagramFont); + textlistx[i]->setZValue(BigZValue); + } + + for (unsigned int i = 0; i < y_grades.size() - 2; i++) { // for y_grade labels + stream.precision(4); + + stream << datalisty[i]; + textlisty[i] = addSimpleText(QString(stream.str().data())); + textlisty[i]->setFlag(QGraphicsItem::ItemIgnoresTransformations); + textlisty[i]->setFont(config_params->diagramFont); + textlisty[i]->setZValue(BigZValue); + } + //create rectangles for visualizing homology dimensions //first, find max dimension unsigned max_hom_dim = 0; @@ -219,6 +258,21 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do } } + //draw tick marks + // first define tick marks for the maxes and mins + xmintick = addLine(QLineF(), blackPen); + xmaxtick = addLine(QLineF(), blackPen); + ymintick = addLine(QLineF(), blackPen); + ymaxtick = addLine(QLineF(), blackPen); + + // define tick marks for the rest of the axis labels + for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + linelistx[i - 1] = addLine(QLineF(), blackPen); + } + for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + linelisty[i - 1] = addLine(QLineF(), blackPen); + } + //draw bounds gray_line_vertical = addLine(QLineF(), grayPen); //(diagram_width, 0, diagram_width, diagram_height, grayPen); gray_line_horizontal = addLine(QLineF(), grayPen); //0, diagram_height, diagram_width, diagram_height, grayPen); @@ -436,6 +490,14 @@ void SliceDiagram::resize_diagram() //redraw labels redraw_labels(); + //reposition tick marks + xmintick->setLine((data_xmin_text->pos().x()) + (data_xmin_text->boundingRect().width() / 2), 0, (data_xmin_text->pos().x()) + (data_xmin_text->boundingRect().width() / 2), (-1 * padding + 13)); + xmaxtick->setLine((data_xmax_text->pos().x()) + (data_xmax_text->boundingRect().width() / 2), 0, (data_xmax_text->pos().x()) + (data_xmax_text->boundingRect().width() / 2), (-1 * padding + 13)); + ymintick->setLine(0, (data_ymin_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2), (-1 * padding + 13), (data_ymin_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2)); + ymaxtick->setLine(0, (data_ymax_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2), (-1 * padding + 13), (data_ymax_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2)); + + redraw_tickmarks(); + //clear selection (because resizing window might combine or split dots in the upper strip of the persistence diagram) clear_selection(); highlight_line->hide(); @@ -601,6 +663,14 @@ void SliceDiagram::zoom_diagram(double angle, double offset, double distance_to_ //draw the labels redraw_labels(); + //reposition tick marks + xmintick->setLine((data_xmin_text->pos().x()) + (data_xmin_text->boundingRect().width() / 2), 0, (data_xmin_text->pos().x()) + (data_xmin_text->boundingRect().width() / 2), (-1 * padding + 13)); + xmaxtick->setLine((data_xmax_text->pos().x()) + (data_xmax_text->boundingRect().width() / 2), 0, (data_xmax_text->pos().x()) + (data_xmax_text->boundingRect().width() / 2), (-1 * padding + 13)); + ymintick->setLine(0, (data_ymin_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2), (-1 * padding + 13), (data_ymin_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2)); + ymaxtick->setLine(0, (data_ymax_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2), (-1 * padding + 13), (data_ymax_text->pos().y()) - (data_ymin_text->boundingRect().height() / 2)); + + redraw_tickmarks(); + //clear selection (because resizing window might combine or split dots in the upper strip of the persistence diagram) clear_selection(); highlight_line->hide(); @@ -693,6 +763,14 @@ void SliceDiagram::receive_parameter_change() x_label->setFont(config_params->diagramFont); y_label->setFont(config_params->diagramFont); + //update fonts for axis labels between max and min + for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + textlistx[i - 1]->setFont(config_params->diagramFont); + } + for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + textlisty[i - 1]->setFont(config_params->diagramFont); + } + //update diagram resize_diagram(); } //end receive_parameter_change() @@ -1152,6 +1230,32 @@ double SliceDiagram::get_pd_scale() return scale_x * scale_y / denominator; } +//redraws the tick marks on the axis diagram +void SliceDiagram::redraw_tickmarks() +{ + + //reposition tick marks + for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + double left = (x_grades[i] - data_xmin) * scale_x; + left = fmin(fmax(0, left), diagram_width + padding); + if (textlistx[i - 1]->text() == " ") { + linelistx[i - 1]->setLine(0, 0, 0, 0); + } else { + linelistx[i - 1]->setLine((left), 0, (left), (-1 * padding + 13)); + } + } + + for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + double bottom = (y_grades[i] - data_ymin) * scale_y; + bottom = fmin(fmax(0, bottom), diagram_height + padding); + if (textlisty[i - 1]->text() == " ") { + linelisty[i - 1]->setLine(0, 0, 0, 0); + } else { + linelisty[i - 1]->setLine(0, bottom, -1 * padding + 13, bottom); + } + } +} + //draws labels on top of white rectangles, so they don't get obscured by other graphics void SliceDiagram::redraw_labels() { @@ -1162,8 +1266,61 @@ void SliceDiagram::redraw_labels() data_ymin_text->setPos(-1 * text_padding - data_ymin_text->boundingRect().width(), data_ymin_text->boundingRect().height() / 2); data_ymax_text->setPos(-1 * text_padding - data_ymax_text->boundingRect().width(), diagram_height + data_ymax_text->boundingRect().height() / 2); - x_label->setPos((diagram_width - x_label->boundingRect().width()) / 2, -1 * text_padding); - y_label->setPos(-1 * text_padding - y_label->boundingRect().height(), (diagram_height - y_label->boundingRect().width()) / 2); + x_label->setPos((diagram_width - x_label->boundingRect().width()) / 2, -1 * text_padding - (data_xmin_text->boundingRect().height())); + y_label->setPos(-1 * text_padding - (data_ymax_text->boundingRect().width()) - y_label->boundingRect().height(), (diagram_height - y_label->boundingRect().width()) / 2); + + //setting position for x_grades axis label + for (unsigned i = 1; i < x_grades.size() - 1; i++) { + double left = (x_grades[i] - data_xmin) * scale_x; + + left = fmin(fmax(0, left), diagram_width + padding); + + textlistx[i - 1]->setPos((left - (textlistx[i - 1]->boundingRect().width() / 2)), -1 * text_padding); + + std::ostringstream stream1; + stream1.clear(); + stream1.precision(4); + stream1 << (datalistx[i - 1] == 0 ? 0 : datalistx[i - 1] * xrev_sign); + textlistx[i - 1]->setText(QString(stream1.str().data())); + } + + //setting position for y_grades axis labels + for (unsigned i = 1; i < y_grades.size() - 1; i++) { + double bottom = (y_grades[i] - data_ymin) * scale_y; + + bottom = fmin(fmax(0, bottom), diagram_height + padding); + + textlisty[i - 1]->setPos(-1 * text_padding - textlisty[i - 1]->boundingRect().width(), (bottom + (textlisty[i - 1]->boundingRect().height() / 2))); + + std::ostringstream stream2; + stream2.clear(); + stream2.precision(4); + stream2 << (datalisty[i - 1] == 0 ? 0 : datalisty[i - 1] * yrev_sign); + textlisty[i - 1]->setText(QString(stream2.str().data())); + } + + double currentdistx = (data_xmin_text->pos().x() + data_xmin_text->boundingRect().width()); + double currentdisty = data_ymin_text->pos().y(); + + //checking for space on the axis for the labels to fit + for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + if (textlistx[i - 1]->pos().x() > currentdistx && (textlistx[i - 1]->pos().x() + textlistx[i - 1]->boundingRect().width()) < data_xmax_text->pos().x()) { + + currentdistx = textlistx[i - 1]->pos().x() + textlistx[i - 1]->boundingRect().width(); + } else { + textlistx[i - 1]->setText(" "); + } + } + + for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + if ((textlisty[i - 1]->pos().y() - textlisty[i - 1]->boundingRect().height()) > currentdisty && textlisty[i - 1]->pos().y() < (data_ymax_text->pos().y() - data_ymax_text->boundingRect().height())) { + + currentdisty = textlisty[i - 1]->pos().y(); + + } else { + textlisty[i - 1]->setText(" "); + } + } std::ostringstream s_xmin; s_xmin.precision(4); @@ -1203,4 +1360,4 @@ void SliceDiagram::redraw_labels() rect6->setRect(0, 0, y_label->boundingRect().height(), y_label->boundingRect().width()); rect6->setPos(y_label->pos().x(), y_label->pos().y()); -} +} \ No newline at end of file diff --git a/interface/slice_diagram.h b/interface/slice_diagram.h index 1a84440c..efdf56b4 100644 --- a/interface/slice_diagram.h +++ b/interface/slice_diagram.h @@ -1,19 +1,15 @@ /********************************************************************** Copyright 2014-2016 The RIVET Developers. See the COPYRIGHT file at the top-level directory of this distribution. - This file is part of RIVET. - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see . **********************************************************************/ @@ -57,6 +53,7 @@ class SliceDiagram : public QGraphicsScene { void redraw_dim_rects(); //redraws the rectangles for the homology dimension visualization void redraw_dots(); //redraws the support points of the multigraded Betti numbers void redraw_labels(); //redraws axis labels in same position on top of rectangles + void redraw_tickmarks(); //redraws tick marks on the axis labels void zoom_diagram(double angle, double offset, double distance_to_origin); //redraws diagram in response to a change in bounds @@ -121,6 +118,14 @@ public slots: //parameters ConfigParameters* config_params; + std::vector datalistx; // contains the data from x_grades + std::vector datalisty; // contains the data from y_grades + + std::vector textlistx; // text items for x_grades labels + std::vector textlisty; // text items for y_grades labels + std::vector linelistx; //tick marks for x_grade labels + std::vector linelisty; //tick marks for y_grade labels + //graphics items QGraphicsSimpleTextItem* data_xmin_text; QGraphicsSimpleTextItem* data_xmax_text; @@ -135,6 +140,12 @@ public slots: QGraphicsLineItem* gray_line_vertical_left; //vertical gray line at the left of the grading rectangle QGraphicsLineItem* gray_line_horizontal_bottom; //horizontal gray line at the bottom of the grading rectangle + //max and min tick marks + QGraphicsLineItem* xmintick; + QGraphicsLineItem* xmaxtick; + QGraphicsLineItem* ymintick; + QGraphicsLineItem* ymaxtick; + QGraphicsRectItem* rect1; QGraphicsRectItem* rect2; QGraphicsRectItem* rect3; @@ -218,4 +229,4 @@ public slots: std::pair compute_endpoint(double coordinate, unsigned offset); //computes an endpoint of a bar in the barcode }; -#endif // SLICE_DIAGRAM_H +#endif // SLICE_DIAGRAM_H \ No newline at end of file From af620cf3ee27a9f2465875e254cf99fbe878bc62 Mon Sep 17 00:00:00 2001 From: cklotte Date: Tue, 16 Jul 2019 16:26:44 -0500 Subject: [PATCH 2/5] Issues fixed --- interface/slice_diagram.cpp | 80 ++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/interface/slice_diagram.cpp b/interface/slice_diagram.cpp index 5cac91d1..1a6d3575 100644 --- a/interface/slice_diagram.cpp +++ b/interface/slice_diagram.cpp @@ -119,7 +119,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do y_label_text = y_text; //xgrades text and line items - for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + for (unsigned int i = 0; i < x_grades.size(); i++) { QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem; textlistx.push_back(text); QGraphicsLineItem* line = new QGraphicsLineItem; @@ -129,7 +129,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do } //ygrades text and line items - for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + for (unsigned int i = 0; i < y_grades.size(); i++) { QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem; textlisty.push_back(text); QGraphicsLineItem* line = new QGraphicsLineItem; @@ -212,7 +212,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do //Draw labels for the labels in between min and max std::ostringstream stream; - for (unsigned int i = 0; i < x_grades.size() - 2; i++) { // for x_grade labels + for (unsigned int i = 0; i < x_grades.size(); i++) { // for x_grade labels stream.precision(4); stream << datalistx[i]; @@ -222,7 +222,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do textlistx[i]->setZValue(BigZValue); } - for (unsigned int i = 0; i < y_grades.size() - 2; i++) { // for y_grade labels + for (unsigned int i = 0; i < y_grades.size(); i++) { // for y_grade labels stream.precision(4); stream << datalisty[i]; @@ -266,11 +266,11 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do ymaxtick = addLine(QLineF(), blackPen); // define tick marks for the rest of the axis labels - for (unsigned int i = 1; i < x_grades.size() - 1; i++) { - linelistx[i - 1] = addLine(QLineF(), blackPen); + for (unsigned int i = 0; i < x_grades.size(); i++) { + linelistx[i] = addLine(QLineF(), blackPen); } - for (unsigned int i = 1; i < y_grades.size() - 1; i++) { - linelisty[i - 1] = addLine(QLineF(), blackPen); + for (unsigned int i = 0; i < y_grades.size(); i++) { + linelisty[i] = addLine(QLineF(), blackPen); } //draw bounds @@ -403,9 +403,9 @@ void SliceDiagram::resize_diagram() //determine scale double left_text_width = std::max(data_ymin_text->boundingRect().width(), data_ymax_text->boundingRect().width()); - double diagram_max_width = view_width - padding - 2 * scene_padding - text_padding - left_text_width; + double diagram_max_width = view_width - padding - 2 * scene_padding - text_padding - left_text_width - y_label->boundingRect().height(); double lower_text_height = std::max(data_xmin_text->boundingRect().height(), data_xmax_text->boundingRect().height()); - double diagram_max_height = view_height - padding - 2 * scene_padding - text_padding - lower_text_height; + double diagram_max_height = view_height - padding - 2 * scene_padding - text_padding - lower_text_height - x_label->boundingRect().width(); if (data_xmax > data_xmin) scale_x = diagram_max_width / (data_xmax - data_xmin); @@ -1235,23 +1235,25 @@ void SliceDiagram::redraw_tickmarks() { //reposition tick marks - for (unsigned int i = 1; i < x_grades.size() - 1; i++) { + for (unsigned int i = 0; i < x_grades.size(); i++) { double left = (x_grades[i] - data_xmin) * scale_x; left = fmin(fmax(0, left), diagram_width + padding); - if (textlistx[i - 1]->text() == " ") { - linelistx[i - 1]->setLine(0, 0, 0, 0); + if (textlistx[i]->isVisible() == false) { + linelistx[i]->hide(); } else { - linelistx[i - 1]->setLine((left), 0, (left), (-1 * padding + 13)); + linelistx[i]->setLine((left), 0, (left), (-1 * (padding/2))); + linelistx[i]->show(); } } - for (unsigned int i = 1; i < y_grades.size() - 1; i++) { + for (unsigned int i = 0; i < y_grades.size(); i++) { double bottom = (y_grades[i] - data_ymin) * scale_y; bottom = fmin(fmax(0, bottom), diagram_height + padding); - if (textlisty[i - 1]->text() == " ") { - linelisty[i - 1]->setLine(0, 0, 0, 0); + if (textlisty[i]->isVisible() == false) { + linelisty[i]->hide(); } else { - linelisty[i - 1]->setLine(0, bottom, -1 * padding + 13, bottom); + linelisty[i]->setLine(0, bottom, -1 * (padding/2), bottom); + linelisty[i]->show(); } } } @@ -1259,7 +1261,7 @@ void SliceDiagram::redraw_tickmarks() //draws labels on top of white rectangles, so they don't get obscured by other graphics void SliceDiagram::redraw_labels() { - + int mindistbetweenlables = 10; //the minimum number of pixels that should be between the axis label numbers int text_padding = 15; //pixels data_xmin_text->setPos(data_xmin_text->boundingRect().width() / (-2), -1 * text_padding); data_xmax_text->setPos(diagram_width - data_xmax_text->boundingRect().width() / 2, -1 * text_padding); @@ -1267,58 +1269,62 @@ void SliceDiagram::redraw_labels() data_ymax_text->setPos(-1 * text_padding - data_ymax_text->boundingRect().width(), diagram_height + data_ymax_text->boundingRect().height() / 2); x_label->setPos((diagram_width - x_label->boundingRect().width()) / 2, -1 * text_padding - (data_xmin_text->boundingRect().height())); - y_label->setPos(-1 * text_padding - (data_ymax_text->boundingRect().width()) - y_label->boundingRect().height(), (diagram_height - y_label->boundingRect().width()) / 2); + y_label->setPos(-1 * text_padding - (data_ymax_text->boundingRect().width()) - y_label->boundingRect().height()-10, (diagram_height - y_label->boundingRect().width()) / 2); //setting position for x_grades axis label - for (unsigned i = 1; i < x_grades.size() - 1; i++) { + for (unsigned i = 0; i < x_grades.size(); i++) { double left = (x_grades[i] - data_xmin) * scale_x; left = fmin(fmax(0, left), diagram_width + padding); - textlistx[i - 1]->setPos((left - (textlistx[i - 1]->boundingRect().width() / 2)), -1 * text_padding); + textlistx[i]->setPos((left - (textlistx[i]->boundingRect().width() / 2)), -1 * text_padding); std::ostringstream stream1; stream1.clear(); stream1.precision(4); - stream1 << (datalistx[i - 1] == 0 ? 0 : datalistx[i - 1] * xrev_sign); - textlistx[i - 1]->setText(QString(stream1.str().data())); + stream1 << (datalistx[i] == 0 ? 0 : datalistx[i] * xrev_sign); + textlistx[i]->setText(QString(stream1.str().data())); + } //setting position for y_grades axis labels - for (unsigned i = 1; i < y_grades.size() - 1; i++) { + for (unsigned i = 0; i < y_grades.size(); i++) { double bottom = (y_grades[i] - data_ymin) * scale_y; bottom = fmin(fmax(0, bottom), diagram_height + padding); - textlisty[i - 1]->setPos(-1 * text_padding - textlisty[i - 1]->boundingRect().width(), (bottom + (textlisty[i - 1]->boundingRect().height() / 2))); + textlisty[i]->setPos(-1 * text_padding - textlisty[i]->boundingRect().width(), (bottom + (textlisty[i]->boundingRect().height() / 2))); std::ostringstream stream2; stream2.clear(); stream2.precision(4); - stream2 << (datalisty[i - 1] == 0 ? 0 : datalisty[i - 1] * yrev_sign); - textlisty[i - 1]->setText(QString(stream2.str().data())); + stream2 << (datalisty[i] == 0 ? 0 : datalisty[i] * yrev_sign); + textlisty[i]->setText(QString(stream2.str().data())); } - double currentdistx = (data_xmin_text->pos().x() + data_xmin_text->boundingRect().width()); + double currentdistx = (data_xmin_text->pos().x() + data_xmin_text->boundingRect().width()) + mindistbetweenlables; double currentdisty = data_ymin_text->pos().y(); //checking for space on the axis for the labels to fit - for (unsigned int i = 1; i < x_grades.size() - 1; i++) { - if (textlistx[i - 1]->pos().x() > currentdistx && (textlistx[i - 1]->pos().x() + textlistx[i - 1]->boundingRect().width()) < data_xmax_text->pos().x()) { + for (unsigned int i = 0; i < x_grades.size(); i++) { + if (textlistx[i]->pos().x() > currentdistx && (textlistx[i]->pos().x() + textlistx[i]->boundingRect().width()) < data_xmax_text->pos().x()) { - currentdistx = textlistx[i - 1]->pos().x() + textlistx[i - 1]->boundingRect().width(); + currentdistx = textlistx[i]->pos().x() + textlistx[i]->boundingRect().width() + mindistbetweenlables; + textlistx[i]->show(); } else { - textlistx[i - 1]->setText(" "); + textlistx[i]->hide(); } } - for (unsigned int i = 1; i < y_grades.size() - 1; i++) { - if ((textlisty[i - 1]->pos().y() - textlisty[i - 1]->boundingRect().height()) > currentdisty && textlisty[i - 1]->pos().y() < (data_ymax_text->pos().y() - data_ymax_text->boundingRect().height())) { + for (unsigned int i = 0; i < y_grades.size(); i++) { + if ((textlisty[i]->pos().y() - textlisty[i]->boundingRect().height()) > currentdisty && textlisty[i]->pos().y() < (data_ymax_text->pos().y() - data_ymax_text->boundingRect().height())) { + + currentdisty = textlisty[i]->pos().y(); - currentdisty = textlisty[i - 1]->pos().y(); + textlisty[i]->show(); } else { - textlisty[i - 1]->setText(" "); + textlisty[i]->hide(); } } From 6f4890c609b45a6a1b8e2b4aacd71b2bb51305c8 Mon Sep 17 00:00:00 2001 From: cklotte Date: Thu, 18 Jul 2019 10:53:12 -0500 Subject: [PATCH 3/5] Made slight adjustments in how the bar diagram is positioned, moved x-axis label down a little, added half-sized tick marks for the labels that don't have numbers, got rid of datalistx and datalisty as they were not necessary, and other bug fixes --- interface/slice_diagram.cpp | 64 ++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/interface/slice_diagram.cpp b/interface/slice_diagram.cpp index 1a6d3575..0fd9d17f 100644 --- a/interface/slice_diagram.cpp +++ b/interface/slice_diagram.cpp @@ -125,7 +125,6 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do QGraphicsLineItem* line = new QGraphicsLineItem; linelistx.push_back(line); - datalistx.push_back(x_grades[i]); } //ygrades text and line items @@ -135,7 +134,6 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do QGraphicsLineItem* line = new QGraphicsLineItem; linelisty.push_back(line); - datalisty.push_back(y_grades[i]); } //pens and brushes @@ -215,7 +213,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do for (unsigned int i = 0; i < x_grades.size(); i++) { // for x_grade labels stream.precision(4); - stream << datalistx[i]; + stream << x_grades[i]; textlistx[i] = addSimpleText(QString(stream.str().data())); textlistx[i]->setFlag(QGraphicsItem::ItemIgnoresTransformations); textlistx[i]->setFont(config_params->diagramFont); @@ -225,7 +223,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do for (unsigned int i = 0; i < y_grades.size(); i++) { // for y_grade labels stream.precision(4); - stream << datalisty[i]; + stream << y_grades[i]; textlisty[i] = addSimpleText(QString(stream.str().data())); textlisty[i]->setFlag(QGraphicsItem::ItemIgnoresTransformations); textlisty[i]->setFont(config_params->diagramFont); @@ -405,7 +403,7 @@ void SliceDiagram::resize_diagram() double left_text_width = std::max(data_ymin_text->boundingRect().width(), data_ymax_text->boundingRect().width()); double diagram_max_width = view_width - padding - 2 * scene_padding - text_padding - left_text_width - y_label->boundingRect().height(); double lower_text_height = std::max(data_xmin_text->boundingRect().height(), data_xmax_text->boundingRect().height()); - double diagram_max_height = view_height - padding - 2 * scene_padding - text_padding - lower_text_height - x_label->boundingRect().width(); + double diagram_max_height = view_height - padding - 2 * scene_padding - text_padding - lower_text_height - x_label->boundingRect().height(); if (data_xmax > data_xmin) scale_x = diagram_max_width / (data_xmax - data_xmin); @@ -506,10 +504,10 @@ void SliceDiagram::resize_diagram() if (primary_selected.size() > 0) update_highlight(); //set scene rectangle (necessary to prevent auto-scrolling) - double scene_rect_x = -left_text_width - text_padding; - double scene_rect_y = -lower_text_height - text_padding; - double scene_rect_w = diagram_width + padding + text_padding + left_text_width; - double scene_rect_h = diagram_height + padding + text_padding + lower_text_height; + double scene_rect_x = -left_text_width - text_padding - y_label->boundingRect().height(); + double scene_rect_y = -lower_text_height - text_padding - x_label->boundingRect().height(); + double scene_rect_w = diagram_width + padding + text_padding + left_text_width + y_label->boundingRect().height() + data_xmax_text->boundingRect().width(); + double scene_rect_h = diagram_height + padding + text_padding + lower_text_height + x_label->boundingRect().height(); redraw_labels(); setSceneRect(scene_rect_x, scene_rect_y, scene_rect_w, scene_rect_h); @@ -764,11 +762,11 @@ void SliceDiagram::receive_parameter_change() y_label->setFont(config_params->diagramFont); //update fonts for axis labels between max and min - for (unsigned int i = 1; i < x_grades.size() - 1; i++) { - textlistx[i - 1]->setFont(config_params->diagramFont); + for (unsigned int i = 0; i < x_grades.size(); i++) { + textlistx[i]->setFont(config_params->diagramFont); } - for (unsigned int i = 1; i < y_grades.size() - 1; i++) { - textlisty[i - 1]->setFont(config_params->diagramFont); + for (unsigned int i = 0; i < y_grades.size(); i++) { + textlisty[i]->setFont(config_params->diagramFont); } //update diagram @@ -1232,27 +1230,49 @@ double SliceDiagram::get_pd_scale() //redraws the tick marks on the axis diagram void SliceDiagram::redraw_tickmarks() -{ +{ + int tickmarksize; + tickmarksize = 8; //reposition tick marks + qDebug() << "data_xmax_text->pos().x(): " << data_xmax_text->pos().x(); + qDebug() << "data_xmax_text->boundingRect().width(): " << data_xmax_text->boundingRect().width(); for (unsigned int i = 0; i < x_grades.size(); i++) { double left = (x_grades[i] - data_xmin) * scale_x; left = fmin(fmax(0, left), diagram_width + padding); if (textlistx[i]->isVisible() == false) { - linelistx[i]->hide(); + if(linelistx[i]->pos().x() < data_xmax_text->pos().x()){ + linelistx[i]->setPos(left, 0); + linelistx[i]->setLine(0, 0, 0, -tickmarksize/2); + } + else{ + linelistx[i]->hide(); + } } else { - linelistx[i]->setLine((left), 0, (left), (-1 * (padding/2))); + linelistx[i]->setPos(left, 0); + linelistx[i]->setLine(0, 0, 0, -tickmarksize); linelistx[i]->show(); } + qDebug() << textlistx[i]->text()<< " " << linelistx[i]->pos().x(); } - + for (unsigned int i = 0; i < y_grades.size(); i++) { double bottom = (y_grades[i] - data_ymin) * scale_y; bottom = fmin(fmax(0, bottom), diagram_height + padding); if (textlisty[i]->isVisible() == false) { - linelisty[i]->hide(); + if(linelisty[i]->pos().y() < data_ymax_text->pos().y() - data_ymax_text->boundingRect().height() - padding){ + linelisty[i]->setPos(0, bottom); + linelisty[i]->setLine(0, 0, -tickmarksize/2, 0); + //linelisty[i]->setLine(0, 0, -tickmarksize/2, bottom); + + } + else{ + linelisty[i]->hide(); + } } else { - linelisty[i]->setLine(0, bottom, -1 * (padding/2), bottom); + linelisty[i]->setPos(0, bottom); + linelisty[i]->setLine(0, 0, -tickmarksize, 0); + //linelisty[i]->setLine(0, 0, -tickmarksize, bottom); linelisty[i]->show(); } } @@ -1268,7 +1288,7 @@ void SliceDiagram::redraw_labels() data_ymin_text->setPos(-1 * text_padding - data_ymin_text->boundingRect().width(), data_ymin_text->boundingRect().height() / 2); data_ymax_text->setPos(-1 * text_padding - data_ymax_text->boundingRect().width(), diagram_height + data_ymax_text->boundingRect().height() / 2); - x_label->setPos((diagram_width - x_label->boundingRect().width()) / 2, -1 * text_padding - (data_xmin_text->boundingRect().height())); + x_label->setPos((diagram_width - x_label->boundingRect().width()) / 2, -1 * text_padding - 5 - (data_xmin_text->boundingRect().height())); y_label->setPos(-1 * text_padding - (data_ymax_text->boundingRect().width()) - y_label->boundingRect().height()-10, (diagram_height - y_label->boundingRect().width()) / 2); //setting position for x_grades axis label @@ -1282,7 +1302,7 @@ void SliceDiagram::redraw_labels() std::ostringstream stream1; stream1.clear(); stream1.precision(4); - stream1 << (datalistx[i] == 0 ? 0 : datalistx[i] * xrev_sign); + stream1 << (x_grades[i] == 0 ? 0 : x_grades[i] * xrev_sign); textlistx[i]->setText(QString(stream1.str().data())); } @@ -1298,7 +1318,7 @@ void SliceDiagram::redraw_labels() std::ostringstream stream2; stream2.clear(); stream2.precision(4); - stream2 << (datalisty[i] == 0 ? 0 : datalisty[i] * yrev_sign); + stream2 << (y_grades[i] == 0 ? 0 : y_grades[i] * yrev_sign); textlisty[i]->setText(QString(stream2.str().data())); } From 9be7ff9f46c24eef2281e4239736534f8a0dde96 Mon Sep 17 00:00:00 2001 From: cklotte Date: Thu, 18 Jul 2019 11:55:51 -0500 Subject: [PATCH 4/5] Deleted all the rect items corresponding to the axis labels. Also, on the previous commit, there were qDebugs and commented out code that wasn't deleted before commiting. I deleted them in this commit --- interface/slice_diagram.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/interface/slice_diagram.cpp b/interface/slice_diagram.cpp index 0fd9d17f..d8932559 100644 --- a/interface/slice_diagram.cpp +++ b/interface/slice_diagram.cpp @@ -185,20 +185,7 @@ void SliceDiagram::create_diagram(const QString x_text, const QString y_text, do y_label->setTransform(QTransform(0, 1, 1, 0, 0, 0)); y_label->setFont(config_params->diagramFont); - rect1 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - rect2 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - rect3 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - rect4 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - rect5 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - rect6 = addRect(0, 0, 0, 0, Qt::NoPen, QBrush(QColor(255, 255, 255))); - int BigZValue = 1000; //probably not the best way to do this... - rect1->setZValue(BigZValue); - rect2->setZValue(BigZValue); - rect3->setZValue(BigZValue); - rect4->setZValue(BigZValue); - rect5->setZValue(BigZValue); - rect6->setZValue(BigZValue); data_xmin_text->setZValue(BigZValue + 1); data_ymin_text->setZValue(BigZValue + 1); @@ -1235,8 +1222,6 @@ void SliceDiagram::redraw_tickmarks() tickmarksize = 8; //reposition tick marks - qDebug() << "data_xmax_text->pos().x(): " << data_xmax_text->pos().x(); - qDebug() << "data_xmax_text->boundingRect().width(): " << data_xmax_text->boundingRect().width(); for (unsigned int i = 0; i < x_grades.size(); i++) { double left = (x_grades[i] - data_xmin) * scale_x; left = fmin(fmax(0, left), diagram_width + padding); @@ -1253,7 +1238,6 @@ void SliceDiagram::redraw_tickmarks() linelistx[i]->setLine(0, 0, 0, -tickmarksize); linelistx[i]->show(); } - qDebug() << textlistx[i]->text()<< " " << linelistx[i]->pos().x(); } for (unsigned int i = 0; i < y_grades.size(); i++) { @@ -1263,7 +1247,6 @@ void SliceDiagram::redraw_tickmarks() if(linelisty[i]->pos().y() < data_ymax_text->pos().y() - data_ymax_text->boundingRect().height() - padding){ linelisty[i]->setPos(0, bottom); linelisty[i]->setLine(0, 0, -tickmarksize/2, 0); - //linelisty[i]->setLine(0, 0, -tickmarksize/2, bottom); } else{ @@ -1272,7 +1255,6 @@ void SliceDiagram::redraw_tickmarks() } else { linelisty[i]->setPos(0, bottom); linelisty[i]->setLine(0, 0, -tickmarksize, 0); - //linelisty[i]->setLine(0, 0, -tickmarksize, bottom); linelisty[i]->show(); } } @@ -1354,36 +1336,19 @@ void SliceDiagram::redraw_labels() s_xmin << (data_xmin == 0 ? 0 : data_xmin * xrev_sign); data_xmin_text->setText(QString(s_xmin.str().data())); - rect1->setRect(0, 0, data_xmin_text->sceneBoundingRect().width(), data_xmin_text->sceneBoundingRect().height()); - rect1->setPos(data_xmin_text->pos().x(), data_xmin_text->pos().y() - data_xmin_text->boundingRect().height()); - std::ostringstream s_ymin; s_ymin.precision(4); s_ymin << (data_ymin == 0 ? 0 : data_ymin * yrev_sign); data_ymin_text->setText(QString(s_ymin.str().data())); - rect2->setRect(0, 0, data_ymin_text->sceneBoundingRect().width(), data_ymin_text->sceneBoundingRect().height()); - rect2->setPos(data_ymin_text->pos().x(), data_ymin_text->pos().y() - data_ymin_text->boundingRect().height()); - std::ostringstream s_xmax; s_xmax.precision(4); s_xmax << (data_xmax == 0 ? 0 : data_xmax * xrev_sign); data_xmax_text->setText(QString(s_xmax.str().data())); - rect3->setRect(0, 0, data_xmax_text->sceneBoundingRect().width(), data_xmax_text->sceneBoundingRect().height()); - rect3->setPos(data_xmax_text->pos().x(), data_xmax_text->pos().y() - data_xmax_text->boundingRect().height()); - std::ostringstream s_ymax; s_ymax.precision(4); s_ymax << (data_ymax == 0 ? 0 : data_ymax * yrev_sign); data_ymax_text->setText(QString(s_ymax.str().data())); - rect4->setRect(0, 0, data_ymax_text->sceneBoundingRect().width(), data_ymax_text->sceneBoundingRect().height()); - rect4->setPos(data_ymax_text->pos().x(), data_ymax_text->pos().y() - data_ymax_text->boundingRect().height()); - - rect5->setRect(0, 0, x_label->boundingRect().width(), x_label->boundingRect().height()); - rect5->setPos(x_label->pos().x(), x_label->pos().y() - x_label->boundingRect().height()); - - rect6->setRect(0, 0, y_label->boundingRect().height(), y_label->boundingRect().width()); - rect6->setPos(y_label->pos().x(), y_label->pos().y()); } \ No newline at end of file From 13d2d5c2231d9e119ce83b1fd2b85885346cc2df Mon Sep 17 00:00:00 2001 From: cklotte Date: Fri, 19 Jul 2019 11:19:52 -0500 Subject: [PATCH 5/5] Fixed the issue where the last tick marks doesn't show up sometimes --- interface/slice_diagram.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/interface/slice_diagram.cpp b/interface/slice_diagram.cpp index d8932559..36375feb 100644 --- a/interface/slice_diagram.cpp +++ b/interface/slice_diagram.cpp @@ -1226,13 +1226,8 @@ void SliceDiagram::redraw_tickmarks() double left = (x_grades[i] - data_xmin) * scale_x; left = fmin(fmax(0, left), diagram_width + padding); if (textlistx[i]->isVisible() == false) { - if(linelistx[i]->pos().x() < data_xmax_text->pos().x()){ - linelistx[i]->setPos(left, 0); - linelistx[i]->setLine(0, 0, 0, -tickmarksize/2); - } - else{ - linelistx[i]->hide(); - } + linelistx[i]->setPos(left, 0); + linelistx[i]->setLine(0, 0, 0, -tickmarksize/2); } else { linelistx[i]->setPos(left, 0); linelistx[i]->setLine(0, 0, 0, -tickmarksize); @@ -1244,14 +1239,8 @@ void SliceDiagram::redraw_tickmarks() double bottom = (y_grades[i] - data_ymin) * scale_y; bottom = fmin(fmax(0, bottom), diagram_height + padding); if (textlisty[i]->isVisible() == false) { - if(linelisty[i]->pos().y() < data_ymax_text->pos().y() - data_ymax_text->boundingRect().height() - padding){ - linelisty[i]->setPos(0, bottom); - linelisty[i]->setLine(0, 0, -tickmarksize/2, 0); - - } - else{ - linelisty[i]->hide(); - } + linelisty[i]->setPos(0, bottom); + linelisty[i]->setLine(0, 0, -tickmarksize/2, 0); } else { linelisty[i]->setPos(0, bottom); linelisty[i]->setLine(0, 0, -tickmarksize, 0);