local NanamiDPS = NanamiDPS local DataStore = NanamiDPS.DataStore local L = NanamiDPS.L local DamageBySpell = {} function DamageBySpell:GetName() return L["Damage by Spell"] end function DamageBySpell:GetBars(segment) if not segment or not segment.data or not segment.data.damage then return {} end -- Aggregate all spells across all players local spellTotals = {} for name, entry in pairs(segment.data.damage) do if entry.spells then for spell, amount in pairs(entry.spells) do spellTotals[spell] = (spellTotals[spell] or 0) + amount end end end local bars = {} for spell, total in pairs(spellTotals) do local r, g, b = NanamiDPS.str2rgb(spell) r = r * 0.5 + 0.4 g = g * 0.5 + 0.4 b = b * 0.5 + 0.4 table.insert(bars, { id = spell, name = spell, value = total, r = r, g = g, b = b, }) end table.sort(bars, function(a, b) return a.value > b.value end) local grandTotal = 0 for _, bar in ipairs(bars) do grandTotal = grandTotal + bar.value end for _, bar in ipairs(bars) do bar.percent = grandTotal > 0 and (bar.value / grandTotal * 100) or 0 end return bars end function DamageBySpell:GetTooltip(spellName, segment, tooltip) tooltip:AddLine("|cffffd100" .. (spellName or L["Unknown"])) if segment and segment.data.damage then local users = {} for name, entry in pairs(segment.data.damage) do if entry.spells and entry.spells[spellName] then table.insert(users, { name = name, amount = entry.spells[spellName] }) end end table.sort(users, function(a, b) return a.amount > b.amount end) if table.getn(users) > 0 then local total = 0 for _, u in ipairs(users) do total = total + u.amount end tooltip:AddDoubleLine("|cffffffff" .. L["Total Amount"], "|cffffffff" .. NanamiDPS.formatNumber(total)) tooltip:AddLine(" ") tooltip:AddLine("|cffffd100" .. L["Players"] .. ":") for _, u in ipairs(users) do local pct = total > 0 and NanamiDPS.round(u.amount / total * 100, 1) or 0 tooltip:AddDoubleLine("|cffffffff" .. u.name, "|cffffffff" .. NanamiDPS.formatNumber(u.amount) .. " (" .. pct .. "%)") end end end end function DamageBySpell:GetReportLines(segment, count) local bars = self:GetBars(segment) local lines = {} count = count or 5 for i = 1, math.min(count, table.getn(bars)) do local d = bars[i] table.insert(lines, string.format("%d. %s - %s (%.1f%%)", i, d.name, NanamiDPS.formatNumber(d.value), d.percent)) end return lines end NanamiDPS:RegisterModule("DamageBySpell", DamageBySpell)