label.py 4.1 KB

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