mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Summary Plot: Add support for multiple plot axis.
This commit is contained in:
committed by
Magne Sjaastad
parent
a3ad9d2c1e
commit
e92e2e8764
@@ -71,31 +71,10 @@ RiuQtChartsPlotWidget::RiuQtChartsPlotWidget( RimPlot* plotDefinition, QWidget*
|
||||
|
||||
layout->addWidget( m_viewer );
|
||||
|
||||
QValueAxis* axisBottom = new QValueAxis();
|
||||
chart->addAxis( axisBottom, Qt::AlignBottom );
|
||||
m_axes[RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM] = axisBottom;
|
||||
|
||||
QValueAxis* axisTop = new QValueAxis();
|
||||
chart->addAxis( axisTop, Qt::AlignTop );
|
||||
m_axes[RiaDefines::PlotAxis::PLOT_AXIS_TOP] = axisTop;
|
||||
|
||||
QValueAxis* axisLeft = new QValueAxis();
|
||||
chart->addAxis( axisLeft, Qt::AlignLeft );
|
||||
m_axes[RiaDefines::PlotAxis::PLOT_AXIS_LEFT] = axisLeft;
|
||||
|
||||
QValueAxis* axisRight = new QValueAxis();
|
||||
chart->addAxis( axisRight, Qt::AlignRight );
|
||||
m_axes[RiaDefines::PlotAxis::PLOT_AXIS_RIGHT] = axisRight;
|
||||
|
||||
enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
|
||||
enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_RIGHT, false );
|
||||
enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
|
||||
enableAxis( RiaDefines::PlotAxis::PLOT_AXIS_TOP, false );
|
||||
|
||||
setAxisAutoScale( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
|
||||
setAxisAutoScale( RiaDefines::PlotAxis::PLOT_AXIS_RIGHT, false );
|
||||
setAxisAutoScale( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
|
||||
setAxisAutoScale( RiaDefines::PlotAxis::PLOT_AXIS_TOP, false );
|
||||
addAxis( RiuPlotAxis::defaultBottom(), true, true );
|
||||
addAxis( RiuPlotAxis::defaultLeft(), true, true );
|
||||
addAxis( RiuPlotAxis::defaultRight(), true, true );
|
||||
addAxis( RiuPlotAxis::defaultTop(), false, false );
|
||||
|
||||
m_viewer->setRubberBand( QChartView::RectangleRubberBand );
|
||||
|
||||
@@ -124,7 +103,7 @@ void RiuQtChartsPlotWidget::axisRangeChanged()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuQtChartsPlotWidget::axisTitleFontSize( RiaDefines::PlotAxis axis ) const
|
||||
int RiuQtChartsPlotWidget::axisTitleFontSize( RiuPlotAxis axis ) const
|
||||
{
|
||||
if ( axisEnabled( axis ) )
|
||||
{
|
||||
@@ -137,7 +116,7 @@ int RiuQtChartsPlotWidget::axisTitleFontSize( RiaDefines::PlotAxis axis ) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuQtChartsPlotWidget::axisValueFontSize( RiaDefines::PlotAxis axis ) const
|
||||
int RiuQtChartsPlotWidget::axisValueFontSize( RiuPlotAxis axis ) const
|
||||
{
|
||||
if ( axisEnabled( axis ) )
|
||||
{
|
||||
@@ -150,11 +129,11 @@ int RiuQtChartsPlotWidget::axisValueFontSize( RiaDefines::PlotAxis axis ) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisFontsAndAlignment( RiaDefines::PlotAxis axis,
|
||||
int titleFontSize,
|
||||
int valueFontSize,
|
||||
bool titleBold,
|
||||
int alignment )
|
||||
void RiuQtChartsPlotWidget::setAxisFontsAndAlignment( RiuPlotAxis axis,
|
||||
int titleFontSize,
|
||||
int valueFontSize,
|
||||
bool titleBold,
|
||||
int alignment )
|
||||
{
|
||||
int titleFontPixelSize = caf::FontTools::pointSizeToPixelSize( titleFontSize );
|
||||
int valueFontPixelSize = caf::FontTools::pointSizeToPixelSize( valueFontSize );
|
||||
@@ -188,7 +167,7 @@ void RiuQtChartsPlotWidget::setAxesFontsAndAlignment( int titleFontSize, int val
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisTitleText( RiaDefines::PlotAxis axis, const QString& title )
|
||||
void RiuQtChartsPlotWidget::setAxisTitleText( RiuPlotAxis axis, const QString& title )
|
||||
{
|
||||
m_axisTitles[axis] = title;
|
||||
applyAxisTitleToPlot( axis );
|
||||
@@ -197,7 +176,7 @@ void RiuQtChartsPlotWidget::setAxisTitleText( RiaDefines::PlotAxis axis, const Q
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisTitleEnabled( RiaDefines::PlotAxis axis, bool enable )
|
||||
void RiuQtChartsPlotWidget::setAxisTitleEnabled( RiuPlotAxis axis, bool enable )
|
||||
{
|
||||
m_axisTitlesEnabled[axis] = enable;
|
||||
applyAxisTitleToPlot( axis );
|
||||
@@ -206,7 +185,7 @@ void RiuQtChartsPlotWidget::setAxisTitleEnabled( RiaDefines::PlotAxis axis, bool
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisFormat( RiaDefines::PlotAxis axis, const QString& format )
|
||||
void RiuQtChartsPlotWidget::setAxisFormat( RiuPlotAxis axis, const QString& format )
|
||||
{
|
||||
auto ax = plotAxis( axis );
|
||||
|
||||
@@ -330,7 +309,7 @@ void RiuQtChartsPlotWidget::clearLegend()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::pair<double, double> RiuQtChartsPlotWidget::axisRange( RiaDefines::PlotAxis axis ) const
|
||||
std::pair<double, double> RiuQtChartsPlotWidget::axisRange( RiuPlotAxis axis ) const
|
||||
{
|
||||
auto ax = plotAxis( axis );
|
||||
|
||||
@@ -349,7 +328,7 @@ std::pair<double, double> RiuQtChartsPlotWidget::axisRange( RiaDefines::PlotAxis
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisRange( RiaDefines::PlotAxis axis, double min, double max )
|
||||
void RiuQtChartsPlotWidget::setAxisRange( RiuPlotAxis axis, double min, double max )
|
||||
{
|
||||
// Note: Especially the Y-axis may be inverted
|
||||
if ( plotAxis( axis )->isReverse() )
|
||||
@@ -365,7 +344,7 @@ void RiuQtChartsPlotWidget::setAxisRange( RiaDefines::PlotAxis axis, double min,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisInverted( RiaDefines::PlotAxis axis, bool isInverted )
|
||||
void RiuQtChartsPlotWidget::setAxisInverted( RiuPlotAxis axis, bool isInverted )
|
||||
{
|
||||
auto ax = plotAxis( axis );
|
||||
ax->setReverse( isInverted );
|
||||
@@ -374,7 +353,7 @@ void RiuQtChartsPlotWidget::setAxisInverted( RiaDefines::PlotAxis axis, bool isI
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisLabelsAndTicksEnabled( RiaDefines::PlotAxis axis, bool enableLabels, bool enableTicks )
|
||||
void RiuQtChartsPlotWidget::setAxisLabelsAndTicksEnabled( RiuPlotAxis axis, bool enableLabels, bool enableTicks )
|
||||
{
|
||||
plotAxis( axis )->setLabelsVisible( enableLabels );
|
||||
plotAxis( axis )->setGridLineVisible( enableTicks );
|
||||
@@ -383,7 +362,7 @@ void RiuQtChartsPlotWidget::setAxisLabelsAndTicksEnabled( RiaDefines::PlotAxis a
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::enableGridLines( RiaDefines::PlotAxis axis, bool majorGridLines, bool minorGridLines )
|
||||
void RiuQtChartsPlotWidget::enableGridLines( RiuPlotAxis axis, bool majorGridLines, bool minorGridLines )
|
||||
{
|
||||
plotAxis( axis )->setGridLineVisible( majorGridLines );
|
||||
plotAxis( axis )->setMinorGridLineVisible( minorGridLines );
|
||||
@@ -398,33 +377,33 @@ void RiuQtChartsPlotWidget::enableGridLines( RiaDefines::PlotAxis axis, bool maj
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setMajorAndMinorTickIntervals( RiaDefines::PlotAxis axis,
|
||||
double majorTickInterval,
|
||||
double minorTickInterval,
|
||||
double minValue,
|
||||
double maxValue )
|
||||
void RiuQtChartsPlotWidget::setMajorAndMinorTickIntervals( RiuPlotAxis axis,
|
||||
double majorTickInterval,
|
||||
double minorTickInterval,
|
||||
double minValue,
|
||||
double maxValue )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setMajorAndMinorTickIntervalsAndRange( RiaDefines::PlotAxis axis,
|
||||
double majorTickInterval,
|
||||
double minorTickInterval,
|
||||
double minTickValue,
|
||||
double maxTickValue,
|
||||
double rangeMin,
|
||||
double rangeMax )
|
||||
void RiuQtChartsPlotWidget::setMajorAndMinorTickIntervalsAndRange( RiuPlotAxis axis,
|
||||
double majorTickInterval,
|
||||
double minorTickInterval,
|
||||
double minTickValue,
|
||||
double maxTickValue,
|
||||
double rangeMin,
|
||||
double rangeMax )
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAutoTickIntervalCounts( RiaDefines::PlotAxis axis,
|
||||
int maxMajorTickIntervalCount,
|
||||
int maxMinorTickIntervalCount )
|
||||
void RiuQtChartsPlotWidget::setAutoTickIntervalCounts( RiuPlotAxis axis,
|
||||
int maxMajorTickIntervalCount,
|
||||
int maxMinorTickIntervalCount )
|
||||
{
|
||||
setAxisMaxMajor( axis, maxMajorTickIntervalCount );
|
||||
setAxisMaxMinor( axis, maxMinorTickIntervalCount );
|
||||
@@ -433,7 +412,7 @@ void RiuQtChartsPlotWidget::setAutoTickIntervalCounts( RiaDefines::PlotAxis axis
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiuQtChartsPlotWidget::majorTickInterval( RiaDefines::PlotAxis axis ) const
|
||||
double RiuQtChartsPlotWidget::majorTickInterval( RiuPlotAxis axis ) const
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 12, 0 )
|
||||
// QValueAxis::tickInterval was introduced in 5.12
|
||||
@@ -447,7 +426,7 @@ double RiuQtChartsPlotWidget::majorTickInterval( RiaDefines::PlotAxis axis ) con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RiuQtChartsPlotWidget::minorTickInterval( RiaDefines::PlotAxis axis ) const
|
||||
double RiuQtChartsPlotWidget::minorTickInterval( RiuPlotAxis axis ) const
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
@@ -455,7 +434,7 @@ double RiuQtChartsPlotWidget::minorTickInterval( RiaDefines::PlotAxis axis ) con
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiuQtChartsPlotWidget::axisExtent( RiaDefines::PlotAxis axis ) const
|
||||
int RiuQtChartsPlotWidget::axisExtent( RiuPlotAxis axis ) const
|
||||
{
|
||||
CAF_ASSERT( false && "Not implemented" );
|
||||
return 100;
|
||||
@@ -535,7 +514,7 @@ void RiuQtChartsPlotWidget::applyPlotTitleToPlot()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::applyAxisTitleToPlot( RiaDefines::PlotAxis axis )
|
||||
void RiuQtChartsPlotWidget::applyAxisTitleToPlot( RiuPlotAxis axis )
|
||||
{
|
||||
QString titleToApply = m_axisTitlesEnabled[axis] ? m_axisTitles[axis] : QString( "" );
|
||||
plotAxis( axis )->setTitleText( titleToApply );
|
||||
@@ -636,7 +615,7 @@ void RiuQtChartsPlotWidget::replot()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::enableAxis( RiaDefines::PlotAxis axis, bool isEnabled )
|
||||
void RiuQtChartsPlotWidget::enableAxis( RiuPlotAxis axis, bool isEnabled )
|
||||
{
|
||||
m_axesEnabled[axis] = isEnabled;
|
||||
plotAxis( axis )->setVisible( isEnabled );
|
||||
@@ -645,7 +624,7 @@ void RiuQtChartsPlotWidget::enableAxis( RiaDefines::PlotAxis axis, bool isEnable
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQtChartsPlotWidget::axisEnabled( RiaDefines::PlotAxis axis ) const
|
||||
bool RiuQtChartsPlotWidget::axisEnabled( RiuPlotAxis axis ) const
|
||||
{
|
||||
auto it = m_axesEnabled.find( axis );
|
||||
if ( it != m_axesEnabled.end() )
|
||||
@@ -657,7 +636,7 @@ bool RiuQtChartsPlotWidget::axisEnabled( RiaDefines::PlotAxis axis ) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisMaxMinor( RiaDefines::PlotAxis axis, int maxMinor )
|
||||
void RiuQtChartsPlotWidget::setAxisMaxMinor( RiuPlotAxis axis, int maxMinor )
|
||||
{
|
||||
QAbstractAxis* ax = plotAxis( axis );
|
||||
QValueAxis* valueAxis = dynamic_cast<QValueAxis*>( ax );
|
||||
@@ -675,7 +654,7 @@ void RiuQtChartsPlotWidget::setAxisMaxMinor( RiaDefines::PlotAxis axis, int maxM
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisMaxMajor( RiaDefines::PlotAxis axis, int maxMajor )
|
||||
void RiuQtChartsPlotWidget::setAxisMaxMajor( RiuPlotAxis axis, int maxMajor )
|
||||
{
|
||||
QAbstractAxis* ax = plotAxis( axis );
|
||||
QValueAxis* valueAxis = dynamic_cast<QValueAxis*>( ax );
|
||||
@@ -693,7 +672,7 @@ void RiuQtChartsPlotWidget::setAxisMaxMajor( RiaDefines::PlotAxis axis, int maxM
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisAutoScale( RiaDefines::PlotAxis axis, bool autoScale )
|
||||
void RiuQtChartsPlotWidget::setAxisAutoScale( RiuPlotAxis axis, bool autoScale )
|
||||
{
|
||||
m_axesAutoScale[axis] = autoScale;
|
||||
|
||||
@@ -706,7 +685,7 @@ void RiuQtChartsPlotWidget::setAxisAutoScale( RiaDefines::PlotAxis axis, bool au
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisScale( RiaDefines::PlotAxis axis, double min, double max )
|
||||
void RiuQtChartsPlotWidget::setAxisScale( RiuPlotAxis axis, double min, double max )
|
||||
{
|
||||
plotAxis( axis )->setRange( min, max );
|
||||
}
|
||||
@@ -714,7 +693,7 @@ void RiuQtChartsPlotWidget::setAxisScale( RiaDefines::PlotAxis axis, double min,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQtChartsPlotWidget::AxisScaleType RiuQtChartsPlotWidget::axisScaleType( RiaDefines::PlotAxis axis ) const
|
||||
RiuQtChartsPlotWidget::AxisScaleType RiuQtChartsPlotWidget::axisScaleType( RiuPlotAxis axis ) const
|
||||
{
|
||||
if ( plotAxis( axis )->type() == QAbstractAxis::AxisTypeLogValue ) return AxisScaleType::LOGARITHMIC;
|
||||
if ( plotAxis( axis )->type() == QAbstractAxis::AxisTypeDateTime ) return AxisScaleType::DATE;
|
||||
@@ -724,7 +703,7 @@ RiuQtChartsPlotWidget::AxisScaleType RiuQtChartsPlotWidget::axisScaleType( RiaDe
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxisScaleType( RiaDefines::PlotAxis axis, RiuQtChartsPlotWidget::AxisScaleType axisScaleType )
|
||||
void RiuQtChartsPlotWidget::setAxisScaleType( RiuPlotAxis axis, RiuQtChartsPlotWidget::AxisScaleType axisScaleType )
|
||||
{
|
||||
QAbstractAxis* removeaxis = plotAxis( axis );
|
||||
QAbstractAxis* insertaxis = nullptr;
|
||||
@@ -742,16 +721,9 @@ void RiuQtChartsPlotWidget::setAxisScaleType( RiaDefines::PlotAxis axis, RiuQtCh
|
||||
insertaxis = new QValueAxis;
|
||||
}
|
||||
|
||||
QChart* chart = qtChart();
|
||||
auto mapToAlignment = []( auto axis ) {
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM ) return Qt::AlignBottom;
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_TOP ) return Qt::AlignTop;
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ) return Qt::AlignLeft;
|
||||
return Qt::AlignRight;
|
||||
};
|
||||
|
||||
QChart* chart = qtChart();
|
||||
if ( chart->axes().contains( removeaxis ) ) chart->removeAxis( removeaxis );
|
||||
chart->addAxis( insertaxis, mapToAlignment( axis ) );
|
||||
chart->addAxis( insertaxis, mapPlotAxisToQtAlignment( axis.axis() ) );
|
||||
|
||||
m_axes[axis] = insertaxis;
|
||||
for ( auto serie : chart->series() )
|
||||
@@ -791,8 +763,8 @@ QtCharts::QChart* RiuQtChartsPlotWidget::qtChart()
|
||||
void RiuQtChartsPlotWidget::attach( RiuPlotCurve* plotCurve,
|
||||
QtCharts::QAbstractSeries* lineSeries,
|
||||
QtCharts::QAbstractSeries* scatterSeries,
|
||||
RiaDefines::PlotAxis xAxis,
|
||||
RiaDefines::PlotAxis yAxis )
|
||||
RiuPlotAxis xAxis,
|
||||
RiuPlotAxis yAxis )
|
||||
{
|
||||
auto addToChart = [this]( std::map<const RiuPlotCurve*, QtCharts::QAbstractSeries*>& curveSeriesMap,
|
||||
auto plotCurve,
|
||||
@@ -860,7 +832,7 @@ void RiuQtChartsPlotWidget::detachItems( RiuPlotWidget::PlotItemType plotItemTyp
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setXAxis( RiaDefines::PlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
void RiuQtChartsPlotWidget::setXAxis( RiuPlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
{
|
||||
setAxis( axis, series );
|
||||
}
|
||||
@@ -868,7 +840,7 @@ void RiuQtChartsPlotWidget::setXAxis( RiaDefines::PlotAxis axis, QtCharts::QAbst
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setYAxis( RiaDefines::PlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
void RiuQtChartsPlotWidget::setYAxis( RiuPlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
{
|
||||
setAxis( axis, series );
|
||||
}
|
||||
@@ -876,8 +848,14 @@ void RiuQtChartsPlotWidget::setYAxis( RiaDefines::PlotAxis axis, QtCharts::QAbst
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::setAxis( RiaDefines::PlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
void RiuQtChartsPlotWidget::setAxis( RiuPlotAxis axis, QtCharts::QAbstractSeries* series )
|
||||
{
|
||||
// Make sure the axis we are about to set exists.
|
||||
if ( m_axes.find( axis ) == m_axes.end() )
|
||||
{
|
||||
addAxis( axis, true, true );
|
||||
}
|
||||
|
||||
if ( qtChart()->series().contains( series ) && !series->attachedAxes().contains( plotAxis( axis ) ) )
|
||||
{
|
||||
auto newAxis = plotAxis( axis );
|
||||
@@ -885,7 +863,7 @@ void RiuQtChartsPlotWidget::setAxis( RiaDefines::PlotAxis axis, QtCharts::QAbstr
|
||||
// Detach any other axis for the same orientation
|
||||
for ( auto ax : series->attachedAxes() )
|
||||
{
|
||||
if ( ax->orientation() == orientation( axis ) )
|
||||
if ( ax->orientation() == orientation( axis.axis() ) )
|
||||
{
|
||||
series->detachAxis( ax );
|
||||
}
|
||||
@@ -907,12 +885,50 @@ void RiuQtChartsPlotWidget::setAxis( RiaDefines::PlotAxis axis, QtCharts::QAbstr
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::rescaleAxis( RiaDefines::PlotAxis axis )
|
||||
void RiuQtChartsPlotWidget::addAxis( RiuPlotAxis plotAxis, bool isEnabled, bool isAutoScale )
|
||||
{
|
||||
QValueAxis* axis = new QValueAxis();
|
||||
qtChart()->addAxis( axis, mapPlotAxisToQtAlignment( plotAxis.axis() ) );
|
||||
m_axes[plotAxis] = axis;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuPlotAxis RiuQtChartsPlotWidget::createNextPlotAxis( RiaDefines::PlotAxis axis )
|
||||
{
|
||||
int minIdx = -1;
|
||||
for ( auto a : m_axes )
|
||||
{
|
||||
if ( a.first.axis() == axis )
|
||||
{
|
||||
minIdx = std::max( a.first.index(), minIdx );
|
||||
}
|
||||
}
|
||||
|
||||
RiuPlotAxis plotAxis( axis, minIdx + 1 );
|
||||
|
||||
addAxis( plotAxis, true, true );
|
||||
return plotAxis;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQtChartsPlotWidget::isMultiAxisSupported() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQtChartsPlotWidget::rescaleAxis( RiuPlotAxis axis )
|
||||
{
|
||||
if ( !m_axesAutoScale[axis] ) return;
|
||||
|
||||
QAbstractAxis* pAxis = plotAxis( axis );
|
||||
Qt::Orientation orr = orientation( axis );
|
||||
Qt::Orientation orr = orientation( axis.axis() );
|
||||
|
||||
double min = std::numeric_limits<double>::max();
|
||||
double max = -std::numeric_limits<double>::max();
|
||||
@@ -966,7 +982,7 @@ void RiuQtChartsPlotWidget::rescaleAxis( RiaDefines::PlotAxis axis )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QAbstractAxis* RiuQtChartsPlotWidget::plotAxis( RiaDefines::PlotAxis axis ) const
|
||||
QAbstractAxis* RiuQtChartsPlotWidget::plotAxis( RiuPlotAxis axis ) const
|
||||
{
|
||||
const auto ax = m_axes.find( axis );
|
||||
if ( ax != m_axes.end() )
|
||||
@@ -1053,3 +1069,14 @@ std::pair<RiuPlotCurve*, int> RiuQtChartsPlotWidget::findClosestCurve( const QPo
|
||||
{
|
||||
return std::make_pair( nullptr, -1 );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Qt::Alignment RiuQtChartsPlotWidget::mapPlotAxisToQtAlignment( RiaDefines::PlotAxis axis )
|
||||
{
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM ) return Qt::AlignBottom;
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_TOP ) return Qt::AlignTop;
|
||||
if ( axis == RiaDefines::PlotAxis::PLOT_AXIS_LEFT ) return Qt::AlignLeft;
|
||||
return Qt::AlignRight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user