minmaxareagraph.py (4690B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\graphs\minmaxareagraph.py 2 import carbonui.const as uiconst 3 from carbonui.primitives.fill import Fill 4 from carbonui.primitives.polygon import Polygon 5 from carbonui.graphs.axis import AxisOrientation 6 from carbonui.graphs import animations 7 from carbonui.uicore import uicore 8 9 class MinMaxAreaGraph(Polygon): 10 default_name = 'MinMaxAreaGraph' 11 default_align = uiconst.TOPLEFT 12 default_state = uiconst.UI_NORMAL 13 default_graphColor = (1, 1, 1, 0.2) 14 default_hoverColor = (1, 1, 1, 1) 15 16 def ApplyAttributes(self, attributes): 17 Polygon.ApplyAttributes(self, attributes) 18 self._categoryAxis = attributes['categoryAxis'] 19 self._valueAxis = attributes['valueAxis'] 20 self._orientation = attributes.get('orientation', AxisOrientation.VERTICAL) 21 self._categoryAxis.onChange.connect(self._AxisChanged) 22 self._valueAxis.onChange.connect(self._AxisChanged) 23 self._values = attributes['values'] 24 self._vertices = None 25 self.graphColor = attributes.get('graphColor', self.default_graphColor) 26 self.hoverColor = attributes.get('hoverColor', self.default_hoverColor) 27 self._locked = False 28 self._dirty = False 29 self._originalColor = self.color 30 self._animation = None 31 self._Build() 32 33 def GetLegendItem(self): 34 return Fill(name='legendVolume', color=self.graphColor, align=uiconst.TOLEFT) 35 36 def Animate(self, animationType, animationDynamics, duration): 37 self.CancelAnimation() 38 self._animation = animations.CreateAnimation(self, self._categoryAxis, self._valueAxis, self._orientation, animationType, animationDynamics, duration, 2) 39 40 def CancelAnimation(self, applyLastFrame = True): 41 self.StopAnimations() 42 self.opacity = 1.0 43 if self._animation: 44 self._animation.Cancel(applyLastFrame) 45 self._animation = None 46 47 def Close(self): 48 self.CancelAnimation(False) 49 super(MinMaxAreaGraph, self).Close() 50 self._categoryAxis.onChange.disconnect(self._AxisChanged) 51 self._valueAxis.onChange.disconnect(self._AxisChanged) 52 53 def _Build(self): 54 positions = self._GetVertexPositions() 55 self.AppendVertices(positions, self._GetTransform(), self.graphColor) 56 triangles = [] 57 for i in xrange(len(self._categoryAxis.GetDataPoints()) - 1): 58 i2 = i * 2 59 triangles.append((i2, i2 + 1, i2 + 2)) 60 triangles.append((i2 + 1, i2 + 3, i2 + 2)) 61 62 self.renderObject.AppendTriangles(triangles) 63 64 def _GetTransform(self): 65 dpiScaling = uicore.desktop.dpiScaling 66 transform = ((1, 0, 0), (0, 1, 0), (0, 0, 1)) 67 if self._orientation == AxisOrientation.VERTICAL: 68 transform = self._categoryAxis.UpdateToViewportTransform(transform, 0, dpiScaling) 69 transform = self._valueAxis.UpdateToViewportTransform(transform, 1, dpiScaling) 70 else: 71 transform = self._categoryAxis.UpdateToViewportTransform(transform, 1, dpiScaling) 72 transform = self._valueAxis.UpdateToViewportTransform(transform, 0, dpiScaling) 73 return transform 74 75 def _GetVertexPositions(self): 76 if self._vertices: 77 return self._vertices 78 positions = [] 79 if self._orientation == AxisOrientation.VERTICAL: 80 for x, value in zip(xrange(len(self._categoryAxis.GetDataPoints())), self._values): 81 positions.append((x, value[1])) 82 positions.append((x, value[0])) 83 84 else: 85 for x, value in zip(xrange(len(self._categoryAxis.GetDataPoints())), self._values): 86 positions.append((value[1], x)) 87 positions.append((value[0], x)) 88 89 self._vertices = positions 90 return positions 91 92 def _AxisChanged(self, _): 93 if self._locked: 94 self._dirty = True 95 else: 96 self._Rescale() 97 98 def LockGraphUpdates(self): 99 self._locked = True 100 101 def UnlockGraphUpdates(self): 102 if self._locked: 103 self._locked = False 104 if self._dirty: 105 self._Rescale() 106 107 def _Rescale(self): 108 self.CancelAnimation(False) 109 self._dirty = False 110 self.renderObject.SetVertices(self._GetVertexPositions(), self._GetTransform()) 111 112 def CancelAnimations(self): 113 self.StopAnimations() 114 self.opacity = 1.0 115 116 def OnMouseEnter(self, *args): 117 self._originalColor = self.color.GetRGBA() 118 self.color = self.hoverColor 119 120 def OnMouseExit(self, *args): 121 self.color = self._originalColor