-- ==================================================================================================================== --
--															--
--	File			PieChart.lua										--
--															--
--															--
--	Author			Zarnivoop, Luckycire(maintainer)		| Version	   :	  7.0.0 |	--
--										| Curse-Project-ID :	 	|	--
--										| License	   :	  MIT/X |	--
--															--
--											| Basis, thx	|		--
--															--
--															--
--				Baltha						| Version	   :	 11.2.0 |	--
--										| Curse-Project-ID :	1188318 |	--
--										| License	   :	  MIT/X |	--
--															--
--											| Revision	|		--
--															--
--															--
--	Path ( Revision )	"..\World of Warcraft\_retail_\Interface\AddOns\Skada\Misc\Changelog\ChangeLog.txt"	--
--															--
-- ==================================================================================================================== --


local _, Skada	  = ...


local L		  = LibStub("AceLocale-3.0"):GetLocale("Skada", false)
local mod	  = Skada:NewModule("Pie chart")


local libwindow	  = LibStub("LibWindow-1.1")
local libgraph    = LibStub("LibGraph-2.0")
local media	  = LibStub("LibSharedMedia-3.0")


local emptyLines  = string.rep("\n", 2)
local blankChars  = string.rep(" " , 6)


local hue
local goldenRatio = 0.618033988749895
local saturation  = 0.3
local value	  = 0.95


mod.name	  = L["Pie chart"]
mod.description   = emptyLines .. blankChars .. "\124cFF00FF00" .. L["Pie chart"] .. "\n" .. blankChars ..  "|cffffffff" .. L["The pie chart; this can be visually customized."]


Skada:AddDisplaySystem("pie", mod)




-- ========================================
--| formerly the common part (Shared.lua) |
-- ========================================
local function GenerateColor(hue, saturation, value)

	local hue_int = math.floor(hue * 6)

	local f	      = hue * 6 - hue_int
	local p       = value * (1 - saturation)
	local q       = value * (1 - f * saturation)
	local t       = value * (1 - (1 - f) * saturation)

	local r, g, b = 255, 255, 255


	if hue_int and hue_int == 0 then

		r = value
		g = t
		b = p
	end


	if hue_int and hue_int == 1 then

		r = q
		g = value
		b = p
	end


	if hue_int and hue_int == 2 then

		r = p
		g = value
		b = t
	end


	if hue_int and hue_int == 3 then

		r = p
		g = q
		b = value
	end


	if hue_int and hue_int == 4 then

		r = t
		g = p
		b = value
	end


	if hue_int and hue_int == 5 then

		r = value
		g = p
		b = q
	end


	return { r, g, b }
end




local function AddButton(self, title, normaltex, highlighttex, clickfunc)

	if not self.buttons then self.buttons = {} end


	local btn = CreateFrame("Button", nil, self)


	btn.title = title

	btn:SetFrameLevel(5)
	btn:ClearAllPoints()

--	btn:SetSize(13, 13)
	btn:SetWidth(13)
	btn:SetHeight(13)

	btn:SetNormalTexture(normaltex)
	btn:SetHighlightTexture(highlighttex, 1.0)
	btn:SetAlpha(0.5)

	btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")


	btn:SetScript("OnClick", clickfunc)


	btn:SetScript("OnEnter",

				function(this)

					GameTooltip_SetDefaultAnchor(GameTooltip, this)
					GameTooltip:SetText(title)
					GameTooltip:Show()
				end

		     )


	btn:SetScript("OnLeave",

				function()

					GameTooltip:Hide()
				end

		     )


	btn:Show()


	table.insert(self.buttons, btn)
	self:AdjustButtons()
end




local function AdjustButtons(self)

	local nr      = 0
	local lastbtn = nil


	for i, btn in ipairs(self.buttons) do

		btn:ClearAllPoints()


		if btn:IsShown() then

			if nr == 0 then

				btn:SetPoint("TOPRIGHT", self	, "TOPRIGHT", -5, 0 - (math.max(self:GetHeight() - btn:GetHeight(), 0) / 2))
			else

				btn:SetPoint("TOPRIGHT", lastbtn, "TOPLEFT", 0, 0)
			end


			lastbtn = btn
			nr	= nr + 1
		end
	end
