chart2/source/view/main/DataTableView.cxx | 49 ++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 13 deletions(-)
New commits: commit 9923f2416b63abc09bf8cd83796d1d681e9de225 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Aug 18 00:09:25 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Aug 18 08:48:34 2022 +0200 chart2: improve keys (symbols) rendering in a data table - better symbol positioning taking symbol height and cell height into account. - symbol height depends on font size (as with the legend) - take symbol aspect ratio into account - remove hardcoded values Change-Id: I3537d82538035cd31b928d4bb6fc5572914fcd13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138463 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/chart2/source/view/main/DataTableView.cxx b/chart2/source/view/main/DataTableView.cxx index 5e1a7157cc3e..5504e08a4950 100644 --- a/chart2/source/view/main/DataTableView.cxx +++ b/chart2/source/view/main/DataTableView.cxx @@ -339,21 +339,40 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV // ROW HEADER // Prepare keys (symbols) sal_Int32 nMaxSymbolWidth = 0; + constexpr const sal_Int32 constSymbolMargin = 100; // 1mm if (bKeys) { + uno::Reference<beans::XPropertySet> xDataTableProperties(m_xDataTableModel); + float fFontHeight = 0.0; + xDataTableProperties->getPropertyValue("CharHeight") >>= fFontHeight; + fFontHeight = o3tl::convert(fFontHeight, o3tl::Length::pt, o3tl::Length::mm100); + + sal_Int32 nSymbolHeight = sal_Int32(fFontHeight * 0.6); + sal_Int32 nSymbolWidth = nSymbolHeight; + for (VSeriesPlotter* pSeriesPlotter : m_pSeriesPlotterList) { if (pSeriesPlotter) { - sal_Int32 nSymbolWidth = 300; - if (pSeriesPlotter->getLegendSymbolStyle() == LegendSymbolStyle::Line) - nSymbolWidth = 600; + awt::Size aCurrentRatio = pSeriesPlotter->getPreferredLegendKeyAspectRatio(); + sal_Int32 nCurrentWidth = aCurrentRatio.Width; + if (aCurrentRatio.Height > 0) + nCurrentWidth = nSymbolHeight * aCurrentRatio.Width / aCurrentRatio.Height; + nSymbolWidth = std::max(nSymbolWidth, nCurrentWidth); + } + } + nMaxSymbolWidth = nSymbolWidth; - nMaxSymbolWidth = std::max(nSymbolWidth, nMaxSymbolWidth); + for (VSeriesPlotter* pSeriesPlotter : m_pSeriesPlotterList) + { + if (pSeriesPlotter) + { + awt::Size aSize(nSymbolWidth, nSymbolHeight); + std::vector<ViewLegendSymbol> aNewEntries + = pSeriesPlotter->createSymbols(aSize, m_xTarget, m_xComponentContext); - std::vector<ViewLegendSymbol> aNewEntries = pSeriesPlotter->createSymbols( - { nSymbolWidth, 300 }, m_xTarget, m_xComponentContext); - aSymbols.insert(aSymbols.end(), aNewEntries.begin(), aNewEntries.end()); + for (auto const& rSymbol : aNewEntries) + aSymbols.push_back(rSymbol); } } } @@ -381,8 +400,8 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV xCellPropertySet->setPropertyValue("ParaAdjust", uno::Any(style::ParagraphAdjust_LEFT)); if (bKeys) { - xCellPropertySet->setPropertyValue("ParaLeftMargin", - uno::Any(nMaxSymbolWidth + sal_Int32(200))); + xCellPropertySet->setPropertyValue( + "ParaLeftMargin", uno::Any(nMaxSymbolWidth + sal_Int32(2 * constSymbolMargin))); } } nRow++; @@ -433,8 +452,8 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV xBroadcaster->unlockBroadcasts(); - pTableObject->DistributeColumns(0, nColumnCount - 1, true, true); - pTableObject->DistributeRows(0, nRowCount - 1, true, true); + pTableObject->DistributeColumns(0, nColumnCount, true, true); + pTableObject->DistributeRows(0, nRowCount, true, true); xBroadcaster->lockBroadcasts(); @@ -461,8 +480,12 @@ void DataTableView::createShapes(basegfx::B2DVector const& rStart, basegfx::B2DV xPropertySet->getPropertyValue("Height") >>= nHeight; if (i > 0) { - aSymbols[i - 1].xSymbol->setPosition( - { nTableX + 100, nTableY + nTotalHeight + 100 }); + auto& rSymbol = aSymbols[i - 1].xSymbol; + sal_Int32 nSymbolHeight = rSymbol->getSize().Height; + sal_Int32 nSymbolY + = basegfx::fround(double(nHeight) / 2.0 - double(nSymbolHeight) / 2.0); + rSymbol->setPosition( + { nTableX + constSymbolMargin, nTableY + nTotalHeight + nSymbolY }); } nTotalHeight += nHeight; }