chartspace.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. from __future__ import absolute_import
  2. # Copyright (c) 2010-2019 openpyxl
  3. """
  4. Enclosing chart object. The various chart types are actually child objects.
  5. Will probably need to call this indirectly
  6. """
  7. from openpyxl.descriptors.serialisable import Serialisable
  8. from openpyxl.descriptors import (
  9. Typed,
  10. String,
  11. Alias,
  12. )
  13. from openpyxl.descriptors.excel import (
  14. ExtensionList,
  15. Relation
  16. )
  17. from openpyxl.descriptors.nested import (
  18. NestedBool,
  19. NestedNoneSet,
  20. NestedString,
  21. NestedMinMax,
  22. )
  23. from openpyxl.descriptors.sequence import NestedSequence
  24. from openpyxl.xml.constants import CHART_NS
  25. from openpyxl.drawing.colors import ColorMapping
  26. from .text import RichText
  27. from .shapes import GraphicalProperties
  28. from .legend import Legend
  29. from ._3d import _3DBase
  30. from .plotarea import PlotArea
  31. from .title import Title
  32. from .pivot import (
  33. PivotFormat,
  34. PivotSource,
  35. )
  36. from .print_settings import PrintSettings
  37. class ChartContainer(Serialisable):
  38. tagname = "chart"
  39. title = Typed(expected_type=Title, allow_none=True)
  40. autoTitleDeleted = NestedBool(allow_none=True)
  41. pivotFmts = NestedSequence(expected_type=PivotFormat)
  42. view3D = _3DBase.view3D
  43. floor = _3DBase.floor
  44. sideWall = _3DBase.sideWall
  45. backWall = _3DBase.backWall
  46. plotArea = Typed(expected_type=PlotArea, )
  47. legend = Typed(expected_type=Legend, allow_none=True)
  48. plotVisOnly = NestedBool()
  49. dispBlanksAs = NestedNoneSet(values=(['span', 'gap', 'zero']))
  50. showDLblsOverMax = NestedBool(allow_none=True)
  51. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  52. __elements__ = ('title', 'autoTitleDeleted', 'pivotFmts', 'view3D',
  53. 'floor', 'sideWall', 'backWall', 'plotArea', 'legend', 'plotVisOnly',
  54. 'dispBlanksAs', 'showDLblsOverMax')
  55. def __init__(self,
  56. title=None,
  57. autoTitleDeleted=None,
  58. pivotFmts=(),
  59. view3D=None,
  60. floor=None,
  61. sideWall=None,
  62. backWall=None,
  63. plotArea=None,
  64. legend=None,
  65. plotVisOnly=True,
  66. dispBlanksAs="gap",
  67. showDLblsOverMax=None,
  68. extLst=None,
  69. ):
  70. self.title = title
  71. self.autoTitleDeleted = autoTitleDeleted
  72. self.pivotFmts = pivotFmts
  73. self.view3D = view3D
  74. self.floor = floor
  75. self.sideWall = sideWall
  76. self.backWall = backWall
  77. if plotArea is None:
  78. plotArea = PlotArea()
  79. self.plotArea = plotArea
  80. self.legend = legend
  81. self.plotVisOnly = plotVisOnly
  82. self.dispBlanksAs = dispBlanksAs
  83. self.showDLblsOverMax = showDLblsOverMax
  84. class Protection(Serialisable):
  85. tagname = "protection"
  86. chartObject = NestedBool(allow_none=True)
  87. data = NestedBool(allow_none=True)
  88. formatting = NestedBool(allow_none=True)
  89. selection = NestedBool(allow_none=True)
  90. userInterface = NestedBool(allow_none=True)
  91. __elements__ = ("chartObject", "data", "formatting", "selection", "userInterface")
  92. def __init__(self,
  93. chartObject=None,
  94. data=None,
  95. formatting=None,
  96. selection=None,
  97. userInterface=None,
  98. ):
  99. self.chartObject = chartObject
  100. self.data = data
  101. self.formatting = formatting
  102. self.selection = selection
  103. self.userInterface = userInterface
  104. class ExternalData(Serialisable):
  105. tagname = "externalData"
  106. autoUpdate = NestedBool(allow_none=True)
  107. id = String() # Needs namespace
  108. def __init__(self,
  109. autoUpdate=None,
  110. id=None
  111. ):
  112. self.autoUpdate = autoUpdate
  113. self.id = id
  114. class ChartSpace(Serialisable):
  115. tagname = "chartSpace"
  116. date1904 = NestedBool(allow_none=True)
  117. lang = NestedString(allow_none=True)
  118. roundedCorners = NestedBool(allow_none=True)
  119. style = NestedMinMax(allow_none=True, min=1, max=48)
  120. clrMapOvr = Typed(expected_type=ColorMapping, allow_none=True)
  121. pivotSource = Typed(expected_type=PivotSource, allow_none=True)
  122. protection = Typed(expected_type=Protection, allow_none=True)
  123. chart = Typed(expected_type=ChartContainer)
  124. spPr = Typed(expected_type=GraphicalProperties, allow_none=True)
  125. graphicalProperties = Alias("spPr")
  126. txPr = Typed(expected_type=RichText, allow_none=True)
  127. textProperties = Alias("txPr")
  128. externalData = Typed(expected_type=ExternalData, allow_none=True)
  129. printSettings = Typed(expected_type=PrintSettings, allow_none=True)
  130. userShapes = Relation()
  131. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  132. __elements__ = ('date1904', 'lang', 'roundedCorners', 'style',
  133. 'clrMapOvr', 'pivotSource', 'protection', 'chart', 'spPr', 'txPr',
  134. 'externalData', 'printSettings', 'userShapes')
  135. def __init__(self,
  136. date1904=None,
  137. lang=None,
  138. roundedCorners=None,
  139. style=None,
  140. clrMapOvr=None,
  141. pivotSource=None,
  142. protection=None,
  143. chart=None,
  144. spPr=None,
  145. txPr=None,
  146. externalData=None,
  147. printSettings=None,
  148. userShapes=None,
  149. extLst=None,
  150. ):
  151. self.date1904 = date1904
  152. self.lang = lang
  153. self.roundedCorners = roundedCorners
  154. self.style = style
  155. self.clrMapOvr = clrMapOvr
  156. self.pivotSource = pivotSource
  157. self.protection = protection
  158. self.chart = chart
  159. self.spPr = spPr
  160. self.txPr = txPr
  161. self.externalData = externalData
  162. self.printSettings = printSettings
  163. self.userShapes = userShapes
  164. def to_tree(self, tagname=None, idx=None, namespace=None):
  165. tree = super(ChartSpace, self).to_tree()
  166. tree.set("xmlns", CHART_NS)
  167. return tree