end




local function ClearLegends(self)


	if not self.legends then self.legends = {} end


	for i, legend in ipairs(self.legends) do

		legend.id = nil
		legend:Hide()
	end


	self.legendoffset = 0
end




local function AdjustLegends(self)

	if self.legends then

		local used  = {}


		for i, legend in ipairs(self.legends) do

			if legend.id then

				table.insert(used, legend)
			else

				legend:Hide()
			end
		end


		local last_legend = nil


		for i, legend in ipairs(used) do

			if self.legendoffset and self.legendoffset > i then

				legend:Hide()
			else
		
				legend:ClearAllPoints()


				if last_legend then

					legend:SetPoint("TOPLEFT", last_legend, "BOTTOMLEFT", 0, -2)
				else

					legend:SetPoint("TOPLEFT", self, "TOPLEFT", 0, -2)
				end


				if (legend:GetTop() - legend:GetHeight()) > (self:GetTop() - self:GetHeight()) then

					legend:Show()
				else

					legend:Hide()
				end

			
				last_legend = legend
			end
		end
	end
end




local function SetupLegendScrolling(self)

	if not self.legends then self.legends = {} end


	self.legendoffset = 0
	self:EnableMouse(true)


	self:SetScript("OnMouseWheel",

				function(f, direction)

					diffLegends = #self.legends - self.legendoffset


					if direction == 1 and self.legendoffset > 0 then

						self.legendoffset = self.legendoffset - 1
					elseif direction == -1 and diffLegends > 10 then

						self.legendoffset = self.legendoffset + 1
					end


					AdjustLegends(self)
				end

		      )
end




local function AddLegend(self, legend_id, legend_label, legend_color)

	if legend_id == nil then return end


	if not self.legends then self.legends = {} end


	local has_legend  = nil
	local free_legend = nil


	for i, legend in ipairs(self.legends) do

		if legend.id == legend_id then

			legend.id = nil
			legend:Hide()
		end


		if free_legend == nil and legend.id == nil then	free_legend = legend end
	end


	local l


	if free_legend then

		l = free_legend
	else

		local backdropFrameInfo =

					{

						bgFile   = "Interface\\Buttons\\WHITE8X8",
					 	tile	 = false,
					 	edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
						edgeSize = 1,
					 	insets	 = { left = 1, right = 1, top = 1, bottom = 1 },

					}


		l = CreateFrame("Frame", nil, self, "BackdropTemplate")


		l:SetFrameLevel(5)

--		l:SetSize(13, 13)
		l:SetWidth(13)
		l:SetHeight(13)

		l:SetBackdrop(backdropFrameInfo)


		table.insert(self.legends, l)


		-- ===================================================================
		-- | these both lines are enough to get font, fontsize and fontflags |
		-- ===================================================================
		local f = l:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
		local g = l:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")


		-- ==================
		-- | set: alignment |
		-- ==================
--		f:SetSize(150, 16)
		f:SetWidth(150)
		f:SetHeight(16)

		f:SetJustifyH("LEFT")
		f:SetPoint("TOPLEFT", l, "TOPRIGHT", 3, 0)


