--[[ © 2017 Thriving Ventures Limited do not share, re-distribute or modify without permission of its author (gustaf@thrivingventures.com). ]] local plugin = plugin; plugin.stored = plugin.stored or {}; local months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" } local chartHTML = [[
]]; local category = {}; category.name = "Analytics"; category.material = "serverguard/menuicons/icon_analytics.png"; category.permissions = "Analytics"; function category:Create(base) self.stepping = 10; base.panel = base:Add("tiger.panel"); base.panel:DockPadding(4, 4, 4, 4); base.panel:Dock(FILL); category.chart = base.panel:Add("DHTML"); category.chart:SetHTML(chartHTML); category.chart:Dock(FILL); function category.chart:ClearData() -- sometimes these are called at weird times self:RunJavascript("if (typeof clearAnalyticsData === \"function\"){ clearAnalyticsData(); }"); end; function category.chart:SetData(month, total, unique) self:RunJavascript("if (typeof setAnalyticsData === \"function\"){ setAnalyticsData('" .. month .. "', " .. total .. ", " .. unique .. "); }"); end; function category.chart:Refresh() local theme = serverguard.themes.GetCurrent(); self:RunJavascript([[ if (typeof drawChart === "function") { background_color = "rgb(]] .. util.ColorString(theme.tiger_panel_bg, true) .. [[)"; text_color = "rgb(]] .. util.ColorString(theme.tiger_panel_label, true) .. [[)"; drawChart(); } ]]); end; function category.chart:OnTigerThemeChanged() self:Refresh(); end; serverguard.themes.AddPanel(category.chart, "tiger_panel_bg"); end; function category:Update(base) if (serverguard.player:HasPermission(LocalPlayer(), "Analytics")) then serverguard.netstream.Start("sgRequestAnalytics", true); end; end; plugin:AddSubCategory("Information", category); serverguard.netstream.Hook("sgSendAnalytics", function(data) if (category and category.chart) then category.chart:ClearData(); for k, v in pairs(data) do if (months[k]) then category.chart:SetData(months[util.ToNumber(k)], util.ToNumber(v.total or 0), util.ToNumber(v.uniques or 0)); end; end; category.chart:Refresh(); end; end);