Chart2 Direct Title/Subtitle Area

Overview

The various style_* method are used to format the Title/Subtitle parts of a Chart.

Setup

General setup for examples.

from __future__ import annotations
from pathlib import Path
import uno
from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.calc import CalcDoc, ZoomKind
from ooodev.loader.lo import Lo
from ooodev.utils.color import StandardColor
from ooodev.utils.data_type.color_range import ColorRange

def main() -> int:
    with Lo.Loader(connector=Lo.ConnectPipe()):
        fnm = Path.cwd() / "tmp" / "piechart.ods"
        doc = CalcDoc.open_doc(fnm=fnm, visible=True)
        Lo.delay(500)
        doc.zoom(ZoomKind.ZOOM_100_PERCENT)

        sheet = doc.sheets[0]
        sheet["A1"].goto()
        chart_table = sheet.charts[0]
        chart_doc = chart_table.chart_doc
        _ = chart_doc.style_border_line(
            color=StandardColor.PURPLE_DARK1,
            width=0.7,
        )
        _ = chart_doc.style_area_gradient(
            step_count=64,
            style=GradientStyle.SQUARE,
            angle=45,
            grad_color=ColorRange(
                StandardColor.BLUE_DARK1,
                StandardColor.PURPLE_LIGHT2,
            ),
        )

        title = chart_doc.get_title()
        if title is None:
            raise ValueError("Title not found")

        title.style_area_color(StandardColor.DEFAULT_BLUE)

        Lo.delay(1_000)
        doc.close()
    return 0

if __name__ == "__main__":
    SystemExit(main())

Color

The style_area_color() method is called to set the background color of a Chart Title or Subtitle.

Before formatting the chart is seen in Fig. 832.

Apply to a Title

# ... other code
title.style_area_color(StandardColor.DEFAULT_BLUE)

The results are seen in Fig. 613 and Fig. 614.

Chart with Title Area Color set

Fig. 613 Chart with Title Area Color set

Chart Title Color Dialog

Fig. 614 Chart Title Color Dialog

Apply to a Subtitle

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_color(StandardColor.DEFAULT_BLUE)

The results are seen in Fig. 615.

Chart with Subtitle Area Color set

Fig. 615 Chart with Subtitle Area Color set

Gradient

The ooodev.format.chart2.direct.title.area.Gradient class is used to set the Title/Subtitle gradient of a Chart.

Before formatting the chart is seen in Fig. 832.

Gradient from preset

Apply the preset gradient

The style_area_gradient_from_preset() method is called to set the background gradient of a Chart Title or Subtitle.

The PresetGradientKind enum is used to select the preset gradient.

Apply to Title
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind

# ... other code
title = chart_doc.get_title()
if title is None:
    raise ValueError("Title not found")

title.style_area_gradient_from_preset(
    preset=PresetGradientKind.PASTEL_DREAM,
)

The results are seen in Fig. 616 and Fig. 617.

Chart with gradient Title

Fig. 616 Chart with gradient Title

Chart Title Gradient Dialog

Fig. 617 Chart Title Gradient Dialog

Apply to Subtitle
from ooodev.format.inner.preset.preset_gradient import PresetGradientKind

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_gradient_from_preset(
    preset=PresetGradientKind.PASTEL_DREAM,
)

The results are seen in Fig. 618.

Chart with gradient Title

Fig. 618 Chart with gradient Title

Apply a custom Gradient

The style_area_gradient() method is called to set the background gradient of a Chart Title or Subtitle.

Apply to Title

from ooodev.utils.data_type.color_range import ColorRange
from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.utils.color import StandardColor

# ... other code
title = chart_doc.get_title()
if title is None:
    raise ValueError("Title not found")

title.style_area_gradient(
    step_count=64,
    style=GradientStyle.SQUARE,
    angle=45,
    grad_color=ColorRange(StandardColor.PURPLE_LIGHT2, StandardColor.BLUE_DARK1),
)

