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

linegraph.py (4214B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\graphs\linegraph.py
      2 import carbonui.const as uiconst
      3 import trinity
      4 from carbonui.graphs import animations
      5 from carbonui.graphs.axis import AxisOrientation
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.primitives.vectorlinetrace import VectorLineTrace, CORNERTYPE_ROUND
      8 from carbonui.uicore import uicore
      9 LEGEND_SPRITE = 'res:/ui/texture/classes/graph/linelegend.png'
     10 
     11 class LineGraph(VectorLineTrace):
     12     default_name = 'LineGraph'
     13     default_cornerType = CORNERTYPE_ROUND
     14     default_state = uiconst.UI_DISABLED
     15     default_lineWidth = 1.0
     16     default_spriteEffect = trinity.TR2_SFX_FILL_AA
     17     default_lineColor = (1.0, 1.0, 1.0, 1.0)
     18 
     19     def ApplyAttributes(self, attributes):
     20         VectorLineTrace.ApplyAttributes(self, attributes)
     21         self._categoryAxis = attributes['categoryAxis']
     22         self._valueAxis = attributes['valueAxis']
     23         self._orientation = attributes.get('orientation', AxisOrientation.VERTICAL)
     24         self._categoryAxis.onChange.connect(self._AxisChanged)
     25         self._valueAxis.onChange.connect(self._AxisChanged)
     26         self._values = attributes['values']
     27         self._dataPoints = attributes.get('dataPoints', None)
     28         self._vertices = None
     29         self._animation = None
     30         self._locked = False
     31         self._dirty = False
     32         self.lineColor = attributes.get('lineColor', self.default_lineColor)
     33         self._Build()
     34 
     35     def _Build(self):
     36         self.AppendVertices(self._GetVertexPositions(), self._GetTransform(), self.lineColor)
     37 
     38     def GetLegendItem(self):
     39         return Sprite(name='legendPoint', texturePath=LEGEND_SPRITE, color=self.lineColor, size=(16, 16), align=uiconst.TOLEFT)
     40 
     41     def Animate(self, animationType, animationDynamics, duration):
     42         self.CancelAnimation()
     43         self._animation = animations.CreateAnimation(self, self._categoryAxis, self._valueAxis, self._orientation, animationType, animationDynamics, duration, 1)
     44 
     45     def CancelAnimation(self, applyLastFrame = True):
     46         self.StopAnimations()
     47         self.opacity = 1.0
     48         if self._animation:
     49             self._animation.Cancel(applyLastFrame)
     50             self._animation = None
     51 
     52     def Close(self):
     53         self.CancelAnimation(False)
     54         super(LineGraph, self).Close()
     55         self._categoryAxis.onChange.disconnect(self._AxisChanged)
     56         self._valueAxis.onChange.disconnect(self._AxisChanged)
     57 
     58     def _AxisChanged(self, _):
     59         if self._locked:
     60             self._dirty = True
     61         else:
     62             self._Rescale()
     63 
     64     def LockGraphUpdates(self):
     65         self._locked = True
     66 
     67     def UnlockGraphUpdates(self):
     68         if self._locked:
     69             self._locked = False
     70             if self._dirty:
     71                 self._Rescale()
     72 
     73     def _Rescale(self):
     74         self.CancelAnimation(False)
     75         self._dirty = False
     76         self.renderObject.SetVertices(self._GetVertexPositions(), self._GetTransform())
     77 
     78     def _GetTransform(self):
     79         dpiScaling = uicore.desktop.dpiScaling
     80         transform = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
     81         if self._orientation == AxisOrientation.VERTICAL:
     82             transform = self._categoryAxis.UpdateToViewportTransform(transform, 0, dpiScaling)
     83             transform = self._valueAxis.UpdateToViewportTransform(transform, 1, dpiScaling)
     84         else:
     85             transform = self._categoryAxis.UpdateToViewportTransform(transform, 1, dpiScaling)
     86             transform = self._valueAxis.UpdateToViewportTransform(transform, 0, dpiScaling)
     87         return transform
     88 
     89     def _GetDataRange(self):
     90         if self._dataPoints is not None:
     91             return self._dataPoints
     92         return xrange(len(self._categoryAxis.GetDataPoints()))
     93 
     94     def _GetVertexPositions(self):
     95         if self._vertices:
     96             return self._vertices
     97         if self._orientation == AxisOrientation.VERTICAL:
     98             vertices = zip(self._GetDataRange(), self._values)
     99         else:
    100             vertices = zip(self._values, self._GetDataRange())
    101         self._vertices = vertices
    102         return vertices
    103 
    104     def SetValues(self, values):
    105         self._vertices = None
    106         self._values = values