GSoC 2019 with LibreOffice: Implement Chart Styles

Code written during GSoC

Gagandeep Singh
Aug 26 · 4 min read

Currently merged patches:

List of patches for setting up Chart Styles

ChartStyle service addition

Last patch in review currently and part of debugging process:

API for creating and updating style

Important patches where I got help from my mentor Markus Mohrhard

First Chart Style Implemented

Implement ChartStyles Object ( a name container for Chart Style )

Description of the Project

So this summer I got the opportunity to work with the Document Foundation on adding Chart Styles feature to LibreOffice. Prior to the start of the project, no work was done in regards to this feature. Let me first explain how Charts’ properties are stored.

According to Official UNO dev guide :

‘…properties are used for non-structural attributes, such as font, size or color of objects…’

Each part of the chart that is selectable or can be inserted like Title, Legend, etc… are represented as disjoint elements inside the code. There exist references between them in a hierarchical manner. The root of this hierarchy is the Chart Document which references the Chart Diagram, Main Title of Chart and is responsible for communicating with the rendering code and the controller ( as LibreOffice follows the frame-controller-model paradigm for objects). The Chart Diagram is used to store references to Coordinate Systems, which represent all the Axes. Chart Diagram also stores Legends, Subtitle and Color Scheme of Diagram. Color Scheme is an array of colors to be applied to the different Data Series in the Diagram.

Again each of these chart elements is disjoint and have their own properties and for each of these chart elements, the property state can either be DIRECT or DEFAULT.

More info on Property states

In a gist, if a user manually sets a property value then the property state becomes direct otherwise, it is left to default. Currently, the default values are hardcoded. But what if, the default values could be changed? This naturally leads us to what is called a Style (within the context of LibreOffice) and to implement these new mutable defaults was the crux of the project.

What has been achieved through this project?

We can create new styles by manually changing the selected chart’s properties and saving it as a style template. These new styles can then be applied to any other selected chart. The following kinds of properties can be applied through styles:

  • Chart elements like Title, Legends locations can be changed and saved in the styles when creating new styles. On applying the styles, new locations for these elements will be set based on the style.
  • Chart elements formatting properties like FillColor, LineStyle, LineColor can be applied through styles.

Note: The last patch that is currently under review may have us change some functionality in the first master-branch merge. The bugs with the above features also need to be ironed out.

What remains to be done?

  • Portability of Styles: What I and my mentor wanted, was to save these styles along with the ODF( Open Document Format, the default file format used by LibreOffice) file so that they can be transported and be available even if the file is opened on any machine that didn’t create these styles. Sadly the current ODF specifications don’t support a way of mapping chart objects to styles on loading the file.
  • Style Updates: Currently, style update feature is not supported, although the API that we have written supports changes to existing styles, we haven’t been able to reflect the changes to all the charts that were using the style after updating it. This would be a very good next feature to add.
  • XColorScheme: Currently we weren’t able to add support for creating and saving new color schemes into the chart styles. This is same as color list selection offered in Microsoft Office Charts.

For more info on the color scheme

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade