--DISPLAY
function()
    local minhit, maxhit = 9999999, 0
    local function tohex(input)
        local output = string.format("%x", input * 255)
        return output
    end

    local function grad(c, minhit, maxhit)
        c = (((maxhit - c) / (maxhit - minhit)) * 1)
        if c > 0.5 then
            c = 1 - (2 * (c - 0.5))
            return c, 1, 0, 1
        else
            c = c * 2
            return 1, c, 0, 1
        end
    end

    local function shorten(val)
        local function round(var, n)
            if (n) then
                var = math.floor((var * 10^n) + 0.5) / (10^n)
            else
                var = math.floor(var+0.5)
            end
            return var
        end
        local n = 2
        if val < 1e3 then
            return round(val, n)
        elseif val > 1e3 and val < 1e6 then
            return round(val / 1e3, n) .. "k"
        elseif val > 1e6 and val < 1e9 then
            return round(val / 1e6, n) .. "M"
        elseif val > 1e9 then
            return round(val / 1e9, n) .. "G"
        end
    end

    local output = "MELEE" .. "\n"
    local totaldmgdone = 0
    for k,v in ipairs(aura_env.swings) do --Get total dmg for average hit
        totaldmgdone = totaldmgdone + v
    end
    if #aura_env.swings > 0 then
        output = output .. shorten(totaldmgdone / #aura_env.swings) .. "\n\n"
    
        for k,v in ipairs(aura_env.swings) do --Get min and max hit
            if v > maxhit then
                maxhit = v
            end
            if v < minhit then
                minhit = v
            end
        end
        for k,v in ipairs(aura_env.swings) do --Final format for output
            local color1, color2, color3, color4 = 0, 0, 0, 0
            color1, color2, color3, color4 = grad(v, minhit, maxhit)
            color1, color2, color3, color4 = tohex(color1), tohex(color2), tohex(color3), tohex(color4)
            color1, color2, color3, color4 = tostring(color1), tostring(color2), tostring(color3), tostring(color4)
            if color1 == "0" then color1 = "00" end
            if color2 == "0" then color2 = "00" end
            if color3 == "0" then color3 = "00" end
            local color = "|c" .. color4 .. color1 .. color2 .. color3
            output = output .. color .. shorten(v) .. "\n"
        end
    end
    return output
end

--PLAYER_REGEN_DISABLED
function()
    aura_env.swings = {}
end

--COMBAT_LOG_EVENT_UNFILTERED
function(...)
    local subEvent = select(3, ...)
    local target = select(10, ...)
    if subEvent == "SWING_DAMAGE" and target == UnitName("player") then
        local block = select(17, ...) or 0
        local var = select(13, ...) + block
        if #aura_env.swings == 10 then
            table.remove(aura_env.swings, 1)
        end
        table.insert(aura_env.swings, var)
    end
end

--INIT
aura_env.swingerino = 10
aura_env.swings = {}
aura_env.pointer = 1