/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
if (xDiagram->getDataTable().is())
m_bTableShiftPosition = true;
//prepare for autoscaling and shape creation // - create plotter for charttypes (for each first scale group at each plotter, as they are independent) // - add series to plotter (thus each charttype can provide minimum and maximum values for autoscaling) // - add plotter to coordinate systems
//iterate through all coordinate systems
uno::Reference<XColorScheme> xColorScheme; if (!rChartModel.usesColorPalette())
xColorScheme = xDiagram->getDefaultColorScheme(); else
xColorScheme = new ChartColorScheme(*rChartModel.getCurrentColorPalette()); auto aCooSysList = xDiagram->getBaseCoordinateSystems();
sal_Int32 nGlobalSeriesIndex = 0; //for automatic symbols for (std::size_t nCS = 0; nCS < aCooSysList.size(); ++nCS)
{ const rtl::Reference<BaseCoordinateSystem>& xCooSys(aCooSysList[nCS]);
VCoordinateSystem* pVCooSys
= SeriesPlotterContainer::addCooSysToList(m_rVCooSysList, xCooSys, rChartModel); // Let's check whether the secondary Y axis is visible try
{ if (xCooSys->getMaximumAxisIndexByDimension(1) > 0)
{
rtl::Reference<Axis> xAxisProp = xCooSys->getAxisByDimension2(1, 1);
xAxisProp->getPropertyValue(u"Show"_ustr) >>= bSecondaryYaxisVisible;
}
} catch (const lang::IndexOutOfBoundsException&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
} //iterate through all chart types in the current coordinate system
std::vector<rtl::Reference<ChartType>> aChartTypeList(xCooSys->getChartTypes2()); for (std::size_t nT = 0; nT < aChartTypeList.size(); ++nT)
{ const rtl::Reference<ChartType>& xChartType(aChartTypeList[nT]); if (nDimensionCount == 3
&& xChartType->getChartType().equalsIgnoreAsciiCase(
CHART2_SERVICE_NAME_CHARTTYPE_PIE))
{ try
{
sal_Int32 n3DRelativeHeightOldValue(100);
uno::Any aAny = xChartType->getFastPropertyValue(
PROP_PIECHARTTYPE_3DRELATIVEHEIGHT); // "3DRelativeHeight"
aAny >>= n3DRelativeHeightOldValue; if (n3DRelativeHeightOldValue != n3DRelativeHeight)
xChartType->setFastPropertyValue(
PROP_PIECHARTTYPE_3DRELATIVEHEIGHT, // "3DRelativeHeight"
uno::Any(n3DRelativeHeight));
} catch (const uno::Exception&)
{
}
}
if (ePieChartSubType != PieChartSubType_NONE)
{
xChartType->setFastPropertyValue(PROP_PIECHARTTYPE_SUBTYPE,
uno::Any(ePieChartSubType)); // Reset the diagram-level property so it's not persistent.
xDiagram->setPropertyValue(u"SubPieType"_ustr, uno::Any(PieChartSubType_NONE));
//ignore secondary axis for charttypes that do not support them if (pSeries->getAttachedAxisIndex() != MAIN_AXIS_INDEX
&& (!(xChartType.is() ? xChartType->isSupportingSecondaryAxis(nDimensionCount)
: true)
|| !bSecondaryYaxisVisible))
{
pSeries->setAttachedAxisIndex(MAIN_AXIS_INDEX);
}
StackingDirection eDirection = pSeries->getStackingDirection(); switch (eDirection)
{ case StackingDirection_NO_STACKING:
xSlot++;
ySlot = -1; if (zSlot < 0)
zSlot = 0; break; case StackingDirection_Y_STACKING:
ySlot++; if (xSlot < 0)
xSlot = 0; if (zSlot < 0)
zSlot = 0; break; case StackingDirection_Z_STACKING:
zSlot++;
xSlot = -1;
ySlot = -1; break; default: // UNO enums have one additional auto-generated case break;
}
pPlotter->addSeries(std::move(pSeries), zSlot, xSlot, ySlot);
}
}
}
auto order
= [](const std::unique_ptr<VSeriesPlotter>& a, const std::unique_ptr<VSeriesPlotter>& b) { return a->getRenderOrder() < b->getRenderOrder();
};
// Loop through coordinate systems in the diagram (though for now // there should only be one coordinate system per diagram). for (auto& pVCooSys : m_rVCooSysList)
{
rtl::Reference<BaseCoordinateSystem> xCooSys = pVCooSys->getModel();
sal_Int32 nDimCount = xCooSys->getDimension(); auto xChartType = AxisHelper::getChartTypeByIndex(xCooSys, 0); bool bComplexCategoryAllowed
= xChartType.is() ? xChartType->isSupportingComplexCategory() : true;
void SeriesPlotterContainer::setScalesFromCooSysToPlotter()
{ //set scales to plotter to enable them to provide the preferred scene AspectRatio for (const std::unique_ptr<VSeriesPlotter>& aPlotter : m_aSeriesPlotterList)
{
VSeriesPlotter* pSeriesPlotter = aPlotter.get();
VCoordinateSystem* pVCooSys
= SeriesPlotterContainer::getCooSysForPlotter(m_rVCooSysList, pSeriesPlotter); if (pVCooSys)
{
pSeriesPlotter->setScales(pVCooSys->getExplicitScales(0, 0),
pVCooSys->getPropertySwapXAndYAxis());
sal_Int32 nMaxAxisIndex = pVCooSys->getMaximumAxisIndexByDimension(
1); //only additional value axis are relevant for series plotter for (sal_Int32 nI = 1; nI <= nMaxAxisIndex; nI++)
pSeriesPlotter->addSecondaryValueScale(pVCooSys->getExplicitScale(1, nI), nI);
}
}
}
void SeriesPlotterContainer::setNumberFormatsFromAxes()
{ //set numberformats to plotter to enable them to display the data labels in the numberformat of the axis for (const std::unique_ptr<VSeriesPlotter>& aPlotter : m_aSeriesPlotterList)
{
VSeriesPlotter* pSeriesPlotter = aPlotter.get();
VCoordinateSystem* pVCooSys
= SeriesPlotterContainer::getCooSysForPlotter(m_rVCooSysList, pSeriesPlotter); if (pVCooSys)
{
AxesNumberFormats aAxesNumberFormats; const rtl::Reference<BaseCoordinateSystem>& xCooSys = pVCooSys->getModel();
sal_Int32 nDimensionCount = xCooSys->getDimension(); for (sal_Int32 nDimensionIndex = 0; nDimensionIndex < nDimensionCount;
++nDimensionIndex)
{ const sal_Int32 nMaximumAxisIndex
= xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); for (sal_Int32 nAxisIndex = 0; nAxisIndex <= nMaximumAxisIndex; ++nAxisIndex)
{ try
{
rtl::Reference<Axis> xAxisProp
= xCooSys->getAxisByDimension2(nDimensionIndex, nAxisIndex); if (xAxisProp.is())
{
sal_Int32 nNumberFormatKey(0); if (xAxisProp->getPropertyValue(CHART_UNONAME_NUMFMT)
>>= nNumberFormatKey)
{
aAxesNumberFormats.setFormat(nNumberFormatKey, nDimensionIndex,
nAxisIndex);
} elseif (nDimensionIndex == 0)
{ //provide a default date format for date axis with own data
aAxesNumberFormats.setFormat(m_nDefaultDateNumberFormat,
nDimensionIndex, nAxisIndex);
}
}
} catch (const lang::IndexOutOfBoundsException&)
{
TOOLS_WARN_EXCEPTION("chart2", "");
}
}
}
}
}
}
void SeriesPlotterContainer::updateScalesAndIncrementsOnAxes()
{ for (auto& nC : m_rVCooSysList)
nC->updateScalesAndIncrementsOnAxes();
}
void SeriesPlotterContainer::doAutoScaling(ChartModel& rChartModel)
{ if (m_aSeriesPlotterList.empty() || m_aAxisUsageList.empty()) // We need these two containers populated to do auto-scaling. Bail out. return;
//iterate over the main scales first than secondary axis for (sal_Int32 nAxisIndex = 0; nAxisIndex <= m_nMaxAxisIndex; ++nAxisIndex)
{ // - first do autoscale for all x and z scales (because they are treated independent) for (auto & [ rAxis, rAxisUsage ] : m_aAxisUsageList)
{
(void)rAxis;
rAxisUsage.prepareAutomaticAxisScaling(rAxisUsage.aAutoScaling, 0, nAxisIndex);
rAxisUsage.prepareAutomaticAxisScaling(rAxisUsage.aAutoScaling, 2, nAxisIndex);
// - second do autoscale for the dependent y scales (the coordinate systems are prepared with x and z scales already ) for (auto & [ rAxis, rAxisUsage ] : m_aAxisUsageList)
{
(void)rAxis;
rAxisUsage.prepareAutomaticAxisScaling(rAxisUsage.aAutoScaling, 1, nAxisIndex);
//get a list of all preferred aspect ratios and combine them //first with special demands wins (less or equal zero <-> arbitrary) double fx, fy, fz;
fx = fy = fz = -1.0; for (const std::unique_ptr<VSeriesPlotter>& aPlotter : m_aSeriesPlotterList)
{
drawing::Direction3D aSingleRatio(aPlotter->getPreferredDiagramAspectRatio()); if (fx < 0 && aSingleRatio.DirectionX > 0)
fx = aSingleRatio.DirectionX;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.