Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/inc/HistogramCalculator.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#pragma once
11
12
#include <sal/types.h>
13
#include <vector>
14
15
namespace chart
16
{
17
/** Largest number of bins a histogram is partitioned into. Higher counts are capped. */
18
constexpr sal_Int32 MAX_HISTOGRAM_BINS = 10000;
19
20
enum class HistogramBinType
21
{
22
    Normal,
23
    Underflow,
24
    Overflow
25
};
26
27
/** Partitions a data set into histogram bins and counts per-bin frequencies.
28
    Binning can be automatic, by fixed bin width, or by fixed bin count. */
29
class HistogramCalculator
30
{
31
    sal_Int32 mnBins = 1;
32
    double mfBinWidth = 1.0;
33
34
    std::vector<std::pair<double, double>> maBinRanges;
35
    std::vector<sal_Int32> maBinFrequencies;
36
    std::vector<HistogramBinType> maBinTypes;
37
38
public:
39
    HistogramCalculator();
40
41
    // nFrequencyType: 0 = auto (Scott's Rule), 1 = fixed bin width, 2 = fixed bin count.
42
    // fFixedBinWidth / nFixedBinCount are consulted only when their mode is selected;
43
    // invalid values (<= 0) fall back to auto.
44
    void computeBinFrequencyHistogram(const std::vector<double>& dataPoints,
45
                                      sal_Int32 nFrequencyType = 0, double fFixedBinWidth = 0.0,
46
                                      sal_Int32 nFixedBinCount = 0, bool bUseUnderflowBin = false,
47
                                      double fUnderflowBinValue = 0.0, bool bUseOverflowBin = false,
48
                                      double fOverflowBinValue = 0.0);
49
50
0
    const std::vector<std::pair<double, double>>& getBinRanges() const { return maBinRanges; }
51
0
    const std::vector<sal_Int32>& getBinFrequencies() const { return maBinFrequencies; }
52
0
    const std::vector<HistogramBinType>& getBinTypes() const { return maBinTypes; }
53
};
54
55
} // namespace chart
56
57
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */