_3d.py 3.1 KB

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