Commit b079efca authored by David Schnur's avatar David Schnur

Merge branch 'code-cleanup' into 0.9-work

Conflicts:
	jquery.flot.js
	jquery.flot.threshold.js
parents bb18e099 bd191efb
{
"bitwise": true,
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"forin": true,
"immed": true,
"noarg": true,
"quotmark": "double",
"smarttabs": true,
"trailing": true,
"undef": true,
"unused": true,
"globals": {
"timezoneJS": true
},
"browser": true,
"jquery": true
}
# Makefile for generating minified files
# Flot Makefile
.PHONY: all
# we cheat and process all .js files instead of an exhaustive list
# The default behavior is to minify all our JavaScript files
all: $(patsubst %.js,%.min.js,$(filter-out %.min.js,$(wildcard *.js)))
%.min.js: %.js
yui-compressor $< -o $@
# Flot's Travis test suite runs JSHint with the options in .jshintrc
test:
./node_modules/.bin/jshint *jquery.flot.js
./node_modules/.bin/jshint jquery.flot*.js
......@@ -32,14 +32,16 @@
o.a = a != null ? a : 1;
o.add = function (c, d) {
for (var i = 0; i < c.length; ++i)
for (var i = 0; i < c.length; ++i) {
o[c.charAt(i)] += d;
}
return o.normalize();
};
o.scale = function (c, f) {
for (var i = 0; i < c.length; ++i)
for (var i = 0; i < c.length; ++i) {
o[c.charAt(i)] *= f;
}
return o.normalize();
};
......@@ -56,9 +58,9 @@
return value < min ? min: (value > max ? max: value);
}
o.r = clamp(0, parseInt(o.r), 255);
o.g = clamp(0, parseInt(o.g), 255);
o.b = clamp(0, parseInt(o.b), 255);
o.r = clamp(0, parseInt(o.r, 10), 255);
o.g = clamp(0, parseInt(o.g, 10), 255);
o.b = clamp(0, parseInt(o.b, 10), 255);
o.a = clamp(0, o.a, 1);
return o;
};
......@@ -68,7 +70,7 @@
};
return o.normalize();
}
};
// extract CSS color property from element, going up in the DOM
// if it's "transparent"
......@@ -78,17 +80,19 @@
c = elem.css(css).toLowerCase();
// keep going until we find an element that has color, or
// we hit the body
if (c != '' && c != 'transparent')
if (c !== "" && c !== "transparent") {
break;
}
elem = elem.parent();
} while (!$.nodeName(elem.get(0), "body"));
// catch Safari's way of signalling transparent
if (c == "rgba(0, 0, 0, 0)")
if (c === "rgba(0, 0, 0, 0)") {
c = "transparent";
}
return $.color.parse(c);
}
};
// parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
// returns color object, if parsing failed, you get black (0, 0,
......@@ -97,39 +101,51 @@
var res, m = $.color.make;
// Look for rgb(num,num,num)
if (res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str))
res = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(str);
if (res) {
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
}
// Look for rgba(num,num,num,num)
if (res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
res = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
if (res) {
return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
}
// Look for rgb(num%,num%,num%)
if (res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str))
res = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(str);
if (res) {
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
}
// Look for rgba(num%,num%,num%,num)
if (res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str))
res = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(str);
if (res) {
return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
}
// Look for #a0b1c2
if (res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str))
res = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(str);
if (res) {
return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
}
// Look for #fff
if (res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str))
res = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(str);
if (res) {
return m(parseInt(res[1]+res[1], 16), parseInt(res[2]+res[2], 16), parseInt(res[3]+res[3], 16));
}
// Otherwise, we're most likely dealing with a named color
var name = $.trim(str).toLowerCase();
if (name == "transparent")
if (name === "transparent") {
return m(255, 255, 255, 0);
else {
} else {
// default to black
res = lookupColors[name] || [0, 0, 0];
return m(res[0], res[1], res[2]);
}
}
};
var lookupColors = {
aqua:[0,255,255],
......
This diff is collapsed.
......@@ -35,10 +35,6 @@ browser, but needs to redraw with canvas text when exporting as an image.
var render, getTextInfo, addText;
// Cache the prototype hasOwnProperty for faster access
var hasOwnProperty = Object.prototype.hasOwnProperty;
function init(plot, classes) {
var Canvas = classes.Canvas;
......@@ -70,14 +66,14 @@ browser, but needs to redraw with canvas text when exporting as an image.
context.textBaseline = "middle";
for (var layerKey in cache) {
if (hasOwnProperty.call(cache, layerKey)) {
if (Object.prototype.hasOwnProperty.call(cache, layerKey)) {
var layerCache = cache[layerKey];
for (var styleKey in layerCache) {
if (hasOwnProperty.call(layerCache, styleKey)) {
if (Object.prototype.hasOwnProperty.call(layerCache, styleKey)) {
var styleCache = layerCache[styleKey],
updateStyles = true;
for (var key in styleCache) {
if (hasOwnProperty.call(styleCache, key)) {
if (Object.prototype.hasOwnProperty.call(styleCache, key)) {
var info = styleCache[key],
positions = info.positions,
......@@ -103,7 +99,7 @@ browser, but needs to redraw with canvas text when exporting as an image.
}
}
if (positions.length == 0) {
if (positions.length === 0) {
delete styleCache[key];
}
}
......@@ -280,9 +276,9 @@ browser, but needs to redraw with canvas text when exporting as an image.
// Tweak the initial y-position to match vertical alignment
if (valign == "middle") {
if (valign === "middle") {
y = Math.round(y - info.height / 2);
} else if (valign == "bottom") {
} else if (valign === "bottom") {
y = Math.round(y - info.height);
} else {
y = Math.round(y);
......@@ -302,7 +298,7 @@ browser, but needs to redraw with canvas text when exporting as an image.
// If so, mark it for inclusion in the next render pass.
for (var i = 0, position; position = positions[i]; i++) {
if (position.x == x && position.y == y) {
if (position.x === x && position.y === y) {
position.active = true;
return;
}
......@@ -322,10 +318,10 @@ browser, but needs to redraw with canvas text when exporting as an image.
// Fill in the x & y positions of each line, adjusting them
// individually for horizontal alignment.
for (var i = 0, line; line = lines[i]; i++) {
if (halign == "center") {
for (var j = 0, line; line = lines[j]; j++) {
if (halign === "center") {
position.lines.push([Math.round(x - line.width / 2), y]);
} else if (halign == "right") {
} else if (halign === "right") {
position.lines.push([Math.round(x - line.width), y]);
} else {
position.lines.push([Math.round(x), y]);
......
......@@ -58,11 +58,12 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
// auto-transformation to numbers so the strings are intact
// for later processing
var xCategories = series.xaxis.options.mode == "categories",
yCategories = series.yaxis.options.mode == "categories";
var xCategories = series.xaxis.options.mode === "categories",
yCategories = series.yaxis.options.mode === "categories";
if (!(xCategories || yCategories))
if (!(xCategories || yCategories)) {
return;
}
var format = datapoints.format;
......@@ -86,31 +87,39 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
}
for (var m = 0; m < format.length; ++m) {
if (format[m].x && xCategories)
if (format[m].x && xCategories) {
format[m].number = false;
}
if (format[m].y && yCategories)
if (format[m].y && yCategories) {
format[m].number = false;
}
}
}
function getNextIndex(categories) {
var index = -1;
for (var v in categories)
if (categories[v] > index)
for (var v in categories) {
if (categories[v] > index) {
index = categories[v];
}
}
return index + 1;
}
function categoriesTickGenerator(axis) {
var res = [];
for (var label in axis.categories) {
var v = axis.categories[label];
if (v >= axis.min && v <= axis.max)
var res = [],
categories = axis.categories;
for (var label in categories) {
if (Object.prototype.hasOwnProperty.call(categories, label)) {
var v = categories[label];
if (v >= axis.min && v <= axis.max) {
res.push([v, label]);
}
}
}
res.sort(function (a, b) { return a[0] - b[0]; });
......@@ -118,27 +127,32 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
}
function setupCategoriesForAxis(series, axis, datapoints) {
if (series[axis].options.mode != "categories")
if (series[axis].options.mode !== "categories") {
return;
}
if (!series[axis].categories) {
// parse options
var c = {}, o = series[axis].options.categories || {};
if ($.isArray(o)) {
for (var i = 0; i < o.length; ++i)
for (var i = 0; i < o.length; ++i) {
c[o[i]] = i;
}
else {
for (var v in o)
} else {
for (var v in o) {
if (Object.prototype.hasOwnProperty.call(o, v)) {
c[v] = o[v];
}
}
}
series[axis].categories = c;
}
// fix ticks
if (!series[axis].options.ticks)
if (!series[axis].options.ticks) {
series[axis].options.ticks = categoriesTickGenerator;
}
transformPointsOnAxis(datapoints, axis, series[axis].categories);
}
......@@ -152,14 +166,16 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
index = getNextIndex(categories);
for (var i = 0; i < points.length; i += ps) {
if (points[i] == null)
if (points[i] == null) {
continue;
}
for (var m = 0; m < ps; ++m) {
var val = points[i + m];
if (val == null || !format[m][formatColumn])
if (val == null || !format[m][formatColumn]) {
continue;
}
if (!(val in categories)) {
categories[val] = index;
......@@ -184,7 +200,7 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
$.plot.plugins.push({
init: init,
options: options,
name: 'categories',
version: '1.0'
name: "categories",
version: "1.0"
});
})(jQuery);
......@@ -59,6 +59,7 @@ The plugin also adds four public methods:
*/
(function ($) {
var options = {
crosshair: {
mode: null, // one of null, "x", "y" or "xy",
......@@ -72,9 +73,9 @@ The plugin also adds four public methods:
var crosshair = { x: -1, y: -1, locked: false };
plot.setCrosshair = function setCrosshair(pos) {
if (!pos)
if (!pos) {
crosshair.x = -1;
else {
} else {
var o = plot.p2c(pos);
crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
......@@ -86,8 +87,9 @@ The plugin also adds four public methods:
plot.clearCrosshair = plot.setCrosshair; // passes null for pos
plot.lockCrosshair = function lockCrosshair(pos) {
if (pos)
if (pos) {
plot.setCrosshair(pos);
}
crosshair.locked = true;
};
......@@ -95,19 +97,21 @@ The plugin also adds four public methods:
crosshair.locked = false;
};
function onMouseOut(e) {
if (crosshair.locked)
function onMouseOut() {
if (crosshair.locked) {
return;
}
if (crosshair.x != -1) {
if (crosshair.x !== -1) {
crosshair.x = -1;
plot.triggerRedrawOverlay();
}
}
function onMouseMove(e) {
if (crosshair.locked)
if (crosshair.locked) {
return;
}
if (plot.getSelection && plot.getSelection()) {
crosshair.x = -1; // hide the crosshair while selecting
......@@ -121,8 +125,9 @@ The plugin also adds four public methods:
}
plot.hooks.bindEvents.push(function (plot, eventHolder) {
if (!plot.getOptions().crosshair.mode)
if (!plot.getOptions().crosshair.mode) {
return;
}
eventHolder.mouseout(onMouseOut);
eventHolder.mousemove(onMouseMove);
......@@ -130,15 +135,16 @@ The plugin also adds four public methods:
plot.hooks.drawOverlay.push(function (plot, ctx) {
var c = plot.getOptions().crosshair;
if (!c.mode)
if (!c.mode) {
return;
}
var plotOffset = plot.getPlotOffset();
ctx.save();
ctx.translate(plotOffset.left, plotOffset.top);
if (crosshair.x != -1) {
if (crosshair.x !== -1) {
var adj = plot.getOptions().crosshair.lineWidth % 2 === 0 ? 0 : 0.5;
ctx.strokeStyle = c.color;
......@@ -146,12 +152,12 @@ The plugin also adds four public methods:
ctx.lineJoin = "round";
ctx.beginPath();
if (c.mode.indexOf("x") != -1) {
if (c.mode.indexOf("x") !== -1) {
var drawX = Math.round(crosshair.x) + adj;
ctx.moveTo(drawX, 0);
ctx.lineTo(drawX, plot.height());
}
if (c.mode.indexOf("y") != -1) {
if (c.mode.indexOf("y") !== -1) {
var drawY = Math.round(crosshair.y) + adj;
ctx.moveTo(0, drawY);
ctx.lineTo(plot.width(), drawY);
......@@ -170,7 +176,8 @@ The plugin also adds four public methods:
$.plot.plugins.push({
init: init,
options: options,
name: 'crosshair',
version: '1.0'
name: "crosshair",
version: "1.0"
});
})(jQuery);
This diff is collapsed.
......@@ -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({
......
......@@ -71,14 +71,16 @@ Google Maps).
var defaultShow = options.series.images.show;
$.each(series, function (i, s) {
if (!(defaultShow || s.images.show))
if (!(defaultShow || s.images.show)) {
return;
}
if (s.data)
if (s.data) {
s = s.data;
}
$.each(s, function (i, p) {
if (typeof p[0] == "string") {
if (typeof p[0] === "string") {
urls.push(p[0]);
points.push(p);
}
......@@ -88,18 +90,20 @@ Google Maps).
$.plot.image.load(urls, function (loadedImages) {
$.each(points, function (i, p) {
var url = p[0];
if (loadedImages[url])
if (loadedImages[url]) {
p[0] = loadedImages[url];
}
});
callback();
});
}
};
$.plot.image.load = function (urls, callback) {
var missing = urls.length, loaded = {};
if (missing == 0)
if (missing === 0) {
callback({});
}
$.each(urls, function (i, url) {
var handler = function () {
......@@ -107,19 +111,21 @@ Google Maps).
loaded[url] = this;
if (missing == 0)
if (missing === 0) {
callback(loaded);
}
};
$('<img />').load(handler).error(handler).attr('src', url);
$("<img />").load(handler).error(handler).attr("src", url);
});
};
function drawSeries(plot, ctx, series) {
var plotOffset = plot.getPlotOffset();
if (!series.images || !series.images.show)
if (!series.images || !series.images.show) {
return;
}
var points = series.datapoints.points,
ps = series.datapoints.pointsize;
......@@ -134,8 +140,9 @@ Google Maps).
// actually we should check img.complete, but it
// appears to be a somewhat unreliable indicator in
// IE6 (false even after load event)
if (!img || img.width <= 0 || img.height <= 0)
if (!img || img.width <= 0 || img.height <= 0) {
continue;
}
if (x1 > x2) {
tmp = x2;
......@@ -150,7 +157,7 @@ Google Maps).
// if the anchor is at the center of the pixel, expand the
// image by 1/2 pixel in each direction
if (series.images.anchor == "center") {
if (series.images.anchor === "center") {
tmp = 0.5 * (x2-x1) / (img.width - 1);
x1 -= tmp;
x2 += tmp;
......@@ -160,10 +167,11 @@ Google Maps).
}
// clip
if (x1 == x2 || y1 == y2 ||
if (x1 === x2 || y1 === y2 ||
x1 >= xaxis.max || x2 <= xaxis.min ||
y1 >= yaxis.max || y2 <= yaxis.min)
y1 >= yaxis.max || y2 <= yaxis.min) {
continue;
}
var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height;
if (x1 < xaxis.min) {
......@@ -214,8 +222,9 @@ Google Maps).
}
function processRawData(plot, series, data, datapoints) {
if (!series.images.show)
if (!series.images.show) {
return;
}
// format is Image, x1, y1, x2, y2 (opposite corners)
datapoints.format = [
......@@ -235,7 +244,7 @@ Google Maps).
$.plot.plugins.push({
init: init,
options: options,
name: 'image',
version: '1.1'
name: "image",
version: "1.1"
});
})(jQuery);
This diff is collapsed.
This diff is collapsed.
......@@ -88,7 +88,7 @@ More detail and specific examples can be found in the included HTML file.
// set labels.show
if (options.series.pie.label.show == "auto") {
if (options.series.pie.label.show === "auto") {
if (options.legend.show) {
options.series.pie.label.show = false;
} else {
......@@ -98,7 +98,7 @@ More detail and specific examples can be found in the included HTML file.
// set radius
if (options.series.pie.radius == "auto") {
if (options.series.pie.radius === "auto") {
if (options.series.pie.label.show) {
options.series.pie.radius = 3/4;
} else {
......@@ -149,7 +149,7 @@ More detail and specific examples can be found in the included HTML file.
}
});
function processDatapoints(plot, series, datapoints) {
function processDatapoints(plot) {
if (!processed) {
processed = true;
canvas = plot.getCanvas();
......@@ -165,13 +165,14 @@ More detail and specific examples can be found in the included HTML file.
combined = 0,
numCombined = 0,
color = options.series.pie.combine.color,
newdata = [];
newdata = [],
i, value;
// Fix up the raw data from Flot, ensuring the data is numeric
for (var i = 0; i < data.length; ++i) {
for (i = 0; i < data.length; ++i) {
var value = data[i].data;
value = data[i].data;
// If the data is an array, we'll assume that it's a standard
// Flot x-y pair, and are concerned only with the second value.
......@@ -180,7 +181,7 @@ More detail and specific examples can be found in the included HTML file.
// new one; this is more efficient and preserves any extra data
// that the user may have stored in higher indexes.
if ($.isArray(value) && value.length == 1) {
if ($.isArray(value) && value.length === 1) {
value = value[0];
}
......@@ -202,15 +203,15 @@ More detail and specific examples can be found in the included HTML file.
// Sum up all the slices, so we can calculate percentages for each
for (var i = 0; i < data.length; ++i) {
for (i = 0; i < data.length; ++i) {
total += data[i].data[0][1];
}
// Count the number of slices with percentages below the combine
// threshold; if it turns out to be just one, we won't combine.
for (var i = 0; i < data.length; ++i) {
var value = data[i].data[0][1];
for (i = 0; i < data.length; ++i) {
value = data[i].data[0][1];
if (value / total <= options.series.pie.combine.threshold) {
combined += value;
numCombined++;
......@@ -220,8 +221,8 @@ More detail and specific examples can be found in the included HTML file.
}
}
for (var i = 0; i < data.length; ++i) {
var value = data[i].data[0][1];
for (i = 0; i < data.length; ++i) {
value = data[i].data[0][1];
if (numCombined < 2 || value / total > options.series.pie.combine.threshold) {
newdata.push({
data: [[1, value]],
......@@ -287,7 +288,7 @@ More detail and specific examples can be found in the included HTML file.
centerTop = canvasHeight / 2 + options.series.pie.offset.top;
centerLeft = canvasWidth / 2;
if (options.series.pie.offset.left == "auto") {
if (options.series.pie.offset.left === "auto") {
if (options.legend.position.match("w")) {
centerLeft += legendWidth / 2;
} else {
......@@ -318,7 +319,7 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.tilt <= 0.8) {
drawShadow();
}
} while (!drawPie() && attempts < REDRAW_ATTEMPTS)
} while (!drawPie() && attempts < REDRAW_ATTEMPTS);
if (attempts >= REDRAW_ATTEMPTS) {
clear();
......@@ -373,8 +374,9 @@ More detail and specific examples can be found in the included HTML file.
function drawPie() {
var startAngle = Math.PI * options.series.pie.startAngle;
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius;
var startAngle = Math.PI * options.series.pie.startAngle,
radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius,
i;
// center and rotate to starting position
......@@ -387,7 +389,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save();
var currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i) {
for (i = 0; i < slices.length; ++i) {
slices[i].startAngle = currentAngle;
drawSlice(slices[i].angle, slices[i].color, true);
}
......@@ -399,7 +401,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save();
ctx.lineWidth = options.series.pie.stroke.width;
currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i) {
for (i = 0; i < slices.length; ++i) {
drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
}
ctx.restore();
......@@ -415,7 +417,9 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.label.show) {
return drawLabels();
} else return true;
} else {
return true;
}
function drawSlice(angle, color, fill) {
......@@ -467,7 +471,7 @@ More detail and specific examples can be found in the included HTML file.
function drawLabel(slice, startAngle, index) {
if (slice.data[0][1] == 0) {
if (slice.data[0][1] === 0) {
return true;
}
......@@ -505,7 +509,7 @@ More detail and specific examples can be found in the included HTML file.
return false;
}
if (options.series.pie.label.background.opacity != 0) {
if (options.series.pie.label.background.opacity !== 0) {
// put in the transparent background separately to avoid blended labels and label boxes
......@@ -561,10 +565,12 @@ More detail and specific examples can be found in the included HTML file.
//-- Additional Interactive related functions --
function isPointInPoly(poly, pt) {
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) || (poly[j][1] <= pt[1] && pt[1]< poly[i][1]))
&& (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
&& (c = !c);
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) {
((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) ||
(poly[j][1] <= pt[1] && pt[1]< poly[i][1])) &&
(pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) &&
(c = !c);
}
return c;
}
......@@ -651,8 +657,8 @@ 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);
var canvasY = parseInt(e.pageY - offset.top);
var canvasX = parseInt(e.pageX - offset.left, 10);
var canvasY = parseInt(e.pageY - offset.top, 10);
var item = findNearbySlice(canvasX, canvasY);
if (options.grid.autoHighlight) {
......@@ -661,7 +667,7 @@ More detail and specific examples can be found in the included HTML file.
for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i];
if (h.auto == eventname && !(item && h.series == item.series)) {
if (h.auto === eventname && !(item && h.series === item.series)) {
unhighlight(h.series);
}
}
......@@ -686,7 +692,7 @@ More detail and specific examples can be found in the included HTML file.
var i = indexOfHighlight(s);
if (i == -1) {
if (i === -1) {
highlights.push({ series: s, auto: auto });
plot.triggerRedrawOverlay();
} else if (!auto) {
......@@ -706,7 +712,7 @@ More detail and specific examples can be found in the included HTML file.
var i = indexOfHighlight(s);
if (i != -1) {
if (i !== -1) {
highlights.splice(i, 1);
plot.triggerRedrawOverlay();
}
......@@ -715,9 +721,10 @@ More detail and specific examples can be found in the included HTML file.
function indexOfHighlight(s) {
for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i];
if (h.series == s)
if (h.series === s) {
return i;
}
}
return -1;
}
......
......@@ -11,17 +11,6 @@ can just fix the size of their placeholders.
*/
/* Inline dependency:
* jQuery resize event - v1.1 - 3/14/2010
* http://benalman.com/projects/jquery-resize-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,h,c){var a=$([]),e=$.resize=$.extend($.resize,{}),i,k="setTimeout",j="resize",d=j+"-special-event",b="delay",f="throttleWindow";e[b]=250;e[f]=true;$.event.special[j]={setup:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.add(l);$.data(this,d,{w:l.width(),h:l.height()});if(a.length===1){g()}},teardown:function(){if(!e[f]&&this[k]){return false}var l=$(this);a=a.not(l);l.removeData(d);if(!a.length){clearTimeout(i)}},add:function(l){if(!e[f]&&this[k]){return false}var n;function m(s,o,p){var q=$(this),r=$.data(this,d);r.w=o!==c?o:q.width();r.h=p!==c?p:q.height();n.apply(this,arguments)}if($.isFunction(l)){n=l;return m}else{n=l.handler;l.handler=m}}};function g(){i=h[k](function(){a.each(function(){var n=$(this),m=n.width(),l=n.height(),o=$.data(this,d);if(m!==o.w||l!==o.h){n.trigger(j,[o.w=m,o.h=l])}});g()},e[b])}})(jQuery,this);
(function ($) {
var options = { }; // no options
......@@ -31,19 +20,20 @@ can just fix the size of their placeholders.
// somebody might have hidden us and we can't plot
// when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0)
if (placeholder.width() === 0 || placeholder.height() === 0) {
return;
}
plot.resize();
plot.setupGrid();
plot.draw();
}
function bindEvents(plot, eventHolder) {
function bindEvents(plot) {
plot.getPlaceholder().resize(onResize);
}
function shutdown(plot, eventHolder) {
function shutdown(plot) {
plot.getPlaceholder().unbind("resize", onResize);
}
......@@ -54,7 +44,7 @@ can just fix the size of their placeholders.
$.plot.plugins.push({
init: init,
options: options,
name: 'resize',
version: '1.0'
name: "resize",
version: "1.0"
});
})(jQuery);
......@@ -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,21 +93,21 @@ 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() ]);
}
}
function onMouseDown(e) {
if (e.which != 1) // only accept left-click
if (e.which !== 1) { // only accept left-click
return;
}
// cancel out any text selections
document.body.focus();
......@@ -135,18 +137,20 @@ The plugin allso adds the following methods to the plot object:
mouseUpHandler = null;
// revert drag stuff for old-school browsers
if (document.onselectstart !== undefined)
if (document.onselectstart !== undefined) {
document.onselectstart = savedhandlers.onselectstart;
if (document.ondrag !== undefined)
}
if (document.ondrag !== undefined) {
document.ondrag = savedhandlers.ondrag;
}
// no more dragging
selection.active = false;
updateSelection(e);
if (selectionIsSane())
if (selectionIsSane()) {
triggerSelectedEvent();
else {
} else {
// this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotselecting", [ null ]);
......@@ -156,15 +160,19 @@ The plugin allso adds the following methods to the plot object:
}
function getSelection() {
if (!selectionIsSane())
if (!selectionIsSane() || !selection.show) {
return null;
}
if (!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) };
}
});
......@@ -177,47 +185,53 @@ The plugin allso adds the following methods to the plot object:
plot.getPlaceholder().trigger("plotselected", [ r ]);
// backwards-compat stuff, to be removed in future
if (r.xaxis && r.yaxis)
if (r.xaxis && r.yaxis) {
plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
}
}
function clamp(min, value, max) {
return value < min ? min: (value > max ? max: value);
}
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());
if (o.selection.mode == "y")
pos.x = pos == selection.first ? 0 : plot.width();
if (o.selection.mode === "y") {
pos.x = pos === selection.first ? 0 : plot.width();
}
if (o.selection.mode == "x")
pos.y = pos == selection.first ? 0 : plot.height();
if (o.selection.mode === "x") {
pos.y = pos === selection.first ? 0 : plot.height();
}
}
function updateSelection(pos) {
if (pos.pageX == null)
if (pos.pageX == null) {
return;
}
setSelectionPos(selection.second, pos);
if (selectionIsSane()) {
selection.show = true;
plot.triggerRedrawOverlay();
}
else
} else {
clearSelection(true);
}
}
function clearSelection(preventEvent) {
if (selection.show) {
selection.show = false;
plot.triggerRedrawOverlay();
if (!preventEvent)
plot.getPlaceholder().trigger("plotunselected", [ ]);
if (!preventEvent) {
plot.getPlaceholder().trigger("plotunselected", []);
}
}
}
......@@ -226,11 +240,13 @@ The plugin allso adds the following methods to the plot object:
var axis, from, to, key, axes = plot.getAxes();
for (var k in axes) {
if (Object.prototype.hasOwnProperty.call(axes, k)) {
axis = axes[k];
if (axis.direction == coord) {
if (axis.direction === coord) {
key = coord + axis.n + "axis";
if (!ranges[key] && axis.n == 1)
if (!ranges[key] && axis.n === 1) {
key = coord + "axis"; // support x1axis as xaxis
}
if (ranges[key]) {
from = ranges[key].from;
to = ranges[key].to;
......@@ -238,10 +254,11 @@ The plugin allso adds the following methods to the plot object:
}
}
}
}
// backwards-compat stuff - to be removed in future
if (!ranges[key]) {
axis = coord == "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
axis = coord === "x" ? plot.getXAxes()[0] : plot.getYAxes()[0];
from = ranges[coord + "1"];
to = ranges[coord + "2"];
}
......@@ -257,35 +274,32 @@ The plugin allso adds the following methods to the plot object:
}
function setSelection(ranges, preventEvent) {
var axis, range, o = plot.getOptions();
var range, o = plot.getOptions();
if (o.selection.mode == "y") {
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);
}
if (o.selection.mode == "x") {
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);
}
selection.show = true;
plot.triggerRedrawOverlay();
if (!preventEvent && selectionIsSane())
if (!preventEvent && selectionIsSane()) {
triggerSelectedEvent();
}
}
function selectionIsSane() {
var minSize = plot.getOptions().selection.minSize;
......@@ -317,10 +331,10 @@ The plugin allso adds the following methods to the plot object:
var c = $.color.parse(o.selection.color);
ctx.strokeStyle = c.scale('a', 0.8).toString();
ctx.strokeStyle = c.scale("a", 0.8).toString();
ctx.lineWidth = 1;
ctx.lineJoin = o.selection.shape;
ctx.fillStyle = c.scale('a', 0.4).toString();
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,
......@@ -337,9 +351,9 @@ 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)
if (mouseUpHandler) {
$(document).unbind("mouseup", mouseUpHandler);
}
});
}
......@@ -354,7 +368,7 @@ The plugin allso adds the following methods to the plot object:
minSize: 5 // minimum number of pixels
}
},
name: 'selection',
version: '1.1'
name: "selection",
version: "1.1"
});
})(jQuery);
......@@ -44,23 +44,27 @@ charts or filled areas).
function findMatchingSeries(s, allseries) {
var res = null;
for (var i = 0; i < allseries.length; ++i) {
if (s == allseries[i])
if (s === allseries[i]) {
break;
}
if (allseries[i].stack == s.stack)
if (allseries[i].stack === s.stack) {
res = allseries[i];
}
}
return res;
}
function stackData(plot, s, datapoints) {
if (s.stack == null || s.stack === false)
if (s.stack == null || s.stack === false) {
return;
}
var other = findMatchingSeries(s, plot.getData());
if (!other)
if (!other) {
return;
}
var ps = datapoints.pointsize,
points = datapoints.points,
......@@ -78,33 +82,34 @@ charts or filled areas).
i = 0, j = 0, l, m;
while (true) {
if (i >= points.length)
if (i >= points.length) {
break;
}
l = newpoints.length;
if (points[i] == null) {
// copy gaps
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
i += ps;
}
else if (j >= otherpoints.length) {
i += ps;
} else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points
if (!withlines) {
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
i += ps;
}
else if (otherpoints[j] == null) {
i += ps;
} else if (otherpoints[j] == null) {
// oops, got a gap
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(null);
}
fromgap = true;
j += otherps;
}
else {
} else {
// cases where we actually got two points
px = points[i + keyOffset];
py = points[i + accumulateOffset];
......@@ -112,44 +117,46 @@ charts or filled areas).
qy = otherpoints[j + accumulateOffset];
bottom = 0;
if (px == qx) {
for (m = 0; m < ps; ++m)
if (px === qx) {
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
newpoints[l + accumulateOffset] += 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 + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx);
newpoints.push(intery + qy);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
newpoints.push(points[i + m]);
}
bottom = qy;
}
j += otherps;
}
else { // px < qx
} else { // px < qx
if (fromgap && withlines) {
// if we come from a gap, we just skip this point
i += ps;
continue;
}
for (m = 0; m < ps; ++m)
for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]);
}
// we might be able to interpolate a point below,
// this can give us a better y
if (withlines && j > 0 && otherpoints[j - otherps] != null)
if (withlines && j > 0 && otherpoints[j - otherps] != null) {
bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
}
newpoints[l + accumulateOffset] += bottom;
......@@ -158,17 +165,19 @@ charts or filled areas).
fromgap = false;
if (l != newpoints.length && withbottom)
if (l !== newpoints.length && withbottom) {
newpoints[l + 2] += bottom;
}
}
// maintain the line steps invariant
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)
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 + 1] = newpoints[l - ps + 1];
}
}
......@@ -182,7 +191,7 @@ charts or filled areas).
$.plot.plugins.push({
init: init,
options: options,
name: 'stack',
version: '1.2'
name: "stack",
version: "1.2"
});
})(jQuery);
......@@ -14,17 +14,17 @@ The symbols are accessed as strings through the standard symbol options:
*/
(function ($) {
function processRawData(plot, series, datapoints) {
function processRawData(plot, series) {
// we normalize the area of each symbol so it is approximately the
// same as a circle of the given radius
var handlers = {
square: function (ctx, x, y, radius, shadow) {
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, shadow) {
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);
......@@ -44,7 +44,7 @@ The symbols are accessed as strings through the standard symbol options:
ctx.lineTo(x - size/2, y + height/2);
}
},
cross: function (ctx, x, y, radius, shadow) {
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);
......@@ -55,9 +55,10 @@ The symbols are accessed as strings through the standard symbol options:
};
var s = series.points.symbol;
if (handlers[s])
if (handlers[s]) {
series.points.symbol = handlers[s];
}
}
function init(plot) {
plot.hooks.processDatapoints.push(processRawData);
......@@ -65,7 +66,7 @@ The symbols are accessed as strings through the standard symbol options:
$.plot.plugins.push({
init: init,
name: 'symbols',
version: '1.0'
name: "symbols",
version: "1.0"
});
})(jQuery);
......@@ -50,8 +50,14 @@ You may need to check for this in hover events.
function init(plot) {
function thresholdData(plot, s, datapoints, below, above, 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;
......@@ -60,46 +66,43 @@ 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];
prevp = p;
if (y < below || y > above)
if (y < below || y > above) {
p = threspoints;
else
} else {
p = newpoints;
}
if (addCrossingPoints && prevp != p && x != null
&& i > 0 && origpoints[i - ps] != null) {
if (addCrossingPoints && prevp !== p && x != null && i > 0 && origpoints[i - ps] != null) {
var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]);
prevp.push(interx);
prevp.push(below);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
prevp.push(origpoints[i + m]);
}
p.push(null); // start new segment
p.push(null);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
p.push(interx);
p.push(below);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
}
p.push(x);
p.push(y);
for (m = 2; m < ps; ++m)
for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]);
}
}
datapoints.points = newpoints;
thresholded.datapoints.points = threspoints;
......@@ -114,8 +117,9 @@ You may need to check for this in hover events.
}
function processThresholds(plot, s, datapoints) {
if (!s.threshold)
if (!s.threshold) {
return;
}
if (s.threshold instanceof Array) {
s.threshold.sort(function(a, b) {
......@@ -125,8 +129,7 @@ You may need to check for this in hover events.
$(s.threshold).each(function(i, th) {
thresholdData(plot, s, datapoints, th.below, th.above, th.color);
});
}
else {
} else {
thresholdData(plot, s, datapoints, s.threshold.below, s.threshold.above, s.threshold.color);
}
}
......@@ -137,7 +140,7 @@ You may need to check for this in hover events.
$.plot.plugins.push({
init: init,
options: options,
name: 'threshold',
version: '1.3'
name: "threshold",
version: "1.3"
});
})(jQuery);
......@@ -30,20 +30,20 @@ API.txt for details.
function formatDate(d, fmt, monthNames, dayNames) {
if (typeof d.strftime == "function") {
if ($.isFunction(d.strftime)) {
return d.strftime(fmt);
}
var leftPad = function(n, pad) {
n = "" + n;
pad = "" + (pad == null ? "0" : pad);
return n.length == 1 ? pad + n : n;
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"];
......@@ -57,7 +57,7 @@ API.txt for details.
if (hours > 12) {
hours12 = hours - 12;
} else if (hours == 0) {
} else if (hours === 0) {
hours12 = 12;
} else {
hours12 = hours;
......@@ -69,30 +69,30 @@ API.txt for details.
if (escape) {
switch (c) {
case 'a': c = "" + dayNames[d.getDay()]; break;
case 'b': c = "" + monthNames[d.getMonth()]; break;
case 'd': c = leftPad(d.getDate()); break;
case 'e': c = leftPad(d.getDate(), " "); break;
case 'h': // For back-compat with 0.7; remove in 1.0
case 'H': c = leftPad(hours); break;
case 'I': c = leftPad(hours12); break;
case 'l': c = leftPad(hours12, " "); break;
case 'm': c = leftPad(d.getMonth() + 1); break;
case 'M': c = leftPad(d.getMinutes()); break;
case "a": c = "" + dayNames[d.getDay()]; break;
case "b": c = "" + monthNames[d.getMonth()]; break;
case "d": c = leftPad(d.getDate()); break;
case "e": c = leftPad(d.getDate(), " "); break;
case "h": // For back-compat with 0.7; remove in 1.0
case "H": c = leftPad(hours); break;
case "I": c = leftPad(hours12); break;
case "l": c = leftPad(hours12, " "); break;
case "m": c = leftPad(d.getMonth() + 1); break;
case "M": c = leftPad(d.getMinutes()); break;
// quarters not in Open Group's strftime specification
case 'q':
case "q":
c = "" + (Math.floor(d.getMonth() / 3) + 1); break;
case 'S': c = leftPad(d.getSeconds()); break;
case 'y': c = leftPad(d.getFullYear() % 100); break;
case 'Y': c = "" + d.getFullYear(); break;
case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;
case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
case 'w': c = "" + d.getDay(); break;
case "S": c = leftPad(d.getSeconds()); break;
case "y": c = leftPad(d.getFullYear() % 100); break;
case "Y": c = "" + d.getFullYear(); break;
case "p": c = (isAM) ? ("" + "am") : ("" + "pm"); break;
case "P": c = (isAM) ? ("" + "AM") : ("" + "PM"); break;
case "w": c = "" + d.getDay(); break;
}
r.push(c);
escape = false;
} else {
if (c == "%") {
if (c === "%") {
escape = true;
} else {
r.push(c);
......@@ -114,7 +114,7 @@ API.txt for details.
sourceObj[sourceMethod] = function() {
return targetObj[targetMethod].apply(targetObj, arguments);
};
};
}
var utc = {
date: d
......@@ -122,7 +122,7 @@ API.txt for details.
// support strftime, if found
if (d.strftime != undefined) {
if (d.strftime !== undefined) {
addProxyMethod(utc, "strftime", d, "strftime");
}
......@@ -137,17 +137,17 @@ API.txt for details.
}
return utc;
};
}
// select time zone strategy. This returns a date-like object tied to the
// desired timezone
function dateGenerator(ts, opts) {
if (opts.timezone == "browser") {
if (opts.timezone === "browser") {
return new Date(ts);
} else if (!opts.timezone || opts.timezone == "utc") {
} else if (!opts.timezone || opts.timezone === "utc") {
return makeUtcWrapper(new Date(ts));
} else if (typeof timezoneJS != "undefined" && typeof timezoneJS.Date != "undefined") {
} else if (typeof timezoneJS !== "undefined" && typeof timezoneJS.Date !== "undefined") {
var d = new timezoneJS.Date();
// timezone-js is fickle, so be sure to set the time zone before
// setting the time.
......@@ -195,17 +195,17 @@ API.txt for details.
[1, "year"]]);
function init(plot) {
plot.hooks.processOptions.push(function (plot, options) {
plot.hooks.processOptions.push(function (plot) {
$.each(plot.getAxes(), function(axisName, axis) {
var opts = axis.options;
if (opts.mode == "time") {
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
......@@ -216,7 +216,7 @@ API.txt for details.
"quarter") ? specQuarters : specMonths;
if (opts.minTickSize != null) {
if (typeof opts.tickSize == "number") {
if (typeof opts.tickSize === "number") {
minSize = opts.tickSize;
} else {
minSize = opts.minTickSize[0] * timeUnitSize[opts.minTickSize[1]];
......@@ -224,29 +224,29 @@ API.txt for details.
}
for (var i = 0; i < spec.length - 1; ++i) {
if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]]
+ spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2
&& spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) {
if (axis.delta < (spec[i][0] * timeUnitSize[spec[i][1]] +
spec[i + 1][0] * timeUnitSize[spec[i + 1][1]]) / 2 &&
spec[i][0] * timeUnitSize[spec[i][1]] >= minSize) {
break;
}
}
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
if (unit == "year") {
if (unit === "year") {
// if given a minTickSize in years, just use it,
// ensuring that it's an integer
if (opts.minTickSize != null && opts.minTickSize[1] == "year") {
if (opts.minTickSize != null && opts.minTickSize[1] === "year") {
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;
......@@ -274,18 +274,18 @@ API.txt for details.
var step = tickSize * timeUnitSize[unit];
if (unit == "second") {
if (unit === "second") {
d.setSeconds(floorInBase(d.getSeconds(), tickSize));
} else if (unit == "minute") {
} else if (unit === "minute") {
d.setMinutes(floorInBase(d.getMinutes(), tickSize));
} else if (unit == "hour") {
} else if (unit === "hour") {
d.setHours(floorInBase(d.getHours(), tickSize));
} else if (unit == "month") {
} else if (unit === "month") {
d.setMonth(floorInBase(d.getMonth(), tickSize));
} else if (unit == "quarter") {
} else if (unit === "quarter") {
d.setMonth(3 * floorInBase(d.getMonth() / 3,
tickSize));
} else if (unit == "year") {
} else if (unit === "year") {
d.setFullYear(floorInBase(d.getFullYear(), tickSize));
}
......@@ -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 {
......@@ -325,7 +325,7 @@ API.txt for details.
v = d.getTime();
ticks.push(v);
if (unit == "month" || unit == "quarter") {
if (unit === "month" || unit === "quarter") {
if (tickSize < 1) {
// a bit complicated - we'll divide the
......@@ -335,22 +335,21 @@ API.txt for details.
d.setDate(1);
var start = d.getTime();
d.setMonth(d.getMonth() +
(unit == "quarter" ? 3 : 1));
d.setMonth(d.getMonth() + (unit === "quarter" ? 3 : 1));
var end = d.getTime();
d.setTime(v + carry * timeUnitSize.hour + (end - start) * tickSize);
carry = d.getHours();
d.setHours(0);
} else {
d.setMonth(d.getMonth() +
tickSize * (unit == "quarter" ? 3 : 1));
tickSize * (unit === "quarter" ? 3 : 1));
}
} else if (unit == "year") {
} else if (unit === "year") {
d.setFullYear(d.getFullYear() + tickSize);
} else {
d.setTime(v + step);
}
} while (v < axis.max && v != prev);
} while (v < axis.max && v !== prev);
return ticks;
};
......@@ -369,15 +368,14 @@ API.txt for details.
// any of these places
var useQuarters = (axis.options.tickSize &&
axis.options.tickSize[1] == "quarter") ||
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;
......@@ -418,8 +416,8 @@ API.txt for details.
$.plot.plugins.push({
init: init,
options: options,
name: 'time',
version: '1.0'
name: "time",
version: "1.0"
});
// Time-axis support used to be in Flot core, which exposed the
......
/*! Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
* Thanks to: Seamus Leahy for adding deltaX and deltaY
*
* Version: 3.1.3
*
* Requires: 1.2.2+
*/
(function (factory) {
if ( typeof define === 'function' && define.amd ) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS style for Browserify
module.exports = factory;
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'];
var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'];
var lowestDelta, lowestDeltaXY;
if ( $.event.fixHooks ) {
for ( var i = toFix.length; i; ) {
$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;
}
}
$.event.special.mousewheel = {
setup: function() {
if ( this.addEventListener ) {
for ( var i = toBind.length; i; ) {
this.addEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = handler;
}
},
teardown: function() {
if ( this.removeEventListener ) {
for ( var i = toBind.length; i; ) {
this.removeEventListener( toBind[--i], handler, false );
}
} else {
this.onmousewheel = null;
}
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
},
unmousewheel: function(fn) {
return this.unbind("mousewheel", fn);
}
});
function handler(event) {
var orgEvent = event || window.event,
args = [].slice.call(arguments, 1),
delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0,
absDeltaXY = 0,
fn;
event = $.event.fix(orgEvent);
event.type = "mousewheel";
// Old school scrollwheel delta
if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; }
if ( orgEvent.detail ) { delta = orgEvent.detail * -1; }
// New school wheel delta (wheel event)
if ( orgEvent.deltaY ) {
deltaY = orgEvent.deltaY * -1;
delta = deltaY;
}
if ( orgEvent.deltaX ) {
deltaX = orgEvent.deltaX;
delta = deltaX * -1;
}
// Webkit
if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; }
if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX * -1; }
// Look for lowest delta to normalize the delta values
absDelta = Math.abs(delta);
if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; }
absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX));
if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; }
// Get a whole value for the deltas
fn = delta > 0 ? 'floor' : 'ceil';
delta = Math[fn](delta / lowestDelta);
deltaX = Math[fn](deltaX / lowestDeltaXY);
deltaY = Math[fn](deltaY / lowestDeltaXY);
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
}));
This diff is collapsed.
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