1###############################################################################
2#
3# ChartRadar - A class for writing the Excel XLSX Radar 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 ChartRadar(chart.Chart):
13 """
14 A class for writing the Excel XLSX Radar 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(ChartRadar, 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 = "marker"
39 self.default_marker = {"type": "none"}
40
41 # Override and reset the default axis values.
42 self.x_axis["defaults"]["major_gridlines"] = {"visible": 1}
43 self.set_x_axis({})
44
45 # Set the available data label positions for this chart type.
46 self.label_position_default = "center"
47 self.label_positions = {"center": "ctr"}
48
49 # Hardcode major_tick_mark for now until there is an accessor.
50 self.y_axis["major_tick_mark"] = "cross"
51
52 ###########################################################################
53 #
54 # Private API.
55 #
56 ###########################################################################
57
58 def _write_chart_type(self, args):
59 # Write the c:radarChart element.
60 self._write_radar_chart(args)
61
62 ###########################################################################
63 #
64 # XML methods.
65 #
66 ###########################################################################
67
68 def _write_radar_chart(self, args):
69 # Write the <c:radarChart> element.
70
71 if args["primary_axes"]:
72 series = self._get_primary_axes_series()
73 else:
74 series = self._get_secondary_axes_series()
75
76 if not len(series):
77 return
78
79 self._xml_start_tag("c:radarChart")
80
81 # Write the c:radarStyle element.
82 self._write_radar_style()
83
84 # Write the series elements.
85 for data in series:
86 self._write_ser(data)
87
88 # Write the c:axId elements
89 self._write_axis_ids(args)
90
91 self._xml_end_tag("c:radarChart")
92
93 def _write_radar_style(self):
94 # Write the <c:radarStyle> element.
95 val = "marker"
96
97 if self.subtype == "filled":
98 val = "filled"
99
100 attributes = [("val", val)]
101
102 self._xml_empty_tag("c:radarStyle", attributes)