From 76c140a5559fe537071ddf21503ac41ccfbe4b70 Mon Sep 17 00:00:00 2001 From: NeverMin Date: Thu, 7 Sep 2017 11:39:24 +0800 Subject: [PATCH 1/2] fixed #1387 --- .../javascripts/app/lib/flot/jquery.flot.js | 326 +++++++++--------- 1 file changed, 163 insertions(+), 163 deletions(-) diff --git a/app/assets/javascripts/app/lib/flot/jquery.flot.js b/app/assets/javascripts/app/lib/flot/jquery.flot.js index aabc544e9..1777dc0f7 100755 --- a/app/assets/javascripts/app/lib/flot/jquery.flot.js +++ b/app/assets/javascripts/app/lib/flot/jquery.flot.js @@ -8,9 +8,9 @@ // for convenience /* Plugin for jQuery for working with colors. - * + * * Version 1.1. - * + * * Inspiration from jQuery color animation plugin by John Resig. * * Released under the MIT license by Ole Laursen, October 2009. @@ -27,7 +27,7 @@ * * V. 1.1: Fix error handling so e.g. parsing an empty string does * produce a color rather than just crashing. - */ + */ (function(B){B.color={};B.color.make=function(F,E,C,D){var G={};G.r=F||0;G.g=E||0;G.b=C||0;G.a=D!=null?D:1;G.add=function(J,I){for(var H=0;H=1){return"rgb("+[G.r,G.g,G.b].join(",")+")"}else{return"rgba("+[G.r,G.g,G.b,G.a].join(",")+")"}};G.normalize=function(){function H(J,K,I){return KI?I:K)}G.r=H(0,parseInt(G.r),255);G.g=H(0,parseInt(G.g),255);G.b=H(0,parseInt(G.b),255);G.a=H(0,G.a,1);return G};G.clone=function(){return B.color.make(G.r,G.b,G.g,G.a)};return G.normalize()};B.color.extract=function(D,C){var E;do{E=D.css(C).toLowerCase();if(E!=""&&E!="transparent"){break}D=D.parent()}while(!B.nodeName(D.get(0),"body"));if(E=="rgba(0, 0, 0, 0)"){E="transparent"}return B.color.parse(E)};B.color.parse=function(F){var E,C=B.color.make;if(E=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10))}if(E=/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(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10),parseFloat(E[4]))}if(E=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55)}if(E=/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(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55,parseFloat(E[4]))}if(E=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(F)){return C(parseInt(E[1],16),parseInt(E[2],16),parseInt(E[3],16))}if(E=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(F)){return C(parseInt(E[1]+E[1],16),parseInt(E[2]+E[2],16),parseInt(E[3]+E[3],16))}var D=B.trim(F).toLowerCase();if(D=="transparent"){return C(255,255,255,0)}else{E=A[D]||[0,0,0];return C(E[0],E[1],E[2])}};var A={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery); // the actual Flot code @@ -37,7 +37,7 @@ // [ series1, series2 ... ] // where series is either just the data as [ [x1, y1], [x2, y2], ... ] // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... } - + var series = [], options = { // the color theme used for graphs @@ -71,7 +71,7 @@ reserveSpace: null, // whether to reserve space even if axis isn't shown tickLength: null, // size in pixels of ticks, or "full" for whole line alignTicksWithAxis: null, // axis number or null for no sync - + // mode specific options tickDecimals: null, // no. of decimals, null means auto tickSize: null, // number or [number, "unit"] @@ -97,7 +97,7 @@ }, lines: { // we don't put in show: false so we can see - // whether lines were actively disabled + // whether lines were actively disabled lineWidth: 2, // in pixels fill: false, fillColor: null, @@ -109,7 +109,7 @@ barWidth: 1, // in units of the x axis fill: true, fillColor: null, - align: "left", // or "center" + align: "left", // or "center" horizontal: false }, shadowSize: 3 @@ -203,7 +203,7 @@ // public attributes plot.hooks = hooks; - + // initialize initPlugins(plot); parseOptions(options_); @@ -228,17 +228,17 @@ $.extend(true, options, p.options); } } - + function parseOptions(opts) { var i; - + $.extend(true, options, opts); - + if (options.xaxis.color == null) options.xaxis.color = options.grid.color; if (options.yaxis.color == null) options.yaxis.color = options.grid.color; - + if (options.xaxis.tickColor == null) // backwards-compatibility options.xaxis.tickColor = options.grid.tickColor; if (options.yaxis.tickColor == null) // backwards-compatibility @@ -248,7 +248,7 @@ options.grid.borderColor = options.grid.color; if (options.grid.tickColor == null) options.grid.tickColor = $.color.parse(options.grid.color).scale('a', 0.22).toString(); - + // fill in defaults in axes, copy at least always the // first as the rest of the code assumes it'll be there for (i = 0; i < Math.max(1, options.xaxes.length); ++i) @@ -301,7 +301,7 @@ fillInSeriesOptions(); processData(); } - + function parseData(d) { var res = []; for (var i = 0; i < d.length; ++i) { @@ -322,7 +322,7 @@ return res; } - + function axisNumber(obj, coord) { var a = obj[coord + "axis"]; if (typeof a == "object") // if we got a real axis, extract number @@ -336,9 +336,9 @@ // return flat array without annoying null entries return $.grep(xaxes.concat(yaxes), function (a) { return a; }); } - + function canvasToAxisCoords(pos) { - // return an object with x/y corresponding to all used axes + // return an object with x/y corresponding to all used axes var res = {}, i, axis; for (i = 0; i < xaxes.length; ++i) { axis = xaxes[i]; @@ -351,7 +351,7 @@ if (axis && axis.used) res["y" + axis.n] = axis.c2p(pos.top); } - + if (res.x1 !== undefined) res.x = res.x1; if (res.y1 !== undefined) @@ -359,7 +359,7 @@ return res; } - + function axisToCanvasCoords(pos) { // get canvas coords from the first pair of x/y found in pos var res = {}, i, axis, key; @@ -377,7 +377,7 @@ } } } - + for (i = 0; i < yaxes.length; ++i) { axis = yaxes[i]; if (axis && axis.used) { @@ -391,10 +391,10 @@ } } } - + return res; } - + function getOrCreateAxis(axes, number) { if (!axes[number - 1]) axes[number - 1] = { @@ -402,13 +402,13 @@ direction: axes == xaxes ? "x" : "y", options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis) }; - + return axes[number - 1]; } function fillInSeriesOptions() { var i; - + // collect what we already got of colors var neededColors = series.length, usedColors = [], @@ -423,7 +423,7 @@ usedColors.push($.color.parse(series[i].color)); } } - + // we might need to generate more colors if higher indices // are assigned for (i = 0; i < assignedColors.length; ++i) { @@ -447,7 +447,7 @@ // FIXME: if we're getting to close to something else, // we should probably skip this one colors.push(c); - + ++i; if (i >= options.colors.length) { i = 0; @@ -459,7 +459,7 @@ var colori = 0, s; for (i = 0; i < series.length; ++i) { s = series[i]; - + // assign colors if (s.color == null) { s.color = colors[colori].toString(); @@ -485,7 +485,7 @@ s.yaxis = getOrCreateAxis(yaxes, axisNumber(s, "y")); } } - + function processData() { var topSentry = Number.POSITIVE_INFINITY, bottomSentry = Number.NEGATIVE_INFINITY, @@ -506,14 +506,14 @@ axis.datamax = bottomSentry; axis.used = false; }); - + for (i = 0; i < series.length; ++i) { s = series[i]; s.datapoints = { points: [] }; - + executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]); } - + // first pass: clean and copy data for (i = 0; i < series.length; ++i) { s = series[i]; @@ -533,7 +533,7 @@ format[format.length - 1].x = true; } } - + s.datapoints.format = format; } @@ -541,13 +541,13 @@ continue; // already filled in s.datapoints.pointsize = format.length; - + ps = s.datapoints.pointsize; points = s.datapoints.points; insertSteps = s.lines.show && s.lines.steps; s.xaxis.used = s.yaxis.used = true; - + for (j = k = 0; j < data.length; ++j, k += ps) { p = data[j]; @@ -571,16 +571,16 @@ if (val == null) { if (f.required) nullify = true; - + if (f.defaultValue != null) val = f.defaultValue; } } - + points[k + m] = val; } } - + if (nullify) { for (m = 0; m < ps; ++m) { val = points[k + m]; @@ -620,7 +620,7 @@ // give the hooks a chance to run for (i = 0; i < series.length; ++i) { s = series[i]; - + executeHooks(hooks.processDatapoints, [ s, s.datapoints]); } @@ -632,7 +632,7 @@ var xmin = topSentry, ymin = topSentry, xmax = bottomSentry, ymax = bottomSentry; - + for (j = 0; j < points.length; j += ps) { if (points[j] == null) continue; @@ -642,7 +642,7 @@ f = format[m]; if (!f || val == fakeInfinity || val == -fakeInfinity) continue; - + if (f.x) { if (val < xmin) xmin = val; @@ -657,7 +657,7 @@ } } } - + if (s.bars.show) { // make sure we got room for the bar on the dancing floor var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2; @@ -670,7 +670,7 @@ xmax += delta + s.bars.barWidth; } } - + updateAxis(s.xaxis, xmin, xmax); updateAxis(s.yaxis, ymin, ymax); } @@ -688,25 +688,25 @@ c.className = cls; c.width = canvasWidth; c.height = canvasHeight; - + if (!skipPositioning) $(c).css({ position: 'absolute', left: 0, top: 0 }); - + $(c).appendTo(placeholder); - + if (!c.getContext) // excanvas hack c = window.G_vmlCanvasManager.initElement(c); // used for resetting in case we get replotted c.getContext("2d").save(); - + return c; } function getCanvasDimensions() { canvasWidth = placeholder.width(); canvasHeight = placeholder.height(); - + if (canvasWidth <= 0 || canvasHeight <= 0) throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight; } @@ -728,7 +728,7 @@ // and save again cctx.save(); } - + function setupCanvases() { var reused, existingCanvas = placeholder.children("canvas.base"), @@ -736,16 +736,16 @@ if (existingCanvas.length == 0 || existingOverlay == 0) { // init everything - + placeholder.html(""); // make sure placeholder is clear - + placeholder.css({ padding: 0 }); // padding messes up the positioning - + if (placeholder.css("position") == 'static') placeholder.css("position", "relative"); // for positioning labels and overlay getCanvasDimensions(); - + canvas = makeCanvas(true, "base"); overlay = makeCanvas(false, "overlay"); // overlay canvas for interactive features @@ -773,10 +773,10 @@ // reset reused canvases plot.resize(); - + // make sure overlay pixels are cleared (canvas is cleared when we redraw) octx.clearRect(0, 0, canvasWidth, canvasHeight); - + // then whack any remaining obvious garbage left eventHolder.unbind(); placeholder.children().not([canvas, overlay]).remove(); @@ -802,23 +802,23 @@ function shutdown() { if (redrawTimeout) clearTimeout(redrawTimeout); - + eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mouseleave", onMouseLeave); eventHolder.unbind("click", onClick); - + executeHooks(hooks.shutdown, [eventHolder]); } function setTransformationHelpers(axis) { // set helper functions on the axis, assumes plot area // has been computed already - + function identity(x) { return x; } - + var s, m, t = axis.options.transform || identity, it = axis.options.inverseTransform; - + // precompute how much the axis is scaling a point // in canvas space if (axis.direction == "x") { @@ -853,7 +853,7 @@ + labels.join("") + '') .appendTo(placeholder); } - + if (axis.direction == "x") { // to avoid measuring the widths of the labels (it's slow), we // construct fixed-size boxes and put the labels inside @@ -888,7 +888,7 @@ if (l) labels.push('
' + l + '
'); } - + if (labels.length > 0) { dummyDiv = makeDummyDiv(labels, ""); if (w == null) @@ -940,14 +940,14 @@ var innermost = $.inArray(axis, sameDirection) == 0; if (!innermost && tickLength == "full") tickLength = 5; - + if (!isNaN(+tickLength)) padding += +tickLength; // compute box if (axis.direction == "x") { lh += padding; - + if (pos == "bottom") { plotOffset.bottom += lh + axismargin; axis.box = { top: canvasHeight - plotOffset.bottom, height: lh }; @@ -959,7 +959,7 @@ } else { lw += padding; - + if (pos == "left") { axis.box = { left: plotOffset.left + axismargin, width: lw }; plotOffset.left += lw + axismargin; @@ -988,7 +988,7 @@ axis.box.height = plotHeight; } } - + function setupGrid() { var i, axes = allAxes(); @@ -998,7 +998,7 @@ axis.show = axis.options.show; 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; setRange(axis); @@ -1031,13 +1031,13 @@ for (i = 0; i < series.length; ++i) minMargin = Math.max(minMargin, series[i].points.radius + series[i].points.lineWidth/2); } - + for (var a in plotOffset) { plotOffset[a] += options.grid.borderWidth; plotOffset[a] = Math.max(minMargin, plotOffset[a]); } } - + plotWidth = canvasWidth - plotOffset.left - plotOffset.right; plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top; @@ -1053,10 +1053,10 @@ insertAxisLabels(); } - + insertLegend(); } - + function setRange(axis) { var opts = axis.options, min = +(opts.min != null ? opts.min : axis.datamin), @@ -1098,7 +1098,7 @@ function setupTickGeneration(axis) { var opts = axis.options; - + // estimate number of ticks var noTicks; if (typeof opts.ticks == "number" && opts.ticks > 0) @@ -1113,7 +1113,7 @@ if (opts.mode == "time") { // pretty handling of time - + // map of app. size of time units in milliseconds var timeUnitSize = { "second": 1000, @@ -1129,9 +1129,9 @@ // an integer algorithm var spec = [ [1, "second"], [2, "second"], [5, "second"], [10, "second"], - [30, "second"], + [30, "second"], [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], - [30, "minute"], + [30, "minute"], [1, "hour"], [2, "hour"], [4, "hour"], [8, "hour"], [12, "hour"], [1, "day"], [2, "day"], [3, "day"], @@ -1155,7 +1155,7 @@ break; size = spec[i][0]; unit = spec[i][1]; - + // special-case the possibility of several years if (unit == "year") { magn = Math.pow(10, Math.floor(Math.log(delta / timeUnitSize.year) / Math.LN10)); @@ -1173,12 +1173,12 @@ } axis.tickSize = opts.tickSize || [size, unit]; - + generator = function(axis) { var ticks = [], tickSize = axis.tickSize[0], unit = axis.tickSize[1], d = new Date(axis.min); - + var step = tickSize * timeUnitSize[unit]; if (unit == "second") @@ -1191,7 +1191,7 @@ d.setUTCMonth(floorInBase(d.getUTCMonth(), tickSize)); if (unit == "year") d.setUTCFullYear(floorInBase(d.getUTCFullYear(), tickSize)); - + // reset smaller components d.setUTCMilliseconds(0); if (step >= timeUnitSize.minute) @@ -1243,11 +1243,11 @@ // first check global format if (opts.timeformat != null) return $.plot.formatDate(d, opts.timeformat, opts.monthNames); - + var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]]; var span = axis.max - axis.min; var suffix = (opts.twelveHourClock) ? " %p" : ""; - + if (t < timeUnitSize.minute) fmt = "%h:%M:%S" + suffix; else if (t < timeUnitSize.day) { @@ -1266,7 +1266,7 @@ } else fmt = "%y"; - + return $.plot.formatDate(d, fmt, opts.monthNames); }; } @@ -1279,7 +1279,7 @@ magn = Math.pow(10, -dec); norm = delta / magn; // norm is between 1.0 and 10.0 - + if (norm < 1.5) size = 1; else if (norm < 3) { @@ -1296,7 +1296,7 @@ size = 10; size *= magn; - + if (opts.minTickSize != null && size < opts.minTickSize) size = opts.minTickSize; @@ -1334,7 +1334,7 @@ if (opts.max == null && niceTicks.length > 1) axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]); } - + generator = function (axis) { // copy ticks, scaled to this axis var ticks = [], v, i; @@ -1345,7 +1345,7 @@ } return ticks; }; - + // we might need an extra decimal since forced // ticks don't necessarily fit naturally if (axis.mode != "time" && opts.tickDecimals == null) { @@ -1367,7 +1367,7 @@ else axis.tickFormatter = formatter; } - + function setTicks(axis) { var oticks = axis.options.ticks, ticks = []; if (oticks == null || (typeof oticks == "number" && oticks > 0)) @@ -1409,7 +1409,7 @@ axis.max = Math.max(axis.max, ticks[ticks.length - 1].v); } } - + function draw() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); @@ -1418,7 +1418,7 @@ // draw background, if any if (grid.show && grid.backgroundColor) drawBackground(); - + if (grid.show && !grid.aboveData) drawGrid(); @@ -1428,7 +1428,7 @@ } executeHooks(hooks.draw, [ctx]); - + if (grid.show && grid.aboveData) drawGrid(); } @@ -1463,10 +1463,10 @@ from = to; to = tmp; } - + return { from: from, to: to, axis: axis }; } - + function drawBackground() { ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -1478,7 +1478,7 @@ function drawGrid() { var i; - + ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -1493,7 +1493,7 @@ axes.xmax = axes.xaxis.max; axes.ymin = axes.yaxis.min; axes.ymax = axes.yaxis.max; - + markings = markings(axes); } @@ -1530,7 +1530,7 @@ xrange.to = xrange.axis.p2c(xrange.to); yrange.from = yrange.axis.p2c(yrange.from); yrange.to = yrange.axis.p2c(yrange.to); - + if (xrange.from == xrange.to || yrange.from == yrange.to) { // draw line ctx.beginPath(); @@ -1549,7 +1549,7 @@ } } } - + // draw the ticks var axes = allAxes(), bw = options.grid.borderWidth; @@ -1558,7 +1558,7 @@ t = axis.tickLength, x, y, xoff, yoff; if (!axis.show || axis.ticks.length == 0) continue - + ctx.strokeStyle = axis.options.tickColor || $.color.parse(axis.options.color).scale('a', 0.22).toString(); ctx.lineWidth = 1; @@ -1577,7 +1577,7 @@ else x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0); } - + // draw tick bar if (!axis.innermost) { ctx.beginPath(); @@ -1586,7 +1586,7 @@ xoff = plotWidth; else yoff = plotHeight; - + if (ctx.lineWidth == 1) { x = Math.floor(x) + 0.5; y = Math.floor(y) + 0.5; @@ -1601,7 +1601,7 @@ ctx.beginPath(); for (i = 0; i < axis.ticks.length; ++i) { var v = axis.ticks[i].v; - + xoff = yoff = 0; if (v < axis.min || v > axis.max @@ -1613,14 +1613,14 @@ if (axis.direction == "x") { x = axis.p2c(v); yoff = t == "full" ? -plotHeight : t; - + if (axis.position == "top") yoff = -yoff; } else { y = axis.p2c(v); xoff = t == "full" ? -plotWidth : t; - + if (axis.position == "left") xoff = -xoff; } @@ -1635,11 +1635,11 @@ ctx.moveTo(x, y); ctx.lineTo(x + xoff, y + yoff); } - + ctx.stroke(); } - - + + // draw border if (bw) { ctx.lineWidth = bw; @@ -1652,7 +1652,7 @@ function insertAxisLabels() { placeholder.find(".tickLabels").remove(); - + var html = ['
']; var axes = allAxes(); @@ -1668,7 +1668,7 @@ continue; var pos = {}, align; - + if (axis.direction == "x") { align = "center"; pos.left = Math.round(plotOffset.left + axis.p2c(tick.v) - axis.labelWidth/2); @@ -1691,10 +1691,10 @@ pos.width = axis.labelWidth; - var style = ["position:absolute", "text-align:" + align ]; + var style = ["position:absolute", "white-space:nowrap", "text-align:" + align ]; for (var a in pos) style.push(a + ":" + pos[a] + "px") - + html.push('
' + tick.label + '
'); } html.push('
'); @@ -1713,18 +1713,18 @@ if (series.points.show) drawSeriesPoints(series); } - + function drawSeriesLines(series) { function plotLine(datapoints, xoffset, yoffset, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize, prevx = null, prevy = null; - + ctx.beginPath(); for (var i = ps; i < points.length; i += ps) { var x1 = points[i - ps], y1 = points[i - ps + 1], x2 = points[i], y2 = points[i + 1]; - + if (x1 == null || x2 == null) continue; @@ -1787,7 +1787,7 @@ if (x1 != prevx || y1 != prevy) ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset); - + prevx = x2; prevy = y2; ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset); @@ -1839,7 +1839,7 @@ continue; // clip x values - + // clip with xmin if (x1 <= x2 && x1 < axisx.min) { if (x2 < axisx.min) @@ -1874,7 +1874,7 @@ ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom)); areaOpen = true; } - + // now first check the case where both is outside if (y1 >= axisy.max && y2 >= axisy.max) { ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max)); @@ -1886,7 +1886,7 @@ ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min)); continue; } - + // else it's a bit more complicated, there might // be a flat maxed out rectangle first, then a // triangular cutout or reverse; to find these @@ -1895,7 +1895,7 @@ // clip the y values, without shortcutting, we // go through all cases in turn - + // clip with ymin if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; @@ -1922,7 +1922,7 @@ ctx.lineTo(axisx.p2c(x1old), axisy.p2c(y1)); // it goes to (x1, y1), but we fill that below } - + // fill triangular section, this sometimes result // in redundant points if (x1, y1) hasn't changed // from previous line to, but we just ignore that @@ -1976,7 +1976,7 @@ var x = points[i], y = points[i + 1]; 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; @@ -1985,7 +1985,7 @@ else symbol(ctx, x, y, radius, shadow); ctx.closePath(); - + if (fillStyle) { ctx.fillStyle = fillStyle; ctx.fill(); @@ -1993,7 +1993,7 @@ ctx.stroke(); } } - + ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -2064,12 +2064,12 @@ drawTop = false; } } - + // clip if (right < axisx.min || left > axisx.max || top < axisy.min || bottom > axisy.max) return; - + if (left < axisx.min) { left = axisx.min; drawLeft = false; @@ -2084,7 +2084,7 @@ bottom = axisy.min; drawBottom = false; } - + if (top > axisy.max) { top = axisy.max; drawTop = false; @@ -2094,7 +2094,7 @@ bottom = axisy.p2c(bottom); right = axisx.p2c(right); top = axisy.p2c(top); - + // fill the bar if (fillStyleCallback) { c.beginPath(); @@ -2131,11 +2131,11 @@ c.stroke(); } } - + function drawSeriesBars(series) { function plotBars(datapoints, barLeft, barRight, offset, fillStyleCallback, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize; - + for (var i = 0; i < points.length; i += ps) { if (points[i] == null) continue; @@ -2162,19 +2162,19 @@ if (filloptions.fillColor) return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor); - + var c = $.color.parse(seriesColor); c.a = typeof fill == "number" ? fill : 0.4; c.normalize(); return c.toString(); } - + function insertLegend() { placeholder.find(".legend").remove(); if (!options.legend.show) return; - + var fragments = [], rowStarted = false, lf = options.legend.labelFormatter, s, label; for (var i = 0; i < series.length; ++i) { @@ -2182,7 +2182,7 @@ label = s.label; if (!label) continue; - + if (i % options.legend.noColumns == 0) { if (rowStarted) fragments.push(''); @@ -2192,14 +2192,14 @@ if (lf) label = lf(label, s); - + fragments.push( '
' + '' + label + ''); } if (rowStarted) fragments.push(''); - + if (fragments.length == 0) return; @@ -2243,10 +2243,10 @@ // interactive features - + var highlights = [], redrawTimeout = null; - + // returns the data item the mouse is over, or null if none is found function findNearbyItem(mouseX, mouseY, seriesFilter) { var maxDistance = options.grid.mouseActiveRadius, @@ -2256,7 +2256,7 @@ for (i = series.length - 1; i >= 0; --i) { if (!seriesFilter(series[i])) continue; - + var s = series[i], axisx = s.xaxis, axisy = s.yaxis, @@ -2273,13 +2273,13 @@ maxx = Number.MAX_VALUE; 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) continue; - + // For points and lines, the cursor must be within a // certain distance to the data point if (x - mx > maxx || x - mx < -maxx || @@ -2300,19 +2300,19 @@ } } } - + if (s.bars.show && !item) { // no other point can be nearby var barLeft = s.bars.align == "left" ? 0 : -s.bars.barWidth/2, barRight = barLeft + s.bars.barWidth; - + for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1], b = points[j + 2]; 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) && + 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))) @@ -2325,13 +2325,13 @@ i = item[0]; j = item[1]; ps = series[i].datapoints.pointsize; - + return { datapoint: series[i].datapoints.points.slice(j * ps, (j + 1) * ps), dataIndex: j, series: series[i], seriesIndex: i }; } - + return null; } @@ -2381,11 +2381,11 @@ h.point[1] == item.datapoint[1])) unhighlight(h.series, h.point); } - + if (item) highlight(item.series, item.datapoint, eventname); } - + placeholder.trigger(eventname, [ pos, item ]); } @@ -2401,7 +2401,7 @@ octx.save(); octx.clearRect(0, 0, canvasWidth, canvasHeight); octx.translate(plotOffset.left, plotOffset.top); - + var i, hi; for (i = 0; i < highlights.length; ++i) { hi = highlights[i]; @@ -2412,10 +2412,10 @@ drawPointHighlight(hi.series, hi.point); } octx.restore(); - + executeHooks(hooks.drawOverlay, [octx]); } - + function highlight(s, point, auto) { if (typeof s == "number") s = series[s]; @@ -2434,13 +2434,13 @@ else if (!auto) highlights[i].auto = false; } - + function unhighlight(s, point) { if (s == null && point == null) { highlights = []; triggerRedrawOverlay(); } - + if (typeof s == "number") s = series[s]; @@ -2454,7 +2454,7 @@ triggerRedrawOverlay(); } } - + function indexOfHighlight(s, p) { for (var i = 0; i < highlights.length; ++i) { var h = highlights[i]; @@ -2464,21 +2464,21 @@ } return -1; } - + function drawPointHighlight(series, point) { var x = point[0], y = point[1], axisx = series.xaxis, axisy = series.yaxis; - + 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; octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString(); var radius = 1.5 * pointRadius, x = axisx.p2c(x), y = axisy.p2c(y); - + octx.beginPath(); if (series.points.symbol == "circle") octx.arc(x, y, radius, 0, 2 * Math.PI, false); @@ -2505,7 +2505,7 @@ // supports a simple vertical gradient properly, so that's // what we support too var gradient = ctx.createLinearGradient(0, top, 0, bottom); - + for (var i = 0, l = spec.colors.length; i < l; ++i) { var c = spec.colors[i]; if (typeof c != "string") { @@ -2518,7 +2518,7 @@ } gradient.addColorStop(i / (l - 1), c); } - + return gradient; } } @@ -2532,7 +2532,7 @@ }; $.plot.version = "0.7"; - + $.plot.plugins = []; // returns a string with the date d formatted according to fmt @@ -2541,7 +2541,7 @@ n = "" + n; return n.length == 1 ? "0" + n : n; }; - + var r = []; var escape = false, padNext = false; var hours = d.getUTCHours(); @@ -2558,7 +2558,7 @@ } for (var i = 0; i < fmt.length; ++i) { var c = fmt.charAt(i); - + if (escape) { switch (c) { case 'h': c = "" + hours; break; @@ -2590,10 +2590,10 @@ } return r.join(""); }; - + // round to nearby lower multiple of base function floorInBase(n, base) { return base * Math.floor(n / base); } - + })(jQuery); From 7677431a6619ac6b94da9ed9f275c84e24281930 Mon Sep 17 00:00:00 2001 From: NeverMin Date: Tue, 12 Sep 2017 16:13:16 +0800 Subject: [PATCH 2/2] fixed whitespaces --- .../javascripts/app/lib/flot/jquery.flot.js | 324 +++++++++--------- 1 file changed, 162 insertions(+), 162 deletions(-) diff --git a/app/assets/javascripts/app/lib/flot/jquery.flot.js b/app/assets/javascripts/app/lib/flot/jquery.flot.js index 1777dc0f7..dd1ec8446 100755 --- a/app/assets/javascripts/app/lib/flot/jquery.flot.js +++ b/app/assets/javascripts/app/lib/flot/jquery.flot.js @@ -8,9 +8,9 @@ // for convenience /* Plugin for jQuery for working with colors. - * + * * Version 1.1. - * + * * Inspiration from jQuery color animation plugin by John Resig. * * Released under the MIT license by Ole Laursen, October 2009. @@ -27,7 +27,7 @@ * * V. 1.1: Fix error handling so e.g. parsing an empty string does * produce a color rather than just crashing. - */ + */ (function(B){B.color={};B.color.make=function(F,E,C,D){var G={};G.r=F||0;G.g=E||0;G.b=C||0;G.a=D!=null?D:1;G.add=function(J,I){for(var H=0;H=1){return"rgb("+[G.r,G.g,G.b].join(",")+")"}else{return"rgba("+[G.r,G.g,G.b,G.a].join(",")+")"}};G.normalize=function(){function H(J,K,I){return KI?I:K)}G.r=H(0,parseInt(G.r),255);G.g=H(0,parseInt(G.g),255);G.b=H(0,parseInt(G.b),255);G.a=H(0,G.a,1);return G};G.clone=function(){return B.color.make(G.r,G.b,G.g,G.a)};return G.normalize()};B.color.extract=function(D,C){var E;do{E=D.css(C).toLowerCase();if(E!=""&&E!="transparent"){break}D=D.parent()}while(!B.nodeName(D.get(0),"body"));if(E=="rgba(0, 0, 0, 0)"){E="transparent"}return B.color.parse(E)};B.color.parse=function(F){var E,C=B.color.make;if(E=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10))}if(E=/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(F)){return C(parseInt(E[1],10),parseInt(E[2],10),parseInt(E[3],10),parseFloat(E[4]))}if(E=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55)}if(E=/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(F)){return C(parseFloat(E[1])*2.55,parseFloat(E[2])*2.55,parseFloat(E[3])*2.55,parseFloat(E[4]))}if(E=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(F)){return C(parseInt(E[1],16),parseInt(E[2],16),parseInt(E[3],16))}if(E=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(F)){return C(parseInt(E[1]+E[1],16),parseInt(E[2]+E[2],16),parseInt(E[3]+E[3],16))}var D=B.trim(F).toLowerCase();if(D=="transparent"){return C(255,255,255,0)}else{E=A[D]||[0,0,0];return C(E[0],E[1],E[2])}};var A={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]}})(jQuery); // the actual Flot code @@ -37,7 +37,7 @@ // [ series1, series2 ... ] // where series is either just the data as [ [x1, y1], [x2, y2], ... ] // or { data: [ [x1, y1], [x2, y2], ... ], label: "some label", ... } - + var series = [], options = { // the color theme used for graphs @@ -71,7 +71,7 @@ reserveSpace: null, // whether to reserve space even if axis isn't shown tickLength: null, // size in pixels of ticks, or "full" for whole line alignTicksWithAxis: null, // axis number or null for no sync - + // mode specific options tickDecimals: null, // no. of decimals, null means auto tickSize: null, // number or [number, "unit"] @@ -97,7 +97,7 @@ }, lines: { // we don't put in show: false so we can see - // whether lines were actively disabled + // whether lines were actively disabled lineWidth: 2, // in pixels fill: false, fillColor: null, @@ -109,7 +109,7 @@ barWidth: 1, // in units of the x axis fill: true, fillColor: null, - align: "left", // or "center" + align: "left", // or "center" horizontal: false }, shadowSize: 3 @@ -203,7 +203,7 @@ // public attributes plot.hooks = hooks; - + // initialize initPlugins(plot); parseOptions(options_); @@ -228,17 +228,17 @@ $.extend(true, options, p.options); } } - + function parseOptions(opts) { var i; - + $.extend(true, options, opts); - + if (options.xaxis.color == null) options.xaxis.color = options.grid.color; if (options.yaxis.color == null) options.yaxis.color = options.grid.color; - + if (options.xaxis.tickColor == null) // backwards-compatibility options.xaxis.tickColor = options.grid.tickColor; if (options.yaxis.tickColor == null) // backwards-compatibility @@ -248,7 +248,7 @@ options.grid.borderColor = options.grid.color; if (options.grid.tickColor == null) options.grid.tickColor = $.color.parse(options.grid.color).scale('a', 0.22).toString(); - + // fill in defaults in axes, copy at least always the // first as the rest of the code assumes it'll be there for (i = 0; i < Math.max(1, options.xaxes.length); ++i) @@ -301,7 +301,7 @@ fillInSeriesOptions(); processData(); } - + function parseData(d) { var res = []; for (var i = 0; i < d.length; ++i) { @@ -322,7 +322,7 @@ return res; } - + function axisNumber(obj, coord) { var a = obj[coord + "axis"]; if (typeof a == "object") // if we got a real axis, extract number @@ -336,9 +336,9 @@ // return flat array without annoying null entries return $.grep(xaxes.concat(yaxes), function (a) { return a; }); } - + function canvasToAxisCoords(pos) { - // return an object with x/y corresponding to all used axes + // return an object with x/y corresponding to all used axes var res = {}, i, axis; for (i = 0; i < xaxes.length; ++i) { axis = xaxes[i]; @@ -351,7 +351,7 @@ if (axis && axis.used) res["y" + axis.n] = axis.c2p(pos.top); } - + if (res.x1 !== undefined) res.x = res.x1; if (res.y1 !== undefined) @@ -359,7 +359,7 @@ return res; } - + function axisToCanvasCoords(pos) { // get canvas coords from the first pair of x/y found in pos var res = {}, i, axis, key; @@ -377,7 +377,7 @@ } } } - + for (i = 0; i < yaxes.length; ++i) { axis = yaxes[i]; if (axis && axis.used) { @@ -391,10 +391,10 @@ } } } - + return res; } - + function getOrCreateAxis(axes, number) { if (!axes[number - 1]) axes[number - 1] = { @@ -402,13 +402,13 @@ direction: axes == xaxes ? "x" : "y", options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis) }; - + return axes[number - 1]; } function fillInSeriesOptions() { var i; - + // collect what we already got of colors var neededColors = series.length, usedColors = [], @@ -423,7 +423,7 @@ usedColors.push($.color.parse(series[i].color)); } } - + // we might need to generate more colors if higher indices // are assigned for (i = 0; i < assignedColors.length; ++i) { @@ -447,7 +447,7 @@ // FIXME: if we're getting to close to something else, // we should probably skip this one colors.push(c); - + ++i; if (i >= options.colors.length) { i = 0; @@ -459,7 +459,7 @@ var colori = 0, s; for (i = 0; i < series.length; ++i) { s = series[i]; - + // assign colors if (s.color == null) { s.color = colors[colori].toString(); @@ -485,7 +485,7 @@ s.yaxis = getOrCreateAxis(yaxes, axisNumber(s, "y")); } } - + function processData() { var topSentry = Number.POSITIVE_INFINITY, bottomSentry = Number.NEGATIVE_INFINITY, @@ -506,14 +506,14 @@ axis.datamax = bottomSentry; axis.used = false; }); - + for (i = 0; i < series.length; ++i) { s = series[i]; s.datapoints = { points: [] }; - + executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]); } - + // first pass: clean and copy data for (i = 0; i < series.length; ++i) { s = series[i]; @@ -533,7 +533,7 @@ format[format.length - 1].x = true; } } - + s.datapoints.format = format; } @@ -541,13 +541,13 @@ continue; // already filled in s.datapoints.pointsize = format.length; - + ps = s.datapoints.pointsize; points = s.datapoints.points; insertSteps = s.lines.show && s.lines.steps; s.xaxis.used = s.yaxis.used = true; - + for (j = k = 0; j < data.length; ++j, k += ps) { p = data[j]; @@ -571,16 +571,16 @@ if (val == null) { if (f.required) nullify = true; - + if (f.defaultValue != null) val = f.defaultValue; } } - + points[k + m] = val; } } - + if (nullify) { for (m = 0; m < ps; ++m) { val = points[k + m]; @@ -620,7 +620,7 @@ // give the hooks a chance to run for (i = 0; i < series.length; ++i) { s = series[i]; - + executeHooks(hooks.processDatapoints, [ s, s.datapoints]); } @@ -632,7 +632,7 @@ var xmin = topSentry, ymin = topSentry, xmax = bottomSentry, ymax = bottomSentry; - + for (j = 0; j < points.length; j += ps) { if (points[j] == null) continue; @@ -642,7 +642,7 @@ f = format[m]; if (!f || val == fakeInfinity || val == -fakeInfinity) continue; - + if (f.x) { if (val < xmin) xmin = val; @@ -657,7 +657,7 @@ } } } - + if (s.bars.show) { // make sure we got room for the bar on the dancing floor var delta = s.bars.align == "left" ? 0 : -s.bars.barWidth/2; @@ -670,7 +670,7 @@ xmax += delta + s.bars.barWidth; } } - + updateAxis(s.xaxis, xmin, xmax); updateAxis(s.yaxis, ymin, ymax); } @@ -688,25 +688,25 @@ c.className = cls; c.width = canvasWidth; c.height = canvasHeight; - + if (!skipPositioning) $(c).css({ position: 'absolute', left: 0, top: 0 }); - + $(c).appendTo(placeholder); - + if (!c.getContext) // excanvas hack c = window.G_vmlCanvasManager.initElement(c); // used for resetting in case we get replotted c.getContext("2d").save(); - + return c; } function getCanvasDimensions() { canvasWidth = placeholder.width(); canvasHeight = placeholder.height(); - + if (canvasWidth <= 0 || canvasHeight <= 0) throw "Invalid dimensions for plot, width = " + canvasWidth + ", height = " + canvasHeight; } @@ -728,7 +728,7 @@ // and save again cctx.save(); } - + function setupCanvases() { var reused, existingCanvas = placeholder.children("canvas.base"), @@ -736,16 +736,16 @@ if (existingCanvas.length == 0 || existingOverlay == 0) { // init everything - + placeholder.html(""); // make sure placeholder is clear - + placeholder.css({ padding: 0 }); // padding messes up the positioning - + if (placeholder.css("position") == 'static') placeholder.css("position", "relative"); // for positioning labels and overlay getCanvasDimensions(); - + canvas = makeCanvas(true, "base"); overlay = makeCanvas(false, "overlay"); // overlay canvas for interactive features @@ -773,10 +773,10 @@ // reset reused canvases plot.resize(); - + // make sure overlay pixels are cleared (canvas is cleared when we redraw) octx.clearRect(0, 0, canvasWidth, canvasHeight); - + // then whack any remaining obvious garbage left eventHolder.unbind(); placeholder.children().not([canvas, overlay]).remove(); @@ -802,23 +802,23 @@ function shutdown() { if (redrawTimeout) clearTimeout(redrawTimeout); - + eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mouseleave", onMouseLeave); eventHolder.unbind("click", onClick); - + executeHooks(hooks.shutdown, [eventHolder]); } function setTransformationHelpers(axis) { // set helper functions on the axis, assumes plot area // has been computed already - + function identity(x) { return x; } - + var s, m, t = axis.options.transform || identity, it = axis.options.inverseTransform; - + // precompute how much the axis is scaling a point // in canvas space if (axis.direction == "x") { @@ -853,7 +853,7 @@ + labels.join("") + '') .appendTo(placeholder); } - + if (axis.direction == "x") { // to avoid measuring the widths of the labels (it's slow), we // construct fixed-size boxes and put the labels inside @@ -888,7 +888,7 @@ if (l) labels.push('
' + l + '
'); } - + if (labels.length > 0) { dummyDiv = makeDummyDiv(labels, ""); if (w == null) @@ -940,14 +940,14 @@ var innermost = $.inArray(axis, sameDirection) == 0; if (!innermost && tickLength == "full") tickLength = 5; - + if (!isNaN(+tickLength)) padding += +tickLength; // compute box if (axis.direction == "x") { lh += padding; - + if (pos == "bottom") { plotOffset.bottom += lh + axismargin; axis.box = { top: canvasHeight - plotOffset.bottom, height: lh }; @@ -959,7 +959,7 @@ } else { lw += padding; - + if (pos == "left") { axis.box = { left: plotOffset.left + axismargin, width: lw }; plotOffset.left += lw + axismargin; @@ -988,7 +988,7 @@ axis.box.height = plotHeight; } } - + function setupGrid() { var i, axes = allAxes(); @@ -998,7 +998,7 @@ axis.show = axis.options.show; 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; setRange(axis); @@ -1031,13 +1031,13 @@ for (i = 0; i < series.length; ++i) minMargin = Math.max(minMargin, series[i].points.radius + series[i].points.lineWidth/2); } - + for (var a in plotOffset) { plotOffset[a] += options.grid.borderWidth; plotOffset[a] = Math.max(minMargin, plotOffset[a]); } } - + plotWidth = canvasWidth - plotOffset.left - plotOffset.right; plotHeight = canvasHeight - plotOffset.bottom - plotOffset.top; @@ -1053,10 +1053,10 @@ insertAxisLabels(); } - + insertLegend(); } - + function setRange(axis) { var opts = axis.options, min = +(opts.min != null ? opts.min : axis.datamin), @@ -1098,7 +1098,7 @@ function setupTickGeneration(axis) { var opts = axis.options; - + // estimate number of ticks var noTicks; if (typeof opts.ticks == "number" && opts.ticks > 0) @@ -1113,7 +1113,7 @@ if (opts.mode == "time") { // pretty handling of time - + // map of app. size of time units in milliseconds var timeUnitSize = { "second": 1000, @@ -1129,9 +1129,9 @@ // an integer algorithm var spec = [ [1, "second"], [2, "second"], [5, "second"], [10, "second"], - [30, "second"], + [30, "second"], [1, "minute"], [2, "minute"], [5, "minute"], [10, "minute"], - [30, "minute"], + [30, "minute"], [1, "hour"], [2, "hour"], [4, "hour"], [8, "hour"], [12, "hour"], [1, "day"], [2, "day"], [3, "day"], @@ -1155,7 +1155,7 @@ break; size = spec[i][0]; unit = spec[i][1]; - + // special-case the possibility of several years if (unit == "year") { magn = Math.pow(10, Math.floor(Math.log(delta / timeUnitSize.year) / Math.LN10)); @@ -1173,12 +1173,12 @@ } axis.tickSize = opts.tickSize || [size, unit]; - + generator = function(axis) { var ticks = [], tickSize = axis.tickSize[0], unit = axis.tickSize[1], d = new Date(axis.min); - + var step = tickSize * timeUnitSize[unit]; if (unit == "second") @@ -1191,7 +1191,7 @@ d.setUTCMonth(floorInBase(d.getUTCMonth(), tickSize)); if (unit == "year") d.setUTCFullYear(floorInBase(d.getUTCFullYear(), tickSize)); - + // reset smaller components d.setUTCMilliseconds(0); if (step >= timeUnitSize.minute) @@ -1243,11 +1243,11 @@ // first check global format if (opts.timeformat != null) return $.plot.formatDate(d, opts.timeformat, opts.monthNames); - + var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]]; var span = axis.max - axis.min; var suffix = (opts.twelveHourClock) ? " %p" : ""; - + if (t < timeUnitSize.minute) fmt = "%h:%M:%S" + suffix; else if (t < timeUnitSize.day) { @@ -1266,7 +1266,7 @@ } else fmt = "%y"; - + return $.plot.formatDate(d, fmt, opts.monthNames); }; } @@ -1279,7 +1279,7 @@ magn = Math.pow(10, -dec); norm = delta / magn; // norm is between 1.0 and 10.0 - + if (norm < 1.5) size = 1; else if (norm < 3) { @@ -1296,7 +1296,7 @@ size = 10; size *= magn; - + if (opts.minTickSize != null && size < opts.minTickSize) size = opts.minTickSize; @@ -1334,7 +1334,7 @@ if (opts.max == null && niceTicks.length > 1) axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]); } - + generator = function (axis) { // copy ticks, scaled to this axis var ticks = [], v, i; @@ -1345,7 +1345,7 @@ } return ticks; }; - + // we might need an extra decimal since forced // ticks don't necessarily fit naturally if (axis.mode != "time" && opts.tickDecimals == null) { @@ -1367,7 +1367,7 @@ else axis.tickFormatter = formatter; } - + function setTicks(axis) { var oticks = axis.options.ticks, ticks = []; if (oticks == null || (typeof oticks == "number" && oticks > 0)) @@ -1409,7 +1409,7 @@ axis.max = Math.max(axis.max, ticks[ticks.length - 1].v); } } - + function draw() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); @@ -1418,7 +1418,7 @@ // draw background, if any if (grid.show && grid.backgroundColor) drawBackground(); - + if (grid.show && !grid.aboveData) drawGrid(); @@ -1428,7 +1428,7 @@ } executeHooks(hooks.draw, [ctx]); - + if (grid.show && grid.aboveData) drawGrid(); } @@ -1463,10 +1463,10 @@ from = to; to = tmp; } - + return { from: from, to: to, axis: axis }; } - + function drawBackground() { ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -1478,7 +1478,7 @@ function drawGrid() { var i; - + ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -1493,7 +1493,7 @@ axes.xmax = axes.xaxis.max; axes.ymin = axes.yaxis.min; axes.ymax = axes.yaxis.max; - + markings = markings(axes); } @@ -1530,7 +1530,7 @@ xrange.to = xrange.axis.p2c(xrange.to); yrange.from = yrange.axis.p2c(yrange.from); yrange.to = yrange.axis.p2c(yrange.to); - + if (xrange.from == xrange.to || yrange.from == yrange.to) { // draw line ctx.beginPath(); @@ -1549,7 +1549,7 @@ } } } - + // draw the ticks var axes = allAxes(), bw = options.grid.borderWidth; @@ -1558,7 +1558,7 @@ t = axis.tickLength, x, y, xoff, yoff; if (!axis.show || axis.ticks.length == 0) continue - + ctx.strokeStyle = axis.options.tickColor || $.color.parse(axis.options.color).scale('a', 0.22).toString(); ctx.lineWidth = 1; @@ -1577,7 +1577,7 @@ else x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0); } - + // draw tick bar if (!axis.innermost) { ctx.beginPath(); @@ -1586,7 +1586,7 @@ xoff = plotWidth; else yoff = plotHeight; - + if (ctx.lineWidth == 1) { x = Math.floor(x) + 0.5; y = Math.floor(y) + 0.5; @@ -1601,7 +1601,7 @@ ctx.beginPath(); for (i = 0; i < axis.ticks.length; ++i) { var v = axis.ticks[i].v; - + xoff = yoff = 0; if (v < axis.min || v > axis.max @@ -1613,14 +1613,14 @@ if (axis.direction == "x") { x = axis.p2c(v); yoff = t == "full" ? -plotHeight : t; - + if (axis.position == "top") yoff = -yoff; } else { y = axis.p2c(v); xoff = t == "full" ? -plotWidth : t; - + if (axis.position == "left") xoff = -xoff; } @@ -1635,11 +1635,11 @@ ctx.moveTo(x, y); ctx.lineTo(x + xoff, y + yoff); } - + ctx.stroke(); } - - + + // draw border if (bw) { ctx.lineWidth = bw; @@ -1652,7 +1652,7 @@ function insertAxisLabels() { placeholder.find(".tickLabels").remove(); - + var html = ['
']; var axes = allAxes(); @@ -1668,7 +1668,7 @@ continue; var pos = {}, align; - + if (axis.direction == "x") { align = "center"; pos.left = Math.round(plotOffset.left + axis.p2c(tick.v) - axis.labelWidth/2); @@ -1694,7 +1694,7 @@ var style = ["position:absolute", "white-space:nowrap", "text-align:" + align ]; for (var a in pos) style.push(a + ":" + pos[a] + "px") - + html.push('
' + tick.label + '
'); } html.push('
'); @@ -1713,18 +1713,18 @@ if (series.points.show) drawSeriesPoints(series); } - + function drawSeriesLines(series) { function plotLine(datapoints, xoffset, yoffset, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize, prevx = null, prevy = null; - + ctx.beginPath(); for (var i = ps; i < points.length; i += ps) { var x1 = points[i - ps], y1 = points[i - ps + 1], x2 = points[i], y2 = points[i + 1]; - + if (x1 == null || x2 == null) continue; @@ -1787,7 +1787,7 @@ if (x1 != prevx || y1 != prevy) ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset); - + prevx = x2; prevy = y2; ctx.lineTo(axisx.p2c(x2) + xoffset, axisy.p2c(y2) + yoffset); @@ -1839,7 +1839,7 @@ continue; // clip x values - + // clip with xmin if (x1 <= x2 && x1 < axisx.min) { if (x2 < axisx.min) @@ -1874,7 +1874,7 @@ ctx.moveTo(axisx.p2c(x1), axisy.p2c(bottom)); areaOpen = true; } - + // now first check the case where both is outside if (y1 >= axisy.max && y2 >= axisy.max) { ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max)); @@ -1886,7 +1886,7 @@ ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min)); continue; } - + // else it's a bit more complicated, there might // be a flat maxed out rectangle first, then a // triangular cutout or reverse; to find these @@ -1895,7 +1895,7 @@ // clip the y values, without shortcutting, we // go through all cases in turn - + // clip with ymin if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; @@ -1922,7 +1922,7 @@ ctx.lineTo(axisx.p2c(x1old), axisy.p2c(y1)); // it goes to (x1, y1), but we fill that below } - + // fill triangular section, this sometimes result // in redundant points if (x1, y1) hasn't changed // from previous line to, but we just ignore that @@ -1976,7 +1976,7 @@ var x = points[i], y = points[i + 1]; 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; @@ -1985,7 +1985,7 @@ else symbol(ctx, x, y, radius, shadow); ctx.closePath(); - + if (fillStyle) { ctx.fillStyle = fillStyle; ctx.fill(); @@ -1993,7 +1993,7 @@ ctx.stroke(); } } - + ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); @@ -2064,12 +2064,12 @@ drawTop = false; } } - + // clip if (right < axisx.min || left > axisx.max || top < axisy.min || bottom > axisy.max) return; - + if (left < axisx.min) { left = axisx.min; drawLeft = false; @@ -2084,7 +2084,7 @@ bottom = axisy.min; drawBottom = false; } - + if (top > axisy.max) { top = axisy.max; drawTop = false; @@ -2094,7 +2094,7 @@ bottom = axisy.p2c(bottom); right = axisx.p2c(right); top = axisy.p2c(top); - + // fill the bar if (fillStyleCallback) { c.beginPath(); @@ -2131,11 +2131,11 @@ c.stroke(); } } - + function drawSeriesBars(series) { function plotBars(datapoints, barLeft, barRight, offset, fillStyleCallback, axisx, axisy) { var points = datapoints.points, ps = datapoints.pointsize; - + for (var i = 0; i < points.length; i += ps) { if (points[i] == null) continue; @@ -2162,19 +2162,19 @@ if (filloptions.fillColor) return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor); - + var c = $.color.parse(seriesColor); c.a = typeof fill == "number" ? fill : 0.4; c.normalize(); return c.toString(); } - + function insertLegend() { placeholder.find(".legend").remove(); if (!options.legend.show) return; - + var fragments = [], rowStarted = false, lf = options.legend.labelFormatter, s, label; for (var i = 0; i < series.length; ++i) { @@ -2182,7 +2182,7 @@ label = s.label; if (!label) continue; - + if (i % options.legend.noColumns == 0) { if (rowStarted) fragments.push(''); @@ -2192,14 +2192,14 @@ if (lf) label = lf(label, s); - + fragments.push( '
' + '' + label + ''); } if (rowStarted) fragments.push(''); - + if (fragments.length == 0) return; @@ -2243,10 +2243,10 @@ // interactive features - + var highlights = [], redrawTimeout = null; - + // returns the data item the mouse is over, or null if none is found function findNearbyItem(mouseX, mouseY, seriesFilter) { var maxDistance = options.grid.mouseActiveRadius, @@ -2256,7 +2256,7 @@ for (i = series.length - 1; i >= 0; --i) { if (!seriesFilter(series[i])) continue; - + var s = series[i], axisx = s.xaxis, axisy = s.yaxis, @@ -2273,13 +2273,13 @@ maxx = Number.MAX_VALUE; 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) continue; - + // For points and lines, the cursor must be within a // certain distance to the data point if (x - mx > maxx || x - mx < -maxx || @@ -2300,19 +2300,19 @@ } } } - + if (s.bars.show && !item) { // no other point can be nearby var barLeft = s.bars.align == "left" ? 0 : -s.bars.barWidth/2, barRight = barLeft + s.bars.barWidth; - + for (j = 0; j < points.length; j += ps) { var x = points[j], y = points[j + 1], b = points[j + 2]; 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) && + 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))) @@ -2325,13 +2325,13 @@ i = item[0]; j = item[1]; ps = series[i].datapoints.pointsize; - + return { datapoint: series[i].datapoints.points.slice(j * ps, (j + 1) * ps), dataIndex: j, series: series[i], seriesIndex: i }; } - + return null; } @@ -2381,11 +2381,11 @@ h.point[1] == item.datapoint[1])) unhighlight(h.series, h.point); } - + if (item) highlight(item.series, item.datapoint, eventname); } - + placeholder.trigger(eventname, [ pos, item ]); } @@ -2401,7 +2401,7 @@ octx.save(); octx.clearRect(0, 0, canvasWidth, canvasHeight); octx.translate(plotOffset.left, plotOffset.top); - + var i, hi; for (i = 0; i < highlights.length; ++i) { hi = highlights[i]; @@ -2412,10 +2412,10 @@ drawPointHighlight(hi.series, hi.point); } octx.restore(); - + executeHooks(hooks.drawOverlay, [octx]); } - + function highlight(s, point, auto) { if (typeof s == "number") s = series[s]; @@ -2434,13 +2434,13 @@ else if (!auto) highlights[i].auto = false; } - + function unhighlight(s, point) { if (s == null && point == null) { highlights = []; triggerRedrawOverlay(); } - + if (typeof s == "number") s = series[s]; @@ -2454,7 +2454,7 @@ triggerRedrawOverlay(); } } - + function indexOfHighlight(s, p) { for (var i = 0; i < highlights.length; ++i) { var h = highlights[i]; @@ -2464,21 +2464,21 @@ } return -1; } - + function drawPointHighlight(series, point) { var x = point[0], y = point[1], axisx = series.xaxis, axisy = series.yaxis; - + 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; octx.strokeStyle = $.color.parse(series.color).scale('a', 0.5).toString(); var radius = 1.5 * pointRadius, x = axisx.p2c(x), y = axisy.p2c(y); - + octx.beginPath(); if (series.points.symbol == "circle") octx.arc(x, y, radius, 0, 2 * Math.PI, false); @@ -2505,7 +2505,7 @@ // supports a simple vertical gradient properly, so that's // what we support too var gradient = ctx.createLinearGradient(0, top, 0, bottom); - + for (var i = 0, l = spec.colors.length; i < l; ++i) { var c = spec.colors[i]; if (typeof c != "string") { @@ -2518,7 +2518,7 @@ } gradient.addColorStop(i / (l - 1), c); } - + return gradient; } } @@ -2532,7 +2532,7 @@ }; $.plot.version = "0.7"; - + $.plot.plugins = []; // returns a string with the date d formatted according to fmt @@ -2541,7 +2541,7 @@ n = "" + n; return n.length == 1 ? "0" + n : n; }; - + var r = []; var escape = false, padNext = false; var hours = d.getUTCHours(); @@ -2558,7 +2558,7 @@ } for (var i = 0; i < fmt.length; ++i) { var c = fmt.charAt(i); - + if (escape) { switch (c) { case 'h': c = "" + hours; break; @@ -2590,10 +2590,10 @@ } return r.join(""); }; - + // round to nearby lower multiple of base function floorInBase(n, base) { return base * Math.floor(n / base); } - + })(jQuery);