standingsGraph.py (6202B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\standings\standingsGraph.py 2 from carbonui.graphs.areagraph import AreaGraph 3 from carbonui.graphs.axis import InteractionLimit 4 from carbonui.graphs.bargraph import DynamicHint 5 from carbonui.graphs.graph import GraphArea 6 from carbonui.graphs.linegraph import LineGraph 7 from carbonui.graphs.pointgraph import PointGraph 8 from carbonui.primitives.container import Container 9 import carbonui.graphs.animations as animations 10 import carbonui.graphs.axis as axis 11 import carbonui.const as uiconst 12 from carbonui.primitives.line import Line 13 from carbonui.uicore import uicore 14 from carbonui.util.color import Color 15 from eve.client.script.ui.shared.standings import standingUIConst 16 from eve.client.script.ui.shared.standings.standingsUtil import GetStandingChangeFormatted 17 from eve.common.script.util.eveFormat import FmtStandingTransaction 18 from eve.common.script.util.standingUtil import RoundStandingChange 19 from localization.formatters.dateTimeFormatters import FormatDateTime 20 MAX_POINTS = 25.0 21 MARGINS_VERTICAL = (0.05, 0.05) 22 MARGINS_HORIZONTAL = (0.005, 0.005) 23 24 class StandingsGraph(Container): 25 default_name = 'StandingsGraph' 26 __notifyevents__ = ['OnStandingHistoryEntryMouseEnter', 'OnStandingHistoryEntryMouseExit'] 27 28 def ApplyAttributes(self, attributes): 29 Container.ApplyAttributes(self, attributes) 30 sm.RegisterNotify(self) 31 self.graphData = [] 32 self.transactions = [] 33 34 def Update(self, fromID, toID, transactions): 35 self.transactions = transactions 36 standingSvc = sm.GetService('standing') 37 self.transactions.reverse() 38 baseStanding = standingSvc.GetStanding(fromID, toID) 39 modifications = [ transaction.modification for transaction in self.transactions ] 40 self.graphData = self.GetGraphData(modifications[:], baseStanding) 41 self.Flush() 42 Line(parent=self, align=uiconst.TOTOP, opacity=0.05) 43 Line(parent=self, align=uiconst.TOBOTTOM, opacity=0.05) 44 self.graphArea = GraphArea(name='graph', parent=self, align=uiconst.TOALL) 45 self.ConstructStandingGraph(self.graphData) 46 47 def ConstructStandingGraph(self, data): 48 dataRange = (min(data), max(data)) 49 verticalAxis = axis.AutoTicksAxis(dataRange, tickCount=1, tickBase=5.0, margins=MARGINS_VERTICAL) 50 self.graphArea.AddAxis(axis.AxisOrientation.VERTICAL, verticalAxis, 1.0, 0.0) 51 verticalAxis.ZoomOn(dataRange) 52 xRange = range(0, len(data)) 53 horizontalAxis = axis.CategoryAxis(xRange, visibleRange=(0, MAX_POINTS), margins=MARGINS_HORIZONTAL, interactionLimit=InteractionLimit.DATA_RANGE) 54 self.graphArea.AddAxis(axis.AxisOrientation.HORIZONTAL, horizontalAxis) 55 numPoints = len(data) 56 if numPoints > MAX_POINTS: 57 horizontalAxis.ZoomOn((numPoints - MAX_POINTS - 1, numPoints - 1)) 58 self.graphArea.AddPanAxis(horizontalAxis) 59 else: 60 horizontalAxis.ZoomOn((0.0, numPoints - 1)) 61 areaGraph = AreaGraph(parent=self.graphArea, categoryAxis=horizontalAxis, valueAxis=verticalAxis, values=data, color=(0.3, 0.3, 0.3, 1.0), lineWidth=1, state=uiconst.UI_DISABLED) 62 self.pointGraph = StandingsPointGraph(parent=self.graphArea, categoryAxis=horizontalAxis, valueAxis=verticalAxis, values=data, pointColor=Color.GRAY2, lineWidth=1, hint=DynamicHint(self.GetPointHint)) 63 lineGraph = LineGraph(parent=self.graphArea, categoryAxis=horizontalAxis, valueAxis=verticalAxis, values=data, lineColor=Color.GRAY2, opacity=1.0, lineWidth=1.0) 64 lineGraph.Animate(animations.AnimationType.GROW, animations.AnimationDynamics.OPPOSITE_AXIS, 0.25) 65 self.pointGraph.Animate(animations.AnimationType.FADE, animations.AnimationDynamics.ALONG_AXIS, 0.6) 66 uicore.animations.FadeTo(areaGraph, 0.0, 1.0, duration=0.4, timeOffset=0.35) 67 68 def GetPointHint(self, index): 69 valueText = '%.2f' % round(self.graphData[index], 2) 70 if index == 0: 71 return valueText 72 transaction = self.transactions[index - 1] 73 body, subject = FmtStandingTransaction(transaction) 74 date = FormatDateTime(transaction.eventDateTime) 75 standingDiff = RoundStandingChange(transaction.modification) 76 diffText = GetStandingChangeFormatted(standingDiff) 77 dateColor = Color.RGBtoHex(*Color.GRAY5) 78 return '%s\n%s\n<color=%s>%s</color>\n<b>%s</b>\n%s' % (valueText, 79 diffText, 80 dateColor, 81 date, 82 body, 83 subject) 84 85 def GetGraphData(self, modifications, standing): 86 ret = [standing] 87 modifications.reverse() 88 for modification in modifications: 89 standing -= modification 90 if round(abs(standing), 1) == 0.0: 91 standing = 0.0 92 ret.append(standing) 93 94 ret.reverse() 95 return ret 96 97 def OnStandingHistoryEntryMouseEnter(self, transaction): 98 try: 99 index = self.transactions.index(transaction) + 1 100 except ValueError: 101 index = None 102 103 self.pointGraph.HilitePoint(index) 104 105 def OnStandingHistoryEntryMouseExit(self, transaction): 106 self.pointGraph.HilitePoint(None) 107 108 109 class StandingsPointGraph(PointGraph): 110 111 def GetPointColors(self): 112 colors = [] 113 for i in xrange(len(self._values)): 114 color = self._GetPointColor(i) 115 for i in xrange(4): 116 colors.append(color) 117 118 return colors 119 120 def _GetPointColor(self, index): 121 if index == 0 or index >= len(self._values): 122 return standingUIConst.COLOR_NEUTRAL 123 else: 124 diff = self._values[index] - self._values[index - 1] 125 if diff > 0: 126 return standingUIConst.COLOR_GOOD 127 return standingUIConst.COLOR_BAD 128 129 def OnMouseEnter(self, *args): 130 PointGraph.OnMouseEnter(self, *args) 131 self.OnHoverStateChange() 132 133 def OnMouseExit(self, *args): 134 PointGraph.OnMouseExit(self, *args) 135 self.OnHoverStateChange() 136 137 def OnHoverStateChange(self): 138 sm.ScatterEvent('OnStandingsGraphHoverStateChange', self._hoverIndex)