Commit ffcd71f4 authored by David Schnur's avatar David Schnur

Miscellaneous code cleanup.

parent 3de9c0e9
......@@ -138,8 +138,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
for (var i = 0; i < o.length; ++i) {
c[o[i]] = i;
}
}
else {
} else {
for (var v in o) {
if (Object.prototype.hasOwnProperty.call(o, v)) {
c[v] = o[v];
......
......@@ -59,6 +59,7 @@ The plugin also adds four public methods:
*/
(function ($) {
var options = {
crosshair: {
mode: null, // one of null, "x", "y" or "xy",
......@@ -178,4 +179,5 @@ The plugin also adds four public methods:
name: "crosshair",
version: "1.0"
});
})(jQuery);
......@@ -113,13 +113,13 @@ shadowSize and lineWidth are derived as well from the points series.
// read errors from points array
var exl = null,
exu = null,
eyl = null,
eyu = null;
var xerr = series.points.xerr,
yerr = series.points.yerr;
exu = null,
eyl = null,
eyu = null,
xerr = series.points.xerr,
yerr = series.points.yerr,
eb = series.points.errorbars;
var eb = series.points.errorbars;
// error bars - first X
if (eb === "x" || eb === "xy") {
if (xerr.asymmetric) {
......@@ -178,13 +178,13 @@ shadowSize and lineWidth are derived as well from the points series.
function drawSeriesErrors(plot, ctx, s){
var points = s.datapoints.points,
ps = s.datapoints.pointsize,
ax = [s.xaxis, s.yaxis],
radius = s.points.radius,
err = [s.points.xerr, s.points.yerr],
invertX = false,
invertY = false,
tmp;
ps = s.datapoints.pointsize,
ax = [s.xaxis, s.yaxis],
radius = s.points.radius,
err = [s.points.xerr, s.points.yerr],
invertX = false,
invertY = false,
tmp;
//sanity check, in case some inverted axis hack is applied to flot
......@@ -204,7 +204,6 @@ shadowSize and lineWidth are derived as well from the points series.
for (var i = 0; i < s.datapoints.points.length; i += ps) {
//parse
var errRanges = parseErrors(s, i);
//cycle xerr & yerr
......@@ -367,7 +366,7 @@ 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();
......@@ -392,9 +391,10 @@ shadowSize and lineWidth are derived as well from the points series.
}
$.plot.plugins.push({
init: init,
options: options,
name: "errorbars",
version: "1.0"
});
init: init,
options: options,
name: "errorbars",
version: "1.0"
});
})(jQuery);
......@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
*/
(function ( $ ) {
(function ($) {
var options = {
series: {
......@@ -37,37 +37,37 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
}
};
function init( plot ) {
function init(plot) {
function findBottomSeries( s, allseries ) {
function findBottomSeries(s, allseries) {
var i;
for ( i = 0; i < allseries.length; ++i ) {
if ( allseries[ i ].id === s.fillBetween ) {
return allseries[ i ];
for (i = 0; i < allseries.length; ++i) {
if (allseries[i].id === s.fillBetween) {
return allseries[i];
}
}
if ( typeof s.fillBetween === "number" ) {
if ( s.fillBetween < 0 || s.fillBetween >= allseries.length ) {
if (typeof s.fillBetween === "number") {
if (s.fillBetween < 0 || s.fillBetween >= allseries.length) {
return null;
}
return allseries[ s.fillBetween ];
return allseries[s.fillBetween];
}
return null;
}
function computeFillBottoms( plot, s, datapoints ) {
function computeFillBottoms(plot, s, datapoints) {
if ( s.fillBetween == null ) {
if (s.fillBetween == null) {
return;
}
var other = findBottomSeries( s, plot.getData() );
var other = findBottomSeries(s, plot.getData());
if ( !other ) {
if (!other) {
return;
}
......@@ -85,42 +85,42 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
j = 0,
l, m;
while ( true ) {
while (true) {
if ( i >= points.length ) {
if (i >= points.length) {
break;
}
l = newpoints.length;
if ( points[ i ] == null ) {
if (points[i] == null) {
// copy gaps
for ( m = 0; m < ps; ++m ) {
newpoints.push( points[ i + m ] );
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
i += ps;
} else if ( j >= otherpoints.length ) {
} else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if ( !withlines ) {
for ( m = 0; m < ps; ++m ) {
newpoints.push( points[ i + m ] );
if (!withlines) {
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
}
i += ps;
} else if ( otherpoints[ j ] == null ) {
} else if (otherpoints[j] == null) {
// oops, got a gap
for ( m = 0; m < ps; ++m ) {
newpoints.push( null );
for (m = 0; m < ps; ++m) {
newpoints.push(null);
}
fromgap = true;
......@@ -130,35 +130,35 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
// cases where we actually got two points
px = points[ i ];
py = points[ i + 1 ];
qx = otherpoints[ j ];
qy = otherpoints[ j + 1 ];
px = points[i];
py = points[i + 1];
qx = otherpoints[j];
qy = otherpoints[j + 1];
bottom = 0;
if ( px === qx ) {
if (px === qx) {
for ( m = 0; m < ps; ++m ) {
newpoints.push( points[ i + m ] );
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
//newpoints[ l + 1 ] += qy;
//newpoints[l + 1] += qy;
bottom = qy;
i += ps;
j += otherps;
} else if ( px > qx ) {
} else if (px > qx) {
// we got past point below, might need to
// insert interpolated extra point
if ( withlines && i > 0 && points[ i - ps ] != null ) {
intery = py + ( points[ i - ps + 1 ] - py ) * ( qx - px ) / ( points[ i - ps ] - px );
newpoints.push( qx );
newpoints.push( intery );
for ( m = 2; m < ps; ++m ) {
newpoints.push( points[ i + m ] );
if (withlines && i > 0 && points[i - ps] != null) {
intery = py + (points[i - ps + 1] - py) * (qx - px) / (points[i - ps] - px);
newpoints.push(qx);
newpoints.push(intery);
for (m = 2; m < ps; ++m) {
newpoints.push(points[i + m]);
}
bottom = qy;
}
......@@ -169,20 +169,20 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
// if we come from a gap, we just skip this point
if ( fromgap && withlines ) {
if (fromgap && withlines) {
i += ps;
continue;
}
for ( m = 0; m < ps; ++m ) {
newpoints.push( points[ i + 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 ) {
bottom = qy + ( otherpoints[ j - otherps + 1 ] - qy ) * ( px - qx ) / ( otherpoints[ j - otherps ] - qx );
if (withlines && j > 0 && otherpoints[j - otherps] != null) {
bottom = qy + (otherpoints[j - otherps + 1] - qy) * (px - qx) / (otherpoints[j - otherps] - qx);
}
//newpoints[l + 1] += bottom;
......@@ -192,28 +192,28 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
fromgap = false;
if ( l !== newpoints.length && withbottom ) {
newpoints[ l + 2 ] = bottom;
if (l !== newpoints.length && withbottom) {
newpoints[l + 2] = bottom;
}
}
// maintain the line steps invariant
if ( withsteps && l !== newpoints.length && l > 0 &&
newpoints[ l ] !== null &&
newpoints[ l ] !== newpoints[ l - ps ] &&
newpoints[ l + 1 ] !== newpoints[ l - ps + 1 ] ) {
if (withsteps && l !== newpoints.length && l > 0 &&
newpoints[l] !== null &&
newpoints[l] !== newpoints[ l - ps ] &&
newpoints[l + 1] !== newpoints[l - ps + 1] ) {
for (m = 0; m < ps; ++m) {
newpoints[ l + ps + m ] = newpoints[ l + m ];
newpoints[l + ps + m] = newpoints[l + m];
}
newpoints[ l + 1 ] = newpoints[ l - ps + 1 ];
newpoints[l + 1] = newpoints[l - ps + 1];
}
}
datapoints.points = newpoints;
}
plot.hooks.processDatapoints.push( computeFillBottoms );
plot.hooks.processDatapoints.push(computeFillBottoms);
}
$.plot.plugins.push({
......
......@@ -1030,8 +1030,7 @@ Licensed under the MIT license.
if (s.color == null) {
s.color = colors[colori].toString();
++colori;
}
else if (typeof s.color === "number") {
} else if (typeof s.color === "number") {
s.color = colors[s.color].toString();
}
......@@ -1066,9 +1065,7 @@ Licensed under the MIT license.
var topSentry = Number.POSITIVE_INFINITY,
bottomSentry = Number.NEGATIVE_INFINITY,
fakeInfinity = Number.MAX_VALUE,
i, j, k, m,
s, points, ps, val, f, p,
data, format;
i, j, k, m, s, points, ps, val, f, p, data, format;
function updateAxis(axis, min, max) {
if (min < axis.datamin && min !== -fakeInfinity) {
......@@ -1089,7 +1086,6 @@ Licensed under the MIT license.
for (i = 0; i < series.length; ++i) {
s = series[i];
s.datapoints = { points: [] };
executeHooks(hooks.processRawData, [ s, s.data, s.datapoints ]);
}
......@@ -1183,8 +1179,7 @@ Licensed under the MIT license.
}
points[k + m] = null;
}
}
else {
} else {
// a little bit of line specific stuff that
// perhaps shouldn't be here, but lacking
// better means...
......@@ -2383,8 +2378,7 @@ Licensed under the MIT license.
}
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.min;
}
else if (x2 <= x1 && x2 < axisx.min) {
} else if (x2 <= x1 && x2 < axisx.min) {
if (x1 < axisx.min) {
continue;
}
......@@ -2399,8 +2393,7 @@ Licensed under the MIT license.
}
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.max;
}
else if (x2 >= x1 && x2 > axisx.max) {
} else if (x2 >= x1 && x2 > axisx.max) {
if (x1 > axisx.max) {
continue;
}
......
......@@ -297,13 +297,13 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
}
$.each(plot.getAxes(), function (_, axis) {
var opts = axis.options,
min, max, d = delta[axis.direction];
min = axis.c2p(axis.p2c(axis.min) + d),
max = axis.c2p(axis.p2c(axis.max) + d);
var opts = axis.options,
min = axis.c2p(axis.p2c(axis.min) + d),
max = axis.c2p(axis.p2c(axis.max) + d),
d = delta[axis.direction],
pr = opts.panRange;
var pr = opts.panRange;
if (pr === false) { // no panning on this axis
return;
}
......
......@@ -80,8 +80,10 @@ The plugin allso adds the following methods to the plot object:
(function ($) {
function init(plot) {
var selection = {
first: { x: -1, y: -1}, second: { x: -1, y: -1},
first: { x: -1, y: -1},
second: { x: -1, y: -1},
show: false,
active: false
};
......@@ -91,14 +93,13 @@ The plugin allso adds the following methods to the plot object:
// 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 = {};
var mouseUpHandler = null;
var savedhandlers = {},
mouseUpHandler = null;
function onMouseMove(e) {
if (selection.active) {
updateSelection(e);
plot.getPlaceholder().trigger("plotselecting", [ getSelection() ]);
}
}
......@@ -159,18 +160,19 @@ The plugin allso adds the following methods to the plot object:
}
function getSelection() {
if (!selectionIsSane()) {
return null;
}
if (!selection.show) {
if (!selectionIsSane() || !selection.show) {
return null;
}
var r = {}, c1 = selection.first, c2 = selection.second;
var r = {},
c1 = selection.first,
c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) {
if (axis.used) {
var p1 = axis.c2p(c1[axis.direction]), p2 = axis.c2p(c2[axis.direction]);
var p1 = axis.c2p(c1[axis.direction]),
p2 = axis.c2p(c2[axis.direction]);
r[name] = { from: Math.min(p1, p2), to: Math.max(p1, p2) };
}
});
......@@ -193,9 +195,10 @@ The plugin allso adds the following methods to the plot object:
}
function setSelectionPos(pos, e) {
var o = plot.getOptions();
var offset = plot.getPlaceholder().offset();
var plotOffset = plot.getPlotOffset();
var o = plot.getOptions(),
offset = plot.getPlaceholder().offset(),
plotOffset = plot.getPlotOffset();
pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width());
pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height());
......@@ -227,7 +230,7 @@ The plugin allso adds the following methods to the plot object:
selection.show = false;
plot.triggerRedrawOverlay();
if (!preventEvent) {
plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotunselected", []);
}
}
}
......@@ -276,10 +279,8 @@ The plugin allso adds the following methods to the plot object:
if (o.selection.mode === "y") {
selection.first.x = 0;
selection.second.x = plot.width();
}
else {
} else {
range = extractRange(ranges, "x");
selection.first.x = range.axis.p2c(range.from);
selection.second.x = range.axis.p2c(range.to);
}
......@@ -287,10 +288,8 @@ The plugin allso adds the following methods to the plot object:
if (o.selection.mode === "x") {
selection.first.y = 0;
selection.second.y = plot.height();
}
else {
} else {
range = extractRange(ranges, "y");
selection.first.y = range.axis.p2c(range.from);
selection.second.y = range.axis.p2c(range.to);
}
......@@ -352,7 +351,6 @@ The plugin allso adds the following methods to the plot object:
plot.hooks.shutdown.push(function (plot, eventHolder) {
eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler) {
$(document).unbind("mouseup", mouseUpHandler);
}
......
......@@ -94,8 +94,7 @@ charts or filled areas).
newpoints.push(points[i + m]);
}
i += ps;
}
else if (j >= otherpoints.length) {
} else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if (!withlines) {
for (m = 0; m < ps; ++m) {
......@@ -103,16 +102,14 @@ charts or filled areas).
}
}
i += ps;
}
else if (otherpoints[j] == null) {
} else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m) {
newpoints.push(null);
}
fromgap = true;
j += otherps;
}
else {
} else {
// cases where we actually got two points
px = points[i + keyOffset];
py = points[i + accumulateOffset];
......@@ -130,8 +127,7 @@ charts or filled areas).
i += ps;
j += otherps;
}
else if (px > qx) {
} else if (px > qx) {
// we got past point below, might need to
// insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) {
......@@ -145,8 +141,7 @@ charts or filled areas).
}
j += otherps;
}
else { // px < qx
} else { // px < qx
if (fromgap && withlines) {
// if we come from a gap, we just skip this point
i += ps;
......
......@@ -49,8 +49,14 @@ You may need to check for this in hover events.
function init(plot) {
function thresholdData(plot, s, datapoints, below, color) {
var ps = datapoints.pointsize, i, x, y, p, prevp,
thresholded = $.extend({}, s); // note: shallow copy
var origpoints = datapoints.points,
ps = datapoints.pointsize,
addCrossingPoints = s.lines.show,
thresholded = $.extend({}, s), // note: shallow copy
threspoints = [],
newpoints = [],
prevp, i, x, y, p, m;
thresholded.datapoints = { points: [], pointsize: ps, format: datapoints.format };
thresholded.label = null;
......@@ -59,13 +65,6 @@ You may need to check for this in hover events.
thresholded.originSeries = s;
thresholded.data = [];
var origpoints = datapoints.points,
addCrossingPoints = s.lines.show;
var threspoints = [];
var newpoints = [];
var m;
for (i = 0; i < origpoints.length; i += ps) {
x = origpoints[i];
y = origpoints[i + 1];
......@@ -129,8 +128,7 @@ You may need to check for this in hover events.
$(s.threshold).each(function(i, th) {
thresholdData(plot, s, datapoints, th.below, th.color);
});
}
else {
} else {
thresholdData(plot, s, datapoints, s.threshold.below, s.threshold.color);
}
}
......
......@@ -40,10 +40,10 @@ API.txt for details.
return n.length === 1 ? pad + n : n;
};
var r = [];
var escape = false;
var hours = d.getHours();
var isAM = hours < 12;
var r = [],
escape = false,
hours = d.getHours(),
isAM = hours < 12;
if (monthNames == null) {
monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
......@@ -203,9 +203,9 @@ API.txt for details.
if (opts.mode === "time") {
axis.tickGenerator = function(axis) {
var ticks = [];
var d = dateGenerator(axis.min, opts);
var minSize = 0;
var ticks = [],
d = dateGenerator(axis.min, opts),
minSize = 0;
// make quarter use a possibility if quarters are
// mentioned in either of these options
......@@ -231,8 +231,8 @@ API.txt for details.
}
}
var size = spec[i][0];
var unit = spec[i][1];
var size = spec[i][0],
unit = spec[i][1];
// special-case the possibility of several years
......@@ -245,8 +245,8 @@ API.txt for details.
size = Math.floor(opts.minTickSize[0]);
} else {
var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10));
var norm = (axis.delta / timeUnitSize.year) / magn;
var magn = Math.pow(10, Math.floor(Math.log(axis.delta / timeUnitSize.year) / Math.LN10)),
norm = (axis.delta / timeUnitSize.year) / magn;
if (norm < 1.5) {
size = 1;
......@@ -315,9 +315,9 @@ API.txt for details.
d.setMonth(0);
}
var carry = 0;
var v = Number.NaN;
var prev;
var carry = 0,
v = Number.NaN,
prev;
do {
......@@ -370,13 +370,12 @@ API.txt for details.
var useQuarters = (axis.options.tickSize &&
axis.options.tickSize[1] === "quarter") ||
(axis.options.minTickSize &&
axis.options.minTickSize[1] === "quarter");
var t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]];
var span = axis.max - axis.min;
var suffix = (opts.twelveHourClock) ? " %p" : "";
var hourCode = (opts.twelveHourClock) ? "%I" : "%H";
var fmt;
axis.options.minTickSize[1] === "quarter"),
t = axis.tickSize[0] * timeUnitSize[axis.tickSize[1]],
span = axis.max - axis.min,
suffix = (opts.twelveHourClock) ? " %p" : "",
hourCode = (opts.twelveHourClock) ? "%I" : "%H",
fmt;
if (t < timeUnitSize.minute) {
fmt = hourCode + ":%M:%S" + suffix;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment