_3d.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors import Typed, Alias
  3. from openpyxl.descriptors.serialisable import Serialisable
  4. from openpyxl.descriptors.nested import (
  5. NestedBool,
  6. NestedInteger,
  7. NestedMinMax,
  8. )
  9. from openpyxl.descriptors.excel import ExtensionList
  10. from .marker import PictureOptions
  11. from .shapes import GraphicalProperties
  12. class View3D(Serialisable):
  13. tagname = "view3D"
  14. rotX = NestedMinMax(min=-90, max=90, allow_none=True)
  15. x_rotation = Alias('rotX')
  16. hPercent = NestedMinMax(min=5, max=500, allow_none=True)
  17. height_percent = Alias('hPercent')
  18. rotY = NestedInteger(min=-90, max=90, allow_none=True)
  19. y_rotation = Alias('rotY')
  20. depthPercent = NestedInteger(allow_none=True)
  21. rAngAx = NestedBool(allow_none=True)
  22. right_angle_axes = Alias('rAngAx')
  23. perspective = NestedInteger(allow_none=True)
  24. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  25. __elements__ = ('rotX', 'hPercent', 'rotY', 'depthPercent', 'rAngAx',
  26. 'perspective',)
  27. def __init__(self,
  28. rotX=15,
  29. hPercent=None,
  30. rotY=20,
  31. depthPercent=None,
  32. rAngAx=True,
  33. perspective=None,
  34. extLst=None,
  35. ):
  36. self.rotX = rotX
  37. self.hPercent = hPercent
  38. self.rotY = rotY
  39. self.depthPercent = depthPercent
  40. self.rAngAx = rAngAx
  41. self.perspective = perspective
  42. class Surface(Serialisable):
  43. tagname = "surface"
  44. thickness = NestedInteger(allow_none=True)
  45. spPr = Typed(expected_type=GraphicalProperties, allow_none=True)
  46. graphicalProperties = Alias('spPr')
  47. pictureOptions = Typed(expected_type=PictureOptions, allow_none=True)
  48. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  49. __elements__ = ('thickness', 'spPr', 'pictureOptions',)
  50. def __init__(self,
  51. thickness=None,
  52. spPr=None,
  53. pictureOptions=None,
  54. extLst=None,
  55. ):
  56. self.thickness = thickness
  57. self.spPr = spPr
  58. self.pictureOptions = pictureOptions
  59. class _3DBase(Serialisable):
  60. """
  61. Base class for 3D charts
  62. """
  63. tagname = "ChartBase"
  64. view3D = Typed(expected_type=View3D, allow_none=True)
  65. floor = Typed(expected_type=Surface, allow_none=True)
  66. sideWall = Typed(expected_type=Surface, allow_none=True)
  67. backWall = Typed(expected_type=Surface, allow_none=True)
  68. def __init__(self,
  69. view3D=None,
  70. floor=None,
  71. sideWall=None,
  72. backWall=None,
  73. ):
  74. if view3D is None:
  75. view3D = View3D()
  76. self.view3D = view3D
  77. if floor is None:
  78. floor = Surface()
  79. self.floor = floor
  80. if sideWall is None:
  81. sideWall = Surface()
  82. self.sideWall = sideWall
  83. if backWall is None:
  84. backWall = Surface()
  85. self.backWall = backWall
  86. super(_3DBase, self).__init__()