CREATE OR REPLACE PACKAGE BODY EFT_NOM.svg IS -- Author : PRIESTJ -- Created : 05/12/2005 17:24:19 -- Purpose : used to create svg objects like graphs and charts -- Public constant declarations pi constant number := 3.14159265; --slice of pie anyone? --JP hacking --need to stick the circle_pointx & circle_pointy in as proper --functions (could even get rid of diameter parameter) --will also need to set up variables. --get the value of x on the circle FUNCTION circle_pointx ( degrees number , diameter number ) RETURN NUMBER IS -- mydegrees NUMBER := 0; -- BEGIN -- -- Avoid problems with doubles -- mydegrees := degrees + 0.5;--0.0001; return cos(mydegrees * (pi / 180)) *(diameter / 2); -- END circle_pointx; -- -- Get the value of y on the circle -- function circle_pointy(degrees number, diameter number) return number is mydegrees number := 0; begin --avoid problems with doubles mydegrees := degrees + 0.5;--0.0001; return sin(mydegrees * (pi / 180)) *(diameter / 2); end circle_pointy; FUNCTION colour_palette ( p_index IN NUMBER ) RETURN VARCHAR2 IS -- l_return VARCHAR2(6); -- BEGIN -- IF p_index = 1 THEN -- l_return := '003D62'; -- ELSIF p_index = 2 THEN -- l_return := 'FFFF00'; -- ELSIF p_index = 3 THEN -- l_return := '00FF00'; -- ELSE -- l_return := '555555'; -- END IF; -- RETURN l_return; -- END colour_palette; --procedure used to display the cheese wedges for our pie chart, exports 3 svg --path tags with attributes PROCEDURE codedpiechart ( p_availcapacity IN NUMBER , p_gasflowed IN NUMBER , p_remainflow IN NUMBER ) IS -- degrees number; charttotal number; currentvalue number; arcx number; arcy number; StartDegrees number; EndDegrees number; wedgesize number; wedgecolor varchar2(7); largearcflag integer := 0; svgtext varchar2(4000); -- BEGIN -- --ensure the first line is vertical -- degrees := 270; -- charttotal := p_availcapacity + p_gasflowed + p_remainflow; for i in 1 .. 3 loop --get the data for our chart depending on which cycle of the loop if i = 1 then currentvalue := p_availcapacity; --availcapcity wedgecolor := '#336699'; elsif i = 2 then currentvalue := p_gasflowed; --gasflowed wedgecolor := '#6699CC'; elsif i = 3 then currentvalue := p_remainflow; --remainflow wedgecolor := '#99CCFF'; end if; StartDegrees := round(degrees); --figure out the angle (in degrees) of our current cheese wedgesize := (currentvalue / charttotal) * 360; degrees := degrees + wedgesize; EndDegrees := round(degrees); --if one of our cheeses is 180 or bigger we need to set the large arc flag --other with the arc (A) won't draw it correctly if wedgesize >= 180 then largearcflag := 1; else largearcflag := 0; end if; svgtext :=''; --print out the svg path tag htp.p(svgtext); end loop; end codedpiechart; procedure piechart ( p_availcapacity IN NUMBER DEFAULT g_availcapacity , p_gasflowed IN NUMBER DEFAULT g_gasflowed , p_remainflow IN NUMBER DEFAULT g_remainflow ) IS begin --'Content-type: image/svg+xml' owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); htp.print(' '); codedpiechart( p_availcapacity , p_gasflowed , p_remainflow ); --htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print('Avail Capacity ('||TO_CHAR(p_availcapacity)||'kWh)'); htp.print('Gas Flowed ('||TO_CHAR(p_gasflowed)||'kWh)'); htp.print('Remaining Flow ('||TO_CHAR(p_remainflow)||'kWh)'); htp.print(''); htp.print(''); end piechart; procedure barchart is begin --'Content-type: image/svg+xml' owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); htp.print(' '); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(''); --htp.print(''); -- htp.print(''); htp.print(''); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(' '); htp.print(''); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); htp.print(''); htp.print('Million'); htp.print('KWh'); htp.print('0 '); htp.print('100'); htp.print('200'); htp.print('300'); htp.print('400'); htp.print('500'); htp.print('600'); htp.print('700'); htp.print('800'); htp.print('900'); htp.print(''); htp.print(''); htp.print(''); htp.print('01/06'); htp.print('02/06'); htp.print('03/06'); htp.print('04/06'); htp.print('05/06'); htp.print('06/06'); htp.print('07/06'); htp.print('08/06'); htp.print('09/06'); htp.print('10/06'); htp.print('11/06'); htp.print('12/06'); htp.print('13/06'); htp.print('14/06'); htp.print('15/06'); htp.print('16/06'); htp.print('17/06'); htp.print('18/06'); htp.print('19/06'); htp.print('20/06'); htp.print('21/06'); htp.print('22/06'); htp.print('23/06'); htp.print('24/06'); htp.print('25/06'); htp.print('26/06'); htp.print('27/06'); htp.print('28/06'); htp.print('29/06'); htp.print('30/06'); htp.print('01/07'); htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- END barchart; -- /* PROCEDURE barchart2 IS -- -- l_tab_inv is table of: -- l_date -- l_inventory -- l_max_cap -- l_min_cap -- l_tab_inv lihp_home_page.t_tab_inv; -- -- Fudged the number just a little... -- l_max_qty NUMBER := 900000000; -- l_x_start NUMBER := 80; l_width NUMBER := 18; l_x_step NUMBER := 8; -- l_y_start NUMBER := 9.1; l_y_step NUMBER := 14; l_height NUMBER := 138; -- BEGIN -- owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); -- htp.print(''); htp.print(''); htp.print(''); -- htp.print(' '); -- htp.print(' '); htp.print(''); -- htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- -- Get Data -- l_tab_inv := lihp_home_page.inventory_details; -- -- Print the boundary -- htp.print(' '); -- -- Y axis lines -- htp.print(' '); -- -- Print the lines -- FOR i IN 1..9 LOOP -- htp.print(''); -- END LOOP; -- htp.print(''); htp.print(''); -- -- Data -- FOR i IN 1..l_tab_inv.COUNT LOOP -- htp.print(' '); -- END LOOP; -- htp.print(''); -- -- Max line -- htp.p(''); -- htp.print(''); htp.print(''); htp.print(' '); -- -- Y axis labels -- htp.print(''); htp.print('GWh'); -- FOR i IN 0..9 LOOP -- htp.print(''||TO_CHAR((l_max_qty/9000000)*i)||' '); -- END LOOP; -- htp.print(''); htp.print(''); htp.print(''); -- -- X axis labels -- FOR i IN 1..l_tab_inv.COUNT LOOP -- htp.print(''||TO_CHAR(l_tab_inv(i).l_date, 'DD/MM')||''); -- END LOOP; -- -- Legends -- htp.print(''||'Inventory Summary'); htp.print(''); htp.print(''||'Inventory'); htp.print(''); htp.print(''); htp.print(''||'Maximum Capacity'); htp.print(''); htp.print(''); htp.print(''||'Minimum Inventory'); -- htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- END barchart2;*/ -- -- -- PROCEDURE piechart2 ( p_pie_tab IN t_pie_tab ) IS -- l_degrees NUMBER; l_arcx NUMBER; l_arcy NUMBER; l_x_startdegrees NUMBER; l_enddegrees NUMBER; l_wedgesize NUMBER; l_largearcflag INTEGER := 0; l_svgtext VARCHAR2(4000); -- l_x_origin NUMBER := 100; l_y_origin NUMBER := 110; l_radius NUMBER := 80; -- BEGIN --'Content-type: image/svg+xml' owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); -- -- Outer box -- htp.print(''); -- -- Piechart Stuff -- l_degrees := 270; -- FOR i IN 2..p_pie_tab.COUNT LOOP -- l_x_startdegrees := ROUND(l_degrees); -- -- Figure out the angle (in degrees) of our current cheese -- l_wedgesize := ( p_pie_tab(i).l_quantity / p_pie_tab(1).l_quantity ) * 360; l_degrees := l_degrees + l_wedgesize; l_enddegrees := ROUND(l_degrees); -- -- If one of our cheeses is 180 or bigger we need to set the large arc flag -- other with the arc (A) won't draw it correctly -- IF l_wedgesize > 359 THEN -- htp.print(''); -- ELSE -- IF l_wedgesize >= 180 THEN -- l_largearcflag := 1; -- ELSE -- l_largearcflag := 0; -- END IF; -- l_svgtext :=''; --print out the svg path tag htp.p(l_svgtext); END IF; -- END LOOP; -- -- Print pie title -- htp.print(''||p_pie_tab(1).l_descr||''); -- -- Print Legend -- FOR j IN 2..p_pie_tab.COUNT LOOP -- htp.print(''); htp.print(''||p_pie_tab(j).l_descr||' ('||TO_CHAR(p_pie_tab(j).l_quantity)||'kWh)'); -- END LOOP; -- htp.print(''); htp.print(''); -- END piechart2; -- -- -- /*PROCEDURE barchart3(p_type IN VARCHAR2 DEFAULT 'A') IS -- -- l_tab_inv is table of: -- l_date -- l_inventory -- l_max_cap -- l_min_cap -- l_tab_inv lihp_home_page.t_tab_inv; -- -- Fudged the number just a little... -- l_max_qty NUMBER := 900000000; -- l_x_start NUMBER := 80; l_width NUMBER := 18; l_x_step NUMBER := 8; -- l_y_start NUMBER := 9.1; l_y_step NUMBER := 14; l_height NUMBER := 146; -- l_idx NUMBER; -- BEGIN -- owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); -- htp.print(''); htp.print(''); htp.print(''); -- htp.print(' '); -- htp.print(' '); htp.print(''); -- htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- -- Get Data -- IF p_type = 'A' THEN -- l_tab_inv := lihp_home_page.inventory_details; -- ELSIF p_type = 'B' THEN -- l_tab_inv := lihp_home_page.all_inventory_details; -- l_max_qty := 1800000000; -- ELSIF p_type = 'C' THEN -- lihp_home_page.g_start_date := (TRUNC(SYSDATE) - 14) + (cout_system_configuration.get_configuration_item('GAS_DAY_OFFSET')/24); lihp_home_page.g_end_date := (TRUNC(SYSDATE) + 14) + (cout_system_configuration.get_configuration_item('GAS_DAY_OFFSET')/24); -- l_tab_inv := lihp_home_page.inventory_details; -- l_width := 9; l_x_step := 5; -- END IF; -- -- Print the boundary -- htp.print(' '); -- -- Y axis lines -- htp.print(' '); -- -- Print the lines -- FOR i IN 1..9 LOOP -- htp.print(''); -- END LOOP; -- htp.print(''); htp.print(''); -- -- Data -- l_idx := l_tab_inv.FIRST; -- FOR z IN 1..l_tab_inv.COUNT LOOP -- IF TRUNC(l_tab_inv(l_idx).l_date) = TRUNC(SYSDATE) THEN htp.print(' '); ELSE htp.print(' '); END IF; -- l_idx := l_tab_inv.NEXT(l_idx); -- END LOOP; -- htp.print(''); -- -- Max line -- htp.p(''); -- htp.print(''); htp.print(''); htp.print(' '); -- -- Y axis labels -- htp.print(''); htp.print('GWh'); -- FOR i IN 0..9 LOOP -- htp.print(''||TO_CHAR((l_max_qty/9000000)*i)||' '); -- END LOOP; -- htp.print(''); htp.print(''); htp.print(''); -- -- X axis labels -- l_idx := l_tab_inv.FIRST; -- FOR i IN 1..l_tab_inv.COUNT LOOP -- htp.print(''||TO_CHAR(l_tab_inv(l_idx).l_date, 'DD/MM')||''); -- l_idx := l_tab_inv.NEXT(l_idx); -- END LOOP; -- -- Legends -- --htp.print(''||'Inventory Summary'); htp.print(''); htp.print(''||'Inventory'); htp.print(''); htp.print(''); htp.print(''||'Maximum Capacity'); htp.print(''); htp.print(''); htp.print(''||'Minimum Inventory'); -- htp.print(''); htp.print(''); htp.print(''); htp.print(''); -- END barchart3;*/ -- -- -- PROCEDURE piechart3 IS -- l_degrees NUMBER; l_arcx NUMBER; l_arcy NUMBER; l_x_startdegrees NUMBER; l_enddegrees NUMBER; l_wedgesize NUMBER; l_largearcflag INTEGER := 0; l_svgtext VARCHAR2(4000); -- l_x_origin NUMBER := 100; l_y_origin NUMBER := 70; l_radius NUMBER := 50; -- l_height NUMBER := 197; l_width NUMBER := 199; -- l_description VARCHAR2(200); l_procedure VARCHAR2(200); -- BEGIN -- -- Determine procedure due to problems with 10g -- BEGIN SELECT hoev.element_value ,hoev.element_procedure INTO l_description ,l_procedure FROM user_homepage usho ,homepage_element hoel ,homepage_element_value hoev WHERE hoel.hoel_id = usho.hoel_id AND hoev.hoev_id = usho.hoev_id AND hoev.hoel_id = usho.hoel_id AND UPPER(hoel.element_name) = UPPER('Piechart') AND usho.syus_id = caco_utilities.get_syus_id; EXCEPTION WHEN OTHERS THEN NULL; END; -- IF l_procedure IS NOT NULL THEN -- execute immediate 'begin svg.g_pie_tab := '||l_procedure||'; end;'; -- END IF; -- IF g_pie_tab.COUNT > 0 THEN --'Content-type: image/svg+xml' owa_util.mime_header('image/svg+xml', true, 'iso-8859-4'); htp.print(''); htp.print(''); htp.print(''); htp.print(' '); -- -- Outer box -- htp.print(''); -- -- Piechart Stuff -- l_degrees := 270; -- FOR i IN 2..g_pie_tab.COUNT LOOP -- l_x_startdegrees := ROUND(l_degrees); -- -- Figure out the angle (in degrees) of our current cheese -- l_wedgesize := ( g_pie_tab(i).l_quantity / g_pie_tab(1).l_quantity ) * 360; l_degrees := l_degrees + l_wedgesize; l_enddegrees := ROUND(l_degrees); -- -- If one of our cheeses is 180 or bigger we need to set the large arc flag -- other with the arc (A) won't draw it correctly -- IF l_wedgesize > 359 THEN -- htp.print(''); -- ELSE -- IF l_wedgesize >= 180 THEN -- l_largearcflag := 1; -- ELSE -- l_largearcflag := 0; -- END IF; -- l_svgtext :=''; --print out the svg path tag htp.p(l_svgtext); END IF; -- END LOOP; -- -- Print pie title -- htp.print(''||g_pie_tab(1).l_descr||''); -- -- Print Legend -- FOR j IN 2..g_pie_tab.COUNT LOOP -- htp.print(''); htp.print(''||g_pie_tab(j).l_descr||' ('||TO_CHAR(g_pie_tab(j).l_quantity, 'FM999G999G999G999G999G999G990')||' '||g_pie_tab(1).l_units||')'); -- END LOOP; -- htp.print(''); htp.print(''); -- END IF; -- END piechart3; -- END svg; /