1###############################################################################
2#
3# ChartArea - A class for writing the Excel XLSX Area charts.
4#
5# SPDX-License-Identifier: BSD-2-Clause
6#
7# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org
8#
9
10from typing import Any, Dict, Optional
11
12from . import chart
13
14
15class ChartArea(chart.Chart):
16 """
17 A class for writing the Excel XLSX Area charts.
18
19
20 """
21
22 ###########################################################################
23 #
24 # Public API.
25 #
26 ###########################################################################
27
28 def __init__(self, options: Optional[Dict[str, Any]] = None) -> None:
29 """
30 Constructor.
31
32 """
33 super().__init__()
34
35 if options is None:
36 options = {}
37
38 self.subtype = options.get("subtype")
39
40 if not self.subtype:
41 self.subtype = "standard"
42
43 self.cross_between = "midCat"
44 self.show_crosses = False
45
46 # Override and reset the default axis values.
47 if self.subtype == "percent_stacked":
48 self.y_axis["defaults"]["num_format"] = "0%"
49
50 # Set the available data label positions for this chart type.
51 self.label_position_default = "center"
52 self.label_positions = {"center": "ctr"}
53
54 self.set_y_axis({})
55
56 ###########################################################################
57 #
58 # Private API.
59 #
60 ###########################################################################
61
62 def _write_chart_type(self, args) -> None:
63 # Override the virtual superclass method with a chart specific method.
64 # Write the c:areaChart element.
65 self._write_area_chart(args)
66
67 ###########################################################################
68 #
69 # XML methods.
70 #
71 ###########################################################################
72 #
73 def _write_area_chart(self, args) -> None:
74 # Write the <c:areaChart> element.
75
76 if args["primary_axes"]:
77 series = self._get_primary_axes_series()
78 else:
79 series = self._get_secondary_axes_series()
80
81 if not series:
82 return
83
84 subtype = self.subtype
85
86 if subtype == "percent_stacked":
87 subtype = "percentStacked"
88
89 self._xml_start_tag("c:areaChart")
90
91 # Write the c:grouping element.
92 self._write_grouping(subtype)
93
94 # Write the series elements.
95 for data in series:
96 self._write_ser(data)
97
98 # Write the c:dropLines element.
99 self._write_drop_lines()
100
101 # Write the c:axId elements
102 self._write_axis_ids(args)
103
104 self._xml_end_tag("c:areaChart")