Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/xlsxwriter/chart_line.py: 15%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1###############################################################################
2#
3# ChartLine - A class for writing the Excel XLSX Line charts.
4#
5# SPDX-License-Identifier: BSD-2-Clause
6# Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7#
9from . import chart
12class ChartLine(chart.Chart):
13 """
14 A class for writing the Excel XLSX Line charts.
17 """
19 ###########################################################################
20 #
21 # Public API.
22 #
23 ###########################################################################
25 def __init__(self, options=None):
26 """
27 Constructor.
29 """
30 super(ChartLine, self).__init__()
32 if options is None:
33 options = {}
35 self.subtype = options.get("subtype")
37 if not self.subtype:
38 self.subtype = "standard"
40 self.default_marker = {"type": "none"}
41 self.smooth_allowed = True
43 # Override and reset the default axis values.
44 if self.subtype == "percent_stacked":
45 self.y_axis["defaults"]["num_format"] = "0%"
47 # Set the available data label positions for this chart type.
48 self.label_position_default = "right"
49 self.label_positions = {
50 "center": "ctr",
51 "right": "r",
52 "left": "l",
53 "above": "t",
54 "below": "b",
55 # For backward compatibility.
56 "top": "t",
57 "bottom": "b",
58 }
60 self.set_y_axis({})
62 ###########################################################################
63 #
64 # Private API.
65 #
66 ###########################################################################
68 def _write_chart_type(self, args):
69 # Override the virtual superclass method with a chart specific method.
70 # Write the c:lineChart element.
71 self._write_line_chart(args)
73 ###########################################################################
74 #
75 # XML methods.
76 #
77 ###########################################################################
79 def _write_line_chart(self, args):
80 # Write the <c:lineChart> element.
82 if args["primary_axes"]:
83 series = self._get_primary_axes_series()
84 else:
85 series = self._get_secondary_axes_series()
87 if not len(series):
88 return
90 subtype = self.subtype
92 if subtype == "percent_stacked":
93 subtype = "percentStacked"
95 self._xml_start_tag("c:lineChart")
97 # Write the c:grouping element.
98 self._write_grouping(subtype)
100 # Write the series elements.
101 for data in series:
102 self._write_ser(data)
104 # Write the c:dropLines element.
105 self._write_drop_lines()
107 # Write the c:hiLowLines element.
108 self._write_hi_low_lines()
110 # Write the c:upDownBars element.
111 self._write_up_down_bars()
113 # Write the c:marker element.
114 self._write_marker_value()
116 # Write the c:axId elements
117 self._write_axis_ids(args)
119 self._xml_end_tag("c:lineChart")
121 def _write_d_pt_point(self, index, point):
122 # Write an individual <c:dPt> element. Override the parent method to
123 # add markers.
125 self._xml_start_tag("c:dPt")
127 # Write the c:idx element.
128 self._write_idx(index)
130 self._xml_start_tag("c:marker")
132 # Write the c:spPr element.
133 self._write_sp_pr(point)
135 self._xml_end_tag("c:marker")
137 self._xml_end_tag("c:dPt")
139 def _write_marker_value(self):
140 # Write the <c:marker> element without a sub-element.
141 attributes = [("val", 1)]
143 self._xml_empty_tag("c:marker", attributes)