-- 		g:SetSize(330, 16)
		g:SetWidth(330)
		g:SetHeight(16)

		g:SetJustifyH("RIGHT")
		g:SetPoint("TOPLEFT", l, "TOPRIGHT", 3, 0)


		-- ====================
		-- | set: text object |
		-- ====================

		l.text1 = f
		l.text2 = g
	end


	l.id = legend_id


	l:SetBackdropColor(legend_color[1], legend_color[2], legend_color[3])
	l:ClearAllPoints()


	local outputLabel, outputValue = Skada:ProcessingDiagram(legend_id, legend_label)


	-- =============
	-- | set: text |
	-- =============
	l.text1:SetText(outputLabel)
	l.text2:SetText(outputValue)


	l.label = legend_label


	l:EnableMouse()


	if self.EnterLegend then l:SetScript("OnEnter",

							function(f)

								l_label = string.sub(legend_label, 1, string.len(legend_id))


								if legend_id == l_label then

									legend_label = l_label
								end


								self.EnterLegend(legend_id, legend_label)
							end

					    )

	end


	if self.LeaveLegend then l:SetScript("OnLeave",

							function(f)

								l_label = string.sub(legend_label, 1, string.len(legend_id))


								if legend_id == l_label then

									legend_label = l_label
								end


								self.LeaveLegend(legend_id, legend_label)
							end

					    )
	end




	if self.ClickLegend then l:SetScript("OnMousedown",

							function(f, button)

								l_label = string.sub(legend_label, 1, string.len(legend_id))


								if legend_id == l_label then

									legend_label = l_label
								end


								self.ClickLegend(legend_id, legend_label, button)
							end
					    )
		end
end





local function showmode(win, id, label, mode)

	if win.selectedmode then table.insert(win.history, win.selectedmode) end
	if mode.Enter	    then mode:Enter(win, id, label)		     end


	win:DisplayMode(mode)
end




local function ClickRow(self, win, id, label, button)

	local click1 = win.metadata.click1
	local click2 = win.metadata.click2
	local click3 = win.metadata.click3


	if button == "RightButton" and IsShiftKeyDown() then

		Skada:OpenMenu(win)
	elseif win.metadata.click then

		win.metadata.click(win, id, label, button)
	elseif button == "RightButton" then

		win:RightClick()
	elseif click1 then

		showmode(win, id, label, click1)
	elseif click2 and IsShiftKeyDown() then

		showmode(win, id, label, click2)
	elseif click3 and IsControlKeyDown() then

		showmode(win, id, label, click3)
	end
end




local function EnterRow(self, win, id, label)

	win.ttactive = false


	Skada:ShowTooltip(win, id, label)
end




local function LeaveRow(self, win, id, label)

	if win.ttactive then

		ttactive = false


		GameTooltip:Hide()
	end
end




local function MakeResizable(self, growup)

	local f


	if self.resizebutton then

		f = self.resizebutton
	else

		f = CreateFrame("Button", "BarGroupResizeButton", self)


		self.resizebutton = f

		f:Show()

		f:SetFrameLevel(11)

--		f:SetSize(13, 13)
		f:SetWidth(13)
		f:SetHeight(13)


		self:SetResizable(true)
	end


	f:SetScript("OnMouseDown",

				function(frame, button)

					if (button == "LeftButton") then

						self.isResizing = true


						if growup then

							self:StartSizing("TOPRIGHT")
						else

							self:StartSizing("BOTTOMRIGHT")
						end


						if self.OnResizingInProgress then

							self:SetScript("OnUpdate",

										function()

											if self.isResizing then

												self:OnResizingInProgress()

											else

												self:SetScript("OnUpdate", nil)
											end
										end

								      )
						end
					end
				end

		   )


	f:SetScript("OnMouseUp",

				function(frame,button)

					if self.isResizing == true then

						self:StopMovingOrSizing()
						self.isResizing = false


						if self.OnResizingDone then self:OnResizingDone() end
					end
				end

		   )

		
	f:ClearAllPoints()
	f:SetNormalTexture("Interface\\CHATFRAME\\UI-ChatIM-SizeGrabber-Down")
	f:SetHighlightTexture("Interface\\CHATFRAME\\UI-ChatIM-SizeGrabber-Down")


	if growup then

		f:SetPoint("TOPRIGHT", self, "TOPRIGHT", 2, 2)
	else

		f:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 2, -2)
	end
end




Skada.AddButton		   = AddButton
Skada.AddLegend		   = AddLegend

