surface_chart.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Integer,
  6. Bool,
  7. Alias,
  8. Sequence,
  9. )
  10. from openpyxl.descriptors.excel import ExtensionList
  11. from openpyxl.descriptors.nested import (
  12. NestedInteger,
  13. NestedBool,
  14. )
  15. from ._chart import ChartBase
  16. from ._3d import _3DBase
  17. from .axis import TextAxis, NumericAxis, SeriesAxis
  18. from .shapes import GraphicalProperties
  19. from .series import Series
  20. class BandFormat(Serialisable):
  21. tagname = "bandFmt"
  22. idx = NestedInteger()
  23. spPr = Typed(expected_type=GraphicalProperties, allow_none=True)
  24. graphicalProperties = Alias("spPr")
  25. __elements__ = ('idx', 'spPr')
  26. def __init__(self,
  27. idx=0,
  28. spPr=None,
  29. ):
  30. self.idx = idx
  31. self.spPr = spPr
  32. class BandFormatList(Serialisable):
  33. tagname = "bandFmts"
  34. bandFmt = Sequence(expected_type=BandFormat, allow_none=True)
  35. __elements__ = ('bandFmt',)
  36. def __init__(self,
  37. bandFmt=(),
  38. ):
  39. self.bandFmt = bandFmt
  40. class _SurfaceChartBase(ChartBase):
  41. wireframe = NestedBool(allow_none=True)
  42. ser = Sequence(expected_type=Series, allow_none=True)
  43. bandFmts = Typed(expected_type=BandFormatList, allow_none=True)
  44. _series_type = "surface"
  45. __elements__ = ('wireframe', 'ser', 'bandFmts')
  46. def __init__(self,
  47. wireframe=None,
  48. ser=(),
  49. bandFmts=None,
  50. **kw
  51. ):
  52. self.wireframe = wireframe
  53. self.ser = ser
  54. self.bandFmts = bandFmts
  55. super().__init__(**kw)
  56. class SurfaceChart3D(_SurfaceChartBase, _3DBase):
  57. tagname = "surface3DChart"
  58. wireframe = _SurfaceChartBase.wireframe
  59. ser = _SurfaceChartBase.ser
  60. bandFmts = _SurfaceChartBase.bandFmts
  61. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  62. x_axis = Typed(expected_type=TextAxis)
  63. y_axis = Typed(expected_type=NumericAxis)
  64. z_axis = Typed(expected_type=SeriesAxis)
  65. __elements__ = _SurfaceChartBase.__elements__ + ('axId',)
  66. def __init__(self, **kw):
  67. self.x_axis = TextAxis()
  68. self.y_axis = NumericAxis()
  69. self.z_axis = SeriesAxis()
  70. super(SurfaceChart3D, self).__init__(**kw)
  71. class SurfaceChart(SurfaceChart3D):
  72. tagname = "surfaceChart"
  73. wireframe = _SurfaceChartBase.wireframe
  74. ser = _SurfaceChartBase.ser
  75. bandFmts = _SurfaceChartBase.bandFmts
  76. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  77. __elements__ = SurfaceChart3D.__elements__
  78. def __init__(self, **kw):
  79. super().__init__(**kw)
  80. self.y_axis.delete = True
  81. self.view3D.x_rotation = 90
  82. self.view3D.y_rotation = 0
  83. self.view3D.perspective = False
  84. self.view3D.right_angle_axes = False