pie_chart.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #Autogenerated schema
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Bool,
  6. MinMax,
  7. Integer,
  8. NoneSet,
  9. Float,
  10. Alias,
  11. Sequence,
  12. )
  13. from openpyxl.descriptors.excel import ExtensionList, Percentage
  14. from openpyxl.descriptors.nested import (
  15. NestedBool,
  16. NestedMinMax,
  17. NestedInteger,
  18. NestedFloat,
  19. NestedNoneSet,
  20. NestedSet,
  21. )
  22. from openpyxl.descriptors.sequence import ValueSequence
  23. from ._chart import ChartBase
  24. from .axis import ChartLines
  25. from .descriptors import NestedGapAmount
  26. from .series import Series
  27. from .label import DataLabelList
  28. class _PieChartBase(ChartBase):
  29. varyColors = NestedBool(allow_none=True)
  30. ser = Sequence(expected_type=Series, allow_none=True)
  31. dLbls = Typed(expected_type=DataLabelList, allow_none=True)
  32. dataLabels = Alias("dLbls")
  33. _series_type = "pie"
  34. __elements__ = ('varyColors', 'ser', 'dLbls')
  35. def __init__(self,
  36. varyColors=True,
  37. ser=(),
  38. dLbls=None,
  39. ):
  40. self.varyColors = varyColors
  41. self.ser = ser
  42. self.dLbls = dLbls
  43. super(_PieChartBase, self).__init__()
  44. class PieChart(_PieChartBase):
  45. tagname = "pieChart"
  46. varyColors = _PieChartBase.varyColors
  47. ser = _PieChartBase.ser
  48. dLbls = _PieChartBase.dLbls
  49. firstSliceAng = NestedMinMax(min=0, max=360)
  50. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  51. __elements__ = _PieChartBase.__elements__ + ('firstSliceAng', )
  52. def __init__(self,
  53. firstSliceAng=0,
  54. extLst=None,
  55. **kw
  56. ):
  57. self.firstSliceAng = firstSliceAng
  58. super(PieChart, self).__init__(**kw)
  59. class PieChart3D(_PieChartBase):
  60. tagname = "pie3DChart"
  61. varyColors = _PieChartBase.varyColors
  62. ser = _PieChartBase.ser
  63. dLbls = _PieChartBase.dLbls
  64. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  65. __elements__ = _PieChartBase.__elements__
  66. class DoughnutChart(_PieChartBase):
  67. tagname = "doughnutChart"
  68. varyColors = _PieChartBase.varyColors
  69. ser = _PieChartBase.ser
  70. dLbls = _PieChartBase.dLbls
  71. firstSliceAng = NestedMinMax(min=0, max=360)
  72. holeSize = NestedMinMax(min=1, max=90, allow_none=True)
  73. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  74. __elements__ = _PieChartBase.__elements__ + ('firstSliceAng', 'holeSize')
  75. def __init__(self,
  76. firstSliceAng=0,
  77. holeSize=10,
  78. extLst=None,
  79. **kw
  80. ):
  81. self.firstSliceAng = firstSliceAng
  82. self.holeSize = holeSize
  83. super(DoughnutChart, self).__init__(**kw)
  84. class CustomSplit(Serialisable):
  85. tagname = "custSplit"
  86. secondPiePt = ValueSequence(expected_type=int)
  87. __elements__ = ('secondPiePt',)
  88. def __init__(self,
  89. secondPiePt=(),
  90. ):
  91. self.secondPiePt = secondPiePt
  92. class ProjectedPieChart(_PieChartBase):
  93. """
  94. From the spec 21.2.2.126
  95. This element contains the pie of pie or bar of pie series on this
  96. chart. Only the first series shall be displayed. The splitType element
  97. shall determine whether the splitPos and custSplit elements apply.
  98. """
  99. tagname = "ofPieChart"
  100. varyColors = _PieChartBase.varyColors
  101. ser = _PieChartBase.ser
  102. dLbls = _PieChartBase.dLbls
  103. ofPieType = NestedSet(values=(['pie', 'bar']))
  104. type = Alias('ofPieType')
  105. gapWidth = NestedGapAmount()
  106. splitType = NestedNoneSet(values=(['auto', 'cust', 'percent', 'pos', 'val']))
  107. splitPos = NestedFloat(allow_none=True)
  108. custSplit = Typed(expected_type=CustomSplit, allow_none=True)
  109. secondPieSize = NestedMinMax(min=5, max=200, allow_none=True)
  110. serLines = Typed(expected_type=ChartLines, allow_none=True)
  111. join_lines = Alias('serLines')
  112. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  113. __elements__ = _PieChartBase.__elements__ + ('ofPieType', 'gapWidth',
  114. 'splitType', 'splitPos', 'custSplit', 'secondPieSize', 'serLines')
  115. def __init__(self,
  116. ofPieType="pie",
  117. gapWidth=None,
  118. splitType="auto",
  119. splitPos=None,
  120. custSplit=None,
  121. secondPieSize=75,
  122. serLines=None,
  123. extLst=None,
  124. **kw
  125. ):
  126. self.ofPieType = ofPieType
  127. self.gapWidth = gapWidth
  128. self.splitType = splitType
  129. self.splitPos = splitPos
  130. self.custSplit = custSplit
  131. self.secondPieSize = secondPieSize
  132. if serLines is None:
  133. self.serLines = ChartLines()
  134. super(ProjectedPieChart, self).__init__(**kw)