##// END OF EJS Templates
Added BoxPlot to examples.pro...
Added BoxPlot to examples.pro Change-Id: Idbc01ef7ff03fc654ff9d2474f0bad91ed6abe71 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2432:53927f716a3d
r2471:983c36673743
Show More
horizontalstackedbarchartitem.cpp
108 lines | 4.5 KiB | text/x-c | CppLexer
/ src / barchart / horizontal / stacked / horizontalstackedbarchartitem.cpp
sauimone
horizontal stacked barchart
r1685 /****************************************************************************
**
Miikka Heikkinen
Fixed the copyright year 2012 -> 2013
r2432 ** Copyright (C) 2013 Digia Plc
sauimone
horizontal stacked barchart
r1685 ** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
#include "horizontalstackedbarchartitem_p.h"
#include "qabstractbarseries_p.h"
#include "qbarset_p.h"
#include "bar_p.h"
QTCOMMERCIALCHART_BEGIN_NAMESPACE
Michal Klocek
Refactors internals...
r2273 HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, QGraphicsItem* item)
: AbstractBarChartItem(series, item)
sauimone
horizontal stacked barchart
r1685 {
}
Marek Rosa
Bar animations refactored
r2316 void HorizontalStackedBarChartItem::initializeLayout()
{
qreal categoryCount = m_series->d_func()->categoryCount();
qreal setCount = m_series->count();
qreal barWidth = m_series->d_func()->barWidth();
m_layout.clear();
for(int category = 0; category < categoryCount; category++) {
for (int set = 0; set < setCount; set++) {
QRectF rect;
QPointF topLeft;
QPointF bottomRight;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2), m_validData);
bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2), m_validData);
Marek Rosa
Bar animations refactored
r2316 } else {
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2), m_validData);
bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2), m_validData);
Marek Rosa
Bar animations refactored
r2316 }
Marek Rosa
Negative values with log axis handled
r2356 if (!m_validData)
return;
Marek Rosa
Bar animations refactored
r2316 rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
}
}
}
sauimone
horizontal stacked barchart
r1685 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
{
QVector<QRectF> layout;
// Use temporary qreals for accuracy
qreal categoryCount = m_series->d_func()->categoryCount();
qreal setCount = m_series->count();
Marek Rosa
New bar calculate layout
r2303 qreal barWidth = m_series->d_func()->barWidth();
for(int category = 0; category < categoryCount; category++) {
qreal positiveSum = 0;
qreal negativeSum = 0;
sauimone
horizontal stacked barchart
r1685 for (int set = 0; set < setCount; set++) {
Marek Rosa
New bar calculate layout
r2303 qreal value = m_series->barSets().at(set)->at(category);
QRectF rect;
QPointF topLeft;
QPointF bottomRight;
if (value < 0) {
Marek Rosa
Negative values with log axis handled
r2356 bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2), m_validData);
Marek Rosa
BarChartItems code cleanup
r2305 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2), m_validData);
Marek Rosa
New bar calculate layout
r2303 else
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2), m_validData);
Marek Rosa
New bar calculate layout
r2303 negativeSum += value;
sauimone
Better support for negative values in stacked barcharts. Negative values are stacked from zero to negative direction. Positive values are stacked from zero to positive direction.
r1897 } else {
Marek Rosa
Negative values with log axis handled
r2356 bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2), m_validData);
Marek Rosa
BarChartItems code cleanup
r2305 if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2), m_validData);
Marek Rosa
New bar calculate layout
r2303 else
Marek Rosa
Negative values with log axis handled
r2356 topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2), m_validData);
Marek Rosa
New bar calculate layout
r2303 positiveSum += value;
sauimone
Better support for negative values in stacked barcharts. Negative values are stacked from zero to negative direction. Positive values are stacked from zero to positive direction.
r1897 }
Marek Rosa
Negative values with log axis handled
r2356 if (!m_validData)
return QVector<QRectF>();
Marek Rosa
New bar calculate layout
r2303 rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
Marek Rosa
Bar animations refactored
r2316 layout.append(rect.normalized());
sauimone
horizontal stacked barchart
r1685 }
}
return layout;
}
#include "moc_horizontalstackedbarchartitem_p.cpp"
QTCOMMERCIALCHART_END_NAMESPACE