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

graph.py (4493B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\graphs\graph.py
      2 from carbonui.primitives.container import Container
      3 import carbonui.const as uiconst
      4 from carbonui.graphs.axis import AxisOrientation
      5 from carbonui.uicore import uicore
      6 
      7 def _UnlockGraphs(locked):
      8     for each in locked:
      9         each.UnlockGraphUpdates()
     10 
     11 
     12 class GraphArea(Container):
     13     default_state = uiconst.UI_ACTIVE
     14     default_clipChildren = True
     15 
     16     def ApplyAttributes(self, attributes):
     17         Container.ApplyAttributes(self, attributes)
     18         self._horizontalAxis = attributes.get('horizontalAxis', [])
     19         self._verticalAxis = attributes.get('verticalAxis', [])
     20         self._zoomAxis = []
     21         self._panAxis = []
     22         self._isPanning = None
     23         self._prevPanPosition = (0, 0)
     24 
     25     def _OnResize(self, *args):
     26         Container._OnResize(self)
     27         width, height = self.GetAbsoluteSize()
     28         locked = self._LockGraphs()
     29         for each in self._horizontalAxis:
     30             each[0].SetViewportRange((each[1] * width, each[2] * width))
     31 
     32         for each in self._verticalAxis:
     33             each[0].SetViewportRange((each[1] * height, each[2] * height))
     34 
     35         _UnlockGraphs(locked)
     36 
     37     def AddAxis(self, orientation, axis, minFactor = 0.0, maxFactor = 1.0):
     38         width, height = self.GetAbsoluteSize()
     39         if orientation == AxisOrientation.HORIZONTAL:
     40             self._horizontalAxis.append((axis,
     41              minFactor,
     42              maxFactor,
     43              AxisOrientation.HORIZONTAL))
     44             axis.SetViewportRange((minFactor * width, maxFactor * width))
     45         else:
     46             self._verticalAxis.append((axis,
     47              minFactor,
     48              maxFactor,
     49              AxisOrientation.VERTICAL))
     50             axis.SetViewportRange((minFactor * height, maxFactor * height))
     51 
     52     def AddZoomAxis(self, axis):
     53         self._zoomAxis.append(self._FindAxis(axis))
     54 
     55     def AddPanAxis(self, axis):
     56         self._panAxis.append(self._FindAxis(axis))
     57 
     58     def _FindAxis(self, axis):
     59         result = None
     60         for each in self._horizontalAxis:
     61             if each[0] == axis:
     62                 result = each
     63                 break
     64 
     65         if result is None:
     66             for each in self._verticalAxis:
     67                 if each[0] == axis:
     68                     result = each
     69                     break
     70 
     71         if result is None:
     72             raise ValueError('axis needs to be added first with AddAxis')
     73         return result
     74 
     75     def OnMouseDown(self, *args):
     76         if not uicore.uilib.leftbtn:
     77             return
     78         self._isPanning = True
     79         self._prevPanPosition = (uicore.uilib.x, uicore.uilib.y)
     80 
     81     def OnMouseUp(self, *args):
     82         self._isPanning = False
     83 
     84     def OnMouseMove(self, *args):
     85         if not self._isPanning or not self._panAxis:
     86             return
     87         newPos = (uicore.uilib.x, uicore.uilib.y)
     88         if newPos != self._prevPanPosition:
     89             width, height = self.GetAbsoluteSize()
     90             locked = self._LockGraphs()
     91             for axis, minv, maxv, orientation in self._panAxis:
     92                 if orientation == AxisOrientation.HORIZONTAL:
     93                     delta = float(newPos[0] - self._prevPanPosition[0]) / width
     94                     axis.Pan(-delta * (maxv - minv))
     95                 else:
     96                     delta = float(newPos[1] - self._prevPanPosition[1]) / height
     97                     axis.Pan(-delta * (maxv - minv))
     98 
     99             _UnlockGraphs(locked)
    100             self._prevPanPosition = newPos
    101 
    102     def OnMouseWheel(self, event, *args):
    103         if not self._zoomAxis:
    104             return
    105         locked = self._LockGraphs()
    106         l, t = self.GetAbsolutePosition()
    107         x, y = uicore.uilib.x - l, uicore.uilib.y - t
    108         size = self.GetAbsoluteSize()
    109         rx = min(max(x / float(size[0]), 0.0), 1.0)
    110         ry = min(max(y / float(size[1]), 0.0), 1.0)
    111         change = 0.1
    112         if event < 0:
    113             change = -change
    114         for axis, minv, maxv, orientation in self._zoomAxis:
    115             if orientation == AxisOrientation.HORIZONTAL:
    116                 axis.Zoom(change, minv * (1 - rx) + maxv * rx)
    117             else:
    118                 axis.Zoom(change, minv * (1 - ry) + maxv * ry)
    119 
    120         _UnlockGraphs(locked)
    121 
    122     def _LockGraphs(self):
    123         locked = []
    124         for each in self.children:
    125             cb = getattr(each, 'LockGraphUpdates', None)
    126             if cb:
    127                 cb()
    128                 locked.append(each)
    129 
    130         return locked