19#include <com/sun/star/table/BorderLine.hpp>
20#include <com/sun/star/table/BorderLine2.hpp>
21#include <com/sun/star/table/TableBorder.hpp>
22#include <com/sun/star/table/BorderLineStyle.hpp>
23#include <com/sun/star/text/XTextRange.hpp>
24#include <com/sun/star/text/XText.hpp>
25#include <com/sun/star/style/ParagraphAdjust.hpp>
26#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
27#include <com/sun/star/drawing/TextVerticalAdjust.hpp>
28#include <com/sun/star/drawing/LineDash.hpp>
29#include <com/sun/star/drawing/LineStyle.hpp>
30#include <com/sun/star/drawing/FillStyle.hpp>
31#include <com/sun/star/util/XBroadcaster.hpp>
32#include <com/sun/star/container/XNameContainer.hpp>
33#include <com/sun/star/uno/XComponentContext.hpp>
43void setTopCell(uno::Reference<beans::XPropertySet>& xPropertySet)
45 xPropertySet->setPropertyValue(
"FillColor",
uno::Any(
Color(0xFFFFFF)));
46 xPropertySet->setPropertyValue(
"TextVerticalAdjust",
uno::Any(drawing::TextVerticalAdjust_TOP));
47 xPropertySet->setPropertyValue(
"ParaAdjust",
uno::Any(style::ParagraphAdjust_CENTER));
49 table::BorderLine2 aBorderLine;
50 aBorderLine.LineWidth = 0;
51 aBorderLine.Color = 0x000000;
53 xPropertySet->setPropertyValue(
"TopBorder",
uno::Any(aBorderLine));
54 xPropertySet->setPropertyValue(
"LeftBorder",
uno::Any(aBorderLine));
57void copyProperty(uno::Reference<beans::XPropertySet>& xOut,
58 uno::Reference<beans::XPropertySet>& xIn, OUString
const& sPropertyName)
60 xOut->setPropertyValue(sPropertyName, xIn->getPropertyValue(sPropertyName));
63uno::Reference<text::XTextRange> getFirstParagraph(uno::Reference<text::XText>
const& xText)
65 uno::Reference<text::XTextRange> xParagraph;
66 uno::Reference<container::XEnumerationAccess> xEnumAccess(xText, uno::UNO_QUERY);
67 if (!xEnumAccess.is())
69 uno::Reference<container::XEnumeration> xEnumeration(xEnumAccess->createEnumeration());
70 xParagraph.set(xEnumeration->nextElement(), uno::UNO_QUERY);
74uno::Reference<beans::XPropertySet>
75getFirstParagraphProperties(uno::Reference<text::XText>
const& xText)
77 uno::Reference<beans::XPropertySet> xPropertySet;
78 auto xParagraph = getFirstParagraph(xText);
81 xPropertySet.set(xParagraph, uno::UNO_QUERY);
90 css::uno::Reference<css::uno::XComponentContext>
const& rComponentContext,
91 bool bAlignAxisValuesWithColumns)
92 : m_xChartModel(xChartModel)
93 , m_xDataTableModel(rDataTableModel)
95 , m_bAlignAxisValuesWithColumns(bAlignAxisValuesWithColumns)
106 copyProperty(xPropertySet, xDataTableProperties,
"CharColor");
107 copyProperty(xPropertySet, xDataTableProperties,
"CharFontFamily");
108 copyProperty(xPropertySet, xDataTableProperties,
"CharFontFamilyAsian");
109 copyProperty(xPropertySet, xDataTableProperties,
"CharFontFamilyComplex");
110 copyProperty(xPropertySet, xDataTableProperties,
"CharFontCharSet");
111 copyProperty(xPropertySet, xDataTableProperties,
"CharFontCharSetAsian");
112 copyProperty(xPropertySet, xDataTableProperties,
"CharFontCharSetComplex");
113 copyProperty(xPropertySet, xDataTableProperties,
"CharFontName");
114 copyProperty(xPropertySet, xDataTableProperties,
"CharFontNameAsian");
115 copyProperty(xPropertySet, xDataTableProperties,
"CharFontNameComplex");
116 copyProperty(xPropertySet, xDataTableProperties,
"CharFontPitch");
117 copyProperty(xPropertySet, xDataTableProperties,
"CharFontPitchAsian");
118 copyProperty(xPropertySet, xDataTableProperties,
"CharFontPitchComplex");
119 copyProperty(xPropertySet, xDataTableProperties,
"CharFontStyleName");
120 copyProperty(xPropertySet, xDataTableProperties,
"CharFontStyleNameAsian");
121 copyProperty(xPropertySet, xDataTableProperties,
"CharFontStyleNameComplex");
123 copyProperty(xPropertySet, xDataTableProperties,
"CharHeight");
124 copyProperty(xPropertySet, xDataTableProperties,
"CharHeightAsian");
125 copyProperty(xPropertySet, xDataTableProperties,
"CharHeightComplex");
126 copyProperty(xPropertySet, xDataTableProperties,
"CharKerning");
127 copyProperty(xPropertySet, xDataTableProperties,
"CharLocale");
128 copyProperty(xPropertySet, xDataTableProperties,
"CharLocaleAsian");
129 copyProperty(xPropertySet, xDataTableProperties,
"CharLocaleComplex");
130 copyProperty(xPropertySet, xDataTableProperties,
"CharPosture");
131 copyProperty(xPropertySet, xDataTableProperties,
"CharPostureAsian");
132 copyProperty(xPropertySet, xDataTableProperties,
"CharPostureComplex");
133 copyProperty(xPropertySet, xDataTableProperties,
"CharRelief");
134 copyProperty(xPropertySet, xDataTableProperties,
"CharShadowed");
135 copyProperty(xPropertySet, xDataTableProperties,
"CharStrikeout");
136 copyProperty(xPropertySet, xDataTableProperties,
"CharUnderline");
137 copyProperty(xPropertySet, xDataTableProperties,
"CharUnderlineColor");
138 copyProperty(xPropertySet, xDataTableProperties,
"CharUnderlineHasColor");
139 copyProperty(xPropertySet, xDataTableProperties,
"CharOverline");
140 copyProperty(xPropertySet, xDataTableProperties,
"CharOverlineColor");
141 copyProperty(xPropertySet, xDataTableProperties,
"CharOverlineHasColor");
142 copyProperty(xPropertySet, xDataTableProperties,
"CharWeight");
143 copyProperty(xPropertySet, xDataTableProperties,
"CharWeightAsian");
144 copyProperty(xPropertySet, xDataTableProperties,
"CharWeightComplex");
145 copyProperty(xPropertySet, xDataTableProperties,
"CharWordMode");
147 drawing::FillStyle eFillStyle = drawing::FillStyle_NONE;
148 xDataTableProperties->getPropertyValue(
"FillStyle") >>= eFillStyle;
149 if (eFillStyle == drawing::FillStyle_SOLID)
151 sal_Int32 aColor = 0;
152 if (xDataTableProperties->getPropertyValue(
"FillColor") >>= aColor)
153 xPropertySet->setPropertyValue(
"CharBackColor",
uno::Any(aColor));
156 xPropertySet->setPropertyValue(
"ParaAdjust",
uno::Any(style::ParagraphAdjust_CENTER));
160 bool bLeft,
bool bTop,
bool bRight,
bool bBottom)
162 xPropertySet->setPropertyValue(
"FillColor",
uno::Any(
Color(0xFFFFFF)));
165 float fFontHeight = 0.0;
166 xDataTableProperties->getPropertyValue(
"CharHeight") >>= fFontHeight;
168 sal_Int32 nXDistance = std::round(fFontHeight * 0.18f);
169 sal_Int32 nYDistance = std::round(fFontHeight * 0.30f);
171 xPropertySet->setPropertyValue(
"TextLeftDistance",
uno::Any(nXDistance));
172 xPropertySet->setPropertyValue(
"TextRightDistance",
uno::Any(nXDistance));
173 xPropertySet->setPropertyValue(
"TextUpperDistance",
uno::Any(nYDistance));
174 xPropertySet->setPropertyValue(
"TextLowerDistance",
uno::Any(nYDistance));
176 xPropertySet->setPropertyValue(
"TextVerticalAdjust",
uno::Any(drawing::TextVerticalAdjust_TOP));
178 drawing::LineStyle eStyle = drawing::LineStyle_NONE;
181 if (eStyle != drawing::LineStyle_NONE)
183 table::BorderLine2 aBorderLine;
185 sal_Int32 nWidth = 0;
189 sal_Int32 nColor = 0;
191 aBorderLine.Color = nColor;
193 aBorderLine.LineStyle = table::BorderLineStyle::SOLID;
195 if (eStyle == drawing::LineStyle_DASH)
202 m_xChartModel->createInstance(
"com.sun.star.drawing.DashTable"),
204 if (xDashTable.is() && xDashTable->hasByName(aDashName))
206 drawing::LineDash aLineDash;
207 xDashTable->getByName(aDashName) >>= aLineDash;
209 if (aLineDash.Dots == 0 && aLineDash.Dashes == 0)
210 aBorderLine.LineStyle = table::BorderLineStyle::SOLID;
211 else if (aLineDash.Dots == 1 && aLineDash.Dashes == 0)
212 aBorderLine.LineStyle = table::BorderLineStyle::DOTTED;
213 else if (aLineDash.Dots == 0 && aLineDash.Dashes == 1)
214 aBorderLine.LineStyle = table::BorderLineStyle::DASHED;
215 else if (aLineDash.Dots == 1 && aLineDash.Dashes == 1)
216 aBorderLine.LineStyle = table::BorderLineStyle::DASH_DOT;
217 else if (aLineDash.Dots == 2 && aLineDash.Dashes == 1)
218 aBorderLine.LineStyle = table::BorderLineStyle::DASH_DOT_DOT;
220 aBorderLine.LineStyle = table::BorderLineStyle::DASHED;
226 xPropertySet->setPropertyValue(
"LeftBorder",
uno::Any(aBorderLine));
228 xPropertySet->setPropertyValue(
"TopBorder",
uno::Any(aBorderLine));
230 xPropertySet->setPropertyValue(
"RightBorder",
uno::Any(aBorderLine));
232 xPropertySet->setPropertyValue(
"BottomBorder",
uno::Any(aBorderLine));
237 sal_Int32 nAxisStepWidth)
249 auto rDelta = rEnd - rStart;
257 catch (
const uno::Exception&)
267 if (!xBroadcaster.is())
270 xBroadcaster->lockBroadcasts();
275 bool bHBorder =
false;
276 bool bVBorder =
false;
277 bool bOutline =
false;
280 std::vector<ViewLegendSymbol> aSymbols;
290 xTableColumns->insertByIndex(0, nColumnCount);
294 xTableRows->insertByIndex(0, nRowCount);
296 sal_Int32 nColumnWidth = 0.0;
301 nColumnWidth = nAxisStepWidth;
303 nColumnWidth = double(nTableSize) / nColumnCount;
309 if (xPropertySet.is())
311 setTopCell(xPropertySet);
326 if (xCellTextRange.is())
328 auto xText = xCellTextRange->getText();
329 xText->insertString(xText->getStart(), rString,
false);
330 auto xTextPropertySet = getFirstParagraphProperties(xText);
331 if (!xTextPropertySet.is())
335 = (bOutline && nColumn == 1) || (bVBorder && nColumn > 1 && nColumn < nColumnCount);
336 bool bRight = (bOutline && nColumn == nColumnCount)
337 || (bVBorder && nColumn > 1 && nColumn < nColumnCount);
346 sal_Int32 nMaxSymbolWidth = 0;
347 constexpr const sal_Int32 constSymbolMargin = 100;
351 float fFontHeight = 0.0;
352 xDataTableProperties->getPropertyValue(
"CharHeight") >>= fFontHeight;
355 sal_Int32 nSymbolHeight = sal_Int32(fFontHeight * 0.6);
356 sal_Int32 nSymbolWidth = nSymbolHeight;
362 awt::Size aCurrentRatio = pSeriesPlotter->getPreferredLegendKeyAspectRatio();
363 sal_Int32 nCurrentWidth = aCurrentRatio.Width;
364 if (aCurrentRatio.Height > 0)
365 nCurrentWidth = nSymbolHeight * aCurrentRatio.Width / aCurrentRatio.Height;
366 nSymbolWidth = std::max(nSymbolWidth, nCurrentWidth);
369 nMaxSymbolWidth = nSymbolWidth;
375 awt::Size aSize(nSymbolWidth, nSymbolHeight);
376 std::vector<ViewLegendSymbol> aNewEntries
379 for (
auto const& rSymbol : aNewEntries)
380 aSymbols.push_back(rSymbol);
391 if (xCellTextRange.is())
393 bool bTop = (bOutline && nRow == 1) || (bHBorder && nRow > 1 && nRow < nRowCount);
395 = (bOutline && nRow == nRowCount) || (bHBorder && nRow > 1 && nRow < nRowCount);
397 auto xText = xCellTextRange->getText();
398 xText->insertString(xText->getStart(), rSeriesName,
false);
399 auto xTextPropertySet = getFirstParagraphProperties(xText);
400 if (!xTextPropertySet.is())
405 xCellPropertySet->setPropertyValue(
"ParaAdjust",
uno::Any(style::ParagraphAdjust_LEFT));
408 xCellPropertySet->setPropertyValue(
409 "ParaLeftMargin",
uno::Any(nMaxSymbolWidth + sal_Int32(2 * constSymbolMargin)));
420 for (
auto const& rValue : rSeries)
425 if (xCellTextRange.is())
427 auto xText = xCellTextRange->getText();
428 xText->insertString(xText->getStart(), rValue,
false);
429 auto xTextPropertySet = getFirstParagraphProperties(xText);
430 if (!xTextPropertySet.is())
436 bool bBottom =
false;
438 if (nColumn > 1 && bVBorder)
441 if (nRow > 1 && bHBorder)
444 if (nRow == nRowCount && bOutline)
447 if (nColumn == nColumnCount && bOutline)
458 xBroadcaster->unlockBroadcasts();
461 pTableObject->DistributeColumns(0, nColumnCount,
true,
true);
462 pTableObject->DistributeRows(0, nRowCount,
true,
true);
464 xBroadcaster->lockBroadcasts();
474 for (sal_Int32
i = 1;
i < xTableColumns->getCount(); ++
i)
476 xPropertySet.set(xTableColumns->getByIndex(
i), uno::UNO_QUERY);
477 xPropertySet->setPropertyValue(
"Width",
uno::Any(nColumnWidth));
482 sal_Int32 nTotalHeight = 0;
483 for (sal_Int32
i = 0;
i < xTableRows->getCount();
i++)
485 sal_Int32 nSymbolIndex =
i - 1;
486 if (nSymbolIndex < sal_Int32(aSymbols.size()))
488 xPropertySet.set(xTableRows->getByIndex(
i), uno::UNO_QUERY);
489 sal_Int32 nHeight = 0;
490 xPropertySet->getPropertyValue(
"Height") >>= nHeight;
493 auto& rSymbol = aSymbols[nSymbolIndex].xSymbol;
494 sal_Int32 nSymbolHeight = rSymbol->getSize().Height;
496 =
basegfx::fround(
double(nHeight) / 2.0 -
double(nSymbolHeight) / 2.0);
497 rSymbol->setPosition(
498 { nTableX + constSymbolMargin, nTableY + nTotalHeight + nSymbolY });
500 nTotalHeight += nHeight;
504 xBroadcaster->unlockBroadcasts();
515 sal_Int32 nWidth = 0;
516 xPropertySet->getPropertyValue(
"Width") >>= nWidth;
527 std::vector<std::unique_ptr<VSeriesPlotter>>& rSeriesPlotterList)
529 for (
auto& rSeriesPlotter : rSeriesPlotterList)
533 for (
auto const& rCategory :
534 rSeriesPlotter->getExplicitCategoriesProvider()->getSimpleCategories())
539 for (
auto const& rString : rSeriesPlotter->getAllSeriesNames())
544 for (
VDataSeries* pSeries : rSeriesPlotter->getAllSeries())
547 for (
int i = 0;
i < pSeries->getTotalPointCount();
i++)
549 double nValue = pSeries->getYValue(
i);
550 rValues.push_back(rSeriesPlotter->getLabelTextForValue(*pSeries,
i,
nValue,
false));
rtl::Reference< DataTable > m_xDataTableModel
void setCellProperties(css::uno::Reference< css::beans::XPropertySet > &xPropertySet, bool bLeft, bool bTop, bool bRight, bool bBottom)
Set the common cell properties (for all cells in the data table, including headers)
rtl::Reference< SvxTableShape > m_xTableShape
void initializeShapes(const rtl::Reference< SvxShapeGroupAnyD > &xTarget)
Initializes and prepares the target and data table shape.
void changePosition(sal_Int32 x, sal_Int32 y)
Repositions the data table shape.
std::vector< VSeriesPlotter * > m_pSeriesPlotterList
VLineProperties m_aLineProperties
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
rtl::Reference< SvxShapeGroupAnyD > m_xTarget
void setCellCharAndParagraphProperties(css::uno::Reference< css::beans::XPropertySet > &xPropertySet)
Set the char and paragraph properties for the input (value) cell.
rtl::Reference<::chart::ChartModel > m_xChartModel
DataTableView(rtl::Reference<::chart::ChartModel > const &xChartDoc, rtl::Reference< DataTable > const &rDataTableModel, css::uno::Reference< css::uno::XComponentContext > const &rComponentContext, bool bAlignAxisValuesWithColumns)
std::vector< OUString > m_aXValues
css::uno::Reference< css::table::XTable > m_xTable
void createShapes(basegfx::B2DVector const &rStart, basegfx::B2DVector const &rEnd, sal_Int32 nAxisStepWidth)
Creates the data table and fills the values.
std::vector< OUString > m_aDataSeriesNames
bool m_bAlignAxisValuesWithColumns
void initializeValues(std::vector< std::unique_ptr< VSeriesPlotter > > &rSeriesPlotterList)
Prepares the values of the chart, which will be shown it the data table.
std::vector< std::vector< OUString > > m_pDataSeriesValues
static OUString createClassifiedIdentifierForParticle(std::u16string_view rParticle)
static OUString createParticleForDataTable(const rtl::Reference<::chart::ChartModel > &xChartModel)
Creates an identifier for the data table.
static rtl::Reference< SvxTableShape > createTable(rtl::Reference< SvxShapeGroupAnyD > const &xTarget, OUString const &rName=OUString())
static void removeSubShapes(const rtl::Reference< SvxShapeGroupAnyD > &xShapes)
Reference< XComponentContext > const m_xComponentContext
Reference< XInterface > xTarget
B2IRange fround(const B2DRange &rRange)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
void initFromPropertySet(const css::uno::Reference< css::beans::XPropertySet > &xProp)