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)
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.
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,
)
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.
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),
)
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.
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,
)
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.
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,
)
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.
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,
)
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.