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