area_chart.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Set,
  6. Bool,
  7. Integer,
  8. Sequence,
  9. Alias,
  10. )
  11. from openpyxl.descriptors.excel import ExtensionList
  12. from openpyxl.descriptors.nested import (
  13. NestedMinMax,
  14. NestedSet,
  15. NestedBool,
  16. )
  17. from ._chart import ChartBase
  18. from .descriptors import NestedGapAmount
  19. from .axis import TextAxis, NumericAxis, SeriesAxis, ChartLines
  20. from .label import DataLabelList
  21. from .series import Series
  22. class _AreaChartBase(ChartBase):
  23. grouping = NestedSet(values=(['percentStacked', 'standard', 'stacked']))
  24. varyColors = NestedBool(nested=True, allow_none=True)
  25. ser = Sequence(expected_type=Series, allow_none=True)
  26. dLbls = Typed(expected_type=DataLabelList, allow_none=True)
  27. dataLabels = Alias("dLbls")
  28. dropLines = Typed(expected_type=ChartLines, allow_none=True)
  29. _series_type = "area"
  30. __elements__ = ('grouping', 'varyColors', 'ser', 'dLbls', 'dropLines')
  31. def __init__(self,
  32. grouping="standard",
  33. varyColors=None,
  34. ser=(),
  35. dLbls=None,
  36. dropLines=None,
  37. ):
  38. self.grouping = grouping
  39. self.varyColors = varyColors
  40. self.ser = ser
  41. self.dLbls = dLbls
  42. self.dropLines = dropLines
  43. super().__init__()
  44. class AreaChart(_AreaChartBase):
  45. tagname = "areaChart"
  46. grouping = _AreaChartBase.grouping
  47. varyColors = _AreaChartBase.varyColors
  48. ser = _AreaChartBase.ser
  49. dLbls = _AreaChartBase.dLbls
  50. dropLines = _AreaChartBase.dropLines
  51. # chart properties actually used by containing classes
  52. x_axis = Typed(expected_type=TextAxis)
  53. y_axis = Typed(expected_type=NumericAxis)
  54. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  55. __elements__ = _AreaChartBase.__elements__ + ('axId',)
  56. def __init__(self,
  57. axId=None,
  58. extLst=None,
  59. **kw
  60. ):
  61. self.x_axis = TextAxis()
  62. self.y_axis = NumericAxis()
  63. super().__init__(**kw)
  64. class AreaChart3D(AreaChart):
  65. tagname = "area3DChart"
  66. grouping = _AreaChartBase.grouping
  67. varyColors = _AreaChartBase.varyColors
  68. ser = _AreaChartBase.ser
  69. dLbls = _AreaChartBase.dLbls
  70. dropLines = _AreaChartBase.dropLines
  71. gapDepth = NestedGapAmount()
  72. x_axis = Typed(expected_type=TextAxis)
  73. y_axis = Typed(expected_type=NumericAxis)
  74. z_axis = Typed(expected_type=SeriesAxis, allow_none=True)
  75. __elements__ = AreaChart.__elements__ + ('gapDepth', )
  76. def __init__(self, gapDepth=None, **kw):
  77. self.gapDepth = gapDepth
  78. super(AreaChart3D, self).__init__(**kw)
  79. self.x_axis = TextAxis()
  80. self.y_axis = NumericAxis()
  81. self.z_axis = SeriesAxis()