comparison Libs/DF/panel.lua @ 56:7c0f819a85c6 v7.3.5.056

- Framework update.
author Tercio
date Sun, 11 Mar 2018 10:50:12 -0300
parents 307f5af3ad02
children 0682d738499b
comparison
equal deleted inserted replaced
55:307f5af3ad02 56:7c0f819a85c6
2413 end 2413 end
2414 2414
2415 end 2415 end
2416 2416
2417 local chart_panel_set_scale = function (self, amt, func, text) 2417 local chart_panel_set_scale = function (self, amt, func, text)
2418
2419 if (type (amt) ~= "number") then 2418 if (type (amt) ~= "number") then
2420 return 2419 return
2421 end 2420 end
2422 2421
2423 local piece = amt / 1000 / 8 2422 --each line amount, then multiply the line index by this number
2424 if (not text or text == "") then 2423 local piece = amt / 8
2425 text = amt > 1000000 and "M" or amt > 1000 and "K" 2424
2426 end
2427
2428 for i = 1, 8 do 2425 for i = 1, 8 do
2429 if (func) then 2426 if (func) then
2430 self ["dpsamt" .. math.abs (i-9)]:SetText ( func (piece*i) .. (text or "")) 2427 self ["dpsamt" .. math.abs (i-9)]:SetText (func (piece*i))
2431 else 2428 else
2432 if (piece*i > 1) then 2429 if (piece*i > 1) then
2433 self ["dpsamt" .. math.abs (i-9)]:SetText ( format ("%.1f", piece*i) .. (text or "")) 2430 self ["dpsamt" .. math.abs (i-9)]:SetText (DF.FormatNumber (piece*i))
2434 else 2431 else
2435 self ["dpsamt" .. math.abs (i-9)]:SetText ( format ("%.3f", piece*i) .. (text or "")) 2432 self ["dpsamt" .. math.abs (i-9)]:SetText (format ("%.3f", piece*i))
2436 end 2433 end
2437 end 2434 end
2438 end 2435 end
2439 end 2436 end
2440 2437
2533 2530
2534 local thisbox = {} 2531 local thisbox = {}
2535 self.BoxLabels [next_box] = thisbox 2532 self.BoxLabels [next_box] = thisbox
2536 2533
2537 local box = DF:NewImage (self.Graphic, nil, 16, 16, "border") 2534 local box = DF:NewImage (self.Graphic, nil, 16, 16, "border")
2538
2539 local text = DF:NewLabel (self.Graphic) 2535 local text = DF:NewLabel (self.Graphic)
2540 2536
2541 local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork") 2537 local border = DF:NewImage (self.Graphic, [[Interface\DialogFrame\UI-DialogBox-Gold-Corner]], 30, 30, "artwork")
2542 border:SetPoint ("center", box, "center", -3, -4) 2538 border:SetPoint ("center", box, "center", -3, -4)
2543 border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]]) 2539 border:SetTexture ([[Interface\DialogFrame\UI-DialogBox-Gold-Corner]])
2544 2540
2545 local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay") 2541 local checktexture = DF:NewImage (self.Graphic, [[Interface\Buttons\UI-CheckBox-Check]], 18, 18, "overlay")
2546 checktexture:SetPoint ("center", box, "center", -1, -1) 2542 checktexture:SetPoint ("center", box, "center", 0, -1)
2547 checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]]) 2543 checktexture:SetTexture ([[Interface\Buttons\UI-CheckBox-Check]])
2548 2544
2549 thisbox.box = box 2545 thisbox.box = box
2550 thisbox.text = text 2546 thisbox.text = text
2551 thisbox.border = border 2547 thisbox.border = border
2555 local button = CreateFrame ("button", nil, self.Graphic) 2551 local button = CreateFrame ("button", nil, self.Graphic)
2556 button:SetSize (20, 20) 2552 button:SetSize (20, 20)
2557 button:SetScript ("OnClick", function() 2553 button:SetScript ("OnClick", function()
2558 chart_panel_enable_line (self, thisbox) 2554 chart_panel_enable_line (self, thisbox)
2559 end) 2555 end)
2560 button:SetPoint ("center", box.widget or box, "center") 2556 button:SetPoint ("topleft", box.widget or box, "topleft", 0, 0)
2557 button:SetPoint ("bottomright", box.widget or box, "bottomright", 0, 0)
2558
2559 button:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
2560 button:SetBackdropColor (0, 0, 0, 0.0)
2561 button:SetBackdropBorderColor (0, 0, 0, 1)
2561 2562
2562 thisbox.button = button 2563 thisbox.button = button
2563 2564
2564 thisbox.box:SetPoint ("right", text, "left", -4, 0) 2565 thisbox.box:SetPoint ("right", text, "left", -4, 0)
2565 2566
2566 if (next_box == 1) then 2567 if (next_box == 1) then
2567 thisbox.text:SetPoint ("topright", self, "topright", -35, -16) 2568 thisbox.text:SetPoint ("topright", self, "topright", -35, -16)
2568 else 2569 else
2569 thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -7, 0) 2570 thisbox.text:SetPoint ("right", self.BoxLabels [next_box-1].box, "left", -17, 0)
2570 end 2571 end
2571 2572
2572 return thisbox 2573 return thisbox
2573 2574
2574 end 2575 end
2575 2576
2576 local realign_labels = function (self) 2577 local realign_labels = function (self)
2578
2579 if (not self.ShowHeader) then
2580 for _, box in ipairs (self.BoxLabels) do
2581 box.check:Hide()
2582 box.button:Hide()
2583 box.border:Hide()
2584 box.box:Hide()
2585 box.text:Hide()
2586 end
2587 return
2588 end
2577 2589
2578 local width = self:GetWidth() - 108 2590 local width = self:GetWidth() - 108
2579 2591
2580 local first_box = self.BoxLabels [1] 2592 local first_box = self.BoxLabels [1]
2581 first_box.text:SetPoint ("topright", self, "topright", -35, -16) 2593 first_box.text:SetPoint ("topright", self, "topright", -35, -16)
2592 2604
2593 if (line_width > width) then 2605 if (line_width > width) then
2594 line_width = box.text:GetStringWidth() + 26 2606 line_width = box.text:GetStringWidth() + 26
2595 box.text:SetPoint ("topright", self, "topright", -35, -40) 2607 box.text:SetPoint ("topright", self, "topright", -35, -40)
2596 else 2608 else
2597 box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -7, 0) 2609 box.text:SetPoint ("right", self.BoxLabels [i-1].box, "left", -27, 0)
2598 end 2610 end
2599 else 2611 else
2600 break 2612 break
2601 end 2613 end
2602 end 2614 end
2603 2615
2616 if (self.HeaderOnlyIndicator) then
2617 for _, box in ipairs (self.BoxLabels) do
2618 box.check:Hide()
2619 box.button:Hide()
2620 end
2621 return
2622 end
2623
2604 end 2624 end
2605 2625
2606 local chart_panel_add_label = function (self, color, name, type, number) 2626 local chart_panel_add_label = function (self, color, name, type, number)
2607 2627
2608 local next_box = self.BoxLabelsAmount 2628 local next_box = self.BoxLabelsAmount
2609 local thisbox = self.BoxLabels [next_box] 2629 local thisbox = self.BoxLabels [next_box]
2610 2630
2611 if (not thisbox) then 2631 if (not thisbox) then
2612 thisbox = create_box (self, next_box) 2632 thisbox = create_box (self, next_box)
2613 end 2633 end
2614 2634
2615 self.BoxLabelsAmount = self.BoxLabelsAmount + 1 2635 self.BoxLabelsAmount = self.BoxLabelsAmount + 1
2616 2636
2617 thisbox.type = type 2637 thisbox.type = type
2618 thisbox.index = number 2638 thisbox.index = number
2619 2639
2620 thisbox.box:SetColorTexture (unpack (color)) 2640 thisbox.box:SetColorTexture (unpack (color))
2621 thisbox.text:SetText (name) 2641 thisbox.text:SetText (name)
2622 2642
2623 thisbox.check:Show() 2643 thisbox.check:Show()
2624 thisbox.button:Show() 2644 thisbox.button:Show()
2625 thisbox.border:Show() 2645 thisbox.border:Hide()
2626 thisbox.box:Show() 2646 thisbox.box:Show()
2627 thisbox.text:Show() 2647 thisbox.text:Show()
2628 2648
2629 thisbox.showing = true 2649 thisbox.showing = true
2630 thisbox.enabled = true 2650 thisbox.enabled = true
2631 2651
2632 realign_labels (self) 2652 realign_labels (self)
2633 2653
2636 local line_default_color = {1, 1, 1} 2656 local line_default_color = {1, 1, 1}
2637 local draw_overlay = function (self, this_overlay, overlayData, color) 2657 local draw_overlay = function (self, this_overlay, overlayData, color)
2638 2658
2639 local pixel = self.Graphic:GetWidth() / self.TimeScale 2659 local pixel = self.Graphic:GetWidth() / self.TimeScale
2640 local index = 1 2660 local index = 1
2641 local r, g, b = unpack (color or line_default_color) 2661 local r, g, b, a = unpack (color or line_default_color)
2642 2662
2643 for i = 1, #overlayData, 2 do 2663 for i = 1, #overlayData, 2 do
2644 local aura_start = overlayData [i] 2664 local aura_start = overlayData [i]
2645 local aura_end = overlayData [i+1] 2665 local aura_end = overlayData [i+1]
2646 2666
2657 else 2677 else
2658 --malformed table 2678 --malformed table
2659 this_block:SetWidth (pixel*5) 2679 this_block:SetWidth (pixel*5)
2660 end 2680 end
2661 2681
2662 this_block:SetColorTexture (r, g, b, 0.25) 2682 this_block:SetColorTexture (r, g, b, a or 0.25)
2663 this_block:Show() 2683 this_block:Show()
2664 2684
2665 index = index + 1 2685 index = index + 1
2666 end 2686 end
2667 2687
2684 end 2704 end
2685 2705
2686 draw_overlay (self, this_overlay, overlayData, color) 2706 draw_overlay (self, this_overlay, overlayData, color)
2687 2707
2688 tinsert (self.OData, {overlayData, color or line_default_color}) 2708 tinsert (self.OData, {overlayData, color or line_default_color})
2689 if (name) then 2709 if (name and self.HeaderShowOverlays) then
2690 self:AddLabel (color or line_default_color, name, "overlay", #self.OData) 2710 self:AddLabel (color or line_default_color, name, "overlay", #self.OData)
2691 end 2711 end
2692 end 2712 end
2693 2713
2694 self.OverlaysAmount = self.OverlaysAmount + 1 2714 self.OverlaysAmount = self.OverlaysAmount + 1
2695 end 2715 end
2716
2717 -- Define the tricube weight function
2718 function calc_cubeweight (i, j, d)
2719 local w = ( 1 - math.abs ((j-i)/d)^3)^3
2720 if w < 0 then
2721 w = 0;
2722 end
2723 return w
2724 end
2725
2726 local calc_lowess_smoothing = function (self, data, bandwidth)
2727 local length = #data
2728 local newData = {}
2729
2730 for i = 1, length do
2731 local A = 0
2732 local B = 0
2733 local C = 0
2734 local D = 0
2735 local E = 0
2736
2737 -- Calculate span of values to be included in the regression
2738 local jmin = floor (i-bandwidth/2)
2739 local jmax = ceil (i+bandwidth/2)
2740 if jmin < 1 then
2741 jmin = 1
2742 end
2743 if jmax > length then
2744 jmax = length
2745 end
2746
2747 -- For all the values in the span, compute the weight and then the linear fit
2748
2749 for j = jmin, jmax do
2750 w = calc_cubeweight (i, j, bandwidth/2)
2751 x = j
2752 y = data [j]
2753
2754 A = A + w*x
2755 B = B + w*y
2756 C = C + w*x^2
2757 D = D + w*x*y
2758 E = E + w
2759 end
2760
2761 -- Calculate a (slope) and b (offset) for the linear fit
2762 local a = (A*B-D*E)/(A^2 - C*E);
2763 local b = (A*D-B*C)/(A^2 - C*E);
2764
2765 -- Calculate the smoothed value by the formula y=a*x+b (x <- i)
2766 newData [i] = a*i+b;
2767
2768 end
2769
2770 return newData
2771 end
2772
2773 local calc_stddev = function (self, data)
2774 local total = 0
2775 for i = 1, #data do
2776 total = total + data[i]
2777 end
2778 local mean = total / #data
2779
2780 local totalDistance = 0
2781 for i = 1, #data do
2782 totalDistance = totalDistance + ((data[i] - mean) ^ 2)
2783 end
2784
2785 local deviation = math.sqrt (totalDistance / #data)
2786 return deviation
2787 end
2788
2789
2696 2790
2697 local SMA_table = {} 2791 local SMA_table = {}
2698 local SMA_max = 0 2792 local SMA_max = 0
2699 local reset_SMA = function() 2793 local reset_SMA = function()
2700 table.wipe (SMA_table) 2794 table.wipe (SMA_table)
2734 local spacement = width - 78 - 60 2828 local spacement = width - 78 - 60
2735 spacement = spacement / 16 2829 spacement = spacement / 16
2736 2830
2737 for i = 1, 17 do 2831 for i = 1, 17 do
2738 local label = self.TimeLabels [i] 2832 local label = self.TimeLabels [i]
2739 label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), 13) 2833 label:SetPoint ("bottomleft", self, "bottomleft", 78 + ((i-1)*spacement), self.TimeLabelsHeight)
2740 label.line:SetHeight (height - 45) 2834 label.line:SetHeight (height - 45)
2741 end 2835 end
2742 2836
2743 local spacement = (self.Graphic:GetHeight()) / 8 2837 local spacement = (self.Graphic:GetHeight()) / 8
2744 for i = 1, 8 do 2838 for i = 1, 8 do
2758 local _data = {} 2852 local _data = {}
2759 local max_value = graphicData.max_value 2853 local max_value = graphicData.max_value
2760 local amount = #graphicData 2854 local amount = #graphicData
2761 2855
2762 local scaleW = 1/self:GetWidth() 2856 local scaleW = 1/self:GetWidth()
2763 2857
2764 local content = graphicData 2858 local content = graphicData
2765 tinsert (content, 1, 0) 2859 tinsert (content, 1, 0)
2766 tinsert (content, 1, 0) 2860 tinsert (content, 1, 0)
2767 tinsert (content, #content+1, 0) 2861 tinsert (content, #content+1, 0)
2768 tinsert (content, #content+1, 0) 2862 tinsert (content, #content+1, 0)
2883 end 2977 end
2884 2978
2885 f:SetTime (max_time) 2979 f:SetTime (max_time)
2886 2980
2887 chart_panel_onresize (f) 2981 chart_panel_onresize (f)
2888 2982 end
2889 end 2983
2890 2984
2891 2985
2892 2986
2893 local chart_panel_vlines_on = function (self) 2987 local chart_panel_vlines_on = function (self)
2894 for i = 1, 17 do 2988 for i = 1, 17 do
2972 f.CloseButton = c 3066 f.CloseButton = c
2973 3067
2974 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0}) 3068 local title = DF:NewLabel (f, nil, "$parentTitle", "chart_title", "Chart!", nil, 20, {1, 1, 0})
2975 title:SetPoint ("topleft", f, "topleft", 110, -13) 3069 title:SetPoint ("topleft", f, "topleft", 110, -13)
2976 3070
2977 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
2978 bottom_texture:SetColorTexture (0, 0, 0, .6)
2979 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 7)
2980 bottom_texture:SetPoint ("bottomright", f, "bottomright", -8, 7)
2981
2982 f.Overlays = {} 3071 f.Overlays = {}
2983 f.OverlaysAmount = 1 3072 f.OverlaysAmount = 1
2984 3073
2985 f.BoxLabels = {} 3074 f.BoxLabels = {}
2986 f.BoxLabelsAmount = 1 3075 f.BoxLabelsAmount = 1
2987 3076
2988 f.TimeLabels = {} 3077 f.ShowHeader = true
2989 for i = 1, 17 do 3078 f.HeaderOnlyIndicator = false
2990 local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall") 3079 f.HeaderShowOverlays = true
2991 time:SetText ("00:00")
2992 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), 13)
2993 f.TimeLabels [i] = time
2994
2995 local line = f:CreateTexture (nil, "border")
2996 line:SetSize (1, h-45)
2997 line:SetColorTexture (1, 1, 1, .1)
2998 line:SetPoint ("bottomleft", time, "topright", 0, -10)
2999 line:Hide()
3000 time.line = line
3001 end
3002 3080
3003 --graphic 3081 --graphic
3004 local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67) 3082 local g = LibStub:GetLibrary("LibGraph-2.0"):CreateGraphLine (name .. "Graphic", f, "topleft","topleft", 108, -35, w - 120, h - 67)
3005 g:SetXAxis (-1,1) 3083 g:SetXAxis (-1,1)
3006 g:SetYAxis (-1,1) 3084 g:SetYAxis (-1,1)
3020 g:SetLineTexture ("line") 3098 g:SetLineTexture ("line")
3021 3099
3022 f.Graphic = g 3100 f.Graphic = g
3023 f.GData = {} 3101 f.GData = {}
3024 f.OData = {} 3102 f.OData = {}
3103 f.ChartFrames = {}
3025 3104
3026 --div lines 3105 --div lines
3027 for i = 1, 8, 1 do 3106 for i = 1, 8, 1 do
3028 local line = g:CreateTexture (nil, "overlay") 3107 local line = g:CreateTexture (nil, "overlay")
3029 line:SetColorTexture (1, 1, 1, .2) 3108 line:SetColorTexture (1, 1, 1, .05)
3030 line:SetWidth (670) 3109 line:SetWidth (670)
3031 line:SetHeight (1.1) 3110 line:SetHeight (1.1)
3032 3111
3033 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall") 3112 local s = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
3034 f ["dpsamt"..i] = s 3113 f ["dpsamt"..i] = s
3035 s:SetText ("100k") 3114 s:SetText ("100k")
3036 s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i))) 3115 s:SetPoint ("topleft", f, "topleft", 27, -61 + (-(24.6*i)))
3037 3116
3038 line:SetPoint ("topleft", s, "bottom", -27, 0) 3117 line:SetPoint ("topleft", s, "bottom", -27, 0)
3118 line:SetPoint ("topright", g, "right", 0, 0)
3039 s.line = line 3119 s.line = line
3040 end 3120 end
3121
3122 --create time labels and the bottom texture to use as a background to these labels
3123 f.TimeLabels = {}
3124 f.TimeLabelsHeight = 16
3125
3126 for i = 1, 17 do
3127 local time = f:CreateFontString (nil, "overlay", "GameFontHighlightSmall")
3128 time:SetText ("00:00")
3129 time:SetPoint ("bottomleft", f, "bottomleft", 78 + ((i-1)*36), f.TimeLabelsHeight)
3130 f.TimeLabels [i] = time
3131
3132 local line = f:CreateTexture (nil, "border")
3133 line:SetSize (1, h-45)
3134 line:SetColorTexture (1, 1, 1, .1)
3135 line:SetPoint ("bottomleft", time, "topright", 0, -10)
3136 line:Hide()
3137 time.line = line
3138 end
3139
3140 local bottom_texture = DF:NewImage (f, nil, 702, 25, "background", nil, nil, "$parentBottomTexture")
3141 bottom_texture:SetColorTexture (.1, .1, .1, .7)
3142 bottom_texture:SetPoint ("topright", g, "bottomright", 0, 0)
3143 bottom_texture:SetPoint ("bottomleft", f, "bottomleft", 8, 12)
3144
3145
3041 3146
3042 f.SetTime = chart_panel_align_timelabels 3147 f.SetTime = chart_panel_align_timelabels
3043 f.EnableVerticalLines = chart_panel_vlines_on 3148 f.EnableVerticalLines = chart_panel_vlines_on
3044 f.DisableVerticalLines = chart_panel_vlines_off 3149 f.DisableVerticalLines = chart_panel_vlines_off
3045 f.SetTitle = chart_panel_set_title 3150 f.SetTitle = chart_panel_set_title
3049 f.CanMove = chart_panel_can_move 3154 f.CanMove = chart_panel_can_move
3050 f.AddLabel = chart_panel_add_label 3155 f.AddLabel = chart_panel_add_label
3051 f.AddOverlay = chart_panel_add_overlay 3156 f.AddOverlay = chart_panel_add_overlay
3052 f.HideCloseButton = chart_panel_hide_close_button 3157 f.HideCloseButton = chart_panel_hide_close_button
3053 f.RightClickClose = chart_panel_right_click_close 3158 f.RightClickClose = chart_panel_right_click_close
3159 f.CalcStdDev = calc_stddev
3160 f.CalcLowessSmoothing = calc_lowess_smoothing
3054 3161
3055 f:SetScript ("OnSizeChanged", chart_panel_onresize) 3162 f:SetScript ("OnSizeChanged", chart_panel_onresize)
3056 chart_panel_onresize (f) 3163 chart_panel_onresize (f)
3057 3164
3058 return f 3165 return f