GSoC: Adding Histogram Chart Native Support (Week 8, prev) and (Week 9, this)

Devansh Varshney varshney.devansh614 at gmail.com
Wed Jul 10 19:00:54 UTC 2024


Hi,

So, the previous week I did not send the weekly update as I was hopeful
that I am close to get this done
and kept pushing to not only get the X and Y axis with proper Bin Range and
Frequency but also the bar
for the Histogram plot. But, I also find the scaling issue which I
encountered by the end of the week.

Here, I am using the analogy of Gradient Descent part of Mathematical
Optimization to explain the situation.

In the beginning of the May, we started off from the top region (Red) with
the highest cost of instability for
the addition of the changes. By the end of May we were able to have the
Histogram specific code but mimicking
Bar/Column Chart and in the beginning of the June we were able to have the
bars attached to each other,
i.e., with ZERO gap between each other.
[image: image.png]


[image: Screenshot from 2024-06-13 21-38-21.png]  [image: Screenshot from
2024-06-17 15-17-27.png]

After having this as a success, we went on our next step, which was to get
the X and Y axis as Bin Ranges and Frequency.
Which could be thought of as somewhere around the location of *Saddle point*.
>From here instead of going towards the
global minima I went towards the local minima, which is got stuck with the
axes' modification.

Though in local minima which took me almost 4 weeks I kept revolving into
it and the result was by last week -

[image: Screenshot from 2024-07-06 19-47-52.png]             [image:
Screenshot from 2024-07-06 19-55-52.png]
```bash
*i/p*- 12,10,15,16,14
*o/p* -
Entering createShapes()
xSeriesTarget is valid: true
xTextTarget is valid: true
m_nBins: 2, m_fBinWidth: 3
minValue: 10, maxValue: 16
m_binRanges: {10, 13} {13, 16}
m_binFrequencies: 3 2
Bin ranges size: 2
Bin frequencies size: 2
Entering doXSlot() for bin index: 0
Bar dimensions - X: 0.25, Width: 0.5, Height: 1
Exiting doXSlot()
Entering doXSlot() for bin index: 1
Bar dimensions - X: 0.75, Width: 0.5, Height: 0.666667
Exiting doXSlot()
Exiting createShapes(
```

I was able to have the bars which were 2 as I am using the *sqrt* method to
calculate the number of bins as of now.

After having been stuck in the local minima for so long, my mentor *Tomaž*
came forward and change the direction of the
descent from the local minima towards the global minima by creating the
*chart2/source/model/template/HistogramDataInterpreter.cxx*
and *chart2/source/tools/HistogramDataSequence.cxx* where we are currently
having the X and Y axis values and dummy values
Hard-coded -

[image: Screenshot from 2024-07-08 18-20-06.png]          [image:
Screenshot from 2024-07-08 18-38-17.png]

In the above images which were being generated via the help of
*HistogramDataInterpreter* the first image is taking the BarChart
as the base hence bars with gaps -
*chart2/source/view/charttypes/VSeriesPlotter.cxx** -*
```cpp
else if( aChartType.equalsIgnoreAsciiCase(
CHART2_SERVICE_NAME_CHARTTYPE_HISTOGRAM ) )
pRet = new BarChart(xChartTypeModel, nDimensionCount);
```
and the next image is where I after cherry-picking the code and replacing
the base object as Histogram.


aNewData.push_back(aData[0]);

{
rtl::Reference<HistogramDataSequence> aValuesDataSequence = new
HistogramDataSequence();
aValuesDataSequence->setValues({ 7, 12, 4, 6 });
aValuesDataSequence->setLabels(
{ u"[1-4)"_ustr, u"[4-8)"_ustr, u"[8-12)"_ustr, u"[12-16]"_ustr });

aDataSequence = aValuesDataSequence;
SetRole(aDataSequence, u"values-y"_ustr);
aNewData.push_back(new LabeledDataSequence(aDataSequence));
}


After this *Tomaž* pointed out some other changes which are better for the
descent, which included the change of inheritance
from *VSeriesPlotter* and *ChartModel* to *BarChart*. The reason being is as*
Histogram* is sort of a *special Barchart* we can reuse
lot of code from Barchart itself and if you look closely in the code you
can find that the ColumnChart and Barchart are utilizing a lot
of code to avoid more redundancy of code -

pPosHelper->isSwapXAndY()

since they are same with only difference of axis difference.

The second is to detach the Bin and Frequency calculation to a separate
class from the *HistogramChartType* model.
to which we can find an appropriate place later.
I have done this and named the class as -
*chart2/source/model/template/HistogramCalculator.hxx*

Third is replacing the hard-coded values with the input, i.e., dynamic
calculation of the values.

Currently, in order to align with the first point, I am reverting my
addition of the *HistogramPositionHelper* with
*BarPositionHelper* and having some -
```bash
Error: attempt to subscript container with out-of-bounds index 2, but
container only holds 2 elements.
```
As of now, I am considering to get the dynamic calculations first and later
update the inheritance. Hence, currently at the
small red region in between local and global minima, hence the instability
with the code
after the intervention and better descent approach made by *Tomaž *it now
won't take that much time now.

[image: image.png]
                    what we thought how our work gonna be




[image: image.png]
                how it's actually going


Till last week, I couldn't figure out why I got stuck this bad. But now it
makes sense from the view point of mathematics. :)

https://gerrit.libreoffice.org/c/core/+/167068
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 1211233 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-06-13 21-38-21.png
Type: image/png
Size: 24313 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-06-17 15-17-27.png
Type: image/png
Size: 25995 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0011.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-07-06 19-47-52.png
Type: image/png
Size: 20016 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0012.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-07-06 19-55-52.png
Type: image/png
Size: 19875 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0013.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-07-08 18-38-17.png
Type: image/png
Size: 21207 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0014.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2024-07-08 18-20-06.png
Type: image/png
Size: 18544 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0015.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 173477 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0016.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 267633 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libreoffice/attachments/20240711/e17aac4f/attachment-0017.png>


More information about the LibreOffice mailing list