Skip to content

Commit

Permalink
Work on #81
Browse files Browse the repository at this point in the history
  • Loading branch information
oxy86 committed Feb 3, 2019
1 parent e2d779d commit 5b95fdd
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 145 deletions.
264 changes: 165 additions & 99 deletions src/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,110 @@ Chart::~Chart(){
}




/**
* @brief Add QAbstractSeries series to chart
* If no series are passed, a new QSplineSeries is created with 1 point at (0,0)
* @param series
*/
void Chart::addSeries(QAbstractSeries *series) {
qDebug() << "Chart::addSeries()" ;
// m_series = series;
if (series) {
m_chart->addSeries(series);
}
else {
m_series = new QSplineSeries();
*m_series << QPointF(0,0);
m_chart->addSeries(m_series);
}

}



/**
* @brief Adds the data point p(qreal,qreal) to the series.
* @param p
*/
void Chart::appendToSeries(const QPointF &p) {
m_series->append(p);
// *m_series<<p;
}


/**
* @brief Removes and deletes all series objects that have been added to the chart.
*/
void Chart::removeAllSeries() {
m_chart->removeAllSeries();
}




/**
* @brief Creates default axes. Must be called AFTER loading a series to the chart
*/
void Chart::createDefaultAxes(){
qDebug() << "Chart::createDefaultAxes()" ;
m_chart->createDefaultAxes();
}



/**
* @brief Removes all previously attached X,Y axes from the QChart
*/
void Chart::removeAllAxes(){
m_chart->removeAxis( m_chart->axisX() );
m_chart->removeAxis( m_chart->axisY() );
}



/**
* @brief Adds the axis axis to the chart and attaches it to the series series
* as a bottom-aligned horizontal axis.
* The chart takes ownership of both the axis and the series.
* Any horizontal axes previously attached to the series are deleted.
* @param axis
* @param series
*/
void Chart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) {
m_chart->setAxisX(axis, series);

}


/**
* @brief Adds the axis axis to the chart and attaches it to the series series
* as a left-aligned horizontal axis.
* The chart takes ownership of both the axis and the series.
* Any vertical axes previously attached to the series are deleted.
* @param axis
* @param series
*/
void Chart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) {
m_chart->setAxisY(axis, series);
}



/**
* @brief Add Axis axis to the QChart. Does not delete previously attached axis
* @param axis
* @param alignment
*/
void Chart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) {
m_chart->addAxis(axis,alignment);
// We could also check if m_series and do:
// barSeries->attachAxis(axisY);
}



/**
* @brief Set the range of the (first) horizontal axis
* @param from
Expand Down Expand Up @@ -141,6 +245,29 @@ void Chart::setAxisYLinePen(const QPen &pen){



/**
* @brief Set the grid line pen of the horizontal axis
* @param font
*/
void Chart::setAxisXGridLinePen(const QPen &pen){
m_chart->axisX()->setGridLinePen(pen);
}



/**
* @brief Set the grid line pen of the vertical axis
* @param font
*/
void Chart::setAxisYGridLinePen(const QPen &pen){
m_chart->axisY()->setGridLinePen(pen);

}





/**
* @brief Toggle the legend of the QChart
* @param toggle
Expand All @@ -156,6 +283,7 @@ void Chart::toggleLegend(const bool &toggle){
}
/**
* @brief Sets the background brush of the QChart
* If no brush defined, it uses a transparent brush.
* @param brush
*/
void Chart::setChartBackgroundBrush(const QBrush & brush) {
Expand All @@ -165,6 +293,7 @@ void Chart::setChartBackgroundBrush(const QBrush & brush) {

/**
* @brief Sets the background pen of the QChart
* If no pen defined, it uses a transparent pen.
* @param brush
*/
void Chart::setChartBackgroundPen(const QBrush & brush) {
Expand All @@ -181,6 +310,28 @@ void Chart::setTheme(QChart::ChartTheme theme) {
}


/**
* @brief Set the theme for when our chart widget is small
* @param chartHeight
*/
void Chart::setThemeSmallWidget(const int minWidth, const int minHeight) {

setTheme();
setBackgroundBrush(QBrush(Qt::transparent));
setChartBackgroundBrush();
setChartBackgroundPen();

toggleLegend(false);
setRenderHint(QPainter::Antialiasing);

setMinimumWidth(minWidth);
setMaximumHeight(minHeight);
setMinimumHeight(minHeight);
setFrameShape(QFrame::NoFrame);
setFrameShape(QFrame::Box);

}


/**
* @brief Set the margins of the QChart
Expand All @@ -203,118 +354,33 @@ void Chart::setTitle(const QString &title, const QFont &font){


/**
* @brief Creates default axes. Must be called AFTER loading a series to the chart
*/
void Chart::createDefaultAxes(){
qDebug() << "Chart::createDefaultAxes()" ;
m_chart->createDefaultAxes();
}

/**
* @brief Removes all previously attached X,Y axes from the QChart
*/
void Chart::removeAllAxes(){
m_chart->removeAxis( m_chart->axisX() );
m_chart->removeAxis( m_chart->axisY() );
}

/**
* @brief Adds the axis axis to the chart and attaches it to the series series
* as a bottom-aligned horizontal axis.
* The chart takes ownership of both the axis and the series.
* Any horizontal axes previously attached to the series are deleted.
* @param axis
* @param series
*/
void Chart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) {
m_chart->setAxisX(axis, series);

}


/**
* @brief Adds the axis axis to the chart and attaches it to the series series
* as a left-aligned horizontal axis.
* The chart takes ownership of both the axis and the series.
* Any vertical axes previously attached to the series are deleted.
* @param axis
* @param series
* @brief Applies a simple theme to axes (default label fonts, line and grid line pen).
* WARNING: Axes must be already attached to m_chart
*/
void Chart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) {
m_chart->setAxisY(axis, series);
}

/**
* @brief Add Axis axis to the QChart. Does not delete previously attached axis
* @param axis
* @param alignment
*/
void Chart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) {
m_chart->addAxis(axis,alignment);
// We could also check if m_series and do:
// barSeries->attachAxis(axisY);
}


