NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

lowhighvaluegraph.py (5245B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\graphs\lowhighvaluegraph.py
      2 import trinity
      3 from carbonui.primitives.vectorlinetrace import VectorLineTrace
      4 import carbonui.const as uiconst
      5 from carbonui.graphs.axis import AxisOrientation
      6 from carbonui.graphs import animations
      7 from carbonui.uicore import uicore
      8 
      9 class LowHighValueGraph(VectorLineTrace):
     10     default_name = 'LowHighValueGraph'
     11     default_align = uiconst.TOPLEFT
     12     default_cornerType = 0
     13     default_spriteEffect = trinity.TR2_SFX_FILL
     14     default_lineWidth = 1.0
     15     default_lineColor = (1.0, 1.0, 1.0, 0.2)
     16 
     17     def ApplyAttributes(self, attributes):
     18         VectorLineTrace.ApplyAttributes(self, attributes)
     19         self._categoryAxis = attributes['categoryAxis']
     20         self._valueAxis = attributes['valueAxis']
     21         self._orientation = attributes.get('orientation', AxisOrientation.VERTICAL)
     22         self._categoryAxis.onChange.connect(self._AxisChanged)
     23         self._valueAxis.onChange.connect(self._AxisChanged)
     24         self._lineColor = attributes.get('lineColor', self.default_lineColor)
     25         self._values = attributes['values']
     26         self._vertices = None
     27         self._locked = False
     28         self._dirty = False
     29         self._animation = None
     30         self._Build()
     31 
     32     def GetLegendItem(self):
     33         line = VectorLineTrace(size=(10, 10), align=uiconst.TOLEFT, spriteEffect=trinity.TR2_SFX_FILL, lineWidth=3)
     34         line.AddPoints(((5, 0), (5, 10)), self._lineColor)
     35         return line
     36 
     37     def Animate(self, animationType, animationDynamics, duration):
     38         self.CancelAnimation()
     39         if animationType == animations.AnimationType.FADE:
     40             if animationDynamics == animations.AnimationDynamics.SIMULTANEOUS:
     41                 uicore.animations.MorphScalar(self, 'opacity', startVal=0.0, endVal=1.0, duration=duration)
     42             else:
     43                 raise ValueError('unsupported animation type')
     44         elif animationType == animations.AnimationType.GROW:
     45             self._animation = animations.CreateVertexAnimation(self, self._categoryAxis, self._valueAxis, self._orientation, animationDynamics, duration, 4)
     46         else:
     47             raise ValueError('unsupported animation type')
     48 
     49     def CancelAnimation(self, applyLastFrame = True):
     50         self.StopAnimations()
     51         self.opacity = 1.0
     52         if self._animation:
     53             self._animation.Cancel(applyLastFrame)
     54             self._animation = None
     55 
     56     def Close(self):
     57         self.CancelAnimation(False)
     58         super(LowHighValueGraph, self).Close()
     59         self._categoryAxis.onChange.disconnect(self._AxisChanged)
     60         self._valueAxis.onChange.disconnect(self._AxisChanged)
     61 
     62     def _Build(self):
     63         positions, colors = self._GetVertexPositions()
     64         self.AppendVertices(positions, self._GetTransform(), colors)
     65 
     66     def _GetTransform(self):
     67         dpiScaling = uicore.desktop.dpiScaling
     68         transform = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
     69         if self._orientation == AxisOrientation.VERTICAL:
     70             transform = self._categoryAxis.UpdateToViewportTransform(transform, 0, dpiScaling)
     71             transform = self._valueAxis.UpdateToViewportTransform(transform, 1, dpiScaling)
     72         else:
     73             transform = self._categoryAxis.UpdateToViewportTransform(transform, 1, dpiScaling)
     74             transform = self._valueAxis.UpdateToViewportTransform(transform, 0, dpiScaling)
     75         return transform
     76 
     77     def _GetVertexPositions(self):
     78         if self._vertices:
     79             return self._vertices
     80         positions = []
     81         if self._orientation == AxisOrientation.VERTICAL:
     82             for x, value in zip(xrange(len(self._categoryAxis.GetDataPoints())), self._values):
     83                 positions.append((x, value[1]))
     84                 positions.append((x, value[1]))
     85                 positions.append((x, value[0]))
     86                 positions.append((x, value[0]))
     87 
     88         else:
     89             for x, value in zip(xrange(len(self._categoryAxis.GetDataPoints())), self._values):
     90                 positions.append((value[1], x))
     91                 positions.append((value[1], x))
     92                 positions.append((value[0], x))
     93                 positions.append((value[0], x))
     94 
     95         colors = []
     96         color = self._lineColor
     97         clearColor = color[0:3] + (0,)
     98         for i in xrange(len(self._categoryAxis.GetDataPoints())):
     99             colors.append(clearColor)
    100             colors.append(color)
    101             colors.append(color)
    102             colors.append(clearColor)
    103 
    104         self._vertices = (positions, colors)
    105         return (positions, colors)
    106 
    107     def _AxisChanged(self, _):
    108         if self._locked:
    109             self._dirty = True
    110         else:
    111             self._Rescale()
    112 
    113     def LockGraphUpdates(self):
    114         self._locked = True
    115 
    116     def UnlockGraphUpdates(self):
    117         if self._locked:
    118             self._locked = False
    119             if self._dirty:
    120                 self._Rescale()
    121 
    122     def _Rescale(self):
    123         self.CancelAnimation(False)
    124         self._dirty = False
    125         positions, _ = self._GetVertexPositions()
    126         self.renderObject.SetVertices(positions, self._GetTransform())
    127 
    128     def CancelAnimations(self):
    129         self.StopAnimations()
    130         self.opacity = 1.0