diff --git a/jquery.colorhelpers.js b/jquery.colorhelpers.js index 2ce381e..412aee7 100644 --- a/jquery.colorhelpers.js +++ b/jquery.colorhelpers.js @@ -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]); diff --git a/jquery.flot.categories.js b/jquery.flot.categories.js index e31c241..24dcee2 100644 --- a/jquery.flot.categories.js +++ b/jquery.flot.categories.js @@ -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; diff --git a/jquery.flot.crosshair.js b/jquery.flot.crosshair.js index 2a8d326..f09c133 100644 --- a/jquery.flot.crosshair.js +++ b/jquery.flot.crosshair.js @@ -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(); diff --git a/jquery.flot.errorbars.js b/jquery.flot.errorbars.js index 0e3af34..7ac49ee 100644 --- a/jquery.flot.errorbars.js +++ b/jquery.flot.errorbars.js @@ -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(); } diff --git a/jquery.flot.image.js b/jquery.flot.image.js index 3644841..91f39a0 100644 --- a/jquery.flot.image.js +++ b/jquery.flot.image.js @@ -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); + } }; $("").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 = [ diff --git a/jquery.flot.js b/jquery.flot.js index b629638..5296cc3 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -638,8 +638,9 @@ Licensed under the MIT license. plot.getAxes = function () { var res = {}, i; $.each(xaxes.concat(yaxes), function (_, axis) { - if (axis) + if (axis) { res[axis.direction + (axis.n != 1 ? axis.n : "") + "axis"] = axis; + } }); return res; }; @@ -680,8 +681,9 @@ Licensed under the MIT license. function executeHooks(hook, args) { args = [plot].concat(args); - for (var i = 0; i < hook.length; ++i) + for (var i = 0; i < hook.length; ++i) { hook[i].apply(this, args); + } } function initPlugins() { @@ -695,8 +697,9 @@ Licensed under the MIT license. for (var i = 0; i < plugins.length; ++i) { var p = plugins[i]; p.init(plot, classes); - if (p.options) + if (p.options) { $.extend(true, options, p.options); + } } } @@ -713,20 +716,26 @@ Licensed under the MIT license. options.colors = opts.colors; } - if (options.xaxis.color == null) + if (options.xaxis.color == null) { options.xaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString(); - if (options.yaxis.color == null) + } + if (options.yaxis.color == null) { options.yaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString(); + } - if (options.xaxis.tickColor == null) // grid.tickColor for back-compatibility + if (options.xaxis.tickColor == null) { // grid.tickColor for back-compatibility options.xaxis.tickColor = options.grid.tickColor || options.xaxis.color; - if (options.yaxis.tickColor == null) // grid.tickColor for back-compatibility + } + if (options.yaxis.tickColor == null) { // grid.tickColor for back-compatibility options.yaxis.tickColor = options.grid.tickColor || options.yaxis.color; + } - if (options.grid.borderColor == null) + if (options.grid.borderColor == null) { options.grid.borderColor = options.grid.color; - if (options.grid.tickColor == null) + } + if (options.grid.tickColor == null) { options.grid.tickColor = $.color.parse(options.grid.color).scale("a", 0.22).toString(); + } // Fill in defaults for axis options, including any unspecified // font-spec fields, if a font-spec was provided. @@ -784,10 +793,12 @@ Licensed under the MIT license. } // backwards compatibility, to be removed in future - if (options.xaxis.noTicks && options.xaxis.ticks == null) + if (options.xaxis.noTicks && options.xaxis.ticks == null) { options.xaxis.ticks = options.xaxis.noTicks; - if (options.yaxis.noTicks && options.yaxis.ticks == null) + } + if (options.yaxis.noTicks && options.yaxis.ticks == null) { options.yaxis.ticks = options.yaxis.noTicks; + } if (options.x2axis) { options.xaxes[1] = $.extend(true, {}, options.xaxis, options.x2axis); options.xaxes[1].position = "top"; @@ -796,31 +807,42 @@ Licensed under the MIT license. options.yaxes[1] = $.extend(true, {}, options.yaxis, options.y2axis); options.yaxes[1].position = "right"; } - if (options.grid.coloredAreas) + if (options.grid.coloredAreas) { options.grid.markings = options.grid.coloredAreas; - if (options.grid.coloredAreasColor) + } + if (options.grid.coloredAreasColor) { options.grid.markingsColor = options.grid.coloredAreasColor; - if (options.lines) + } + if (options.lines) { $.extend(true, options.series.lines, options.lines); - if (options.points) + } + if (options.points) { $.extend(true, options.series.points, options.points); - if (options.bars) + } + if (options.bars) { $.extend(true, options.series.bars, options.bars); - if (options.shadowSize != null) + } + if (options.shadowSize != null) { options.series.shadowSize = options.shadowSize; - if (options.highlightColor != null) + } + if (options.highlightColor != null) { options.series.highlightColor = options.highlightColor; + } // save options on axes for future reference - for (i = 0; i < options.xaxes.length; ++i) + for (i = 0; i < options.xaxes.length; ++i) { getOrCreateAxis(xaxes, i + 1).options = options.xaxes[i]; - for (i = 0; i < options.yaxes.length; ++i) + } + for (i = 0; i < options.yaxes.length; ++i) { getOrCreateAxis(yaxes, i + 1).options = options.yaxes[i]; + } // add hooks from options - for (var n in hooks) - if (options.hooks[n] && options.hooks[n].length) + for (var n in hooks) { + if (options.hooks[n] && options.hooks[n].length) { hooks[n] = hooks[n].concat(options.hooks[n]); + } + } executeHooks(hooks.processOptions, [options]); } @@ -843,9 +865,9 @@ Licensed under the MIT license. $.extend(true, s, d[i]); d[i].data = s.data; - } - else + } else { s.data = d[i]; + } res.push(s); } @@ -854,10 +876,12 @@ Licensed under the MIT license. function axisNumber(obj, coord) { var a = obj[coord + "axis"]; - if (typeof a == "object") // if we got a real axis, extract number + if (typeof a == "object") { // if we got a real axis, extract number a = a.n; - if (typeof a != "number") + } + if (typeof a != "number") { a = 1; // default to first axis + } return a; } @@ -871,20 +895,24 @@ Licensed under the MIT license. var res = {}, i, axis; for (i = 0; i < xaxes.length; ++i) { axis = xaxes[i]; - if (axis && axis.used) + if (axis && axis.used) { res["x" + axis.n] = axis.c2p(pos.left); + } } for (i = 0; i < yaxes.length; ++i) { axis = yaxes[i]; - if (axis && axis.used) + if (axis && axis.used) { res["y" + axis.n] = axis.c2p(pos.top); + } } - if (res.x1 !== undefined) + if (res.x1 !== undefined) { res.x = res.x1; - if (res.y1 !== undefined) + } + if (res.y1 !== undefined) { res.y = res.y1; + } return res; } @@ -897,8 +925,9 @@ Licensed under the MIT license. axis = xaxes[i]; if (axis && axis.used) { key = "x" + axis.n; - if (pos[key] == null && axis.n == 1) + if (pos[key] == null && axis.n == 1) { key = "x"; + } if (pos[key] != null) { res.left = axis.p2c(pos[key]); @@ -911,8 +940,9 @@ Licensed under the MIT license. axis = yaxes[i]; if (axis && axis.used) { key = "y" + axis.n; - if (pos[key] == null && axis.n == 1) + if (pos[key] == null && axis.n == 1) { key = "y"; + } if (pos[key] != null) { res.top = axis.p2c(pos[key]); @@ -925,12 +955,13 @@ Licensed under the MIT license. } function getOrCreateAxis(axes, number) { - if (!axes[number - 1]) + if (!axes[number - 1]) { axes[number - 1] = { n: number, // save the number for future reference direction: axes == xaxes ? "x" : "y", options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis) }; + } return axes[number - 1]; } @@ -981,8 +1012,12 @@ Licensed under the MIT license. if (variation >= 0) { if (variation < 0.5) { variation = -variation - 0.2; - } else variation = 0; - } else variation = -variation; + } else { + variation = 0; + } + } else { + variation = -variation; + } } colors[i] = c.scale("rgb", 1 + variation); @@ -999,19 +1034,22 @@ Licensed under the MIT license. s.color = colors[colori].toString(); ++colori; } - else if (typeof s.color == "number") + else if (typeof s.color == "number") { s.color = colors[s.color].toString(); + } // turn on lines automatically in case nothing is set if (s.lines.show == null) { var v, show = true; - for (v in s) + for (v in s) { if (s[v] && s[v].show) { show = false; break; } - if (show) + } + if (show) { s.lines.show = true; + } } // If nothing was provided for lines.zero, default it to match @@ -1036,10 +1074,12 @@ Licensed under the MIT license. data, format; function updateAxis(axis, min, max) { - if (min < axis.datamin && min != -fakeInfinity) + if (min < axis.datamin && min != -fakeInfinity) { axis.datamin = min; - if (max > axis.datamax && max != fakeInfinity) + } + if (max > axis.datamax && max != fakeInfinity) { axis.datamax = max; + } } $.each(allAxes(), function (_, axis) { @@ -1081,8 +1121,9 @@ Licensed under the MIT license. s.datapoints.format = format; } - if (s.datapoints.pointsize != null) + if (s.datapoints.pointsize != null) { continue; // already filled in + } s.datapoints.pointsize = format.length; @@ -1104,20 +1145,23 @@ Licensed under the MIT license. if (f) { if (f.number && val != null) { val = +val; // convert to number - if (isNaN(val)) + if (isNaN(val)) { val = null; - else if (val == Infinity) + } else if (val == Infinity) { val = fakeInfinity; - else if (val == -Infinity) + } else if (val == -Infinity) { val = -fakeInfinity; + } } if (val == null) { - if (f.required) + if (f.required) { nullify = true; + } - if (f.defaultValue != null) + if (f.defaultValue != null) { val = f.defaultValue; + } } } @@ -1152,8 +1196,9 @@ Licensed under the MIT license. && points[k - ps] != points[k] && points[k - ps + 1] != points[k + 1]) { // copy the point to make room for a middle point - for (m = 0; m < ps; ++m) + for (m = 0; m < ps; ++m) { points[k + ps + m] = points[k + m]; + } // middle point has same y points[k + 1] = points[k - ps + 1]; @@ -1183,26 +1228,32 @@ Licensed under the MIT license. xmax = bottomSentry, ymax = bottomSentry; for (j = 0; j < points.length; j += ps) { - if (points[j] == null) + if (points[j] == null) { continue; + } for (m = 0; m < ps; ++m) { val = points[j + m]; f = format[m]; - if (!f || f.autoscale === false || val == fakeInfinity || val == -fakeInfinity) + if (!f || f.autoscale === false || val == fakeInfinity || val == -fakeInfinity) { continue; + } if (f.x) { - if (val < xmin) + if (val < xmin) { xmin = val; - if (val > xmax) + } + if (val > xmax) { xmax = val; + } } if (f.y) { - if (val < ymin) + if (val < ymin) { ymin = val; - if (val > ymax) + } + if (val > ymax) { ymax = val; + } } } } @@ -1228,8 +1279,7 @@ Licensed under the MIT license. if (s.bars.horizontal) { ymin += delta; ymax += delta + s.bars.barWidth; - } - else { + } else { xmin += delta; xmax += delta + s.bars.barWidth; } @@ -1240,10 +1290,12 @@ Licensed under the MIT license. } $.each(allAxes(), function (_, axis) { - if (axis.datamin == topSentry) + if (axis.datamin == topSentry) { axis.datamin = null; - if (axis.datamax == bottomSentry) + } + if (axis.datamax == bottomSentry) { axis.datamax = null; + } }); } @@ -1255,8 +1307,9 @@ Licensed under the MIT license. placeholder.css("padding", 0) // padding messes up the positioning .children(":not(.flot-base,.flot-overlay)").remove(); - if (placeholder.css("position") == "static") + if (placeholder.css("position") == "static") { placeholder.css("position", "relative"); // for positioning labels and overlay + } surface = new Canvas("flot-base", placeholder); overlay = new Canvas("flot-overlay", placeholder); // overlay canvas for interactive features @@ -1294,15 +1347,17 @@ Licensed under the MIT license. eventHolder.bind("mouseleave", onMouseLeave); } - if (options.grid.clickable) + if (options.grid.clickable) { eventHolder.click(onClick); + } executeHooks(hooks.bindEvents, [eventHolder]); } function shutdown() { - if (redrawTimeout) + if (redrawTimeout) { clearTimeout(redrawTimeout); + } eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mouseleave", onMouseLeave); @@ -1325,23 +1380,24 @@ Licensed under the MIT license. if (axis.direction == "x") { s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min)); m = Math.min(t(axis.max), t(axis.min)); - } - else { + } else { s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min)); s = -s; m = Math.max(t(axis.max), t(axis.min)); } // data point to canvas coordinate - if (t == identity) // slight optimization + if (t == identity) { // slight optimization axis.p2c = function (p) { return (p - m) * s; }; - else + } else { axis.p2c = function (p) { return (t(p) - m) * s; }; + } // canvas coordinate to data point - if (!it) + if (!it) { axis.c2p = function (c) { return m + c / s; }; - else + } else { axis.c2p = function (c) { return it(m + c / s); }; + } } function measureTickLabels(axis) { @@ -1359,8 +1415,9 @@ Licensed under the MIT license. var t = ticks[i]; - if (!t.label) + if (!t.label) { continue; + } var info = surface.getTextInfo(layer, t.label, font, null, maxWidth); @@ -1392,8 +1449,9 @@ Licensed under the MIT license. var samePosition = $.grep(all, function (a) { return a && a.options.position == pos && a.reserveSpace; }); - if ($.inArray(axis, samePosition) == samePosition.length - 1) + if ($.inArray(axis, samePosition) == samePosition.length - 1) { axisMargin = 0; // outermost + } // Determine whether the axis is the first (innermost) on its side @@ -1402,14 +1460,16 @@ Licensed under the MIT license. // determine tick length - if we're innermost, we can use "full" if (tickLength == null) { - if (innermost) + if (innermost) { tickLength = "full"; - else + } else { tickLength = 5; + } } - if (!isNaN(+tickLength)) + if (!isNaN(+tickLength)) { padding += +tickLength; + } // compute box if (axis.direction == "x") { @@ -1418,20 +1478,17 @@ Licensed under the MIT license. if (pos == "bottom") { plotOffset.bottom += lh + axisMargin; axis.box = { top: surface.height - plotOffset.bottom, height: lh }; - } - else { + } else { axis.box = { top: plotOffset.top + axisMargin, height: lh }; plotOffset.top += lh + axisMargin; } - } - else { + } else { lw += padding; if (pos == "left") { axis.box = { left: plotOffset.left + axisMargin, width: lw }; plotOffset.left += lw + axisMargin; - } - else { + } else { plotOffset.right += lw + axisMargin; axis.box = { left: surface.width - plotOffset.right, width: lw }; } @@ -1450,8 +1507,7 @@ Licensed under the MIT license. if (axis.direction == "x") { axis.box.left = plotOffset.left - axis.labelWidth / 2; axis.box.width = surface.width - plotOffset.left - plotOffset.right + axis.labelWidth; - } - else { + } else { axis.box.top = plotOffset.top - axis.labelHeight / 2; axis.box.height = surface.height - plotOffset.bottom - plotOffset.top + axis.labelHeight; } @@ -1469,8 +1525,9 @@ Licensed under the MIT license. // customize) if (minMargin == null) { minMargin = 0; - for (i = 0; i < series.length; ++i) + for (i = 0; i < series.length; ++i) { minMargin = Math.max(minMargin, 2 * (series[i].points.radius + series[i].points.lineWidth/2)); + } } margins.x = margins.y = Math.ceil(minMargin); @@ -1480,8 +1537,9 @@ Licensed under the MIT license. // jump as much around with replots $.each(allAxes(), function (_, axis) { var dir = axis.direction; - if (axis.reserveSpace) + if (axis.reserveSpace) { margins[dir] = Math.ceil(Math.max(margins[dir], (dir == "x" ? axis.labelWidth : axis.labelHeight) / 2)); + } }); plotOffset.left = Math.max(margins.x, plotOffset.left); @@ -1507,8 +1565,7 @@ Licensed under the MIT license. for (var a in plotOffset) { if(typeof(options.grid.borderWidth) == "object") { plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0; - } - else { + } else { plotOffset[a] += showGrid ? options.grid.borderWidth : 0; } } @@ -1516,8 +1573,9 @@ Licensed under the MIT license. // init axes $.each(axes, function (_, axis) { axis.show = axis.options.show; - if (axis.show == null) + if (axis.show == null) { axis.show = axis.used; // by default an axis is visible if it's got data + } axis.reserveSpace = axis.show || axis.options.reserveSpace; @@ -1540,8 +1598,9 @@ Licensed under the MIT license. // with all dimensions calculated, we can compute the // axis bounding boxes, start from the outside // (reverse order) - for (i = allocatedAxes.length - 1; i >= 0; --i) + for (i = allocatedAxes.length - 1; i >= 0; --i) { allocateAxisBoxFirstPhase(allocatedAxes[i]); + } // make sure we've got enough space for things that // might stick out @@ -1577,14 +1636,15 @@ Licensed under the MIT license. // degenerate case var widen = max == 0 ? 1 : 0.01; - if (opts.min == null) + if (opts.min == null) { min -= widen; + } // always widen max if we couldn't widen min to ensure we // don't fall into min == max which doesn't work - if (opts.max == null || opts.min != null) + if (opts.max == null || opts.min != null) { max += widen; - } - else { + } + } else { // consider autoscaling var margin = opts.autoscaleMargin; if (margin != null) { @@ -1592,13 +1652,15 @@ Licensed under the MIT license. min -= delta * margin; // make sure we don't go below zero if all values // are positive - if (min < 0 && axis.datamin != null && axis.datamin >= 0) + if (min < 0 && axis.datamin != null && axis.datamin >= 0) { min = 0; + } } if (opts.max == null) { max += delta * margin; - if (max > 0 && axis.datamax != null && axis.datamax <= 0) + if (max > 0 && axis.datamax != null && axis.datamax <= 0) { max = 0; + } } } } @@ -1611,12 +1673,13 @@ Licensed under the MIT license. // estimate number of ticks var noTicks; - if (typeof opts.ticks == "number" && opts.ticks > 0) + if (typeof opts.ticks == "number" && opts.ticks > 0) { noTicks = opts.ticks; - else + } else { // heuristic based on the model a*sqrt(x) fitted to // some data points that seemed reasonable noTicks = 0.3 * Math.sqrt(axis.direction == "x" ? surface.width : surface.height); + } var delta = (axis.max - axis.min) / noTicks, dec = -Math.floor(Math.log(delta) / Math.LN10), @@ -1704,8 +1767,9 @@ Licensed under the MIT license. }; } - if ($.isFunction(opts.tickFormatter)) + if ($.isFunction(opts.tickFormatter)) { axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); }; + } if (opts.alignTicksWithAxis != null) { var otherAxis = (axis.direction == "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1]; @@ -1713,10 +1777,12 @@ Licensed under the MIT license. // consider snapping min/max to outermost nice ticks var niceTicks = axis.tickGenerator(axis); if (niceTicks.length > 0) { - if (opts.min == null) + if (opts.min == null) { axis.min = Math.min(axis.min, niceTicks[0]); - if (opts.max == null && niceTicks.length > 1) + } + if (opts.max == null && niceTicks.length > 1) { axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]); + } } axis.tickGenerator = function (axis) { @@ -1739,8 +1805,9 @@ Licensed under the MIT license. // only proceed if the tick interval rounded // with an extra decimal doesn't give us a // zero at end - if (!(ts.length > 1 && /\..*0$/.test((ts[1] - ts[0]).toFixed(extraDec)))) + if (!(ts.length > 1 && /\..*0$/.test((ts[1] - ts[0]).toFixed(extraDec)))) { axis.tickDecimals = extraDec; + } } } } @@ -1748,14 +1815,15 @@ Licensed under the MIT license. function setTicks(axis) { var oticks = axis.options.ticks, ticks = []; - if (oticks == null || (typeof oticks == "number" && oticks > 0)) + if (oticks == null || (typeof oticks == "number" && oticks > 0)) { ticks = axis.tickGenerator(axis); - else if (oticks) { - if ($.isFunction(oticks)) + } else if (oticks) { + if ($.isFunction(oticks)) { // generate the ticks ticks = oticks(axis); - else + } else { ticks = oticks; + } } // clean up/labelify the supplied ticks, copy them over @@ -1766,25 +1834,30 @@ Licensed under the MIT license. var t = ticks[i]; if (typeof t == "object") { v = +t[0]; - if (t.length > 1) + if (t.length > 1) { label = t[1]; - } - else + } + } else { v = +t; - if (label == null) + } + if (label == null) { label = axis.tickFormatter(v, axis); - if (!isNaN(v)) + } + if (!isNaN(v)) { axis.ticks.push({ v: v, label: label }); + } } } function snapRangeToTicks(axis, ticks) { if (axis.options.autoscaleMargin && ticks.length > 0) { // snap to ticks - if (axis.options.min == null) + if (axis.options.min == null) { axis.min = Math.min(axis.min, ticks[0].v); - if (axis.options.max == null && ticks.length > 1) + } + if (axis.options.max == null && ticks.length > 1) { axis.max = Math.max(axis.max, ticks[ticks.length - 1].v); + } } } @@ -1797,8 +1870,9 @@ Licensed under the MIT license. var grid = options.grid; // draw background, if any - if (grid.show && grid.backgroundColor) + if (grid.show && grid.backgroundColor) { drawBackground(); + } if (grid.show && !grid.aboveData) { drawGrid(); @@ -1830,8 +1904,9 @@ Licensed under the MIT license. axis = axes[i]; 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; @@ -1893,27 +1968,33 @@ Licensed under the MIT license. yrange = extractRange(m, "y"); // fill in missing - if (xrange.from == null) + if (xrange.from == null) { xrange.from = xrange.axis.min; - if (xrange.to == null) + } + if (xrange.to == null) { xrange.to = xrange.axis.max; - if (yrange.from == null) + } + if (yrange.from == null) { yrange.from = yrange.axis.min; - if (yrange.to == null) + } + if (yrange.to == null) { yrange.to = yrange.axis.max; + } // clip if (xrange.to < xrange.axis.min || xrange.from > xrange.axis.max || - yrange.to < yrange.axis.min || yrange.from > yrange.axis.max) + yrange.to < yrange.axis.min || yrange.from > yrange.axis.max) { continue; + } xrange.from = Math.max(xrange.from, xrange.axis.min); xrange.to = Math.min(xrange.to, xrange.axis.max); yrange.from = Math.max(yrange.from, yrange.axis.min); yrange.to = Math.min(yrange.to, yrange.axis.max); - if (xrange.from == xrange.to && yrange.from == yrange.to) + if (xrange.from == xrange.to && yrange.from == yrange.to) { continue; + } // then draw xrange.from = xrange.axis.p2c(xrange.from); @@ -1929,8 +2010,7 @@ Licensed under the MIT license. ctx.moveTo(xrange.from, yrange.from); ctx.lineTo(xrange.to, yrange.to); ctx.stroke(); - } - else { + } else { // fill area ctx.fillStyle = m.color || options.grid.markingsColor; ctx.fillRect(xrange.from, yrange.to, @@ -1947,25 +2027,27 @@ Licensed under the MIT license. for (var j = 0; j < axes.length; ++j) { var axis = axes[j], box = axis.box, t = axis.tickLength, x, y, xoff, yoff; - if (!axis.show || axis.ticks.length == 0) + if (!axis.show || axis.ticks.length == 0) { continue; + } ctx.lineWidth = 1; // find the edges if (axis.direction == "x") { x = 0; - if (t == "full") + if (t == "full") { y = (axis.position == "top" ? 0 : plotHeight); - else + } else { y = box.top - plotOffset.top + (axis.position == "top" ? box.height : 0); - } - else { + } + } else { y = 0; - if (t == "full") + if (t == "full") { x = (axis.position == "left" ? 0 : plotWidth); - else + } else { x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0); + } } // draw tick bar @@ -1973,10 +2055,11 @@ Licensed under the MIT license. ctx.strokeStyle = axis.options.color; ctx.beginPath(); xoff = yoff = 0; - if (axis.direction == "x") + if (axis.direction == "x") { xoff = plotWidth + 1; - else + } else { yoff = plotHeight + 1; + } if (ctx.lineWidth == 1) { if (axis.direction == "x") { @@ -2005,29 +2088,32 @@ Licensed under the MIT license. // skip those lying on the axes if we got a border || (t == "full" && ((typeof bw == "object" && bw[axis.position] > 0) || bw > 0) - && (v == axis.min || v == axis.max))) + && (v == axis.min || v == axis.max))) { continue; + } if (axis.direction == "x") { x = axis.p2c(v); yoff = t == "full" ? -plotHeight : t; - if (axis.position == "top") + if (axis.position == "top") { yoff = -yoff; - } - else { + } + } else { y = axis.p2c(v); xoff = t == "full" ? -plotWidth : t; - if (axis.position == "left") + if (axis.position == "left") { xoff = -xoff; + } } if (ctx.lineWidth == 1) { - if (axis.direction == "x") + if (axis.direction == "x") { x = Math.floor(x) + 0.5; - else + } else { y = Math.floor(y) + 0.5; + } } ctx.moveTo(x, y); @@ -2086,8 +2172,7 @@ Licensed under the MIT license. ctx.lineTo(0- bw.left/2, 0); ctx.stroke(); } - } - else { + } else { ctx.lineWidth = bw; ctx.strokeStyle = options.grid.borderColor; ctx.strokeRect(-bw/2, -bw/2, plotWidth + bw, plotHeight + bw); @@ -2100,8 +2185,9 @@ Licensed under the MIT license. function drawAxisLabels() { $.each(allAxes(), function (_, axis) { - if (!axis.show || axis.ticks.length == 0) + if (!axis.show || axis.ticks.length == 0) { return; + } var box = axis.box, legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis", @@ -2114,8 +2200,9 @@ Licensed under the MIT license. for (var i = 0; i < axis.ticks.length; ++i) { tick = axis.ticks[i]; - if (!tick.label || tick.v < axis.min || tick.v > axis.max) + if (!tick.label || tick.v < axis.min || tick.v > axis.max) { continue; + } if (axis.direction == "x") { halign = "center"; @@ -2143,12 +2230,15 @@ Licensed under the MIT license. } function drawSeries(series) { - if (series.lines.show) + if (series.lines.show) { drawSeriesLines(series); - if (series.bars.show) + } + if (series.bars.show) { drawSeriesBars(series); - if (series.points.show) + } + if (series.points.show) { drawSeriesPoints(series); + } } function drawSeriesLines(series) { @@ -2162,68 +2252,74 @@ Licensed under the MIT license. var x1 = points[i - ps], y1 = points[i - ps + 1], x2 = points[i], y2 = points[i + 1]; - if (x1 == null || x2 == null) + if (x1 == null || x2 == null) { continue; + } // clip with ymin if (y1 <= y2 && y1 < axisy.min) { - if (y2 < axisy.min) + if (y2 < axisy.min) { continue; // line segment is outside + } // compute new intersection point x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.min; - } - else if (y2 <= y1 && y2 < axisy.min) { - if (y1 < axisy.min) + } else if (y2 <= y1 && y2 < axisy.min) { + if (y1 < axisy.min) { continue; + } x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.min; } // clip with ymax if (y1 >= y2 && y1 > axisy.max) { - if (y2 > axisy.max) + if (y2 > axisy.max) { continue; + } x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.max; - } - else if (y2 >= y1 && y2 > axisy.max) { - if (y1 > axisy.max) + } else if (y2 >= y1 && y2 > axisy.max) { + if (y1 > axisy.max) { continue; + } x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.max; } // clip with xmin if (x1 <= x2 && x1 < axisx.min) { - if (x2 < axisx.min) + if (x2 < axisx.min) { continue; + } y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.min; - } - else if (x2 <= x1 && x2 < axisx.min) { - if (x1 < axisx.min) + } else if (x2 <= x1 && x2 < axisx.min) { + if (x1 < axisx.min) { continue; + } y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.min; } // clip with xmax if (x1 >= x2 && x1 > axisx.max) { - if (x2 > axisx.max) + if (x2 > axisx.max) { continue; + } y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.max; - } - else if (x2 >= x1 && x2 > axisx.max) { - if (x1 > axisx.max) + } else if (x2 >= x1 && x2 > axisx.max) { + if (x1 > axisx.max) { continue; + } y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.max; } - if (x1 != prevx || y1 != prevy) + if (x1 != prevx || y1 != prevy) { ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset); + } prevx = x2; prevy = y2; @@ -2243,8 +2339,9 @@ Licensed under the MIT license. // direction to sketch out top, then once we hit the // end we go backwards to sketch the bottom while (true) { - if (ps > 0 && i > points.length + ps) + if (ps > 0 && i > points.length + ps) { break; + } i += ps; // ps is negative if going backwards @@ -2272,35 +2369,40 @@ Licensed under the MIT license. } } - if (x1 == null || x2 == null) + if (x1 == null || x2 == null) { continue; + } // clip x values // clip with xmin if (x1 <= x2 && x1 < axisx.min) { - if (x2 < axisx.min) + if (x2 < axisx.min) { continue; + } y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.min; } else if (x2 <= x1 && x2 < axisx.min) { - if (x1 < axisx.min) + if (x1 < axisx.min) { continue; + } y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.min; } // clip with xmax if (x1 >= x2 && x1 > axisx.max) { - if (x2 > axisx.max) + if (x2 > axisx.max) { continue; + } y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x1 = axisx.max; } else if (x2 >= x1 && x2 > axisx.max) { - if (x1 > axisx.max) + if (x1 > axisx.max) { continue; + } y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; x2 = axisx.max; } @@ -2317,8 +2419,7 @@ Licensed under the MIT license. ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.max)); continue; - } - else if (y1 <= axisy.min && y2 <= axisy.min) { + } else if (y1 <= axisy.min && y2 <= axisy.min) { ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.min)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min)); continue; @@ -2337,8 +2438,7 @@ Licensed under the MIT license. if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.min; - } - else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) { + } else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) { x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.min; } @@ -2347,8 +2447,7 @@ Licensed under the MIT license. if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) { x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y1 = axisy.max; - } - else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) { + } else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) { x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; y2 = axisy.max; } @@ -2400,8 +2499,9 @@ Licensed under the MIT license. plotLineArea(series.datapoints, series.xaxis, series.yaxis); } - if (lw > 0) + if (lw > 0) { plotLine(series.datapoints, 0, 0, series.xaxis, series.yaxis); + } ctx.restore(); } @@ -2411,16 +2511,18 @@ Licensed under the MIT license. for (var i = 0; i < points.length; i += ps) { var x = points[i], y = points[i + 1]; - if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) + if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) { continue; + } ctx.beginPath(); x = axisx.p2c(x); y = axisy.p2c(y) + offset; - if (symbol == "circle") + if (symbol == "circle") { ctx.arc(x, y, radius, 0, shadow ? Math.PI : Math.PI * 2, false); - else + } else { symbol(ctx, x, y, radius, shadow); + } ctx.closePath(); if (fillStyle) { @@ -2444,8 +2546,9 @@ Licensed under the MIT license. // Doing the conditional here allows the shadow setting to still be // optional even with a lineWidth of 0. - if( lw == 0 ) + if( lw == 0 ) { lw = 0.0001; + } if (lw > 0 && sw > 0) { // draw shadow in two steps @@ -2492,8 +2595,7 @@ Licensed under the MIT license. drawLeft = true; drawRight = false; } - } - else { + } else { drawLeft = drawRight = drawTop = true; drawBottom = false; left = x + barLeft; @@ -2513,8 +2615,9 @@ Licensed under the MIT license. // clip if (right < axisx.min || left > axisx.max || - top < axisy.min || bottom > axisy.max) + top < axisy.min || bottom > axisy.max) { return; + } if (left < axisx.min) { left = axisx.min; @@ -2558,22 +2661,26 @@ Licensed under the MIT license. // FIXME: inline moveTo is buggy with excanvas c.moveTo(left, bottom + offset); - if (drawLeft) + if (drawLeft) { c.lineTo(left, top + offset); - else + } else { c.moveTo(left, top + offset); - if (drawTop) + } + if (drawTop) { c.lineTo(right, top + offset); - else + } else { c.moveTo(right, top + offset); - if (drawRight) + } + if (drawRight) { c.lineTo(right, bottom + offset); - else + } else { c.moveTo(right, bottom + offset); - if (drawBottom) + } + if (drawBottom) { c.lineTo(left, bottom + offset); - else + } else { c.moveTo(left, bottom + offset); + } c.stroke(); } } @@ -2583,8 +2690,9 @@ Licensed under the MIT license. var points = datapoints.points, ps = datapoints.pointsize; for (var i = 0; i < points.length; i += ps) { - if (points[i] == null) + if (points[i] == null) { continue; + } drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth); } } @@ -2619,11 +2727,13 @@ Licensed under the MIT license. function getFillStyle(filloptions, seriesColor, bottom, top) { var fill = filloptions.fill; - if (!fill) + if (!fill) { return null; + } - if (filloptions.fillColor) + if (filloptions.fillColor) { return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor); + } var c = $.color.parse(seriesColor); c.a = typeof fill == "number" ? fill : 0.4; @@ -2635,8 +2745,9 @@ Licensed under the MIT license. placeholder.find(".legend").remove(); - if (!options.legend.show) + if (!options.legend.show) { return; + } var fragments = [], entries = [], rowStarted = false, lf = options.legend.labelFormatter, s, label; @@ -2680,8 +2791,9 @@ Licensed under the MIT license. var entry = entries[i]; if (i % options.legend.noColumns == 0) { - if (rowStarted) + if (rowStarted) { fragments.push(""); + } fragments.push(""); rowStarted = true; } @@ -2692,29 +2804,34 @@ Licensed under the MIT license. ); } - if (rowStarted) + if (rowStarted) { fragments.push(""); + } - if (fragments.length == 0) + if (fragments.length == 0) { return; + } var table = "" + fragments.join("") + "
"; - if (options.legend.container != null) + if (options.legend.container != null) { $(options.legend.container).html(table); - else { + } else { var pos = "", p = options.legend.position, m = options.legend.margin; - if (m[0] == null) + if (m[0] == null) { m = [m, m]; - if (p.charAt(0) == "n") + } + if (p.charAt(0) == "n") { pos += "top:" + (m[1] + plotOffset.top) + "px;"; - else if (p.charAt(0) == "s") + } else if (p.charAt(0) == "s") { pos += "bottom:" + (m[1] + plotOffset.bottom) + "px;"; - if (p.charAt(1) == "e") + } + if (p.charAt(1) == "e") { pos += "right:" + (m[0] + plotOffset.right) + "px;"; - else if (p.charAt(1) == "w") + } else if (p.charAt(1) == "w") { pos += "left:" + (m[0] + plotOffset.left) + "px;"; + } var legend = $("
" + table.replace("style='", "style='position:absolute;" + pos +";") + "
").appendTo(placeholder); if (options.legend.backgroundOpacity != 0.0) { // put in the transparent background @@ -2723,10 +2840,11 @@ Licensed under the MIT license. var c = options.legend.backgroundColor; if (c == null) { c = options.grid.backgroundColor; - if (c && typeof c == "string") + if (c && typeof c == "string") { c = $.color.parse(c); - else + } else { c = $.color.extract(legend, "background-color"); + } c.a = 1; c = c.toString(); } @@ -2749,8 +2867,9 @@ Licensed under the MIT license. item = null, foundPoint = false, i, j, ps; for (i = series.length - 1; i >= 0; --i) { - if (!seriesFilter(series[i])) + if (!seriesFilter(series[i])) { continue; + } var s = series[i], axisx = s.xaxis, @@ -2764,22 +2883,26 @@ Licensed under the MIT license. ps = s.datapoints.pointsize; // with inverse transforms, we can't use the maxx/maxy // optimization, sadly - if (axisx.options.inverseTransform) + if (axisx.options.inverseTransform) { maxx = Number.MAX_VALUE; - if (axisy.options.inverseTransform) + } + if (axisy.options.inverseTransform) { maxy = Number.MAX_VALUE; + } if (s.lines.show || s.points.show) { for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1]; - if (x == null) + if (x == null) { continue; + } // For points and lines, the cursor must be within a // certain distance to the data point if (x - mx > maxx || x - mx < -maxx || - y - my > maxy || y - my < -maxy) + y - my > maxy || y - my < -maxy) { continue; + } // We have to calculate distances in pixels, not in // data units, because the scales of the axes may be different @@ -2802,16 +2925,18 @@ Licensed under the MIT license. for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1], b = points[j + 2]; - if (x == null) + if (x == null) { continue; + } // for a bar graph, the cursor must be inside the bar if (series[i].bars.horizontal ? (mx <= Math.max(b, x) && mx >= Math.min(b, x) && my >= y + barLeft && my <= y + barRight) : (mx >= x + barLeft && mx <= x + barRight && - my >= Math.min(b, y) && my <= Math.max(b, y))) + my >= Math.min(b, y) && my <= Math.max(b, y))) { item = [i, j / ps]; + } } } } @@ -2831,15 +2956,17 @@ Licensed under the MIT license. } function onMouseMove(e) { - if (options.grid.hoverable) + if (options.grid.hoverable) { triggerClickHoverEvent("plothover", e, function (s) { return s["hoverable"] != false; }); + } } function onMouseLeave(e) { - if (options.grid.hoverable) + if (options.grid.hoverable) { triggerClickHoverEvent("plothover", e, function (s) { return false; }); + } } function onClick(e) { @@ -2873,12 +3000,14 @@ Licensed under the MIT license. if (h.auto == eventname && !(item && h.series == item.series && h.point[0] == item.datapoint[0] && - h.point[1] == item.datapoint[1])) + h.point[1] == item.datapoint[1])) { unhighlight(h.series, h.point); + } } - if (item) + if (item) { highlight(item.series, item.datapoint, eventname); + } } placeholder.trigger(eventname, [ pos, item ]); @@ -2891,8 +3020,9 @@ Licensed under the MIT license. return; } - if (!redrawTimeout) + if (!redrawTimeout) { redrawTimeout = setTimeout(drawOverlay, t); + } } function drawOverlay() { @@ -2907,10 +3037,11 @@ Licensed under the MIT license. for (i = 0; i < highlights.length; ++i) { hi = highlights[i]; - if (hi.series.bars.show) + if (hi.series.bars.show) { drawBarHighlight(hi.series, hi.point); - else + } else { drawPointHighlight(hi.series, hi.point); + } } octx.restore(); @@ -2918,8 +3049,9 @@ Licensed under the MIT license. } function highlight(s, point, auto) { - if (typeof s == "number") + if (typeof s == "number") { s = series[s]; + } if (typeof point == "number") { var ps = s.datapoints.pointsize; @@ -2931,9 +3063,9 @@ Licensed under the MIT license. highlights.push({ series: s, point: point, auto: auto }); triggerRedrawOverlay(); - } - else if (!auto) + } else if (!auto) { highlights[i].auto = false; + } } function unhighlight(s, point) { @@ -2943,8 +3075,9 @@ Licensed under the MIT license. return; } - if (typeof s == "number") + if (typeof s == "number") { s = series[s]; + } if (typeof point == "number") { var ps = s.datapoints.pointsize; @@ -2963,8 +3096,9 @@ Licensed under the MIT license. for (var i = 0; i < highlights.length; ++i) { var h = highlights[i]; if (h.series == s && h.point[0] == p[0] - && h.point[1] == p[1]) + && h.point[1] == p[1]) { return i; + } } return -1; } @@ -2974,8 +3108,9 @@ Licensed under the MIT license. axisx = series.xaxis, axisy = series.yaxis, highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale("a", 0.5).toString(); - if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) + if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) { return; + } var pointRadius = series.points.radius + series.points.lineWidth / 2; octx.lineWidth = pointRadius; @@ -2985,10 +3120,11 @@ Licensed under the MIT license. y = axisy.p2c(y); octx.beginPath(); - if (series.points.symbol == "circle") + if (series.points.symbol == "circle") { octx.arc(x, y, radius, 0, 2 * Math.PI, false); - else + } else { series.points.symbol(octx, x, y, radius, false); + } octx.closePath(); octx.stroke(); } @@ -3006,9 +3142,9 @@ Licensed under the MIT license. } function getColorOrGradient(spec, bottom, top, defaultColor) { - if (typeof spec == "string") + if (typeof spec == "string") { return spec; - else { + } else { // assume this is a gradient spec; IE currently only // supports a simple vertical gradient properly, so that's // what we support too @@ -3018,10 +3154,12 @@ Licensed under the MIT license. var c = spec.colors[i]; if (typeof c != "string") { var co = $.color.parse(defaultColor); - if (c.brightness != null) + if (c.brightness != null) { co = co.scale("rgb", c.brightness); - if (c.opacity != null) + } + if (c.opacity != null) { co.a *= c.opacity; + } c = co.toString(); } gradient.addColorStop(i / (l - 1), c); diff --git a/jquery.flot.navigate.js b/jquery.flot.navigate.js index aca52ed..204dded 100644 --- a/jquery.flot.navigate.js +++ b/jquery.flot.navigate.js @@ -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); diff --git a/jquery.flot.pie.js b/jquery.flot.pie.js index 68071de..981fe89 100644 --- a/jquery.flot.pie.js +++ b/jquery.flot.pie.js @@ -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; } diff --git a/jquery.flot.resize.js b/jquery.flot.resize.js index d751cf4..7817787 100644 --- a/jquery.flot.resize.js +++ b/jquery.flot.resize.js @@ -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(); diff --git a/jquery.flot.selection.js b/jquery.flot.selection.js index 09e2f08..c1346a2 100644 --- a/jquery.flot.selection.js +++ b/jquery.flot.selection.js @@ -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); + } }); } diff --git a/jquery.flot.stack.js b/jquery.flot.stack.js index 235d532..795eccc 100644 --- a/jquery.flot.stack.js +++ b/jquery.flot.stack.js @@ -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]; } } diff --git a/jquery.flot.symbol.js b/jquery.flot.symbol.js index f8523ab..acd9305 100644 --- a/jquery.flot.symbol.js +++ b/jquery.flot.symbol.js @@ -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) { diff --git a/jquery.flot.threshold.js b/jquery.flot.threshold.js index f0de51c..1798b9c 100644 --- a/jquery.flot.threshold.js +++ b/jquery.flot.threshold.js @@ -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) {