Skada.AdjustButtons	   = AdjustButtons
Skada.AdjustLegends	   = AdjustLegends

Skada.ClearLegends	   = ClearLegends
Skada.ClickRow		   = ClickRow

Skada.EnterRow		   = EnterRow
Skada.GenerateColor	   = GenerateColor

Skada.LeaveRow		   = LeaveRow
Skada.MakeResizable	   = MakeResizable

Skada.SetupLegendScrolling = SetupLegendScrolling




-- ===============
--| the pie part |
-- ===============
function mod:OnInitialize()

	self.db = LibStub("AceDB-3.0"):New("SkadaGraphsPDB")
end




function mod:HandlePieSelection(win, num)


end


--  =============
--  | pie chart |
--  =============
function mod:Create(win)

	if not win.frame then

		hue = math.random()


		if self.db.global.piesaturation then saturation = self.db.global.piesaturation end


		win.colorcache = {}


		--  ===============================
		--  | pie chart: backdrop (frame) |
		--  ===============================
		local backdropFrameInfo =

				{

					bgFile	 = media:Fetch("background", "Solid"),
				 	tile	 = false,
				 	edgeSize = 0,
					insets	 = { left = 0, right = 0, top = 0, bottom = 0 },
				}


		--  ====================
		--  | pie chart: frame |
		--  ====================
		win.frame     = CreateFrame("Frame", win.db.name .. "PieChartFrame", UIParent, "BackdropTemplate")
		win.frame.win = win


		win.frame:SetMovable(true)
		win.frame:SetClampedToScreen(true)
