-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGUI_Graph.lua
1386 lines (1183 loc) · 38.2 KB
/
GUI_Graph.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local Recount = _G.Recount
local Graph = LibStub:GetLibrary("LibGraph-2.0")
local AceLocale = LibStub("AceLocale-3.0")
local L = AceLocale:GetLocale("Recount")
local revision = tonumber(string.sub("$Revision: 1563 $", 12, -3))
if Recount.Version < revision then
Recount.Version = revision
end
local ipairs = ipairs
local math = math
local pairs = pairs
local string = string
local table = table
local tinsert = tinsert
local type = type
local CreateFrame = CreateFrame
local GetCursorPosition = GetCursorPosition
local GetMouseButtonClicked = GetMouseButtonClicked
local MouseIsOver = MouseIsOver
local UIParent = UIParent
local FauxScrollFrame_GetOffset = FauxScrollFrame_GetOffset
local FauxScrollFrame_OnVerticalScroll = FauxScrollFrame_OnVerticalScroll
local FauxScrollFrame_Update = FauxScrollFrame_Update
local me = {}
local Epsilon = 0.000000000000000001
local GraphColors = {
Damage = {1.0, 0.0, 0.0, 1.0},
DamageTaken = {1.0, 1.0, 0.0, 1.0},
Healing = {0.0, 1.0, 0.0, 1.0},
HealingTaken = {0.0, 1.0, 1.0, 1.0},
Overhealing = {0.5, 0.0, 1.0, 1.0},
Threat = {1.0, 0.5, 0, 1.0},
TPS = {1.0, 0.6, 0.8, 1.0},
}
me.GraphColors = {}
local ClassCount = {}
local GraphName = {
Damage = "Damage",
DamageTaken = "Damage Taken",
Healing = "Healing",
HealingTaken = "Healing Taken",
Overhealing = "Overhealing",
}
local ShadeVariant = {
1.0, -- 1
0.6, -- 2
0.8, -- 3
0.4, -- 4
0.7, -- 5
0.5, -- 6
0.3, -- 7
0.9, -- 8
}
function me:DataCopy(data)
if not (data and data[1]) then
return
end
local Copy = Recount:GetTable()
Copy[1] = Recount:GetTable()
Copy[2] = Recount:GetTable()
for i = 1,#data[1] do
Copy[1][i] = data[1][i]
Copy[2][i] = data[2][i]
end
return Copy
end
function me:DataSparsen(data, amount)
local Keep = Recount:GetTable()
if #data[1] == 0 then
return
end
local Min, Max, MinV, MaxV, CurVal
local Time = data[1][1] + 0.5
Keep[1] = true
Min = 0
for k, v in ipairs(data[1]) do
CurVal = data[2][k]
if v > Time and v < (Time + amount) then
if Min == 0 then
Min = k
Max = k
MinV = CurVal
MaxV = CurVal
elseif CurVal < MinV then
Min = k
MinV = CurVal
elseif CurVal >= MaxV then
Max = k
MaxV = CurVal
end
elseif v >= (Time + amount) then
if Min ~= 0 then
Keep[Min] = true
Keep[Max] = true
end
Time = v
Min = k
Max = k
MinV = CurVal
MaxV = CurVal
end
end
if Min ~= 0 then
Keep[Min] = true
Keep[Max] = true
Keep[#data[1]] = true
end
local i = #data[1]
while i > 0 do
if not Keep[i] then
table.remove(data[1], i)
table.remove(data[2], i)
end
i = i - 1
end
Recount:FreeTable(Keep)
end
function me:FilterDataByTime(data)
local filtered = Recount:GetTable()
filtered[1] = Recount:GetTable()
filtered[2] = Recount:GetTable()
local First = true
local Last = 0
for k, v in ipairs(data[1]) do
if v >= Recount.TimeRangeLower and v <= Recount.TimeRangeUpper then
--Need to add value right at the front edge
if First then
if k ~= 1 then
--If not first need to LERP to find the edge value
local Weight = (Recount.TimeRangeLower - data[1][k - 1]) / (data[1][k] - data[1][k - 1])
filtered[2][#filtered[2] + 1] = Weight * data[2][k] + (1 - Weight) * data[2][k - 1]
else
--If this is first then insert 0 at front
filtered[2][#filtered[2] + 1] = 0
end
filtered[1][#filtered[1] + 1] = Recount.TimeRangeLower
First = false
end
filtered[1][#filtered[1] + 1] = v
filtered[2][#filtered[2] + 1] = data[2][k]
Last = k
end
end
--Only add a trailer if we have data otherwise don't do anything
if Last ~= 0 then
--Do we have something we can LERP with?
if data[1][Last + 1] then
--Yes, so calculate a weight and then LERP
local Weight = (Recount.TimeRangeUpper - data[1][Last]) / (data[1][Last + 1] - data[1][Last])
filtered[2][#filtered[2] + 1] = Weight * data[2][Last + 1] + (1 - Weight) * data[2][Last]
else
--No so lets insert 0
filtered[2][#filtered[2] + 1] = 0
end
filtered[1][#filtered[1] + 1] = Recount.TimeRangeUpper
end
return filtered
end
function me:FindMax(data)
local Min = data[2][1]
local Max = data[2][1]
for _, v in ipairs(data[2]) do
if v > Max then
Max = v
end
if v < Min then
Min = v
end
end
return Min, Max
end
function me:SetMin(data, Min)
for k, v in ipairs(data[2]) do
if v < Min then
data[2][k] = Min
end
end
end
function me:IntegrateData(data)
local CurSum = 0
local LastNum = 0
local NotFirst = false
for k, v in ipairs(data[1]) do
if NotFirst then
CurSum = CurSum + 0.5 * (data[2][k] + LastNum) * (v - data[1][k - 1])
LastNum = data[2][k]
data[2][k] = CurSum
else
LastNum = data[2][k]
data[2][k] = 0
end
NotFirst = true
end
end
function me:NormalizeData(data)
local Min, Max = me:FindMax(data)
local Width = Max - Min
for k, v in ipairs(data[2]) do
data[2][k] = 100 * (v - Min) / Width
end
end
function me:HideTextures()
if not self.Textures then
self.Textures = {}
end
for k, t in pairs(self.Textures) do
t:Hide()
end
end
--Make sure to show a texture after you grab it or its free for anyone else to grab
function me:FindTexture()
for k, t in pairs(self.Textures) do
if not t:IsShown() then
return t
end
end
local g = self:CreateTexture(nil, "BACKGROUND")
table.insert(self.Textures, g)
return g
end
local function SortForStack(a, b)
if a[1] > b[1] then
return true
elseif a[1] == b[1] and a[4] > b[4] then
return true
end
return false
end
local function SortForDisplay(a, b)
if a[1] < b[1] then
return true
elseif a[1] == b[1] and a[4] < b[4] then
return true
end
return false
end
function me:AddDataSeries(a, b)
--If ones nil just return the other one
if a == nil or table.maxn(a) < 2 then
return b
elseif b == nil or table.maxn(b) < 2 then
return a
end
local LastA, LastAT, Temp
local PosA, PosB, LengthA, LengthB
PosA = 1
PosB = 1
LengthA = table.maxn(a[1])
LengthB = table.maxn(b[1])
a[2][PosA] = math.max(a[2][PosA], 0)
b[2][PosB] = math.max(b[2][PosB], 0)
while PosA <= #a[1] or PosB <= LengthB do
if PosA <= #a[1] then
if PosB <= LengthB then
if a[1][PosA] < b[1][PosB] then
if PosB ~= 1 then
--Need to lerp first calculate a weight
Temp = (a[1][PosA] - b[1][PosB - 1]) / (b[1][PosB] - b[1][PosB - 1])
--Now perform the lerp
Temp = Temp * b[2][PosB] + (1 - Temp) * b[2][PosB - 1]
else
--If the first value can't lerp just pass the first value
Temp = b[2][1]
end
LastAT = a[1][PosA]
LastA = a[2][PosA]
a[2][PosA] = a[2][PosA] + Temp
PosA = PosA + 1
if PosA <= LengthA and a[2][PosA] < 0 then
a[2][PosA] = 0
end
elseif a[1][PosA] == b[1][PosB] then
LastAT = a[1][PosA]
LastA = a[2][PosA]
a[2][PosA] = a[2][PosA] + b[2][PosB]
PosA = PosA + 1
PosB = PosB + 1
else
if PosA ~= 1 then
--Need to lerp first calculate a weight
Temp = (b[1][PosB] - LastAT) / (a[1][PosA] - LastAT)
--Now perform the lerp
Temp = Temp * a[2][PosA] + (1 - Temp) * LastA
else
--If the first value can't lerp just pass the first value
Temp = a[2][1]
end
tinsert(a[1],PosA, b[1][PosB])
tinsert(a[2],PosA, b[2][PosB] + Temp)
PosA = PosA + 1
PosB = PosB + 1
if PosB <= LengthB and b[2][PosB] < 0 then
b[2][PosB] = 0
end
end
else
LastAT = a[1][PosA]
LastA = a[2][PosA]
a[2][PosA] = a[2][PosA] + b[2][LengthB]
PosA = PosA + 1
if PosA <= LengthA and a[2][PosA] < 0 then
a[2][PosA] = 0
end
end
else
--Then PosB must be <= LengthB
a[1][PosA] = b[1][PosB]
a[2][PosA] = b[2][PosB] + LastA
PosB = PosB + 1
PosA = PosA + 1
if PosB <= LengthB and b[2][PosB] < 0 then
b[2][PosB] = 0
end
end
end
return a
end
function me:DivideDataSeries(a, b)
--If ones nil just return the other one
if a == nil or table.maxn(a) < 2 then
return b
elseif b == nil or table.maxn(b) < 2 then
return a
end
local LastA, LastB, Temp
local PosA, PosB, LengthA, LengthB
PosA = 1
PosB = 1
LengthA = #a[1]
LengthB = #b[1]
while PosA <= LengthA do
if PosB <= LengthB then
if a[1][PosA] <= b[1][PosB] then
if PosB ~= 1 then
--Need to lerp first calculate a weight
Temp = (a[1][PosA] - b[1][PosB - 1]) / (b[1][PosB] - b[1][PosB - 1])
--Now perform the lerp
Temp = Temp * b[2][PosB] + (1 - Temp) * b[2][PosB - 1]
else
--If the first value can't lerp instead just pass the first value
Temp = b[2][1]
end
if Temp ~= 0 then
a[2][PosA] = (100 * a[2][PosA]) / Temp
else
a[2][PosA] = 0
end
if a[2][PosA] < 0 then
a[2][PosA] = 0
end
PosA = PosA + 1
else
PosB = PosB + 1
if PosB <= LengthB and b[2][PosB] < 0 then
b[2][PosB] = 0
end
end
else
a[2][PosA] = 100*a[2][PosA] / (b[2][LengthB] + Epsilon)
PosA = PosA + 1
end
end
end
function me:RefreshGraph()
local Graph = Recount.GraphWindow.LineGraph
local Length, MaxLength, Filtered, Result, MinAmount, MaxAmount, DataMax, Temp
local Stacked = Recount:GetTable()
Graph:ResetData()
local i = 1
MaxLength = 0
MaxAmount = 0
MinAmount = 0
--If time range is not set need to find what will be used then
if not Recount.TimeRangeSet then
local TimeRangeLower, TimeRangeUpper
if Recount.GraphWindow.Data then
for k, v in pairs(Recount.GraphWindow.Data) do
if v[1][1] then
if TimeRangeLower == nil or v[1][1] < TimeRangeLower then
TimeRangeLower = v[1][1]
end
if TimeRangeUpper == nil or v[1][table.maxn(v[1])] > TimeRangeUpper then
TimeRangeUpper = v[1][table.maxn(v[1])]
end
end
end
end
--Need to pretend like a Time Range is set then
Recount.TimeRangeLower = TimeRangeLower
Recount.TimeRangeUpper = TimeRangeUpper
Graph:SetXAxis(TimeRangeLower, TimeRangeUpper)
Graph:LockXMin(true)
Graph:LockXMax(true)
end
if Recount.GraphWindow.Data then
for k, v in pairs(Recount.GraphWindow.Data) do
if type(v) == "table" and table.maxn(v[1]) > 0 and (v[1][1] ~= nil) and me.Enabled[k] then
--Figure out the color used
local color = me.GraphColors[k]
--Start procecssing this data
Filtered = me:FilterDataByTime(v)
--Need to ensure its actually a copy if not then copy it
if Filtered == v then
Filtered = me:DataCopy(v)
end
if table.maxn(Filtered[1]) > 0 then
if Recount.GraphWindow.IntegrateOn then
me:IntegrateData(Filtered)
end
if not Recount.GraphWindow.StackedOn then
Length = Filtered[1][table.maxn(Filtered[1])] - Filtered[1][1]
if Length > 300 then
me:DataSparsen(Filtered, Length / 100)
end
if Recount.GraphWindow.NormalizeOn then
me:NormalizeData(Filtered)
end
local _
_, DataMax = me:FindMax(Filtered)
me:SetMin(Filtered, 0)
if MaxAmount < DataMax then
MaxAmount = DataMax
end
Graph:AddDataSeries(Filtered, color, true)
if MaxLength < Length then
MaxLength = Length
end
--Done with it so lets remove it
Recount:FreeTableRecurse(Filtered)
else
--Stacked Graph Data needs to be stored for the moment
local _
_, DataMax = me:FindMax(Filtered)
Temp = Recount:GetTable()
Temp[1] = DataMax
Temp[2] = Filtered
Temp[3] = color
Temp[4] = k
table.insert(Stacked, Temp)
end
end
end
i = i + 1
end
end
if Recount.GraphWindow.StackedOn then
local Current = Recount:GetTable()
table.sort(Stacked, SortForStack)
for k, v in pairs(Stacked) do
for k2, v2 in pairs(v[2][2]) do
if v2 < 0 then
v[2][2][k2] = 0
end
end
end
for k, v in pairs(Stacked) do
Length = v[2][1][table.maxn(v[2][1])] - v[2][1][1]
if Length > 200 then
me:DataSparsen(v[2], Length / 70)
end
Current = me:AddDataSeries(v[2],Current)
if Current ~= v[2] then
Recount:FreeTableRecurse(v[2])
v[2] = Current
end
end
if Recount.GraphWindow.NormalizeOn then
--Divide now by the total
local Total = me:DataCopy(Current)
for k, v in pairs(Stacked) do
me:DivideDataSeries(v[2], Total)
end
end
table.sort(Stacked, SortForDisplay)
if Stacked[1] and Stacked[1][2] then
local _
_, MaxAmount = me:FindMax(Stacked[1][2])
for k, v in pairs(Stacked) do
Length = v[2][1][table.maxn(v[2][1])] - v[2][1][1]
if Length > 200 then
me:DataSparsen(v[2], Length / 70)
end
if MaxLength < Length then
MaxLength = Length
end
Graph:AddFilledDataSeries(v[2], v[3], true)
--Recount:PrintLiteral(v[2])
--break
end
end
--Can't free current because its already in there
Recount:FreeTableRecurse(Current)
for k, v in pairs(Stacked) do
Recount:FreeTableRecurse(v[2])
Recount:FreeTable(v)
end
Recount:FreeTable(Stacked)
end
Graph:SetYAxis(0, MaxAmount)
if MaxAmount < 100 then
DataMax = 10
elseif MaxAmount < 250 then
DataMax = 25
elseif MaxAmount < 500 then
DataMax = 50
elseif MaxAmount < 1500 then
DataMax = 100
elseif MaxAmount < 3000 then
DataMax = 200
else
DataMax = 100 * math.floor(MaxAmount / 1000)
end
local XMin = Graph.XMin
local XMax = Graph.XMax
--Hack fix for no data
if XMin == nil or XMax == nil then
Graph:SetXAxis(5, 30)
XMin = Graph.XMin
XMax = Graph.XMax
end
MaxLength = XMax - XMin
if MaxLength < 60 then
Graph:SetGridSpacing(5, DataMax)
Graph.TimeRef:SetText(L["X Gridlines Represent"].." 5 "..L["Seconds"])
elseif MaxLength < 180 then
Graph:SetGridSpacing(15, DataMax)
Graph.TimeRef:SetText(L["X Gridlines Represent"].." 15 "..L["Seconds"])
elseif MaxLength < 400 then
Graph:SetGridSpacing(30, DataMax)
Graph.TimeRef:SetText(L["X Gridlines Represent"].." 30 "..L["Seconds"])
elseif MaxLength < 600 then
Graph:SetGridSpacing(60, DataMax)
Graph.TimeRef:SetText(L["X Gridlines Represent"].." 60 "..L["Seconds"])
else
Graph:SetGridSpacing(math.floor(MaxLength / 100) * 10, DataMax)
Graph.TimeRef:SetText(L["X Gridlines Represent"].." "..(math.floor(MaxLength / 100) * 10).." "..L["Seconds"])
end
local Background = Recount.GraphWindow.GraphBackground
Background:HideTextures()
local CurPos = XMin
local Width = Background:GetWidth() / (XMax - XMin)
local T
--Code for drawing the various fights with a red background
for k, v in ipairs(Recount.db2.CombatTimes) do
if CurPos < v[1] then
if v[1] > XMax then
return
end
T = Background:FindTexture()
T:Show()
if Recount.GraphWindow.LastTimeOver ~= k then
T:SetColorTexture(1, 0, 0, 0.1)
else
T:SetColorTexture(1, 1, 0, 0.1)
end
T:SetPoint("TOPLEFT", Background, "TOPLEFT", (v[1] - XMin) * Width, 0)
if v[2] > XMax then
T:SetPoint("BOTTOMRIGHT", Background, "BOTTOMRIGHT", 0, 0)
return
end
T:SetPoint("BOTTOMRIGHT", Background, "BOTTOMLEFT", (v[2] - XMin) * Width, 0)
T.id = k
CurPos = v[2]
elseif CurPos < v[2] then
T = Background:FindTexture()
T:Show()
if Recount.GraphWindow.LastTimeOver ~= k then
T:SetColorTexture(1, 0, 0, 0.1)
else
T:SetColorTexture(1, 1, 0, 0.1)
end
T:SetPoint("TOPLEFT", Background, "TOPLEFT", (CurPos - XMin) * Width, 0)
if v[2] > XMax then
T:SetPoint("BOTTOMRIGHT", Background, "BOTTOMRIGHT", 0, 0)
return
end
T:SetPoint("BOTTOMRIGHT", Background, "BOTTOMLEFT", (v[2] - XMin) * Width, 0)
T.id = k
CurPos = v[2]
end
end
end
function me:SelectCombatTimes(id)
local Graph = Recount.GraphWindow.LineGraph
local Rows = Recount.GraphWindow.TimeRows
local offset = FauxScrollFrame_GetOffset(Recount.GraphWindow.ScrollBar2)
if Recount.TimeRangeSet == (id + offset) then
Recount.TimeRangeSet = false
Rows[id].Background:Hide()
Graph:LockXMin(false)
Graph:LockXMax(false)
me:RefreshGraph()
return
end
Recount.TimeRangeSet = id + offset
local Times = Recount.db2.CombatTimes[id + offset]
Recount.TimeRangeLower = Times[1] - 30
Recount.TimeRangeUpper = Times[2] + 30
for i = 1, 10 do
Rows[i].Background:Hide()
end
Rows[id].Background:Show()
Graph:LockXMin(true)
Graph:LockXMax(true)
Graph:SetXAxis(Recount.TimeRangeLower, Recount.TimeRangeUpper)
me:RefreshGraph()
end
function me:SelectCombatTime(time)
for k, v in pairs(Recount.db2.CombatTimes) do
if v[1] <= time and time <= v[2] then
local Graph = Recount.GraphWindow.LineGraph
Recount.TimeRangeSet = k
Recount.TimeRangeLower = v[1] - 30
Recount.TimeRangeUpper = v[2] + 30
Graph:LockXMin(true)
Graph:LockXMax(true)
Graph:SetXAxis(Recount.TimeRangeLower, Recount.TimeRangeUpper)
me:RefreshGraph()
Recount:GraphRefreshCombat()
return
end
end
end
function me:HighlightCombatTime(time)
local TimeOver = nil
if time then
for k, v in pairs(Recount.db2.CombatTimes) do
if v[1] <= time and time <= v[2] then
TimeOver = k
break
end
end
end
if TimeOver ~= Recount.GraphWindow.LastTimeOver then
for _, v in pairs(Recount.GraphWindow.GraphBackground.Textures) do
if v.id == TimeOver then
v:SetColorTexture(1, 1, 0, 0.1)
elseif v.id == Recount.GraphWindow.LastTimeOver then
v:SetColorTexture(1, 0, 0, 0.1)
end
end
Recount.GraphWindow.LastTimeOver = TimeOver
end
end
function Recount:CheckFontStringLength(fontstring, maxwidth)
local Text = fontstring:GetText()
while fontstring:GetStringWidth() > maxwidth do
Text = string.sub(Text, 1, string.len(Text) - 1)
fontstring:SetText(Text.."...")
end
end
function Recount:SetGraphData(name, data, combat)
Recount.GraphWindow.Title:SetText(L["Graph Window"].." - "..name)
Recount.GraphWindow.Data = data
Recount.GraphWindow.CombatTime = combat
Recount.GraphWindow:Show()
Recount:SetWindowTop(Recount.GraphWindow)
--Need to reset class counts if in compare mode
if Recount.GraphCompare then
for k, _ in pairs(ClassCount) do
ClassCount[k] = nil
end
end
local Class, Shade
if me.Enabled == nil then
me.Enabled = {}
end
local i = 1
if Recount.GraphWindow.Data then
for k, _ in pairs(Recount.GraphWindow.Data) do
local color = GraphColors[k]
if type(color) ~= "table" then
if Recount.GraphCompare and Recount.GraphClass[k] then
Class = Recount.GraphClass[k]
ClassCount[Class] = (ClassCount[Class] or 0) + 1
if ClassCount[Class] <= 8 then
Shade = ShadeVariant[ClassCount[Class]]
color = {Shade * Recount.db.profile.Colors.Class[Class].r, Shade * Recount.db.profile.Colors.Class[Class].g, Shade * Recount.db.profile.Colors.Class[Class].b, 1}
else
color = {math.random(), math.random(), math.random(), 1}
end
else
color = {math.random(), math.random(), math.random(), 1}
end
end
me.GraphColors[k] = color
me.Enabled[k] = true
if i <= 10 then
Recount.GraphWindow.Rows[i]:Show()
Recount.GraphWindow.Rows[i].Key:SetVertexColor(color[1], color[2], color[3], 1)
Recount.GraphWindow.Rows[i].Name:SetText(GraphName[k] or k)
end
i = i + 1
end
end
Recount.GraphWindow.Entries = i - 1
for j = i, 10 do
Recount.GraphWindow.Rows[j]:Hide()
end
Recount:GraphRefreshData()
Recount:GraphRefreshCombat()
me:RefreshGraph()
end
function Recount:GraphRefreshData()
local data = Recount.GraphWindow.Data
local size = Recount.GraphWindow.Entries
FauxScrollFrame_Update(Recount.GraphWindow.ScrollBar1, size, 10, 20)
local offset = FauxScrollFrame_GetOffset(Recount.GraphWindow.ScrollBar1)
local Rows = Recount.GraphWindow.Rows
local i = 1 - offset
if Recount.GraphWindow.Data then
for k, v in pairs(Recount.GraphWindow.Data) do
if i >= 1 and i <= 10 then
Rows[i]:Show()
Rows[i].Key:SetVertexColor(me.GraphColors[k][1], me.GraphColors[k][2], me.GraphColors[k][3], 1)
Rows[i].Name:SetText(GraphName[k] or k)
Recount:CheckFontStringLength(Rows[i].Name, 180)
Rows[i].Enabled:SetChecked(me.Enabled[k])
Rows[i].Enabled.Key = k
end
i = i + 1
end
end
while i <= 10 do
Rows[i]:Hide()
i = i + 1
end
end
function Recount:GraphRefreshCombat()
local combat = Recount.db2.CombatTimes
local size = table.getn(combat)
FauxScrollFrame_Update(Recount.GraphWindow.ScrollBar2, size, 10, 20)
local offset = FauxScrollFrame_GetOffset(Recount.GraphWindow.ScrollBar2)
local Rows = Recount.GraphWindow.TimeRows
for i = 1, 10 do
local c = combat[i + offset]
if c then
Rows[i]:Show()
Rows[i].Who:SetText(c[5])
Recount:CheckFontStringLength(Rows[i].Who, 115)
Rows[i].Start:SetText(c[3])
Rows[i].End:SetText(c[4])
if i + offset ~= Recount.TimeRangeSet then
Rows[i].Background:Hide()
else
Rows[i].Background:Show()
end
else
Rows[i]:Hide()
end
end
end
function Recount:CreateGraphWindow()
Recount.GraphWindow = CreateFrame("Frame", "Recount_GraphWindow", UIParent, BackdropTemplateMixin and "BackdropTemplate")
local theFrame = Recount.GraphWindow
theFrame.Me = me
theFrame:ClearAllPoints()
theFrame:SetPoint("CENTER", UIParent)
theFrame:SetHeight(432 + 20)
theFrame:SetWidth(625 + 24)
theFrame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
edgeFile = "Interface\\AddOns\\Recount\\textures\\otravi-semi-full-border", edgeSize = 32,
insets = {left = 1, right = 1, top = 20, bottom = 1},
})
theFrame:SetBackdropBorderColor(1.0, 0.0, 0.0)
theFrame:SetBackdropColor(24 / 255, 24 / 255, 24 / 255)
Recount.Colors:RegisterBorder("Other Windows", "Title", theFrame)
Recount.Colors:RegisterBackground("Other Windows", "Background", theFrame)
theFrame:EnableMouse(true)
theFrame:SetMovable(true)
--theFrame:RegisterForDrag("LeftButton")
--theFrame:SetScript("OnDragStart",theFrame.StartMoving)
--theFrame:SetScript("OnDragStop",theFrame.StopMovingOrSizing)
theFrame:SetFrameLevel(Recount.MainWindow:GetFrameLevel() + 20)
theFrame:SetScript("OnMouseDown", function(this, button)
if (((not this.isLocked) or (this.isLocked == 0)) and (button == "LeftButton")) then
Recount:SetWindowTop(this)
this:StartMoving()
this.isMoving = true
end
end)
theFrame:SetScript("OnMouseUp", function(this)
if (this.isMoving) then
local point, relativeTo, relativePoint, xOfs, yOfs = this:GetPoint(1)
Recount.db.profile.GraphWindowX = xOfs
Recount.db.profile.GraphWindowY = yOfs
this:StopMovingOrSizing()
this.isMoving = false
end
end)
theFrame:SetScript("OnShow", function(this)
Recount:SetWindowTop(this)
end)
theFrame:SetScript("OnHide", function(this)
if (this.isMoving) then
local point, relativeTo, relativePoint, xOfs, yOfs = this:GetPoint(1)
Recount.db.profile.GraphWindowX = xOfs
Recount.db.profile.GraphWindowY = yOfs
this:StopMovingOrSizing()
this.isMoving = false
end
end)
theFrame.Title = theFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
theFrame.Title:SetPoint("TOPLEFT", theFrame, "TOPLEFT", 6, -15)
theFrame.Title:SetTextColor(1.0, 1.0, 1.0, 1.0)
theFrame.Title:SetText(L["Graph Window"])
--Recount.Colors:UnregisterItem(Recount.GraphWindow.Title)
Recount.Colors:RegisterFont("Other Windows", "Title Text", Recount.GraphWindow.Title)
theFrame.LineGraph = Graph:CreateGraphLine("Recount_GraphWindow_LineGraph", theFrame, "TOPLEFT", "TOPLEFT", 1, -32, 400, 418)
theFrame.LineGraph:SetAutoScale(true)
theFrame.LineGraph:SetYAxis(0, 100)
theFrame.LineGraph:SetGridSpacing(15, 25)
theFrame.LineGraph:LockYMin(true)
theFrame.LineGraph:SetYLabels(true, true)
theFrame.LineGraph:SetFrameLevel(theFrame:GetFrameLevel() + 2)
theFrame.LineGraph.TimeRef = theFrame.LineGraph:CreateFontString(nil, "OVERLAY", "GameFontNormal")
theFrame.LineGraph.TimeRef:SetPoint("TOP", theFrame.LineGraph, "TOP", 0, -2)
theFrame.LineGraph.TimeRef:SetTextColor(1.0, 1.0, 1.0, 1.0)
theFrame.GraphBackground = CreateFrame("Frame", nil, theFrame)
theFrame.GraphBackground:SetAllPoints(theFrame.LineGraph)
theFrame.GraphBackground.HideTextures = me.HideTextures
theFrame.GraphBackground.FindTexture = me.FindTexture
theFrame.GraphBackground:EnableMouse(true)
theFrame.GraphBackground.TimeSelect = theFrame.GraphBackground:CreateTexture(nil, "BACKGROUND")
theFrame.GraphBackground.TimeSelect:SetColorTexture(0, 1, 0, 0.1)
theFrame.GraphBackground.TimeSelect:Hide()
theFrame.GraphBackground:SetScript("OnUpdate", function(this)
local sX = this:GetCenter()
local Scale = this:GetEffectiveScale()
local mX = GetCursorPosition()
local TimePos
local GraphWindow = Recount.GraphWindow
if Recount.TimeRangeUpper and (MouseIsOver(GraphWindow.GraphBackground) or Recount.GraphWindow.Dragging) then
TimePos = (mX / Scale - sX + this:GetWidth() / 2) / this:GetWidth()
TimePos = TimePos * (Recount.TimeRangeUpper - Recount.TimeRangeLower) + Recount.TimeRangeLower
if MouseIsOver(GraphWindow.GraphBackground) then
me:HighlightCombatTime(TimePos)
end
if GraphWindow.Dragging then
local Graph = GraphWindow.LineGraph
local Background = GraphWindow.GraphBackground
local XMin = Graph.XMin
local XMax = Graph.XMax
--Hack fix for no data
if XMin == nil or XMax == nil then
Graph:SetXAxis(5, 30)
XMin = Graph.XMin
XMax = Graph.XMax
end
local Width = Background:GetWidth() / (XMax - XMin)
local Left, Right
Left = math.max(math.min(GraphWindow.DragTimeStart, XMax),XMin)
Right = math.max(math.min(TimePos, XMax),XMin)
if Right < Left then