RGraph = window.RGraph || {isRGraph:
true
};
(
function
(win, doc, undefined)
{
var
RG = RGraph,
ua = navigator.userAgent,
ma = Math,
active =
null
;
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 || [];
if
(!ca.resizing.originalw) { ca.resizing.originalw = ca.width; }
if
(!ca.resizing.originalh) { ca.resizing.originalh = ca.height; }
var
resizeHandleSize = 15;
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)'
;
}
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
);
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)
);
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'
]);
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'
]);
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'
]);
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'
]);
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'
]);
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'
]);
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'
]);
if
(obj.get(
'chart.resizable'
) && !ca.rgraphResizewrapper) {
ca.rgraphResizewrapper = $(
'<div id="rgraph_resize_container_'
+ ca.id +
'"></div>'
).css({
'float'
: ca.style.cssFloat,
position:
'relative'
}).get(0);
$(ca).wrap(ca.rgraphResizewrapper);
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'
);
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'
;
}
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'
);
}
}
}
if
(
typeof
ca.rgraph_resize_window_mousemove_listener_installed !=
'boolean'
) {
window.addEventListener(
'mousemove'
, window_onmousemove,
false
);
ca.rgraph_resize_window_mousemove_listener_installed =
true
;
}
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'
) {
var
placeHolderDIV = document.createElement(
'DIV'
);
placeHolderDIV.style.width = ca.resizing.originalw +
'px'
;
placeHolderDIV.style.height = ca.resizing.originalh +
'px'
;
placeHolderDIV.style.display =
'inline-block'
;
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);
}
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.style.top = 0;
ca.width = parseInt(div.style.width);
ca.height = parseInt(div.style.height);
ca.getContext(
'2d'
).translate(0.5,0.5);
var
objects = RG.ObjectRegistry.getObjectsByCanvasID(ca.id);
for
(
var
i=0,len=objects.length; i<len; i+=1) {
RG.resetColorsToOriginalValues(objects[i]);
if
(
typeof
objects[i].reset ===
'function'
) {
objects[i].reset();
}
}
RG.cache = [];
RG.fireCustomEvent(ca.__object__,
'onresizebeforedraw'
);
RG.redrawCanvas(ca);
ca.resizing.mousedown =
false
;
div.style.display =
'none'
;
document.body.removeChild(div);
}
if
(RG.Registry.Get(
'chart.zoomed.div'
) || RGraph.Registry.Get(
'chart.zoomed.img'
)) {
RG.Registry.Set(
'chart.zoomed.div'
,
null
);
RG.Registry.Set(
'chart.zoomed.img'
,
null
);
}
RG.FireCustomEvent(ca.__object__,
'onresizeend'
);
};
var
window_onmouseup = MouseupFunc;
if
(
typeof
ca.rgraph_resize_window_mouseup_listener_installed !=
'boolean'
) {
window.addEventListener(
'mouseup'
, window_onmouseup,
false
);
ca.rgraph_resize_window_mouseup_listener_installed =
true
;
}
var
canvas_onmousemove =
function
(e)
{
e = RG.fixEventObject(e);
var
coords = RG.getMouseXY(e);
var
obj = e.target.__object__;
var
ca = e.target;
var
co = ca.getContext(
'2d'
);
var
cursor = ca.style.cursor;
if
(!ca.resizing.original_cursor) {
ca.resizing.original_cursor = cursor;
}
if
( (coords[0] > (ca.width - resizeHandleSize)
&& coords[0] < ca.width
&& coords[1] > (ca.height - resizeHandleSize)
&& coords[1] < ca.height)) {
ca.style.cursor =
'move'
;
}
else
if
( coords[0] > (ca.width - resizeHandleSize - resizeHandleSize)
&& coords[0] < ca.width - resizeHandleSize
&& coords[1] > (ca.height - resizeHandleSize)
&& coords[1] < ca.height) {
ca.style.cursor =
'pointer'
;
}
else
{
if
(ca.resizing.original_cursor) {
ca.style.cursor = ca.resizing.original_cursor;
ca.resizing.original_cursor =
null
;
}
else
{
ca.style.cursor =
'default'
;
}
}
};
if
(
typeof
ca.rgraph_resize_mousemove_listener_installed !=
'boolean'
) {
ca.addEventListener(
'mousemove'
, canvas_onmousemove,
false
);
ca.rgraph_resize_mousemove_listener_installed =
true
;
}
var
canvas_onmouseout =
function
(e)
{
e.target.style.cursor =
'default'
;
e.target.title =
''
;
};
if
(
typeof
ca.rgraph_resize_mouseout_listener_installed !=
'boolean'
) {
ca.addEventListener(
'mouseout'
, canvas_onmouseout,
false
);
ca.rgraph_resize_mouseout_listener_installed =
true
;
}
var
canvas_onmousedown =
function
(e)
{
e = RG.fixEventObject(e);
var
coords = RG.getMouseXY(e);
var
canvasXY = RG.getCanvasXY(e.target);
var
ca = e.target;
active = ca;
if
( coords[0] > (ca.width - resizeHandleSize)
&& coords[0] < ca.width
&& coords[1] > (ca.height - resizeHandleSize)
&& coords[1] < ca.height) {
RG.fireCustomEvent(obj,
'onresizebegin'
);
if
(ca.resizing.original_css_border ==
null
) {
ca.resizing.original_css_border = ca.style.border;
}
if
(ca.resizing.original_css_shadow ==
null
) {
ca.resizing.original_css_shadow = ca.style.boxShadow;
}
ca.resizing.mousedown =
true
;
var
div = document.createElement(
'DIV'
);
div.style.position =
'absolute'
;
div.style.left = canvasXY[0] +
'px'
;
div.style.top = canvasXY[1] +
'px'
;
div.style.width = ca.width +
'px'
;
div.style.height = ca.height +
'px'
;
div.style.border =
'1px dotted black'
;
div.style.backgroundColor =
'gray'
;
div.style.opacity = 0.5;
div.__canvas__ = e.target;
document.body.appendChild(div);
ca.resizing.div = div;
ca.resizing.placeHolders.push(div);
for
(
var
i=0; i<(ca.resizing.placeHolders.length - 1); ++i) {
ca.resizing.placeHolders[i].style.display =
'none'
;
}
div.onmouseup =
function
(e)
{
MouseupFunc(e);
}
ca.resizing.div.onmouseover =
function
(e)
{
e = RG.fixEventObject(e);
e.stopPropagation();
}
ca.resizing.originalx = e.pageX;
ca.resizing.originaly = e.pageY;
ca.resizing.originalCanvasX = RG.getCanvasXY(ca)[0];
ca.resizing.originalCanvasY = RG.getCanvasXY(ca)[1];
}
if
( coords[0] > (ca.width - resizeHandleSize - resizeHandleSize)
&& coords[0] < ca.width - resizeHandleSize
&& coords[1] > (ca.height - resizeHandleSize)
&& coords[1] < ca.height
&& ca.resizing.originalw
&& ca.resizing.originaly) {
RG.fireCustomEvent(ca.__object__,
'onresizebegin'
);
ca.width = ca.resizing.originalw;
ca.height = ca.resizing.originalh;
if
(ca.__link__ && ca.__link__.style.display ===
'none'
) {
ca.__link__.style.display =
'inline'
;
}
if
(
typeof
ca.parentNode.id ===
'string'
&& ca.parentNode.id.substring(0, 24) ===
'rgraph_resize_container_'
) {
ca.parentNode.style.width = ca.resizing.originalw +
'px'
;
ca.parentNode.style.height = ca.resizing.originalh +
'px'
;
}
ca.style.border = ca.resizing.original_css_border;
ca.style.boxShadow = ca.resizing.original_css_shadow;
ca.style.left = (parseInt(ca.style.left)) +
'px'
;
ca.style.top = (parseInt(ca.style.top)) +
'px'
;
ca.getContext(
'2d'
).translate(0.5,0.5);
RG.fireCustomEvent(ca.__object__,
'onresizebeforedraw'
);
var
objects = RG.ObjectRegistry.getObjectsByCanvasID(ca.id);
for
(
var
i=0; i<objects.length; i+=1) {
RG.resetColorsToOriginalValues(objects[i]);
if
(objects[i].reset) {
objects[i].reset();
}
RG.redrawCanvas(objects[i].canvas);
}
RG.cache = [];
if
(ca.resizing.div) {
ca.resizing.div.style.width = ca.__original_width__ +
'px'
;
ca.resizing.div.style.height = ca.__original_height__ +
'px'
;
}
RG.fireCustomEvent(ca.__object__,
'onresize'
);
RG.fireCustomEvent(ca.__object__,
'onresizeend'
);
}
};
if
(
typeof
ca.rgraph_resize_mousedown_listener_installed !=
'boolean'
) {
ca.addEventListener(
'mousedown'
, canvas_onmousedown,
false
);
ca.rgraph_resize_mousedown_listener_installed =
true
;
}
}
};
})(window, document);