--		win.frame:Size(550, 200)
		win.frame:SetWidth(550)
		win.frame:SetHeight(200)



		win.frame:SetBackdrop(backdropFrameInfo)


		win.frame:SetBackdropBorderColor(1.0, 0.0, 0.0)


		if self.db.global.piebgcolor then

			win.frame:SetBackdropColor(self.db.global.piebgcolor.r or 0, self.db.global.piebgcolor.g or 0, self.db.global.piebgcolor.b or 0, self.db.global.piebgcolor.a or 0.83)
		else

			self.db.global.piebgcolor = { r, g, b, a }
			win.frame:SetBackdropColor(0, 0, 0, 0.83)
		end


		win.frame:SetPoint("TOPLEFT", UIParent, "CENTER", 0, 0)
		win.frame:EnableMouse()


		win.frame:SetScript("OnMousedown",

						function(f, button)

							if button == "RightButton" then	win:RightClick() end
						end

				   )


		--  ===========================
		--  | pie chart: legend frame |
		--  ===========================
		win.frame.legendframe = CreateFrame("Frame", nil, win.frame)


		win.frame.legendframe:SetWidth(345)

		win.frame.legendframe:SetPoint("TOPRIGHT"   , win.frame, "TOPRIGHT"   , -10, -20)
		win.frame.legendframe:SetPoint("BOTTOMRIGHT", win.frame, "BOTTOMRIGHT", -10,  20)


		win.frame.legendframe.AddLegend     = Skada.AddLegend
		win.frame.legendframe.ClearLegends  = Skada.ClearLegends


		win.frame.legendframe.ClickLegend   = function(id, label, button)

								Skada.ClickRow(win.frame, win, id, label, button)
						      end


		win.frame.legendframe.EnterLegend   = function(id, label)

								Skada.EnterRow(win.frame, win, id, label)
						      end


		win.frame.legendframe.LeaveLegend   = function(id, label)

								Skada.LeaveRow(win.frame, win, id, label)
						      end


		win.frame.legendframe.AdjustLegends = Skada.AdjustLegends


		Skada.SetupLegendScrolling(win.frame.legendframe)


		win.frame.MakeResizable		    = Skada.MakeResizable
		win.frame.OnResizingInProgress	    = function(self)

								win.chart:SetWidth(min(win.frame:GetWidth()  - 140, win.frame:GetHeight()))
								win.chart:SetHeight(min(win.frame:GetWidth() - 140, win.frame:GetHeight()))

								win:UpdateDisplay()
								win.frame.legendframe:AdjustLegends()
						      end


		win.frame.OnResizingDone	    = function(self)

								win.db.width  = win.frame:GetWidth()
								win.db.height = win.frame:GetHeight()
						      end


		win.frame:MakeResizable()
		win.frame:SetResizeBounds(484, 198)


		--  =======================================
		--  | pie chart: backdrop (button header) |
		--  =======================================
		local backdropButtonInfo =

			{

				bgFile   = media:Fetch("statusbar", "Aluminium"),
			 	tile     = false,
			 	edgeSize = 0,
			 	insets   = { left = 0, right = 0, top = 0, bottom = 0 },
			}


		--  ============================
		--  | pie chart: button header |
		--  ============================
		win.header = CreateFrame("Button", nil, win.frame, "BackdropTemplate")


		win.header:SetHeight(24)


		win.header:SetPoint("BOTTOMLEFT" , win.frame, "TOPLEFT" , 0, 0)
		win.header:SetPoint("BOTTOMRIGHT", win.frame, "TOPRIGHT", 0, 0)


		win.header:SetScript("OnMouseDown",

						function()

							win.frame:StartMoving()
						end

				    )


		win.header:SetScript("OnMouseUp",

						function()

							win.frame:StopMovingOrSizing()
							libwindow.SavePosition(win.frame)
						end

				    )


		win.header:SetBackdrop(backdropButtonInfo)


		win.header:SetBackdropBorderColor(1.0, 0.0, 0.0)
		win.header:SetBackdropColor(0, 0, 1, 0.2)


		if self.db.global.pieheaderbg then
 
			win.header:SetBackdropColor(self.db.global.pieheaderbg.r or 0.1, self.db.global.pieheaderbg.g or 0.1, self.db.global.pieheaderbg.b or 0.3, self.db.global.pieheaderbg.a or 0.8)
		else

			self.db.global.pieheaderbg = { r, g, b, a }
			win.header:SetBackdropColor(0.1, 0.1, 0.3, 0.8)
		end


		win.header:SetText(win.db.name)


		--  ===================
		--  | pie chart: font |
		--  ===================
		local titleFont = CreateFont("TitleFont")


		titleFont:SetFont(media:Fetch('font', win.db.barfont), win.db.barfontsize, win.db.barfontflags)


		win.header:SetNormalFontObject(titleFont)


		win.header.AddButton	 = Skada.AddButton
		win.header.AdjustButtons = Skada.AdjustButtons


		if not(self.db.global.pieenableheader) then self.db.global.pieenableheader = true end


		local size = min(win.frame:GetWidth() - 140, win.frame:GetHeight())
		local g    = libgraph:CreateGraphPieChart("PieChart", win.frame, "TOPLEFT", "TOPLEFT", 0, 0, size, size)


		g:SetSelectionFunc(function(f, n) self:HandlePieSelection(win, n) end)
		win.chart = g


		--  ======================
		--  | pie chart: buttons |
		--  ======================
		Skada:MenuButton(win, mod, reportButton, function() Skada:ShowPopup(win)        end, 20,  15, "Interface\\Buttons\\UI-StopButton"	  , "Interface\\Buttons\\UI-StopButton")
		Skada:MenuButton(win, mod, reportButton, function() Skada:OpenReportWindow(win) end, 20,   0, "Interface\\Buttons\\UI-GuildButton-MOTD-Up", "Interface\\Buttons\\UI-GuildButton-MOTD-Up")
		Skada:MenuButton(win, mod, menuButton  , function() Skada:OpenMenu(win)         end, 20, -15, "Interface\\Buttons\\UI-OptionsButton"	  , "Interface\\Buttons\\UI-OptionsButton")
	end


	win.frame:Show()


	libwindow.RegisterConfig(win.frame, win.db)
	libwindow.RestorePosition(win.frame)
