diff --git a/jquery.flot.canvas.js b/jquery.flot.canvas.js index 0f8c711..b7b8161 100644 --- a/jquery.flot.canvas.js +++ b/jquery.flot.canvas.js @@ -31,9 +31,8 @@ browser, but needs to redraw with canvas text when exporting as an image. var options = { canvas: true - }; - - var render, getTextInfo, addText; + }, + render, getTextInfo, addText; function init(plot, classes) { diff --git a/jquery.flot.errorbars.js b/jquery.flot.errorbars.js index 282d083..55f3274 100644 --- a/jquery.flot.errorbars.js +++ b/jquery.flot.errorbars.js @@ -82,9 +82,8 @@ shadowSize and lineWidth are derived as well from the points series. var format = [ { x: true, number: true, required: true }, { y: true, number: true, required: true } - ]; - - var errors = series.points.errorbars; + ], + errors = series.points.errorbars; // error bars - first X then Y if (errors === "x" || errors === "xy") { // lower / upper error @@ -95,6 +94,7 @@ shadowSize and lineWidth are derived as well from the points series. format.push({ x: true, number: true, required: true }); } } + if (errors === "y" || errors === "xy") { // lower / upper error if (series.points.yerr.asymmetric) { @@ -109,10 +109,10 @@ shadowSize and lineWidth are derived as well from the points series. function parseErrors(series, i) { - var points = series.datapoints.points; + var points = series.datapoints.points, - // read errors from points array - var exl = null, + // read errors from points array + exl = null, exu = null, eyl = null, eyu = null, @@ -184,7 +184,7 @@ shadowSize and lineWidth are derived as well from the points series. err = [s.points.xerr, s.points.yerr], invertX = false, invertY = false, - tmp; + tmp, errRanges, minmax, e, x, y, upper, lower, drawLower, drawUpper; //sanity check, in case some inverted axis hack is applied to flot @@ -204,23 +204,23 @@ shadowSize and lineWidth are derived as well from the points series. for (var i = 0; i < s.datapoints.points.length; i += ps) { - var errRanges = parseErrors(s, i); + errRanges = parseErrors(s, i); //cycle xerr & yerr - for (var e = 0; e < err.length; e++){ + for (e = 0; e < err.length; e++){ - var minmax = [ax[e].min, ax[e].max]; + minmax = [ax[e].min, ax[e].max]; //draw this error? if (errRanges[e * err.length]){ //data coordinates - var x = points[i], - y = points[i + 1]; + x = points[i]; + y = points[i + 1]; //errorbar ranges - var upper = [x, y][e] + errRanges[e * err.length + 1], - lower = [x, y][e] - errRanges[e * err.length]; + upper = [x, y][e] + errRanges[e * err.length + 1]; + lower = [x, y][e] - errRanges[e * err.length]; //points outside of the canvas if (err[e].err === "x") { @@ -235,8 +235,8 @@ shadowSize and lineWidth are derived as well from the points series. } // prevent errorbars getting out of the canvas - var drawUpper = true, - drawLower = true; + drawUpper = true, + drawLower = true; if (upper > minmax[1]) { drawUpper = false; diff --git a/jquery.flot.image.js b/jquery.flot.image.js index 3f46deb..b322266 100644 --- a/jquery.flot.image.js +++ b/jquery.flot.image.js @@ -66,9 +66,9 @@ Google Maps). $.plot.image = {}; $.plot.image.loadDataImages = function(series, options, callback) { - var urls = [], points = []; - - var defaultShow = options.series.images.show; + var urls = [], + points = [], + defaultShow = options.series.images.show; $.each(series, function(i, s) { if (!(defaultShow || s.images.show)) { diff --git a/jquery.flot.js b/jquery.flot.js index 1c56934..72bb07e 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -48,17 +48,17 @@ Licensed under the MIT license. this.element = element; - var context = this.context = element.getContext("2d"); + var context = this.context = element.getContext("2d"), - // Determine the screen's ratio of physical to device-independent - // pixels. This is the ratio between the canvas width that the browser - // advertises and the number of pixels actually present in that space. + // Determine the screen's ratio of physical to device-independent + // pixels. This is the ratio between the canvas width that the browser + // advertises and the number of pixels actually present in that space. - // The iPhone 4, for example, has a device-independent width of 320px, - // but its screen is actually 640px wide. It therefore has a pixel - // ratio of 2, while most normal devices have a ratio of 1. + // The iPhone 4, for example, has a device-independent width of 320px, + // but its screen is actually 640px wide. It therefore has a pixel + // ratio of 2, while most normal devices have a ratio of 1. - var devicePixelRatio = window.devicePixelRatio || 1, + devicePixelRatio = window.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || @@ -370,22 +370,23 @@ Licensed under the MIT license. var cx = textWidth / 2, cy = textHeight / 2, - transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px"; - - // Transforms alter the div's appearance without changing - // its origin. This will make it difficult to position it - // later, since we'll be positioning the new bounding box - // with respect to the old origin. We can work around this - // by adding a translation to align the new bounding box's - // top-left corner with the origin, using the same matrix. - - // Rather than examining all four points, we can use the - // angle to figure out in advance which two points are in - // the top-left quadrant; we can then use the x-coordinate - // of the first (left-most) point and the y-coordinate of - // the second (top-most) point as the bounding box corner. - - var x, y; + transformOrigin = Math.floor(cx) + "px " + Math.floor(cy) + "px", + + // Transforms alter the div's appearance without changing + // its origin. This will make it difficult to position it + // later, since we'll be positioning the new bounding box + // with respect to the old origin. We can work around this + // by adding a translation to align the new bounding box's + // top-left corner with the origin, using the same matrix. + + // Rather than examining all four points, we can use the + // angle to figure out in advance which two points are in + // the top-left quadrant; we can then use the x-coordinate + // of the first (left-most) point and the y-coordinate of + // the second (top-most) point as the bounding box corner. + + x, y; + if (angle < 90) { x = Math.floor(cx * cos + cy * sin - cx); y = Math.floor(cx * sin + cy * cos - cy); @@ -1902,10 +1903,12 @@ Licensed under the MIT license. } function setupTickGeneration(axis) { - var opts = axis.options; + var opts = axis.options, + + // estimate number of ticks + + noTicks; - // estimate number of ticks - var noTicks; if (isNumeric(opts.ticks) && opts.ticks > 0) { noTicks = opts.ticks; } else { @@ -1982,15 +1985,16 @@ Licensed under the MIT license. axis.tickFormatter = function(value, axis) { - var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1; - var formatted = "" + Math.round(value * factor) / factor; + var factor = axis.tickDecimals ? Math.pow(10, axis.tickDecimals) : 1, + formatted = "" + Math.round(value * factor) / factor; // If tickDecimals was specified, ensure that we have exactly that // much precision; otherwise default to the value's own precision. if (axis.tickDecimals != null) { - var decimal = formatted.indexOf("."); - var precision = decimal === -1 ? 0 : formatted.length - decimal - 1; + var decimal = formatted.indexOf("."), + precision = decimal === -1 ? 0 : formatted.length - decimal - 1; + if (precision < axis.tickDecimals) { return (precision ? formatted : formatted + ".") + ("" + factor).substr(1, axis.tickDecimals - precision); } @@ -2063,8 +2067,9 @@ Licensed under the MIT license. var i, v; axis.ticks = []; for (i = 0; i < ticks.length; ++i) { - var label = null; - var t = ticks[i]; + var label = null, + t = ticks[i]; + if (typeof t === "object") { v = +t[0]; if (t.length > 1) { @@ -2184,10 +2189,10 @@ Licensed under the MIT license. surface.removeText(markingLayer); // process markings - var markingsUnderGrid = []; - var markingsAboveGrid = []; + var markingsUnderGrid = [], + markingsAboveGrid = [], + markings = options.grid.markings; - var markings = options.grid.markings; if (markings) { if ($.isFunction(markings)) { axes = plot.getAxes(); @@ -2448,9 +2453,12 @@ Licensed under the MIT license. if (m.text) { // left aligned horizontal position: - var xPos = xrange.from + plotOffset.left; - // top baselined vertical position: - var yPos = (yrange.to + plotOffset.top); + + var xPos = xrange.from + plotOffset.left, + + // top baselined vertical position: + + yPos = (yrange.to + plotOffset.top); if (!!m.textAlign) { switch (m.textAlign.toLowerCase()) { @@ -3482,8 +3490,8 @@ Licensed under the MIT license. return; } - var pointRadius; - var radius; + var pointRadius, radius; + if (series.points.show) { pointRadius = series.points.radius + series.points.lineWidth / 2; radius = 1.5 * pointRadius; @@ -3596,8 +3604,9 @@ Licensed under the MIT license. // @param {number} radius The radius of the corner of the rectangle // to be drawn. function roundRect(ctx, x, y, width, height, radius) { - var r = x + width; - var b = y + height; + var r = x + width, + b = y + height; + ctx.beginPath(); ctx.moveTo(x + radius, y); ctx.lineTo(r - radius, y); diff --git a/jquery.flot.pie.js b/jquery.flot.pie.js index 50662fd..79466ef 100644 --- a/jquery.flot.pie.js +++ b/jquery.flot.pie.js @@ -59,11 +59,11 @@ More detail and specific examples can be found in the included HTML file. // Maximum redraw attempts when fitting labels within the plot - var REDRAW_ATTEMPTS = 10; + var REDRAW_ATTEMPTS = 10, - // Factor by which to shrink the pie when fitting labels within the plot + // Factor by which to shrink the pie when fitting labels within the plot - var REDRAW_SHRINK = 0.95; + REDRAW_SHRINK = 0.95; function init(plot) { @@ -74,11 +74,11 @@ More detail and specific examples can be found in the included HTML file. centerLeft = null, centerTop = null, processed = false, - ctx = null; + ctx = null, - // interactive variables + // interactive variables - var highlights = []; + highlights = []; // add hook to determine if pie plugin in enabled, and then perform necessary operations @@ -340,11 +340,11 @@ More detail and specific examples can be found in the included HTML file. function drawShadow() { - var shadowLeft = options.series.pie.shadow.left; - var shadowTop = options.series.pie.shadow.top; - var edge = 10; - var alpha = options.series.pie.shadow.alpha; - var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; + var shadowLeft = options.series.pie.shadow.left, + shadowTop = options.series.pie.shadow.top, + edge = 10, + alpha = options.series.pie.shadow.alpha, + radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; if (radius >= canvasWidth / 2 - shadowLeft || radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop || radius <= edge) { return; // shadow would be outside canvas, so don't draw it @@ -455,8 +455,8 @@ More detail and specific examples can be found in the included HTML file. function drawLabels() { - var currentAngle = startAngle; - var radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius; + var currentAngle = startAngle, + radius = options.series.pie.label.radius > 1 ? options.series.pie.label.radius : maxRadius * options.series.pie.label.radius; for (var i = 0; i < slices.length; ++i) { if (slices[i].percent >= options.series.pie.label.threshold * 100) { @@ -489,16 +489,16 @@ More detail and specific examples can be found in the included HTML file. text = plf(text, slice); } - var halfAngle = ((startAngle + slice.angle) + startAngle) / 2; - var x = centerLeft + Math.round(Math.cos(halfAngle) * radius); - var y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt; + var halfAngle = ((startAngle + slice.angle) + startAngle) / 2, + x = centerLeft + Math.round(Math.cos(halfAngle) * radius), + y = centerTop + Math.round(Math.sin(halfAngle) * radius) * options.series.pie.tilt, + html = "" + text + ""; - var html = "" + text + ""; target.append(html); - var label = target.children("#pieLabel" + index); - var labelTop = (y - label.height() / 2); - var labelLeft = (x - label.width() / 2); + var label = target.children("#pieLabel" + index), + labelTop = (y - label.height() / 2), + labelLeft = (x - label.width() / 2); label.css("top", labelTop); label.css("left", labelLeft); @@ -656,10 +656,10 @@ More detail and specific examples can be found in the included HTML file. function triggerClickHoverEvent(eventname, e) { - var offset = plot.offset(); - var canvasX = parseInt(e.pageX - offset.left, 10); - var canvasY = parseInt(e.pageY - offset.top, 10); - var item = findNearbySlice(canvasX, canvasY); + var offset = plot.offset(), + canvasX = parseInt(e.pageX - offset.left, 10), + canvasY = parseInt(e.pageY - offset.top, 10), + item = findNearbySlice(canvasX, canvasY); if (options.grid.autoHighlight) { @@ -730,9 +730,8 @@ More detail and specific examples can be found in the included HTML file. function drawOverlay(plot, octx) { - var options = plot.getOptions(); - - var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; + var options = plot.getOptions(), + radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; octx.save(); octx.translate(centerLeft, centerTop); diff --git a/jquery.flot.selection.js b/jquery.flot.selection.js index 28d324f..c8b11dc 100644 --- a/jquery.flot.selection.js +++ b/jquery.flot.selection.js @@ -87,15 +87,15 @@ The plugin allso adds the following methods to the plot object: show: false, active: false, touch: false - }; + }, - // FIXME: The drag handling implemented here should be - // abstracted out, there's some similar code from a library in - // the navigation plugin, this should be massaged a bit to fit - // the Flot cases here better and reused. Doing this would - // make this plugin much slimmer. + // FIXME: The drag handling implemented here should be + // abstracted out, there's some similar code from a library in + // the navigation plugin, this should be massaged a bit to fit + // the Flot cases here better and reused. Doing this would + // make this plugin much slimmer. - var savedhandlers = {}, + savedhandlers = {}, mouseUpHandler = null; function onMouseMove(e) { @@ -206,9 +206,9 @@ The plugin allso adds the following methods to the plot object: function setSelectionPos(pos, e) { var o = plot.getOptions(), offset = plot.getPlaceholder().offset(), - plotOffset = plot.getPlotOffset(); + plotOffset = plot.getPlotOffset(), + coordHolder = selection.touch ? e.originalEvent.changedTouches[0] : e; - var coordHolder = selection.touch ? e.originalEvent.changedTouches[0] : e; pos.x = clamp(0, coordHolder.pageX - offset.left - plotOffset.left, plot.width()); pos.y = clamp(0, coordHolder.pageY - offset.top - plotOffset.top, plot.height()); @@ -340,23 +340,24 @@ The plugin allso adds the following methods to the plot object: plot.hooks.drawOverlay.push(function(plot, ctx) { // draw selection if (selection.show && selectionIsSane()) { - var plotOffset = plot.getPlotOffset(); - var o = plot.getOptions(); + var plotOffset = plot.getPlotOffset(), + o = plot.getOptions(), + c, x, y, w, h; ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); - var c = $.color.parse(o.selection.color); + c = $.color.parse(o.selection.color); ctx.strokeStyle = c.scale("a", 0.8).toString(); ctx.lineWidth = 1; ctx.lineJoin = o.selection.shape; ctx.fillStyle = c.scale("a", 0.4).toString(); - var x = Math.min(selection.first.x, selection.second.x) + 0.5, - y = Math.min(selection.first.y, selection.second.y) + 0.5, - w = Math.abs(selection.second.x - selection.first.x) - 1, - h = Math.abs(selection.second.y - selection.first.y) - 1; + x = Math.min(selection.first.x, selection.second.x) + 0.5; + y = Math.min(selection.first.y, selection.second.y) + 0.5; + w = Math.abs(selection.second.x - selection.first.x) - 1; + h = Math.abs(selection.second.y - selection.first.y) - 1; ctx.fillRect(x, y, w, h); ctx.strokeRect(x, y, w, h); diff --git a/jquery.flot.symbol.js b/jquery.flot.symbol.js index 19d84cc..f144bdf 100644 --- a/jquery.flot.symbol.js +++ b/jquery.flot.symbol.js @@ -19,42 +19,42 @@ The symbols are accessed as strings through the standard symbol options: // same as a circle of the given radius var handlers = { - square: function(ctx, x, y, radius) { - // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 - var size = radius * Math.sqrt(Math.PI) / 2; - ctx.rect(x - size, y - size, size + size, size + size); - }, - diamond: function(ctx, x, y, radius) { - // pi * r^2 = 2s^2 => s = r * sqrt(pi/2) - var size = radius * Math.sqrt(Math.PI / 2); - ctx.moveTo(x - size, y); - ctx.lineTo(x, y - size); - ctx.lineTo(x + size, y); - ctx.lineTo(x, y + size); - ctx.lineTo(x - size, y); - }, - triangle: function(ctx, x, y, radius, shadow) { - // pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3)) - var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)); - var height = size * Math.sin(Math.PI / 3); - ctx.moveTo(x - size / 2, y + height / 2); - ctx.lineTo(x + size / 2, y + height / 2); - if (!shadow) { - ctx.lineTo(x, y - height / 2); - ctx.lineTo(x - size / 2, y + height / 2); + square: function(ctx, x, y, radius) { + // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 + var size = radius * Math.sqrt(Math.PI) / 2; + ctx.rect(x - size, y - size, size + size, size + size); + }, + diamond: function(ctx, x, y, radius) { + // pi * r^2 = 2s^2 => s = r * sqrt(pi/2) + var size = radius * Math.sqrt(Math.PI / 2); + ctx.moveTo(x - size, y); + ctx.lineTo(x, y - size); + ctx.lineTo(x + size, y); + ctx.lineTo(x, y + size); + ctx.lineTo(x - size, y); + }, + triangle: function(ctx, x, y, radius, shadow) { + // pi * r^2 = 1/2 * s^2 * sin (pi / 3) => s = r * sqrt(2 * pi / sin(pi / 3)) + var size = radius * Math.sqrt(2 * Math.PI / Math.sin(Math.PI / 3)), + height = size * Math.sin(Math.PI / 3); + ctx.moveTo(x - size / 2, y + height / 2); + ctx.lineTo(x + size / 2, y + height / 2); + if (!shadow) { + ctx.lineTo(x, y - height / 2); + ctx.lineTo(x - size / 2, y + height / 2); + } + }, + cross: function(ctx, x, y, radius) { + // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 + var size = radius * Math.sqrt(Math.PI) / 2; + ctx.moveTo(x - size, y - size); + ctx.lineTo(x + size, y + size); + ctx.moveTo(x - size, y + size); + ctx.lineTo(x + size, y - size); } }, - cross: function(ctx, x, y, radius) { - // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2 - var size = radius * Math.sqrt(Math.PI) / 2; - ctx.moveTo(x - size, y - size); - ctx.lineTo(x + size, y + size); - ctx.moveTo(x - size, y + size); - ctx.lineTo(x + size, y - size); - } - }; + s = series.points.symbol; - var s = series.points.symbol; if (handlers[s]) { series.points.symbol = handlers[s]; } diff --git a/jquery.flot.time.js b/jquery.flot.time.js index d9b525d..0499e9d 100644 --- a/jquery.flot.time.js +++ b/jquery.flot.time.js @@ -35,15 +35,15 @@ API.txt for details. } var leftPad = function(n, pad) { - n = "" + n; - pad = "" + (pad == null ? "0" : pad); - return n.length === 1 ? pad + n : n; - }; - - var r = [], + n = "" + n; + pad = "" + (pad == null ? "0" : pad); + return n.length === 1 ? pad + n : n; + }, + r = [], escape = false, hours = d.getHours(), - isAM = hours < 12; + isAM = hours < 12, + c, hours12; if (monthNames == null) { monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; @@ -53,8 +53,6 @@ API.txt for details. dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; } - var hours12; - if (hours > 12) { hours12 = hours - 12; } else if (hours === 0) { @@ -65,7 +63,7 @@ API.txt for details. for (var i = 0; i < fmt.length; ++i) { - var c = fmt.charAt(i); + c = fmt.charAt(i); if (escape) { switch (c) { @@ -81,7 +79,7 @@ API.txt for details. case "e": c = leftPad(d.getDate(), " "); break; - case "h": // For back-compat with 0.7; remove in 1.0 + case "h": // For back-compat with 0.7; remove in 1.0 case "H": c = leftPad(hours); break; @@ -193,37 +191,43 @@ API.txt for details. // map of app. size of time units in milliseconds var timeUnitSize = { - "second": 1000, - "minute": 60 * 1000, - "hour": 60 * 60 * 1000, - "day": 24 * 60 * 60 * 1000, - "month": 30 * 24 * 60 * 60 * 1000, - "quarter": 3 * 30 * 24 * 60 * 60 * 1000, - "year": 365.2425 * 24 * 60 * 60 * 1000 - }; - - // the allowed tick sizes, after 1 year we use - // an integer algorithm - - var baseSpec = [ - [1, "second"], [2, "second"], [5, "second"], [10, "second"], - [30, "second"], - [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], - [30, "minute"], - [1, "hour"], [2, "hour"], [4, "hour"], - [8, "hour"], [12, "hour"], - [1, "day"], [2, "day"], [3, "day"], - [0.25, "month"], [0.5, "month"], [1, "month"], - [2, "month"] - ]; - - // we don't know which variant(s) we'll need yet, but generating both is - // cheap - - var specMonths = baseSpec.concat([[3, "month"], [6, "month"], - [1, "year"]]); - var specQuarters = baseSpec.concat([[1, "quarter"], [2, "quarter"], - [1, "year"]]); + "second": 1000, + "minute": 60 * 1000, + "hour": 60 * 60 * 1000, + "day": 24 * 60 * 60 * 1000, + "month": 30 * 24 * 60 * 60 * 1000, + "quarter": 3 * 30 * 24 * 60 * 60 * 1000, + "year": 365.2425 * 24 * 60 * 60 * 1000 + }, + + // the allowed tick sizes, after 1 year we use + // an integer algorithm + + baseSpec = [ + [1, "second"], [2, "second"], [5, "second"], [10, "second"], + [30, "second"], + [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], + [30, "minute"], + [1, "hour"], [2, "hour"], [4, "hour"], + [8, "hour"], [12, "hour"], + [1, "day"], [2, "day"], [3, "day"], + [0.25, "month"], [0.5, "month"], [1, "month"], + [2, "month"] + ], + + // we don't know which variant(s) we'll need yet, but generating both is + // cheap + + specMonths = baseSpec.concat([ + [3, "month"], + [6, "month"], + [1, "year"] + ]), + specQuarters = baseSpec.concat([ + [1, "quarter"], + [2, "quarter"], + [1, "year"] + ]); function init(plot) { plot.hooks.processOptions.push(function(plot) { @@ -236,12 +240,12 @@ API.txt for details. var ticks = [], d = dateGenerator(axis.min, opts), - minSize = 0; + minSize = 0, - // make quarter use a possibility if quarters are - // mentioned in either of these options + // make quarter use a possibility if quarters are + // mentioned in either of these options - var spec = (opts.tickSize && opts.tickSize[1] === + spec = (opts.tickSize && opts.tickSize[1] === "quarter") || (opts.minTickSize && opts.minTickSize[1] === "quarter") ? specQuarters : specMonths;