/**
* @brief Add QAbstractSeries series to chart
* If no series are passed, a new QSplineSeries is created with 1 point at (0,0)
* @param series
*/
void Chart::addSeries(QAbstractSeries *series) {
qDebug() << "Chart::addSeries()" ;
// m_series = series;
if (series) {
m_chart->addSeries(series);
}
else {
m_series = new QSplineSeries();
*m_series << QPointF(0,0);
m_chart->addSeries(m_series);
}

}



/**
* @brief Adds the data point p(qreal,qreal) to the series.
* @param p
*/
void Chart::appendToSeries(const QPointF &p) {
m_series->append(p);
// *m_series<<p;
}
void Chart::setAxesThemeDefault() {
setAxisXLabelFont();
setAxisXLinePen();
setAxisXGridLinePen();
setAxisYLabelFont();
setAxisYLinePen();
setAxisYGridLinePen();

setMargins(QMargins());

/**
* @brief Removes and deletes all series objects that have been added to the chart.
*/
void Chart::removeAllSeries() {
m_chart->removeAllSeries();
}




void Chart::resetToTrivial() {
removeAllSeries();
addSeries();
createDefaultAxes();
m_chart->axisX()->setLabelsAngle(-80);
setTitle("Chart", QFont("Times",8));

setMargins(QMargins());

setAxisXRange(0,1);
setAxisYRange(0,1);
setAxisXLabelFont(QFont("Times", 7));
setAxisYLabelFont(QFont("Times", 7));

QPen axisPen;
axisPen.setBrush( QBrush(QColor(0,0,0,0)) );
axisPen.setWidthF(0.5);
axisPen.setStyle(Qt::SolidLine);
setAxisYLinePen(axisPen);
setMargins(QMargins());

setAxesThemeDefault();

}

16 changes: 12 additions & 4 deletions src/chart.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,21 @@ class Chart : public QChartView
void setAxisXRange(const int &from, const int &to);
void setAxisYRange(const int &from, const int &to);

void setAxisXLabelFont(const QFont &font=QFont());
void setAxisYLabelFont(const QFont &font=QFont());
void setAxesThemeDefault ();

void setAxisXLabelFont(const QFont &font=QFont("Helvetica", 5 ));
void setAxisYLabelFont(const QFont &font=QFont("Helvetica", 6 ));

void setAxisXLinePen(const QPen &pen = QPen(QColor("#d0d0d0"), 1,Qt::SolidLine) );
void setAxisYLinePen(const QPen &pen = QPen(QColor("#d0d0d0"), 1,Qt::SolidLine) );

void setAxisXGridLinePen(const QPen &pen = QPen(QColor("#e0e0e0"), 1,Qt::DotLine) );
void setAxisYGridLinePen(const QPen &pen = QPen(QColor("#e0e0e0"), 1,Qt::DotLine) );

void setAxisXLinePen(const QPen &pen);
void setAxisYLinePen(const QPen &pen);

void setTheme(QChart::ChartTheme theme=QChart::ChartThemeQt);
void setThemeSmallWidget(const int minWidth, const int minHeight);

void setChartBackgroundBrush(const QBrush & brush = QBrush(Qt::transparent));
void setChartBackgroundPen(const QBrush & brush = QBrush(Qt::transparent));
void setMargins(const QMargins &margins = QMargins());
Expand Down
10 changes: 6 additions & 4 deletions src/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6993,24 +6993,26 @@ void Graph::prominenceDistribution(const int &index, QBarSeries *series, QBarSet
int size = seriesPQ.size();
QString min = QString::null;
QString max = QString::null;
QString value = QString::null;

while (!seriesPQ.empty()) {
qDebug() << seriesPQ.top().value << " : " << seriesPQ.top().frequency << endl;
if ( series->type() == QAbstractSeries::SeriesTypeBar) {
set->append( seriesPQ.top().frequency );
axisX->append(QString::number( seriesPQ.top().value ));
value = QString::number( seriesPQ.top().value, 'f', 2);
axisX->append( value );
if (size == seriesPQ.size() ) {
min = QString::number( seriesPQ.top().value );
min = value;
}
if ( seriesPQ.size() == 1 ) {
max = QString::number( seriesPQ.top().value );
max = value;
}
}
seriesPQ.pop();
}
axisX->setMin(min);
axisX->setMax(max);

qDebug() << "axisX min: " << axisX->min() << " max: " << axisX->max();
series->append( set );
}

Expand Down
Loading

0 comments on commit 5b95fdd

Please sign in to comment.