end




function mod:Destroy(win)

	wipe(win.colorcache)

	win.colorcache = nil
	win.frame.legendframe:ClearLegends()

	hue = math.random()

	win.frame:Hide()

	win.frame      = nil
	win.chart      = nil
	win.header     = nil
end




function mod:SetTitle(win, title)

	win.header:SetText(title)
end




local function round(num)

	local mult = 10^(0)


	return math.floor(num * mult + 0.5) / mult
end




function mod:Update(win)

	local total = 0


	for i, data in ipairs(win.dataset) do

		if data.id and not data.ignore then

			if data.value > 0 then total = total + data.value end
		end
	end


	win.chart:ResetPie()

	for i, data in ipairs(win.dataset) do

		if data.id and not data.ignore then

			local color


			if win.colorcache[data.id] then

				color = win.colorcache[data.id]
			else

				hue   = hue + goldenRatio
				hue   = hue - (math.floor(hue))

				color = Skada.GenerateColor(hue, saturation, value)


				win.colorcache[data.id] = color
			end


			if data.value > 0 then win.chart:AddPie(round((data.value / math.max(0.000001, total)) * 100), { color[1], color[2], color[3] }) end


			if data.id ~= nil and data.valuetext ~= nil then


				data.spellid = (tostring(data.spellid  ) or  0)
				data.label   = data.label .. "|" .. data.valuetext .. "|" .. data.spellid


				win.frame.legendframe:AddLegend(data.id, data.label, color)
			end
		end
	end


	win.frame.legendframe:AdjustLegends()
	win.chart:CompletePie({ 0.2, 0.2, 0.4 })
end




function mod:Wipe(win)

	win.chart:ResetPie()
	win.frame.legendframe:ClearLegends()
end




function mod:Show(win)

	win.frame:Show()
end




function mod:Hide(win)

	win.frame:Hide()
end




function mod:IsShown(win)

	return win.frame:IsShown()
end




function mod:ApplySettings(win)

	if win.db.barslocked then

		win.header:EnableMouse(false)
		win.frame.resizebutton:Hide()
	else

		win.header:EnableMouse(true)
		win.frame.resizebutton:Show()
	end


	if self.db.global.pieenableheader then

		win.header:Show()
	else

		win.header:Hide()
	end


	if self.db.global.piebgcolor then

		if not self.db.global.piebgcolor.r then	self.db.global.piebgcolor.r =    0 end
		if not self.db.global.piebgcolor.g then	self.db.global.piebgcolor.g =    0 end
		if not self.db.global.piebgcolor.b then	self.db.global.piebgcolor.b =    0 end
		if not self.db.global.piebgcolor.a then	self.db.global.piebgcolor.a = 0.83 end


		win.frame:SetBackdropColor(self.db.global.piebgcolor.r or 0, self.db.global.piebgcolor.g or 0, self.db.global.piebgcolor.b or 0, self.db.global.piebgcolor.a or 0.83)
	end


	if self.db.global.pieheaderbg then

		if not self.db.global.pieheaderbg.r then self.db.global.pieheaderbg.r = 0.1 end
		if not self.db.global.pieheaderbg.g then self.db.global.pieheaderbg.g = 0.1 end
		if not self.db.global.pieheaderbg.b then self.db.global.pieheaderbg.b = 0.3 end
		if not self.db.global.pieheaderbg.a then self.db.global.pieheaderbg.a = 0.8 end


		win.header:SetBackdropColor(self.db.global.pieheaderbg.r or 0.1, self.db.global.pieheaderbg.g or 0.1, self.db.global.pieheaderbg.b or 0.3, self.db.global.pieheaderbg.a or 0.8)
	end


	local pieFontHeader = CreateFont("FontTitle")


	if not self.db.global.pieheaderfont	 then self.db.global.pieheaderfont      = "Accidental Presidency" end
	if not self.db.global.pieheaderfontsize	 then self.db.global.pieheaderfontsize  = 13			  end
	if not self.db.global.pieheaderfontflags then self.db.global.pieheaderfontflags = ""			  end


	pieFontHeader:SetFont(media:Fetch('font', self.db.global.pieheaderfont), self.db.global.pieheaderfontsize, self.db.global.pieheaderfontflags)


	win.header:SetNormalFontObject(pieFontHeader)


	if self.db.global.piesaturation then

		saturation = self.db.global.piesaturation
		wipe(win.colorcache)
	end
