diff options
author | Kurt Nordback <kurt.nordback@protonmail.com> | 2024-01-08 09:37:28 -0700 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-01-12 07:55:02 +0100 |
commit | ca3112f38ea67d3cff1c9784adcc30ffcb200a0a (patch) | |
tree | 01b2be4e75369c0be08b68b2faaf58c2f4ea96f1 /chart2/source/view | |
parent | ba8f4bff6015013013df652efbfaf4d9ae10c881 (diff) |
tdf#159043: combo chart render order isn't right
Change-Id: If20446c8bd5a67f73c24444126c26ed6bd160aed
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161797
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2/source/view')
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 42 | ||||
-rw-r--r-- | chart2/source/view/inc/VSeriesPlotter.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/main/SeriesPlotterContainer.cxx | 7 |
3 files changed, 51 insertions, 0 deletions
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index f9fa8fe0fea9..34a702d7b696 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -2307,6 +2307,48 @@ OUString VSeriesPlotter::getCategoryName( sal_Int32 nPointIndex ) const return OUString(); } +namespace { +// The following it to support rendering order for combo charts. A chart type +// with a lower rendering order is rendered before (i.e., behind) a chart with a +// higher rendering order. The rendering orders are based on rough guesses about +// how much one chart (type) will obscure another chart (type). The intent is to +// minimize obscuring of data, by putting charts that generally cover more +// pixels (e.g., area charts) behind ones that generally cover fewer (e.g., line +// charts). +struct ROrderPair +{ + ROrderPair(OUString n, sal_Int32 r) : chartName(n), renderOrder(r) {} + + OUString chartName; + sal_Int32 renderOrder; +}; + +const ROrderPair pairList[] = { + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_AREA, 0), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_BAR, 6), // bar & column are same + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_COLUMN, 6), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_LINE, 8), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_SCATTER, 5), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_PIE, 1), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_NET, 3), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET, 2), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK, 7), + ROrderPair(CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE, 4) +}; +} // unnamed + +sal_Int32 VSeriesPlotter::getRenderOrder() const +{ + OUString aChartType = m_xChartTypeModel->getChartType(); + for (size_t n = 0; n < sizeof(pairList); ++n) { + if (aChartType.equalsIgnoreAsciiCase(pairList[n].chartName)) { + return pairList[n].renderOrder; + } + } + SAL_WARN("chart2", "Unsupported chart type in getRenderOrder()"); + return 0; +} + std::vector<VDataSeries const*> VSeriesPlotter::getAllSeries() const { std::vector<VDataSeries const*> aAllSeries; diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index eaf27495d0ed..45676830b538 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -275,6 +275,8 @@ public: OUString getLabelTextForValue(VDataSeries const & rDataSeries, sal_Int32 nPointIndex, double fValue, bool bAsPercentage); + sal_Int32 getRenderOrder() const; + protected: VSeriesPlotter( rtl::Reference< ::chart::ChartType > xChartTypeModel diff --git a/chart2/source/view/main/SeriesPlotterContainer.cxx b/chart2/source/view/main/SeriesPlotterContainer.cxx index bcc5b0f482a3..67e4d75c0b9b 100644 --- a/chart2/source/view/main/SeriesPlotterContainer.cxx +++ b/chart2/source/view/main/SeriesPlotterContainer.cxx @@ -317,6 +317,13 @@ void SeriesPlotterContainer::initializeCooSysAndSeriesPlotter(ChartModel& rChart } } + auto order + = [](const std::unique_ptr<VSeriesPlotter>& a, const std::unique_ptr<VSeriesPlotter>& b) { + return a->getRenderOrder() < b->getRenderOrder(); + }; + + std::stable_sort(m_aSeriesPlotterList.begin(), m_aSeriesPlotterList.end(), order); + //transport seriesnames to the coordinatesystems if needed if (m_aSeriesPlotterList.empty()) return; |