-
-
Notifications
You must be signed in to change notification settings - Fork 318
/
chart.py
59 lines (51 loc) · 2.25 KB
/
chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from office365.entity import Entity
from office365.onedrive.workbooks.charts.axes import WorkbookChartAxes
from office365.onedrive.workbooks.charts.data_labels import WorkbookChartDataLabels
from office365.runtime.paths.resource_path import ResourcePath
from office365.runtime.queries.service_operation import ServiceOperationQuery
class WorkbookChart(Entity):
"""Represents a chart object in a workbook."""
def set_position(self, startCell, endCell):
"""Positions the chart relative to cells on the worksheet.
:param str startCell: The start cell. It is where the chart is moved to. The start cell is the top-left or
top-right cell, depending on the user's right-to-left display settings.
:param str endCell: The end cell. If specified, the chart's width and height is set to fully cover up
this cell/range.
"""
payload = {"startCell": startCell, "endCell": endCell}
qry = ServiceOperationQuery(self, "setPosition", None, payload)
self.context.add_query(qry)
return self
@property
def axes(self):
"""Represents chart axes."""
return self.properties.get(
"protection",
WorkbookChartAxes(self.context, ResourcePath("axes", self.resource_path)),
)
@property
def data_labels(self):
"""Represents the datalabels on the chart."""
return self.properties.get(
"dataLabels",
WorkbookChartDataLabels(
self.context, ResourcePath("dataLabels", self.resource_path)
),
)
@property
def worksheet(self):
"""The worksheet containing the current chart."""
from office365.onedrive.workbooks.worksheets.worksheet import WorkbookWorksheet
return self.properties.get(
"worksheet",
WorkbookWorksheet(
self.context, ResourcePath("worksheet", self.resource_path)
),
)
def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"dataLabels": self.data_labels,
}
default_value = property_mapping.get(name, None)
return super(WorkbookChart, self).get_property(name, default_value)