Commit f24a67e7 authored by David Schnur's avatar David Schnur

Wrap one-statement if and for blocks in braces.

parent 05dfea77
......@@ -32,14 +32,16 @@
o.a = a != null ? a : 1;
o.add = function (c, d) {
for (var i = 0; i < c.length; ++i)
for (var i = 0; i < c.length; ++i) {
o[c.charAt(i)] += d;
}
return o.normalize();
};
o.scale = function (c, f) {
for (var i = 0; i < c.length; ++i)
for (var i = 0; i < c.length; ++i) {
o[c.charAt(i)] *= f;
}
return o.normalize();
};
......@@ -78,14 +80,16 @@
c = elem.css(css).toLowerCase();
// keep going until we find an element that has color, or
// we hit the body
if (c !== "" && c != "transparent")
if (c !== "" && c != "transparent") {
break;
}
elem = elem.parent();
} while (!$.nodeName(elem.get(0), "body"));
// catch Safari's way of signalling transparent
if (c == "rgba(0, 0, 0, 0)")
if (c == "rgba(0, 0, 0, 0)") {
c = "transparent";
}
return $.color.parse(c);
};
......@@ -98,39 +102,45 @@
// Look for rgb(num,num,num)
res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str);
if (res)
if (res) {
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
}
// Look for rgba(num,num,num,num)
res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
if (res)
if (res) {
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
}
// Look for rgb(num%,num%,num%)
res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str);
if (res)
if (res) {
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
}
// Look for rgba(num%,num%,num%,num)
res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
if (res)
if (res) {
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
}
// Look for #a0b1c2
res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str);
if (res)
if (res) {
return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
}
// Look for #fff
res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str);
if (res)
if (res) {
return m(parseInt(res[1]+res[1], 16), parseInt(res[2]+res[2], 16), parseInt(res[3]+res[3], 16));
}
// Otherwise, we're most likely dealing with a named color
var name = $.trim(str).toLowerCase();
if (name == "transparent")
if (name == "transparent") {
return m(255, 255, 255, 0);
else {
} else {
// default to black
res = lookupColors[name] || [0, 0, 0];
return m(res[0], res[1], res[2]);
......
......@@ -61,8 +61,9 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
var xCategories = series.xaxis.options.mode == "categories",
yCategories = series.yaxis.options.mode == "categories";
if (!(xCategories || yCategories))
if (!(xCategories || yCategories)) {
return;
}
var format = datapoints.format;
......@@ -86,20 +87,24 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
}
for (var m = 0; m < format.length; ++m) {
if (format[m].x && xCategories)
if (format[m].x && xCategories) {
format[m].number = false;
}
if (format[m].y && yCategories)
if (format[m].y && yCategories) {
format[m].number = false;
}
}
}
function getNextIndex(categories) {
var index = -1;
for (var v in categories)
if (categories[v] > index)
for (var v in categories) {
if (categories[v] > index) {
index = categories[v];
}
}
return index + 1;
}
......@@ -108,8 +113,9 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
var res = [];
for (var label in axis.categories) {
var v = axis.categories[label];
if (v >= axis.min && v <= axis.max)
if (v >= axis.min && v <= axis.max) {
res.push([v, label]);
}
}
res.sort(function (a, b) { return a[0] - b[0]; });
......@@ -118,27 +124,31 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
}
function setupCategoriesForAxis(series, axis, datapoints) {
if (series[axis].options.mode != "categories")
if (series[axis].options.mode != "categories") {
return;
}
if (!series[axis].categories) {
// parse options
var c = {}, o = series[axis].options.categories || {};
if ($.isArray(o)) {
for (var i = 0; i < o.length; ++i)
for (var i = 0; i < o.length; ++i) {
c[o[i]] = i;
}
}
else {
for (var v in o)
for (var v in o) {
c[v] = o[v];
}
}
series[axis].categories = c;
}
// fix ticks
if (!series[axis].options.ticks)
if (!series[axis].options.ticks) {
series[axis].options.ticks = categoriesTickGenerator;
}
transformPointsOnAxis(datapoints, axis, series[axis].categories);
}
......@@ -152,14 +162,16 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
index = getNextIndex(categories);
for (var i = 0; i < points.length; i += ps) {
if (points[i] == null)
if (points[i] == null) {
continue;
}
for (var m = 0; m < ps; ++m) {
var val = points[i + m];
if (val == null || !format[m][formatColumn])
if (val == null || !format[m][formatColumn]) {
continue;
}
if (!(val in categories)) {
categories[val] = index;
......
......@@ -72,9 +72,9 @@ The plugin also adds four public methods:
var crosshair = { x: -1, y: -1, locked: false };
plot.setCrosshair = function setCrosshair(pos) {
if (!pos)
if (!pos) {
crosshair.x = -1;
else {
} else {
var o = plot.p2c(pos);
crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
......@@ -86,8 +86,9 @@ The plugin also adds four public methods:
plot.clearCrosshair = plot.setCrosshair; // passes null for pos
plot.lockCrosshair = function lockCrosshair(pos) {
if (pos)
if (pos) {
plot.setCrosshair(pos);
}
crosshair.locked = true;
};
......@@ -96,8 +97,9 @@ The plugin also adds four public methods:
};
function onMouseOut(e) {
if (crosshair.locked)
if (crosshair.locked) {
return;
}
if (crosshair.x != -1) {
crosshair.x = -1;
......@@ -106,8 +108,9 @@ The plugin also adds four public methods:
}
function onMouseMove(e) {
if (crosshair.locked)
if (crosshair.locked) {
return;
}
if (plot.getSelection && plot.getSelection()) {
crosshair.x = -1; // hide the crosshair while selecting
......@@ -121,8 +124,9 @@ The plugin also adds four public methods:
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
if (!plot.getOptions().crosshair.mode)
if (!plot.getOptions().crosshair.mode) {
return;
}
eventHolder.mouseout(onMouseOut);
eventHolder.mousemove(onMouseMove);
......@@ -130,8 +134,9 @@ The plugin also adds four public methods:
plot.hooks.drawOverlay.push(function (plot, ctx) {
var c = plot.getOptions().crosshair;
if (!c.mode)
if (!c.mode) {
return;
}
var plotOffset = plot.getPlotOffset();
......
......@@ -74,8 +74,9 @@ shadowSize and lineWidth are derived as well from the points series.
};
function processRawData(plot, series, data, datapoints){
if (!series.points.errorbars)
if (!series.points.errorbars) {
return;
}
// x,y values
var format = [
......@@ -90,16 +91,18 @@ shadowSize and lineWidth are derived as well from the points series.
if (series.points.xerr.asymmetric) {
format.push({ x: true, number: true, required: true });
format.push({ x: true, number: true, required: true });
} else
} else {
format.push({ x: true, number: true, required: true });
}
}
if (errors == "y" || errors == "xy") {
// lower / upper error
if (series.points.yerr.asymmetric) {
format.push({ y: true, number: true, required: true });
format.push({ y: true, number: true, required: true });
} else
} else {
format.push({ y: true, number: true, required: true });
}
}
datapoints.format = format;
}
......@@ -122,29 +125,42 @@ shadowSize and lineWidth are derived as well from the points series.
if (xerr.asymmetric) {
exl = points[i + 2];
exu = points[i + 3];
if (eb == "xy")
if (eb == "xy") {
if (yerr.asymmetric){
eyl = points[i + 4];
eyu = points[i + 5];
} else eyl = points[i + 4];
} else {
eyl = points[i + 4];
}
}
} else {
exl = points[i + 2];
if (eb == "xy")
if (eb == "xy") {
if (yerr.asymmetric) {
eyl = points[i + 3];
eyu = points[i + 4];
} else eyl = points[i + 3];
} else {
eyl = points[i + 3];
}
}
}
// only Y
} else if (eb == "y")
} else if (eb == "y") {
if (yerr.asymmetric) {
eyl = points[i + 2];
eyu = points[i + 3];
} else eyl = points[i + 2];
} else {
eyl = points[i + 2];
}
}
// symmetric errors?
if (exu == null) exu = exl;
if (eyu == null) eyu = eyl;
if (exu == null) {
exu = exl;
}
if (eyu == null) {
eyu = eyl;
}
var errRanges = [exl, exu, eyl, eyu];
// nullify if not showing
......@@ -206,12 +222,16 @@ shadowSize and lineWidth are derived as well from the points series.
lower = [x, y][e] - errRanges[e * err.length];
//points outside of the canvas
if (err[e].err == "x")
if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max)
if (err[e].err == "x") {
if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max) {
continue;
if (err[e].err == "y")
if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max)
}
}
if (err[e].err == "y") {
if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max) {
continue;
}
}
// prevent errorbars getting out of the canvas
var drawUpper = true,
......@@ -281,16 +301,27 @@ shadowSize and lineWidth are derived as well from the points series.
// error bar - avoid plotting over circles
if (err.err == "x"){
if (upper > x + radius) drawPath(ctx, [[upper,y],[Math.max(x + radius,minmax[0]),y]]);
else drawUpper = false;
if (lower < x - radius) drawPath(ctx, [[Math.min(x - radius,minmax[1]),y],[lower,y]] );
else drawLower = false;
}
else {
if (upper < y - radius) drawPath(ctx, [[x,upper],[x,Math.min(y - radius,minmax[0])]] );
else drawUpper = false;
if (lower > y + radius) drawPath(ctx, [[x,Math.max(y + radius,minmax[1])],[x,lower]] );
else drawLower = false;
if (upper > x + radius) {
drawPath(ctx, [[upper,y],[Math.max(x + radius,minmax[0]),y]]);
} else {
drawUpper = false;
}
if (lower < x - radius) {
drawPath(ctx, [[Math.min(x - radius,minmax[1]),y],[lower,y]] );
} else {
drawLower = false;
}
} else {
if (upper < y - radius) {
drawPath(ctx, [[x,upper],[x,Math.min(y - radius,minmax[0])]] );
} else {
drawUpper = false;
}
if (lower > y + radius) {
drawPath(ctx, [[x,Math.max(y + radius,minmax[1])],[x,lower]] );
} else {
drawLower = false;
}
}
//internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps
......@@ -300,21 +331,33 @@ shadowSize and lineWidth are derived as well from the points series.
// upper cap
if (drawUpper) {
if (err.upperCap == "-"){
if (err.err=="x") drawPath(ctx, [[upper,y - radius],[upper,y + radius]] );
else drawPath(ctx, [[x - radius,upper],[x + radius,upper]] );
if (err.err=="x") {
drawPath(ctx, [[upper,y - radius],[upper,y + radius]] );
} else {
drawPath(ctx, [[x - radius,upper],[x + radius,upper]] );
}
} else if ($.isFunction(err.upperCap)){
if (err.err=="x") err.upperCap(ctx, upper, y, radius);
else err.upperCap(ctx, x, upper, radius);
if (err.err=="x") {
err.upperCap(ctx, upper, y, radius);
} else {
err.upperCap(ctx, x, upper, radius);
}
}
}
// lower cap
if (drawLower) {
if (err.lowerCap == "-"){
if (err.err=="x") drawPath(ctx, [[lower,y - radius],[lower,y + radius]] );
else drawPath(ctx, [[x - radius,lower],[x + radius,lower]] );
if (err.err=="x") {
drawPath(ctx, [[lower,y - radius],[lower,y + radius]] );
} else {
drawPath(ctx, [[x - radius,lower],[x + radius,lower]] );
}
} else if ($.isFunction(err.lowerCap)){
if (err.err=="x") err.lowerCap(ctx, lower, y, radius);
else err.lowerCap(ctx, x, lower, radius);
if (err.err=="x") {
err.lowerCap(ctx, lower, y, radius);
} else {
err.lowerCap(ctx, x, lower, radius);
}
}
}
}
......@@ -322,8 +365,9 @@ shadowSize and lineWidth are derived as well from the points series.
function drawPath(ctx, pts){
ctx.beginPath();
ctx.moveTo(pts[0][0], pts[0][1]);
for (var p=1; p < pts.length; p++)
for (var p=1; p < pts.length; p++) {
ctx.lineTo(pts[p][0], pts[p][1]);
}
ctx.stroke();
}
......@@ -333,8 +377,9 @@ shadowSize and lineWidth are derived as well from the points series.
ctx.save();
ctx.translate(plotOffset.left, plotOffset.top);
$.each(plot.getData(), function (i, s) {
if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show))
if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) {
drawSeriesErrors(plot, ctx, s);
}
});
ctx.restore();
}
......
......@@ -71,11 +71,13 @@ Google Maps).
var defaultShow = options.series.images.show;
$.each(series, function (i, s) {
if (!(defaultShow || s.images.show))
if (!(defaultShow || s.images.show)) {
return;
}
if (s.data)
if (s.data) {
s = s.data;
}
$.each(s, function (i, p) {
if (typeof p[0] == "string") {
......@@ -88,8 +90,9 @@ Google Maps).
$.plot.image.load(urls, function (loadedImages) {
$.each(points, function (i, p) {
var url = p[0];
if (loadedImages[url])
if (loadedImages[url]) {
p[0] = loadedImages[url];
}
});
callback();
......@@ -98,8 +101,9 @@ Google Maps).
$.plot.image.load = function (urls, callback) {
var missing = urls.length, loaded = {};
if (missing == 0)
if (missing == 0) {
callback({});
}
$.each(urls, function (i, url) {
var handler = function () {
......@@ -107,8 +111,9 @@ Google Maps).
loaded[url] = this;
if (missing == 0)
if (missing == 0) {
callback(loaded);
}
};
$("<img />").load(handler).error(handler).attr("src", url);
......@@ -118,8 +123,9 @@ Google Maps).
function drawSeries(plot, ctx, series) {
var plotOffset = plot.getPlotOffset();
if (!series.images || !series.images.show)
if (!series.images || !series.images.show) {
return;
}
var points = series.datapoints.points,
ps = series.datapoints.pointsize;
......@@ -134,8 +140,9 @@ Google Maps).
// actually we should check img.complete, but it
// appears to be a somewhat unreliable indicator in
// IE6 (false even after load event)
if (!img || img.width <= 0 || img.height <= 0)
if (!img || img.width <= 0 || img.height <= 0) {
continue;
}
if (x1 > x2) {
tmp = x2;
......@@ -162,8 +169,9 @@ Google Maps).
// clip
if (x1 == x2 || y1 == y2 ||
x1 >= xaxis.max || x2 <= xaxis.min ||
y1 >= yaxis.max || y2 <= yaxis.min)
y1 >= yaxis.max || y2 <= yaxis.min) {
continue;
}
var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height;
if (x1 < xaxis.min) {
......@@ -214,8 +222,9 @@ Google Maps).
}
function processRawData(plot, series, data, datapoints) {
if (!series.images.show)
if (!series.images.show) {
return;
}
// format is Image, x1, y1, x2, y2 (opposite corners)
datapoints.format = [
......
This diff is collapsed.
......@@ -100,10 +100,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
*
* Requires: 1.2.2+
*/
//(function(d){function e(a){var b=a||window.event,c=[].slice.call(arguments,1),f=0,e=0,g=0,a=d.event.fix(b);a.type="mousewheel";b.wheelDelta&&(f=b.wheelDelta/120);b.detail&&(f=-b.detail/3);g=f;void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(g=0,e=-1*f);void 0!==b.wheelDeltaY&&(g=b.wheelDeltaY/120);void 0!==b.wheelDeltaX&&(e=-1*b.wheelDeltaX/120);c.unshift(a,f,e,g);return(d.event.dispatch||d.event.handle).apply(this,c)}var c=["DOMMouseScroll","mousewheel"];if(d.event.fixHooks)for(var h=c.length;h;)d.event.fixHooks[c[--h]]=d.event.mouseHooks;d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],e,!1);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
(function(d){function e(a){var b=a||window.event,c=[].slice.call(arguments,1),f=0,e=0,g=0,a=d.event.fix(b);a.type="mousewheel";b.wheelDelta&&(f=b.wheelDelta/120);b.detail&&(f=-b.detail/3);g=f;void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(g=0,e=-1*f);void 0!==b.wheelDeltaY&&(g=b.wheelDeltaY/120);void 0!==b.wheelDeltaX&&(e=-1*b.wheelDeltaX/120);c.unshift(a,f,e,g);return(d.event.dispatch||d.event.handle).apply(this,c)}var c=["DOMMouseScroll","mousewheel"];if(d.event.fixHooks)for(var h=c.length;h;)d.event.fixHooks[c[--h]]=d.event.mouseHooks;d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],e,!1);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
(function ($) {
var options = {
......@@ -128,10 +125,11 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
var c = plot.offset();
c.left = e.pageX - c.left;
c.top = e.pageY - c.top;
if (zoomOut)
if (zoomOut) {
plot.zoomOut({ center: c });
else
} else {
plot.zoom({ center: c });
}
}
function onMouseWheel(e, delta) {
......@@ -144,20 +142,23 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
panTimeout = null;
function onDragStart(e) {
if (e.which != 1) // only accept left-click
if (e.which != 1) { // only accept left-click
return false;
}
var c = plot.getPlaceholder().css("cursor");
if (c)
if (c) {
prevCursor = c;
}
plot.getPlaceholder().css("cursor", plot.getOptions().pan.cursor);
prevPageX = e.pageX;
prevPageY = e.pageY;
}
function onDrag(e) {
var frameRate = plot.getOptions().pan.frameRate;
if (panTimeout || !frameRate)
if (panTimeout || !frameRate) {
return;
}
panTimeout = setTimeout(function () {
plot.pan({ left: prevPageX - e.pageX,
......@@ -195,26 +196,30 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
}
plot.zoomOut = function (args) {
if (!args)
if (!args) {
args = {};
}
if (!args.amount)
if (!args.amount) {
args.amount = plot.getOptions().zoom.amount;
}
args.amount = 1 / args.amount;
plot.zoom(args);
};
plot.zoom = function (args) {
if (!args)
if (!args) {
args = {};
}
var c = args.center,
amount = args.amount || plot.getOptions().zoom.amount,
w = plot.width(), h = plot.height();
if (!c)
if (!c) {
c = { left: w / 2, top: h / 2 };
}
var xf = c.left / w,
yf = c.top / h,
......@@ -236,8 +241,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
zr = opts.zoomRange,
pr = opts.panRange;
if (zr === false) // no zooming on this axis
if (zr === false) { // no zooming on this axis
return;
}
min = axis.c2p(min);
max = axis.c2p(max);
......@@ -261,8 +267,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
var range = max - min;
if (zr &&
((zr[0] != null && range < zr[0]) ||
(zr[1] != null && range > zr[1])))
(zr[1] != null && range > zr[1]))) {
return;
}
opts.min = min;
opts.max = max;
......@@ -271,8 +278,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
plot.setupGrid();
plot.draw();
if (!args.preventEvent)
if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotzoom", [ plot, args ]);
}
};
plot.pan = function (args) {
......@@ -281,10 +289,12 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
y: +args.top
};
if (isNaN(delta.x))
if (isNaN(delta.x)) {
delta.x = 0;
if (isNaN(delta.y))
}
if (isNaN(delta.y)) {
delta.y = 0;
}
$.each(plot.getAxes(), function (_, axis) {
var opts = axis.options,
......@@ -294,8 +304,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
max = axis.c2p(axis.p2c(axis.max) + d);
var pr = opts.panRange;
if (pr === false) // no panning on this axis
if (pr === false) { // no panning on this axis
return;
}
if (pr) {
// check whether we hit the wall
......@@ -319,8 +330,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
plot.setupGrid();
plot.draw();
if (!args.preventEvent)
if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotpan", [ plot, args ]);
}
};
function shutdown(plot, eventHolder) {
......@@ -329,8 +341,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
eventHolder.unbind("dragstart", onDragStart);
eventHolder.unbind("drag", onDrag);
eventHolder.unbind("dragend", onDragEnd);
if (panTimeout)
if (panTimeout) {
clearTimeout(panTimeout);
}
}
plot.hooks.bindEvents.push(bindEvents);
......
......@@ -181,7 +181,7 @@ More detail and specific examples can be found in the included HTML file.
// that the user may have stored in higher indexes.
if ($.isArray(value) && value.length == 1) {
value = value[0];
value = value[0];
}
if ($.isArray(value)) {
......@@ -415,7 +415,9 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.label.show) {
return drawLabels();
} else return true;
} else {
return true;
}
function drawSlice(angle, color, fill) {
......@@ -561,10 +563,11 @@ More detail and specific examples can be found in the included HTML file.
//-- Additional Interactive related functions --
function isPointInPoly(poly, pt) {
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || (poly[j][1] <= pt[1] && pt[1]< poly[i][1]))
&& (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
&& (c = !c);
}
return c;
}
......@@ -715,8 +718,9 @@ More detail and specific examples can be found in the included HTML file.
function indexOfHighlight(s) {
for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i];
if (h.series == s)
if (h.series == s) {
return i;
}
}
return -1;
}
......
......@@ -31,8 +31,9 @@ can just fix the size of their placeholders.
// somebody might have hidden us and we can't plot
// when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0)
if (placeholder.width() == 0 || placeholder.height() == 0) {
return;
}
plot.resize();
plot.setupGrid();
......
......@@ -104,8 +104,9 @@ The plugin allso adds the following methods to the plot object:
}
function onMouseDown(e) {
if (e.which != 1) // only accept left-click
if (e.which != 1) { // only accept left-click
return;
}
// cancel out any text selections
document.body.focus();
......@@ -135,18 +136,20 @@ The plugin allso adds the following methods to the plot object:
mouseUpHandler = null;
// revert drag stuff for old-school browsers
if (document.onselectstart !== undefined)
if (document.onselectstart !== undefined) {
document.onselectstart = savedhandlers.onselectstart;
if (document.ondrag !== undefined)
}
if (document.ondrag !== undefined) {
document.ondrag = savedhandlers.ondrag;
}
// no more dragging
selection.active = false;
updateSelection(e);
if (selectionIsSane())
if (selectionIsSane()) {
triggerSelectedEvent();
else {
} else {
// this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotselecting", [ null ]);
......@@ -156,10 +159,13 @@ The plugin allso adds the following methods to the plot object:
}
function getSelection() {
if (!selectionIsSane())
if (!selectionIsSane()) {
return null;
}
if (!selection.show) return null;
if (!selection.show) {
return null;
}
var r = {}, c1 = selection.first, c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) {
......@@ -177,8 +183,9 @@ The plugin allso adds the following methods to the plot object:
plot.getPlaceholder().trigger("plotselected", [ r ]);
// backwards-compat stuff, to be removed in future
if (r.xaxis && r.yaxis)
if (r.xaxis && r.yaxis) {
plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
}
}
function clamp(min, value, max) {
......@@ -192,32 +199,36 @@ The plugin allso adds the following methods to the plot object:
pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width());
pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height());
if (o.selection.mode == "y")
if (o.selection.mode == "y") {
pos.x = pos == selection.first ? 0 : plot.width();
}
if (o.selection.mode == "x")
if (o.selection.mode == "x") {
pos.y = pos == selection.first ? 0 : plot.height();
}
}
function updateSelection(pos) {
if (pos.pageX == null)
if (pos.pageX == null) {
return;
}
setSelectionPos(selection.second, pos);
if (selectionIsSane()) {
selection.show = true;
plot.triggerRedrawOverlay();
}
else
} else {
clearSelection(true);
}
}
function clearSelection(preventEvent) {
if (selection.show) {
selection.show = false;
plot.triggerRedrawOverlay();
if (!preventEvent)
if (!preventEvent) {
plot.getPlaceholder().trigger("plotunselected", [ ]);
}
}
}
......@@ -229,8 +240,9 @@ The plugin allso adds the following methods to the plot object:
axis = axes[k];
if (axis.direction == coord) {
key = coord + axis.n + "axis";
if (!ranges[key] && axis.n == 1)
if (!ranges[key] && axis.n == 1) {
key = coord + "axis"; // support x1axis as xaxis
}
if (ranges[key]) {
from = ranges[key].from;
to = ranges[key].to;
......@@ -283,8 +295,9 @@ The plugin allso adds the following methods to the plot object:
selection.show = true;
plot.triggerRedrawOverlay();
if (!preventEvent && selectionIsSane())
if (!preventEvent && selectionIsSane()) {
triggerSelectedEvent();
}
}
function selectionIsSane() {
......@@ -338,8 +351,9 @@ The plugin allso adds the following methods to the plot object:
eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler)
if (mouseUpHandler) {
$(document).unbind("mouseup", mouseUpHandler);
}
});
}
......
......@@ -44,23 +44,27 @@ charts or filled areas).
function findMatchingSeries(s, allseries) {
var res = null;
for (var i = 0; i < allseries.length; ++i) {
if (s == allseries[i])
if (s == allseries[i]) {
break;
}
if (allseries[i].stack == s.stack)
if (allseries[i].stack == s.stack) {
res = allseries[i];
}
}
return res;
}
function stackData(plot, s, datapoints) {
if (s.stack == null || s.stack === false)
if (s.stack == null || s.stack === false) {
return;
}
var other = findMatchingSeries(s, plot.getData());
if (!other)
if (!other) {
return;
}
var ps = datapoints.pointsize,
points = datapoints.points,
......@@ -78,29 +82,33 @@ charts or filled areas).
i = 0, j = 0, l, m;
while (true) {
if (i >= points.length)
if (i >= points.length) {
break;
}
l = newpoints.length;
if (points[i] == null) {
// copy gaps
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
i += ps;
}
else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if (!withlines) {
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
}
i += ps;
}
else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(null);
}
fromgap = true;
j += otherps;
}
......@@ -113,8 +121,9 @@ charts or filled areas).
bottom = 0;
if (px == qx) {
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
newpoints[l + accumulateOffset] += qy;
bottom = qy;
......@@ -129,8 +138,9 @@ charts or filled areas).
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx);
newpoints.push(intery + qy);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
newpoints.push(points[i + m]);
}
bottom = qy;
}
......@@ -143,13 +153,15 @@ charts or filled areas).
continue;
}
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
// we might be able to interpolate a point below,
// this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null)
if (withlines && j > 0 && otherpoints[j - otherps] != null) {
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
}
newpoints[l + accumulateOffset] += bottom;
......@@ -158,8 +170,9 @@ charts or filled areas).
fromgap = false;
if (l != newpoints.length && withbottom)
if (l != newpoints.length && withbottom) {
newpoints[l + 2] += bottom;
}
}
// maintain the line steps invariant
......@@ -167,8 +180,9 @@ charts or filled areas).
&& newpoints[l] != null
&& newpoints[l] != newpoints[l - ps]
&& newpoints[l + 1] != newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints[l + ps + m] = newpoints[l + m];
}
newpoints[l + 1] = newpoints[l - ps + 1];
}
}
......
......@@ -55,8 +55,9 @@ The symbols are accessed as strings through the standard symbol options:
};
var s = series.points.symbol;
if (handlers[s])
if (handlers[s]) {
series.points.symbol = handlers[s];
}
}
function init(plot) {
......
......@@ -71,33 +71,38 @@ You may need to check for this in hover events.
y = origpoints[i + 1];
prevp = p;
if (y < below)
if (y < below) {
p = threspoints;
else
} else {
p = newpoints;
}
if (addCrossingPoints && prevp != p && x != null
&& i > 0 && origpoints[i - ps] != null) {
var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]);
prevp.push(interx);
prevp.push(below);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
prevp.push(origpoints[i + m]);
}
p.push(null); // start new segment
p.push(null);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
p.push(interx);
p.push(below);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
}
p.push(x);
p.push(y);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
}
datapoints.points = newpoints;
......@@ -113,8 +118,9 @@ You may need to check for this in hover events.
}
function processThresholds(plot, s, datapoints) {
if (!s.threshold)
if (!s.threshold) {
return;
}
if (s.threshold instanceof Array) {
s.threshold.sort(function(a, b) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment