// version: 2017-11-25 /** * o--------------------------------------------------------------------------------o * | This file is part of the RGraph package - you can learn more at: | * | | * | http://www.rgraph.net | * | | * | RGraph is licensed under the Open Source MIT license. That means that it's | * | totally free to use and there are no restrictions on what you can do with it! | * o--------------------------------------------------------------------------------o */ RGraph = window.RGraph || {isRGraph: true}; // Module pattern (function (win, doc, undefined) { var RG = RGraph, ua = navigator.userAgent, ma = Math, active = null; /** * This function can be used to allow resizing * * @param object obj Your graph object */ RGraph.allowResizing = RGraph.AllowResizing = function (obj) { var ca = obj.canvas, co = obj.context, pa2 = RG.path2; ca.resizing = ca.resizing || {}; ca.resizing.placeHolders = ca.resizing.placeHolders || []; /** * Store the original width/height on the canvas */ if (!ca.resizing.originalw) { ca.resizing.originalw = ca.width; } if (!ca.resizing.originalh) { ca.resizing.originalh = ca.height; } // The size of the resize handle (so '15' isn't littered throughout the code) var resizeHandleSize = 15; // Add the original width and height to the canvas if ( !ca.resizing.__rgraph_original_width__ || !ca.resizing.__rgraph_original_height__ || !ca.resizing.__adjustX || !ca.resizing.__adjustY ) { ca.resizing.__rgraph_original_width__ = ca.width; ca.resizing.__rgraph_original_height__ = ca.height; ca.resizing.adjustX = (typeof obj.get('chart.resize.handle.adjust') == 'object' && typeof obj.get('chart.resize.handle.adjust')[0] == 'number' ? obj.Get('chart.resize.handle.adjust')[0] : 0); ca.resizing.adjustY = (typeof obj.get('chart.resize.handle.adjust') == 'object' && typeof obj.get('chart.resize.handle.adjust')[1] == 'number' ? obj.Get('chart.resize.handle.adjust')[1] : 0); ca.resizing.bgcolor = obj.get('chart.resize.handle.background') || 'rgba(0,0,0,0)'; } // Draw the resize handle pa2(co, 'b m % % r % % % % f %', ca.width - resizeHandleSize - resizeHandleSize + ca.resizing.adjustX, ca.height - resizeHandleSize, ca.width - resizeHandleSize - resizeHandleSize + ca.resizing.adjustX, ca.height - resizeHandleSize + ca.resizing.adjustY, 2 * resizeHandleSize, resizeHandleSize, ca.resizing.bgcolor ); // Draw the arrows pa2(co, 'b lw 1 m % % l % % m % % l % % s gray f transparent', ma.round(ca.width - (resizeHandleSize / 2) + ca.resizing.adjustX), ca.height - resizeHandleSize + ca.resizing.adjustY, ma.round(ca.width - (resizeHandleSize / 2) + ca.resizing.adjustX), ca.height + ca.resizing.adjustY, ca.width + ca.resizing.adjustX, ma.round(ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY), ca.width - resizeHandleSize + ca.resizing.adjustX, ma.round(ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY) ); // Top arrow head pa2(co, [ 'b', 'm', ca.width - (resizeHandleSize / 2) + ca.resizing.adjustX, ca.height - resizeHandleSize + ca.resizing.adjustY, 'l',ca.width - (resizeHandleSize / 2) + 3 + ca.resizing.adjustX, ca.height - resizeHandleSize + 3 + ca.resizing.adjustY, 'l',ca.width - (resizeHandleSize / 2) - 3 + ca.resizing.adjustX, ca.height - resizeHandleSize + 3 + ca.resizing.adjustY, 'c', 'f','gray']); // Bottom arrow head pa2(co, ['b','m', ca.width - (resizeHandleSize / 2) + ca.resizing.adjustX, ca.height + ca.resizing.adjustY,'l', ca.width - (resizeHandleSize / 2) + 3 + ca.resizing.adjustX, ca.height - 3 + ca.resizing.adjustY,'l', ca.width - (resizeHandleSize / 2) - 3 + ca.resizing.adjustX, ca.height - 3 + ca.resizing.adjustY,'c','f', 'gray']); // Left arrow head pa2(co, ['b','m', ca.width - resizeHandleSize + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY,'l', ca.width - resizeHandleSize + 3 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + 3 + ca.resizing.adjustY,'l', ca.width - resizeHandleSize + 3 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) - 3 + ca.resizing.adjustY,'c','f', 'gray']); // Right arrow head pa2(co, ['b','m',ca.width + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY,'l',ca.width - 3 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + 3 + ca.resizing.adjustY,'l',ca.width - 3 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) - 3 + ca.resizing.adjustY,'c','f', 'gray']); // Square at the centre of the arrows pa2(co, ['b','m',ca.width + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY,'r',ca.width - (resizeHandleSize / 2) - 2 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) - 2 + ca.resizing.adjustY, 4, 4,'r',ca.width - (resizeHandleSize / 2) - 2 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) - 2 + ca.resizing.adjustY, 4, 4,'s','gray','f','white']); // Draw the "Reset" button pa2(co, ['b','m',ma.round(ca.width - resizeHandleSize - 3 + ca.resizing.adjustX), ca.height - resizeHandleSize / 2 + ca.resizing.adjustY,'l',ma.round(ca.width - resizeHandleSize - resizeHandleSize + ca.resizing.adjustX), ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY,'l',ca.width - resizeHandleSize - resizeHandleSize + 2 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) - 2 + ca.resizing.adjustY,'l',ca.width - resizeHandleSize - resizeHandleSize + 2 + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + 2 + ca.resizing.adjustY,'l',ca.width - resizeHandleSize - resizeHandleSize + ca.resizing.adjustX, ca.height - (resizeHandleSize / 2) + ca.resizing.adjustY,'s','gray','f','gray']); // The vertical line at the end of the reset button pa2(co, ['b','m', ma.round(ca.width - resizeHandleSize - resizeHandleSize - 1 + ca.resizing.adjustX), ca.height - (resizeHandleSize / 2) - 3 + ca.resizing.adjustY,'l', ma.round(ca.width - resizeHandleSize - resizeHandleSize - 1 + ca.resizing.adjustX), ca.height - (resizeHandleSize / 2) + 3 + ca.resizing.adjustY,'s','f']); /** * The code inside this if() condition only runs once due to the if() condition tests- if * the obj.rgraphResizewrapper variable exists then the code has run */ if (obj.get('chart.resizable') && !ca.rgraphResizewrapper) { // ** TODO ** Needs fixing // // // Wrap the canvas // ** NEEDS FIXING ** // ca.rgraphResizewrapper = $('
').css({ 'float': ca.style.cssFloat, position: 'relative' }).get(0); $(ca).wrap(ca.rgraphResizewrapper); // TODO Might need to add more properties here (eg margin, padding etc) ca.style.cssFloat = 'none'; ca.style.top = 0; ca.style.left = 0; var window_onmousemove = function (e) { var ca = active, obj = ca ? ca.__object__ : null; if (ca) { e = RG.fixEventObject(e); if (ca.resizing.mousedown) { var newWidth = ca.width + (e.pageX - ca.resizing.originalx), newHeight = ca.height + (e.pageY - ca.resizing.originaly), minWidth = obj.get('resizableMinwidth'), minHeight = obj.get('resizableMinheight'); // Check for maximum width if (newWidth > (ca.resizing.originalw / 2) && (typeof obj.get('resizableMaxwidth') === 'number' ? newWidth < obj.get('resizableMaxwidth') : true) && (typeof minWidth === 'number' ? newWidth > minWidth : true) ) { ca.resizing.div.style.width = newWidth + 'px'; } // Check for maximum height if (newHeight > (ca.resizing.originalh / 2) && (typeof obj.get('resizableMaxheight') === 'number' ? newHeight < obj.get('resizableMaxheight') : true) && (typeof minHeight === 'number' ? newHeight > minHeight : true) ) { ca.resizing.div.style.height = newHeight + 'px'; } RG.fireCustomEvent(ca.__object__, 'onresize'); } } } // Install the function as an event listener - but only once if (typeof ca.rgraph_resize_window_mousemove_listener_installed != 'boolean') { window.addEventListener('mousemove', window_onmousemove, false); ca.rgraph_resize_window_mousemove_listener_installed = true; } // The window onmouseup function var MouseupFunc = function (e) { if (!ca.resizing || !ca.resizing.div || !ca.resizing.mousedown) { return; } if (ca.resizing.div) { var div = ca.resizing.div; var coords = RG.getCanvasXY(ca); var parentNode = ca.parentNode; if (ca.style.position != 'absolute') { // Create a DIV to go in the canvases place var placeHolderDIV = document.createElement('DIV'); placeHolderDIV.style.width = ca.resizing.originalw + 'px'; placeHolderDIV.style.height = ca.resizing.originalh + 'px'; placeHolderDIV.style.display = 'inline-block'; // Added 5th Nov 2010 placeHolderDIV.style.position = ca.style.position; placeHolderDIV.style.left = ca.style.left; placeHolderDIV.style.top = ca.style.top; placeHolderDIV.style.cssFloat = ca.style.cssFloat; parentNode.insertBefore(placeHolderDIV, ca); } // Now set the canvas to be positioned absolutely ca.style.backgroundColor = 'white'; ca.style.position = 'absolute'; ca.style.border = '1px dashed gray'; ca.style.boxShadow = '2px 2px 5px #ddd'; ca.style.left = 0;//(ca.resizing.originalCanvasX - 2) + 'px'; ca.style.top = 0;//(ca.resizing.originalCanvasY - 2) + 'px'; // Set the dimensions of the canvas using the HTML attributes ca.width = parseInt(div.style.width); ca.height = parseInt(div.style.height); // Because resizing the canvas resets any tranformation - the antialias fix needs to be reapplied. ca.getContext('2d').translate(0.5,0.5); // Reset the gradient parsing status by setting all of the color values back to their original // values before Draw was first called var objects = RG.ObjectRegistry.getObjectsByCanvasID(ca.id); for (var i=0,len=objects.length; i