vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Do graph stuff
2 -- This should be a separate addon someday
3  
4 GraphHandler = {};
5 GraphHandler.Legend = {};
6  
7 GraphHandler.Legend.OnEnter = function()
8 if( this.item or this.tooltop ) then
9 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
10 if (this.item and this.item ~= "") then
11 GameTooltip:SetHyperlink("item:"..this.item);
12 elseif (this.tooltip) then
13 GameTooltip:SetText(this.tooltip);
14 end
15 end
16 end
17  
18 GraphHandler.Legend.OnLeave = function()
19 if( this.item or this.tooltop ) then
20 this.updateToolTip = nil;
21 GameTooltip:Hide();
22 end
23 end
24  
25 GraphHandler.Legend.OnClick = function(button)
26 if ( button == "LeftButton" ) then
27 if( IsShiftKeyDown() and this.item ) then
28 GraphHandler.Legend.ChatLink(this.item, this.name, this.color);
29 end
30 end
31 end
32  
33 GraphHandler.Legend.ChatLink = FishingBuddy.ChatLink;
34  
35 GraphHandler.BAR = "BAR";
36 GraphHandler.LEGEND = "LEGEND";
37 GraphHandler.LINE = "LINE";
38 GraphHandler.LABEL = "LABEL";
39 GraphHandler.TEXT = "TEXT";
40  
41 GraphHandler.InitElements = function()
42 if ( not this.elements ) then
43 this.elements = {};
44 this.elements[GraphHandler.BAR] = {};
45 this.elements[GraphHandler.LINE] = {};
46 this.elements[GraphHandler.LEGEND] = {};
47 this.elements[GraphHandler.LABEL] = {};
48 this.elements[GraphHandler.TEXT] = {};
49 end
50 end
51  
52 local function SetColorBar(bar, base, x, y, width, height, r, g, b)
53 local name;
54 if ( type(bar) == "STRING" ) then
55 name = bar;
56 bar = getglobal(name);
57 elseif ( bar ) then
58 name = bar:GetName();
59 end
60 if ( bar ) then
61 if ( not r ) then
62 r = 1.0;
63 g = 1.0;
64 b = 1.0;
65 end
66 if ( base ) then
67 local tex = getglobal(name.."Texture");
68 if ( x and y ) then
69 bar:ClearAllPoints();
70 bar:SetPoint("BOTTOMLEFT", base, "BOTTOMLEFT", x, y);
71 end
72 if ( width ) then
73 bar:SetWidth(width);
74 end
75 if ( height ) then
76 bar:SetHeight(height);
77 end
78 tex:SetVertexColor(r, g, b);
79 bar:Show();
80 else
81 bar:Hide();
82 end
83 end
84 end
85  
86 -- Registration functions
87  
88 GraphHandler.Register = function(kind, what)
89 local frame = this;
90 local lastframe = nil;
91 for idx=1,5 do
92 frame = frame:GetParent();
93 if ( frame == lastframe ) then
94 break;
95 end
96 if ( frame and frame.elements ) then
97 if ( not frame.elements[kind] ) then
98 frame.elements[kind] = {};
99 end
100 tinsert(frame.elements[kind], what);
101 break;
102 end
103 lastframe = frame;
104 end
105 end
106  
107 GraphHandler.PlotData = function(frame, data, offset, skip, r, g, b)
108 local limit = table.getn(data);
109 local start = 1;
110 if ( data[0] ) then
111 start = 0;
112 limit = limit - 1;
113 end
114  
115 local bdx=offset+1;
116 local bwid = frame.barWidth;
117 local bspc = frame.barSpacing;
118 local maxval = frame.maxVal;
119 local xoff = offset*bspc;
120 local yoff = 0;
121 local graphHeight = frame:GetHeight();
122 for idx=start,limit,1 do
123 local bar = frame.elements[GraphHandler.BAR][bdx];
124 bdx = bdx + skip + 1;
125 if ( bar ) then
126 if ( (maxval > 0) and (data[idx] > 0) ) then
127 local height = (data[idx]*graphHeight)/maxval;
128 SetColorBar(bar, frame, xoff, 0, bwid, height, r, g, b);
129 else
130 bar:Hide();
131 end
132 end
133 xoff = xoff + bwid + skip*bspc;
134 end
135 return xoff - skip*bspc;
136 end
137  
138 GraphHandler.PlotLegend = function(frame, ldx, name, item, texture, r, g, b)
139 local legend = frame.elements[GraphHandler.LEGEND][ldx];
140 if ( legend ) then
141 local name = legend:GetName();
142 local icon = getglobal(name.."Icon");
143 local tex = getglobal(name.."IconTexture");
144 local color = getglobal(name.."Color");
145 -- SetColorBar(color, legend, nil, nil, nil, nil, r, g, b);
146 SetColorBar(color, legend, 0, 1, 10, 16, r, g, b);
147 icon:Show();
148 tex:SetTexture(texture);
149 tex:Show();
150 legend:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, -(ldx-1)*21);
151 legend.item = item;
152 legend.name = name;
153 legend:Show();
154 end
155 end
156  
157 GraphHandler.PlotGrid = function(frame, label, texth, width, textv, height)
158 local ldx=1;
159 local tdx=1;
160 if ( not width ) then
161 width = frame:GetWidth();
162 end
163 if ( not height ) then
164 height = frame:GetHeight();
165 end
166 if ( label ) then
167 local button = frame.elements[GraphHandler.TEXT][tdx];
168 if ( button ) then
169 local text = getglobal(button:GetName().."T");
170 text:SetText(label);
171 text:SetPoint("BOTTOM", frame, "BOTTOM", 0, -28);
172 text:SetVertexColor(1.0, 1.0, 1.0);
173 text:Show();
174 tdx = tdx + 1;
175 end
176 end
177 if ( texth ) then
178 local linesh = 0;
179 for _,_ in texth do
180 linesh = linesh + 1;
181 end
182 local offset = height/(linesh-1);
183 for label,tick in texth do
184 local line = frame.elements[GraphHandler.LINE][ldx];
185 if ( line ) then
186 ldx = ldx + 1;
187 line:SetHeight(1);
188 line:SetWidth(width);
189 line:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 0, tick*offset);
190 line:SetAlpha(0.5);
191 line:Show();
192 local button = frame.elements[GraphHandler.TEXT][tdx];
193 if ( button ) then
194 local text = getglobal(button:GetName().."T");
195 if ( type(label) ~= "string" ) then
196 label = string.format("%3d", label);
197 end
198 text:SetText(label);
199 text:SetPoint("LEFT", line, "LEFT", -(text:GetWidth()+4), 0);
200 tdx = tdx + 1;
201 end
202 end
203 end
204 end
205 if ( textv ) then
206 local linesv = 0;
207 for _,_ in textv do
208 linesv = linesv + 1;
209 end
210 local offset = frame.barSpacing + frame.barWidth;
211 for label,tick in textv do
212 local line = frame.elements[GraphHandler.LINE][ldx];
213 if ( line ) then
214 local xpos = tick*offset;
215 ldx = ldx + 1;
216 line:SetHeight(height);
217 line:SetWidth(1);
218 line:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", xpos, 0);
219 line:SetAlpha(0.5);
220 line:Show();
221 local button = frame.elements[GraphHandler.TEXT][tdx];
222 if ( button ) then
223 local text = getglobal(button:GetName().."T");
224 if ( type(label) ~= "string" ) then
225 label = string.format("%3d", label);
226 end
227 text:SetText(label);
228 local wid = text:GetWidth();
229 if ( xpos < wid ) then
230 text:SetPoint("TOPLEFT", line, "BOTTOMLEFT", 0, -4);
231 elseif ( xpos > (width - wid) ) then
232 text:SetPoint("TOPRIGHT", line, "BOTTOMRIGHT", 0, -4);
233 else
234 text:SetPoint("TOP", line, "BOTTOM", 0, -4);
235 end
236 tdx = tdx + 1;
237 end
238 end
239 end
240 end
241 end