end




function mod:AddDisplayOptions(win, options)

options.pieoptionstitle =

			{

			  type  = "group",
			  name  = L["Title bar"],
			  order = 4,

			  args  =

				{

			     pieoptionstitle =

					{

						   type = "description",
						   name = "\124cnNORMAL_FONT_COLOR:" .. L["Options: title bar"]  .. " " ..  "|cffffffff" .. win.db.name .. emptyLines,
						  order = 0,

					},

			pieenableheader =

					{

						   type = "toggle",
						   name = L["Enable header"],
						   desc = L["Enables/disables the header bar."],
						    get = function()

								  return self.db.global.pieenableheader
							  end,
						    set = function(win, showtotal)

								  self.db.global.pieenableheader = not self.db.global.pieenableheader
				         			  Skada:ApplySettings()
							  end,
						  order = 1,
					},

			    pieheaderbg =

					{

						   type = "color",
						   name = L["Background color"],
						   desc = L["The background color of the header."],
					       hasAlpha = true,
						    get = function(i)

								  return self.db.global.pieheaderbg.r, self.db.global.pieheaderbg.g, self.db.global.pieheaderbg.b, self.db.global.pieheaderbg.a
							  end,
						    set = function(i, r, g, b, a)

								  self.db.global.pieheaderbg = { ["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a }
								  Skada:ApplySettings()
							  end,
						  order = 2,

					},

				  piebg =

					{

						   type = "range",
						   name = L["Color saturation"],
						   desc = L["The color saturation value used by the pie chart."],
						    min = 0,
						    max = 1,
						   step = 0.05,
						    get = function()

								  return self.db.global.piesaturation
							  end,
						    set = function(win, saturation)

								  self.db.global.piesaturation = saturation
								  Skada:ApplySettings()
							  end,
						  order = 3,
					},

			  pieheaderfont =

					{

						   type = 'select',
					  dialogControl = 'LSM30_Font',
						   name = L["Font"],
						   desc = L["The font used by the header."],
						 values = AceGUIWidgetLSMlists.font,
						    get = function()

								  return self.db.global.pieheaderfont
							  end,
						    set = function(win,key)

								  self.db.global.pieheaderfont = key
								  Skada:ApplySettings()
							  end,
						  order = 4,

					},

		      pieheaderfontsize =

					{

						   type = "range",
						   name = L["Font size"],
						   desc = L["The font size used by the header."],
						    min = 12,
						    max = 40,
						   step = 1,
						    get = function()

								  return self.db.global.pieheaderfontsize
							  end,
						    set = function(win, size)

								  self.db.global.pieheaderfontsize = size
								  Skada:ApplySettings()
							  end,
						  order = 5,

					},

		     pieheaderfontflags =

					{

						   type = 'select',
						   name = L["Font flags"],
						   desc = L["Sets the font flags for the header."],
						 values = { [""] = L["None"], ["OUTLINE"] = L["Outline"], ["THICKOUTLINE"] = L["Thick outline"],
								    ["MONOCHROME"] = L["Monochrome"], ["OUTLINEMONOCHROME"] = L["Outlined monochrome"] },
						    get = function()

								  return self.db.global.pieheaderfontflags
							  end,
						    set = function(win, key)

								  self.db.global.pieheaderfontflags = key
								  Skada:ApplySettings()
							  end,
						  order = 6,

					},
				}
			}
end