Source code

Download source archive ↓

src/openpyxl/chart/label.py

1# Copyright (c) 2010-2024 openpyxl
2
3from openpyxl.descriptors.serialisable import Serialisable
4from openpyxl.descriptors import (
5    Sequence,
6    Alias,
7    Typed
8)
9from openpyxl.descriptors.excel import ExtensionList
10from openpyxl.descriptors.nested import (
11    NestedNoneSet,
12    NestedBool,
13    NestedString,
14    NestedInteger,
15    )
16
17from .shapes import GraphicalProperties
18from .text import RichText
19
20
21class _DataLabelBase(Serialisable):
22
23    numFmt = NestedString(allow_none=True, attribute="formatCode")
24    spPr = Typed(expected_type=GraphicalProperties, allow_none=True)
25    graphicalProperties = Alias('spPr')
26    txPr = Typed(expected_type=RichText, allow_none=True)
27    textProperties = Alias('txPr')
28    dLblPos = NestedNoneSet(values=['bestFit', 'b', 'ctr', 'inBase', 'inEnd',
29                                    'l', 'outEnd', 'r', 't'])
30    position = Alias('dLblPos')
31    showLegendKey = NestedBool(allow_none=True)
32    showVal = NestedBool(allow_none=True)
33    showCatName = NestedBool(allow_none=True)
34    showSerName = NestedBool(allow_none=True)
35    showPercent = NestedBool(allow_none=True)
36    showBubbleSize = NestedBool(allow_none=True)
37    showLeaderLines = NestedBool(allow_none=True)
38    separator = NestedString(allow_none=True)
39    extLst = Typed(expected_type=ExtensionList, allow_none=True)
40
41    __elements__ = ("numFmt", "spPr", "txPr", "dLblPos", "showLegendKey",
42                    "showVal", "showCatName", "showSerName", "showPercent", "showBubbleSize",
43                    "showLeaderLines", "separator")
44
45    def __init__(self,
46                 numFmt=None,
47                 spPr=None,
48                 txPr=None,
49                 dLblPos=None,
50                 showLegendKey=None,
51                 showVal=None,
52                 showCatName=None,
53                 showSerName=None,
54                 showPercent=None,
55                 showBubbleSize=None,
56                 showLeaderLines=None,
57                 separator=None,
58                 extLst=None,
59                 ):
60        self.numFmt = numFmt
61        self.spPr = spPr
62        self.txPr = txPr
63        self.dLblPos = dLblPos
64        self.showLegendKey = showLegendKey
65        self.showVal = showVal
66        self.showCatName = showCatName
67        self.showSerName = showSerName
68        self.showPercent = showPercent
69        self.showBubbleSize = showBubbleSize
70        self.showLeaderLines = showLeaderLines
71        self.separator = separator
72
73
74class DataLabel(_DataLabelBase):
75
76    tagname = "dLbl"
77
78    idx = NestedInteger()
79
80    numFmt = _DataLabelBase.numFmt
81    spPr = _DataLabelBase.spPr
82    txPr = _DataLabelBase.txPr
83    dLblPos = _DataLabelBase.dLblPos
84    showLegendKey = _DataLabelBase.showLegendKey
85    showVal = _DataLabelBase.showVal
86    showCatName = _DataLabelBase.showCatName
87    showSerName = _DataLabelBase.showSerName
88    showPercent = _DataLabelBase.showPercent
89    showBubbleSize = _DataLabelBase.showBubbleSize
90    showLeaderLines = _DataLabelBase.showLeaderLines
91    separator = _DataLabelBase.separator
92    extLst = _DataLabelBase.extLst
93
94    __elements__ = ("idx",)  + _DataLabelBase.__elements__
95
96    def __init__(self, idx=0, **kw ):
97        self.idx = idx
98        super().__init__(**kw)
99
100
101class DataLabelList(_DataLabelBase):
102
103    tagname = "dLbls"
104
105    dLbl = Sequence(expected_type=DataLabel, allow_none=True)
106
107    delete = NestedBool(allow_none=True)
108    numFmt = _DataLabelBase.numFmt
109    spPr = _DataLabelBase.spPr
110    txPr = _DataLabelBase.txPr
111    dLblPos = _DataLabelBase.dLblPos
112    showLegendKey = _DataLabelBase.showLegendKey
113    showVal = _DataLabelBase.showVal
114    showCatName = _DataLabelBase.showCatName
115    showSerName = _DataLabelBase.showSerName
116    showPercent = _DataLabelBase.showPercent
117    showBubbleSize = _DataLabelBase.showBubbleSize
118    showLeaderLines = _DataLabelBase.showLeaderLines
119    separator = _DataLabelBase.separator
120    extLst = _DataLabelBase.extLst
121
122    __elements__ = ("delete", "dLbl",) + _DataLabelBase.__elements__
123
124    def __init__(self, dLbl=(), delete=None,  **kw):
125        self.dLbl = dLbl
126        self.delete = delete
127        super().__init__(**kw)