// THIS FILE HAS BEEN MINIFIED

if(typeof(RGraph) == 'undefined') RGraph = {isRGraph:true,type:'common'};RGraph.AllowAdjusting = function (obj)
{
var canvas = obj.canvas;var context = obj.context;RGraph.Register(obj);if(obj.type == 'line'){
canvas.onmousedown = function (e)
{
e = RGraph.FixEventObject(e);var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var coords = obj.coords;var mouseCoords = RGraph.getMouseXY(e);RGraph.Redraw();for (var i=0; i<coords.length; ++i){
if(   mouseCoords[0] > coords[i][0] - 5
&& mouseCoords[1] > coords[i][1] - 5
&& mouseCoords[0] < coords[i][0] + 5
&& mouseCoords[1] < coords[i][1] + 5
){
var numDataSeries = obj.original_data.length;var numDataPoints = obj.original_data[0].length;var data_series = i / numDataPoints;data_series = Math.floor(data_series);canvas.style.cursor = 'ns-resize';RGraph.Registry.Set('chart.adjusting.line.' + id, [obj, i, [coords[i][0], coords[i][1]], data_series]);return;}
}
}
canvas.onmousemove = function (e)
{
e = RGraph.FixEventObject(e);var id = e.target.__object__.id;var state = RGraph.Registry.Get('chart.adjusting.line.' + id);if(state){
var obj = state[0];var idx = state[1];var canvas = obj.canvas;var context = obj.context;var data_series = state[3];var points = obj.original_data[data_series];var mouseCoords = RGraph.getMouseXY(e);var x = mouseCoords[0];var y = mouseCoords[1];if(y >= (obj.canvas.height - obj.Get('chart.gutter'))){
y = obj.canvas.height - obj.Get('chart.gutter');} else if(y <= obj.Get('chart.gutter')){
y = obj.Get('chart.gutter');}
var pos = obj.canvas.height - (2 * obj.Get('chart.gutter'));pos = pos - (y - obj.Get('chart.gutter'));var value = (obj.max / (obj.canvas.height - (2 * obj.Get('chart.gutter')))) * pos;for (var i=0; i<data_series; ++i){
idx -= obj.original_data[0].length;}
obj.original_data[data_series][idx] = value;obj.Set('chart.ymax', obj.max);canvas.style.cursor = 'ns-resize';RGraph.Redraw();RGraph.FireCustomEvent(obj, 'onadjust');return;} else {
var canvas = e.target;var context = canvas.__object__.context;var obj = canvas.__object__;var mouseCoords = RGraph.getMouseXY(e);var x = mouseCoords[0];var y = mouseCoords[1];for (var i=0; i<obj.coords.length; ++i){
if(   x > obj.coords[i][0] - 5
&& y > obj.coords[i][1] - 5
&& x < obj.coords[i][0] + 5
&& y < obj.coords[i][1] + 5
){
canvas.style.cursor = 'ns-resize';return;}
}
}
e.target.style.cursor = null;}
canvas.onmouseup = function (e)
{
var id = e.target.__object__.id;RGraph.Registry.Set('chart.adjusting.line.' + id, null);e.target.style.cursor = null;}
canvas.onmouseout = function (e)
{
canvas.onmouseup(e);}
} else if(obj.type == 'hprogress'){
canvas.onmousedown = function (e)
{
var id = e.target.__object__.id;RGraph.Registry.Set('chart.adjusting.progress.' + id, [true]);canvas.onmousemove(e);}
canvas.onmousemove = function (e)
{
var id = e.target.__object__.id;var state = RGraph.Registry.Get('chart.adjusting.progress.' + id);if(state && state.length){
var obj = e.target.__object__;var canvas = obj.canvas;var context = obj.context;if(obj.type == 'hprogress'){
var coords = RGraph.getMouseXY(e);coords[0] = Math.max(0, coords[0] - obj.Get('chart.gutter'));var barWidth = canvas.width - (2 * obj.Get('chart.gutter'));var value = (coords[0] / barWidth) * obj.max;obj.value = Math.max(0, value.toFixed());RGraph.Clear(obj.canvas);obj.Draw();} else if(obj.type == 'vprogress'){
var coords = RGraph.getMouseXY(e);coords[1] = Math.max(0, coords[1] - obj.Get('chart.gutter'));var barHeight = canvas.height - (2 * obj.Get('chart.gutter'));var value = ( (barHeight - coords[1]) / barHeight) * obj.max;obj.value = Math.max(0, value.toFixed());RGraph.Clear(obj.canvas);obj.Draw();}
RGraph.FireCustomEvent(obj, 'onadjust');}
}
canvas.onmouseup = function (e)
{
var id = e.target.__object__.id;RGraph.Registry.Set('chart.adjusting.progress.' + id, null);}
canvas.onmouseout = function (e)
{
canvas.onmouseup(e);}
} else if(obj.type == 'rose'){
obj.Set('chart.ymax', obj.max);canvas.onmousemove = function (e)
{
var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var coords = RGraph.getMouseXY(e);var segment = RGraph.Registry.Get('chart.adjusting.rose.' + id);var x = Math.abs(coords[0] - obj.centerx);var y = Math.abs(coords[1] - obj.centery);var theta = Math.atan(y / x) * (180 / Math.PI);if(coords[0] >= obj.centerx && coords[1] < obj.centery){
theta = 90 - theta;} else if(coords[0] >= obj.centerx && coords[1] >= obj.centery){
theta += 90;} else if(coords[0] < obj.centerx && coords[1] >= obj.centery){
theta = 90 - theta;theta = 180 + theta;} else if(coords[0] < obj.centerx && coords[1] < obj.centery){
theta = theta + 270;}
var Opp = y;var Adj = x;var Hyp = Math.abs(Adj / Math.sin(theta / (180 / Math.PI)));for (var i=0; i<obj.angles.length; ++i){
if(
theta > obj.angles[i][0]
&& theta < obj.angles[i][1] ){
if(RGraph.Registry.Get('chart.adjusting.rose.' + id) && i == segment[5]){
var newvalue = (Hyp / (obj.radius - 25) ) * obj.max;obj.data[i] = Math.min(newvalue, obj.max);RGraph.Clear(obj.canvas);obj.Draw();RGraph.FireCustomEvent(obj, 'onadjust');}
if(Hyp <= (obj.angles[i][2] + 5) && Hyp >= (obj.angles[i][2] - 5) ){
canvas.style.cursor = 'move';return;} else if(obj.Get('chart.tooltips') && Hyp <= (obj.angles[i][2] - 5) ){
canvas.style.cursor = 'pointer';return;}
}
}
canvas.style.cursor = 'default';}
canvas.onmousedown = function (e)
{
var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var coords = RGraph.getMouseXY(e);var segment = RGraph.getSegment(e, 5);if(segment && segment.length && !RGraph.Registry.Get('chart.adjusting.rose.' + id)){
var x = Math.abs(coords[0] - obj.centerx);var y = Math.abs(coords[1] - obj.centery);var a = Math.atan(y / x) * (180 / Math.PI);if(coords[0] >= obj.centerx && coords[1] < obj.centery){
a = 90 - a;a += 270;} else if(coords[0] >= obj.centerx && coords[1] >= obj.centery){
} else if(coords[0] < obj.centerx && coords[1] >= obj.centery){
a = 90 - a;a += 90;} else if(coords[0] < obj.centerx && coords[1] < obj.centery){
a += 180;}
var hyp = Math.abs(y / Math.sin(a / 57.3));if(hyp >= (segment[2] - 10) ){
if(RGraph.Registry.Get('chart.tooltip')){
RGraph.Registry.Get('chart.tooltip').style.display = 'none';RGraph.Registry.Set('chart.tooltip', null);}
RGraph.Registry.Set('chart.adjusting.rose.' + id, segment);e.stopPropagation();}
}
}
canvas.onmouseup = function (e)
{
var obj = e.target.__object__;var id = obj.id;if(RGraph.Registry.Get('chart.adjusting.rose.' + id)){
RGraph.Registry.Set('chart.adjusting.rose.' + id, null);e.stopPropagation();return false;}
}
canvas.onmouseout = function (e)
{
canvas.onmouseup(e);}
} else if(obj.type == 'bar'){
if(obj.Get('chart.grouping') == 'stacked'){
alert('[BAR] Adjusting stacked bar charts is not supported');return;}
var canvas = obj.canvas;var context = obj.context;canvas.onmousemove = function (e)
{
var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var mouse = RGraph.getMouseXY(e);var mousex = mouse[0];var mousey = mouse[1];for (var i=0; i<obj.coords.length; ++i){
if(mousex > obj.coords[i][0] && mousex < (obj.coords[i][0] + obj.coords[i][2])){
if(mousey > (obj.coords[i][1] - 5) && mousey < (obj.coords[i][1] + 5)){
canvas.style.cursor = 'ns-resize';} else {
canvas.style.cursor = 'default';}
var idx = RGraph.Registry.Get('chart.adjusting.bar.' + id)
if(typeof(idx) == 'number'){
var newheight = obj.grapharea - (mousey - obj.Get('chart.gutter'));var newvalue = (newheight / obj.grapharea) * obj.max;if(newvalue > obj.max) newvalue = obj.max;if(newvalue < 0)       newvalue = 0;for (var j=0, index=0; j<obj.data.length; ++j,++index){
if(typeof(obj.data[j]) == 'object'){
for (var k=0; k<obj.data[j].length && index <= idx; ++k, ++index){
if(index == idx){
obj.data[j][k] = newvalue;var b = true;break;}
}
--index;} else if(typeof(obj.data[j]) == 'number'){
if(index == idx){
obj.data[j] = newvalue;break;}
}
if(b){
break;}
}
RGraph.Clear(canvas);obj.Draw();RGraph.FireCustomEvent(obj, 'onadjust');}
return;}
}
canvas.style.cursor = 'default';}
canvas.onmousedown = function (e)
{
var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var mouse = RGraph.getMouseXY(e);var mousex = mouse[0];var mousey = mouse[1];for (var i=0; i<obj.coords.length; ++i){
if(
mousex > obj.coords[i][0] && mousex < (obj.coords[i][0] + obj.coords[i][2])
){
obj.Set('chart.ymax', obj.max);RGraph.Registry.Set('chart.adjusting.bar.' + id, i);canvas.onmousemove(e);}
}
}
canvas.onmouseup = function (e)
{
var id = e.target.__object__.id;RGraph.Registry.Set('chart.adjusting.bar.' + id, null);}
canvas.onmouseout = function (e)
{
canvas.onmouseup(e);}
} else if(obj.type == 'tradar'){
var canvas = obj.canvas;var context = obj.context;canvas.onmousemove = function (e)
{
var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var mouseDown = RGraph.Registry.Get('chart.adjusting.tradar.' + id);var mouseCoords = RGraph.getMouseXY(e);if(mouseDown){
canvas.style.cursor = 'pointer';var dx = mouseCoords[0] - obj.centerx;var dy = mouseCoords[1] - obj.centery;var hyp = Math.sqrt((dx * dx) + (dy * dy));var newvalue = (hyp / (obj.size / 2)) * obj.max;newvalue = Math.min(obj.max, newvalue);newvalue = Math.max(0, newvalue);if( (dx >= 0 ? true : false) == mouseDown[1] && (dy >= 0 ? true : false) == mouseDown[2]){
obj.data[mouseDown[0]] = newvalue;RGraph.Clear(canvas);obj.Draw();RGraph.FireCustomEvent(obj, 'onadjust');}
} else {
for (var i=0; i<obj.coords.length; ++i){
var dx = Math.abs(mouseCoords[0] - obj.coords[i][0]);var dy = Math.abs(mouseCoords[1] - obj.coords[i][1]);var a = Math.atan(dy / dx);var hyp = Math.sqrt((dx * dx) + (dy * dy));if(hyp <= 5){
canvas.style.cursor = 'pointer';return;}
}
canvas.style.cursor = 'default';}
}
canvas.onmousedown = function (e)
{
e = RGraph.FixEventObject(e);var obj = e.target.__object__;var id = obj.id;var canvas = obj.canvas;var context = obj.context;var mouseCoords = RGraph.getMouseXY(e);for (var i=0; i<obj.coords.length; ++i){
var dx = Math.abs(mouseCoords[0] - obj.coords[i][0]);var dy = Math.abs(mouseCoords[1] - obj.coords[i][1]);var a = Math.atan(dy / dx);var hyp = Math.sqrt((dx * dx) + (dy * dy));if(hyp <= 5){
canvas.style.cursor = 'pointer';RGraph.Registry.Set('chart.adjusting.tradar.' + id, [i, obj.coords[i][0] > obj.centerx, obj.coords[i][1] > obj.centery]);return;}
}
canvas.style.cursor = 'default';}
canvas.onmouseup = function (e)
{
RGraph.Registry.Set('chart.adjusting.tradar.' + e.target.id, null);canvas.style.cursor = 'default';}
canvas.onmouseout = function (e)
{
canvas.onmouseup(e);}
}
}
