13#include <document.hxx>
74 double mfMinimum = std::numeric_limits<double>::max();
75 double mfMaximum = std::numeric_limits<double>::min();
109 static constexpr double interpolate(
double x1,
double y1,
double x2,
double y2,
double x)
111 return (y1 * (x2 -
x) + y2 * (
x - x1)) / (x2 - x1);
135 rValue.maValue = fInterpolated;
147 if (rValue.maValue != 0.0)
149 double fNewValue = rValue.maValue > 0.0 ? 1.0 : -1.0;
157 rValue.maValue = fNewValue;
246 void createMarker(std::vector<SparklineMarker>& rMarkers,
double x,
double y,
249 auto& rMarker = rMarkers.emplace_back();
253 std::round(
x + nHalfSizeX), std::round(
y + nHalfSizeY));
255 rMarker.maColor = rColor;
262 double nMax = rSparklineValues.
mfMaximum;
266 double nMin = rSparklineValues.
mfMinimum;
270 std::vector<SparklineValue>
const& rValueList = rSparklineValues.
getValuesList();
271 std::vector<basegfx::B2DPolygon> aPolygons;
272 aPolygons.emplace_back();
273 double numebrOfSteps = rValueList.size() - 1;
275 double nDelta = nMax - nMin;
277 std::vector<SparklineMarker> aMarkers;
278 size_t nValueIndex = 0;
280 for (
auto const& rSparklineValue : rValueList)
284 aPolygons.emplace_back();
288 auto& aPolygon = aPolygons.back();
289 double nValue = rSparklineValue.maValue;
291 double nP = (
nValue - nMin) / nDelta;
292 double x = rRectangle.
GetWidth() * (xStep / numebrOfSteps);
295 aPolygon.append({
x,
y });
332 double nZero = 0 - nMin / nDelta;
337 double x2 = double(rRectangle.
GetWidth());
341 aAxisPolygon.
append({ x1,
y });
342 aAxisPolygon.
append({ x2,
y });
351 for (
auto& rPolygon : aPolygons)
358 for (
auto& rMarker : aMarkers)
362 auto& rPolygon = rMarker.maPolygon;
363 rPolygon.transform(aMatrix);
408 double nMax = rSparklineValues.
mfMaximum;
412 double nMin = rSparklineValues.
mfMinimum;
416 std::vector<SparklineValue>
const& rValueList = rSparklineValues.
getValuesList();
423 double numberOfSteps = rValueList.size();
424 double nDelta = nMax - nMin;
426 double nColumnSize = rRectangle.
GetWidth() / numberOfSteps;
427 nColumnSize = nColumnSize - (nColumnSize * 0.3);
429 double nZero = (0 - nMin) / nDelta;
430 double nZeroPosition = 0.0;
438 double x2 = double(rRectangle.
GetWidth());
441 aAxisPolygon.
append({ x1, nZeroPosition });
442 aAxisPolygon.
append({ x2, nZeroPosition });
451 size_t nValueIndex = 0;
453 for (
auto const& rSparklineValue : rValueList)
455 double nValue = rSparklineValue.maValue;
462 double nP = (
nValue - nMin) / nDelta;
463 double x = rRectangle.
GetWidth() * (xStep / numberOfSteps);
493 void render(std::shared_ptr<sc::Sparkline>
const& pSparkline,
497 rRenderContext.
Push();
504 aOutputRectangle.
shrink(6);
511 auto const& rRangeList = pSparkline->getInputRange();
513 if (rRangeList.empty())
518 auto pSparklineGroup = pSparkline->getSparklineGroup();
519 auto const& rAttributes = pSparklineGroup->getAttributes();
521 ScRange aRange = rRangeList[0];
530 if (!rAttributes.shouldDisplayHidden() &&
isCellHidden(rCurrent))
533 double fCellValue = 0.0;
539 auto eDisplayEmpty = rAttributes.getDisplayEmptyCellsAs();
550 aSparklineValues.
add(fCellValue, eAction);
553 if (rAttributes.isRightToLeft())
558 drawColumn(rRenderContext, aOutputRectangle, aSparklineValues,
559 pSparklineGroup->getAttributes());
564 drawColumn(rRenderContext, aOutputRectangle, aSparklineValues,
565 pSparklineGroup->getAttributes());
569 drawLine(rRenderContext, aOutputRectangle, aSparklineValues,
570 pSparklineGroup->getAttributes());
void SetAntialiasing(AntialiasingFlags nMode)
void DrawPolygon(const tools::Polygon &rPoly)
bool DrawPolyLineDirect(const basegfx::B2DHomMatrix &rObjectTransform, const basegfx::B2DPolygon &rB2DPolygon, double fLineWidth=0.0, double fTransparency=0.0, const std::vector< double > *=nullptr, basegfx::B2DLineJoin eLineJoin=basegfx::B2DLineJoin::NONE, css::drawing::LineCap eLineCap=css::drawing::LineCap_BUTT, double fMiterMinimumAngle=basegfx::deg2rad(15.0))
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
void IncCol(SCCOL nDelta=1)
void IncRow(SCROW nDelta=1)
SC_DLLPUBLIC double GetValue(const ScAddress &rPos) const
SC_DLLPUBLIC bool RowHidden(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
SC_DLLPUBLIC bool ColHidden(SCCOL nCol, SCTAB nTab, SCCOL *pFirstCol=nullptr, SCCOL *pLastCol=nullptr) const
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
void translate(double fX, double fY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
Iterator to traverse the addresses in a range if the range is one dimensional.
ScAddress const & first()
RangeTraverser(ScRange const &rRange)
Common properties for a group of sparklines.
std::optional< double > getManualMax() const
bool shouldDisplayXAxis() const
Color getColorHigh() const
Color getColorAxis() const
Color getColorNegative() const
Color getColorMarkers() const
AxisType getMaxAxisType() const
Color getColorFirst() const
AxisType getMinAxisType() const
std::optional< double > getManualMin() const
Color getColorLast() const
double getLineWeight() const
Line weight or width in points.
Color getColorSeries() const
Color getColorLow() const
Render a provided sparkline into the input rectangle.
void drawLine(vcl::RenderContext &rRenderContext, tools::Rectangle const &rRectangle, SparklineValues const &rSparklineValues, sc::SparklineAttributes const &rAttributes)
void render(std::shared_ptr< sc::Sparkline > const &pSparkline, vcl::RenderContext &rRenderContext, tools::Rectangle const &rRectangle, tools::Long nOneX, tools::Long nOneY, double fScaleX, double fScaleY)
void drawColumn(vcl::RenderContext &rRenderContext, tools::Rectangle const &rRectangle, SparklineValues const &rSparklineValues, sc::SparklineAttributes const &rAttributes)
void createMarker(std::vector< SparklineMarker > &rMarkers, double x, double y, Color const &rColor)
SparklineRenderer(ScDocument &rDocument)
static void setFillAndLineColor(vcl::RenderContext &rRenderContext, sc::SparklineAttributes const &rAttributes, double nValue, size_t nValueIndex, SparklineValues const &rSparklineValues)
bool isCellHidden(ScAddress const &rAddress)
Contains and manages the values of the sparkline.
static constexpr double interpolate(double x1, double y1, double x2, double y2, double x)
void interpolatePastValues(double nCurrentValue, size_t nCurrentIndex)
void add(double fValue, SparklineValue::Action eAction)
std::vector< SparklineValue > const & getValuesList() const
std::vector< SparklineValue > maValueList
std::vector< size_t > maToInterpolateIndex
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
CAUTION! The following defines must be in the same namespace as the respective type.
Contains the marker polygon and the color of a marker.
basegfx::B2DPolygon maPolygon
Sparkline value and action that needs to me performed on the value.
SparklineValue(double aValue, Action eAction)