The results are seen in Fig. 619 and Fig. 620.

Chart with gradient Title

Fig. 619 Chart with gradient Title

Chart Title Gradient Dialog

Fig. 620 Chart Title Gradient Dialog

Apply to Subtitle

from ooodev.utils.data_type.color_range import ColorRange
from ooo.dyn.awt.gradient_style import GradientStyle
from ooodev.utils.color import StandardColor

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_gradient(
    step_count=64,
    style=GradientStyle.SQUARE,
    angle=45,
    grad_color=ColorRange(StandardColor.PURPLE_LIGHT2, StandardColor.BLUE_DARK1),
)

The results are seen in Fig. 621.

Chart with gradient Title

Fig. 621 Chart with gradient Title

Image

The style_area_image_from_preset() method is called to set the background image of a Chart Title or Subtitle.

Before formatting the chart is seen in Fig. 832.

Apply image

The PresetImageKind enum is used to select an image preset.

Apply to Title

from ooodev.format.inner.preset.preset_image import PresetImageKind
# ... other code

title = chart_doc.get_title()
if title is None:
    raise ValueError("Title not found")

title.style_area_image_from_preset(
    preset=PresetImageKind.SPACE,
)

The results are seen in Fig. 622 and Fig. 623.

Chart with Title Image

Fig. 622 Chart with Title Image

Chart Title Image Dialog

Fig. 623 Chart Title Image Dialog

Apply to Subtitle

from ooodev.format.inner.preset.preset_image import PresetImageKind

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_image_from_preset(
    preset=PresetImageKind.SPACE,
)

The results are seen in Fig. 624.

Chart with Title Image

Fig. 624 Chart with Title Image

Pattern

The style_area_pattern_from_preset() method is called to set the background pattern of a Chart Title or Subtitle.

Before formatting the chart is seen in Fig. 832.

The PresetPatternKind enum is used to select a pattern preset.

Apply to Title

from ooodev.format.inner.preset.preset_pattern import PresetPatternKind

# ... other code
title = chart_doc.get_title()
if title is None:
    raise ValueError("Title not found")

title.style_area_pattern_from_preset(
    preset=PresetPatternKind.HORIZONTAL_BRICK,
)

The results are seen in Fig. 625 and Fig. 626.

Chart with Title pattern

Fig. 625 Chart with Title pattern

Chart Title Pattern Dialog

Fig. 626 Chart Title Pattern Dialog

Apply to Subtitle

from ooodev.format.inner.preset.preset_pattern import PresetPatternKind

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_pattern_from_preset(
    preset=PresetPatternKind.HORIZONTAL_BRICK,
)

The results are seen in Fig. 627.

Chart with Subtitle pattern

Fig. 627 Chart with Subtitle pattern

Hatch

The style_area_hatch_from_preset() method is called to set the background hatch of a Chart Title or Subtitle.

Before formatting the chart is seen in Fig. 832.

The PresetHatchKind enum is used to select a hatch preset.

Apply to Title

from ooodev.format.inner.preset.preset_hatch import PresetHatchKind

# ... other code
title = chart_doc.get_title()
if title is None:
    raise ValueError("Title not found")

title.style_area_hatch_from_preset(
    preset=PresetHatchKind.YELLOW_45_DEGREES_CROSSED,
)

The results are seen in Fig. 628 and Fig. 629.

Chart with Title hatch

Fig. 628 Chart with Title hatch

Chart Title Hatch Dialog

Fig. 629 Chart Title Hatch Dialog

Apply to Subtitle

from ooodev.format.inner.preset.preset_hatch import PresetHatchKind

# ... other code
sub_title = chart_doc.first_diagram.get_title()
if sub_title is None:
    raise ValueError("Title not found")

sub_title.style_area_hatch_from_preset(
    preset=PresetHatchKind.YELLOW_45_DEGREES_CROSSED,
)

The results are seen in Fig. 630.

Chart with Title hatch

Fig. 630 Chart with Title hatch