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
/* 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.
......@@ -18,7 +18,7 @@
*
* V. 1.1: Fix error handling so e.g. parsing an empty string does
* produce a color rather than just crashing.
*/
*/
(function($) {
$.color = {};
......@@ -32,17 +32,19 @@
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();
};
o.toString = function () {
if (o.a >= 1.0) {
return "rgb("+[o.r, o.g, o.b].join(",")+")";
......@@ -55,10 +57,10 @@
function clamp(min, value, max) {
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,18 +80,20 @@
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,
// 0) out
......@@ -97,40 +101,52 @@
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],
azure:[240,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]);
......
......@@ -52,17 +52,18 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
categories: null
}
};
function processRawData(plot, series, data, datapoints) {
// if categories are enabled, we need to disable
// 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";
if (!(xCategories || yCategories))
var xCategories = series.xaxis.options.mode === "categories",
yCategories = series.yaxis.options.mode === "categories";
if (!(xCategories || yCategories)) {
return;
}
var format = datapoints.format;
......@@ -81,68 +82,81 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
format[format.length - 1].x = true;
}
}
datapoints.format = format;
}
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)
res.push([v, label]);
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]; });
return res;
}
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) {
if (Object.prototype.hasOwnProperty.call(o, v)) {
c[v] = o[v];
}
}
}
else {
for (var v in o)
c[v] = o[v];
}
series[axis].categories = c;
}
// fix ticks
if (!series[axis].options.ticks)
if (!series[axis].options.ticks) {
series[axis].options.ticks = categoriesTickGenerator;
}
transformPointsOnAxis(datapoints, axis, series[axis].categories);
}
function transformPointsOnAxis(datapoints, axis, categories) {
// go through the points, transforming them
var points = datapoints.points,
......@@ -152,20 +166,22 @@ 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;
++index;
}
points[i + m] = categories[val];
}
}
......@@ -180,11 +196,11 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
plot.hooks.processRawData.push(processRawData);
plot.hooks.processDatapoints.push(processDatapoints);
}
$.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",
......@@ -66,28 +67,29 @@ The plugin also adds four public methods:
lineWidth: 1
}
};
function init(plot) {
// position of crosshair in pixels
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()));
}
plot.triggerRedrawOverlay();
};
plot.clearCrosshair = plot.setCrosshair; // passes null for pos
plot.lockCrosshair = function lockCrosshair(pos) {
if (pos)
if (pos) {
plot.setCrosshair(pos);
}
crosshair.locked = true;
};
......@@ -95,34 +97,37 @@ 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
return;
}
var offset = plot.offset();
crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width()));
crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
plot.triggerRedrawOverlay();
}
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);
......@@ -166,11 +172,12 @@ The plugin also adds four public methods:
eventHolder.unbind("mousemove", onMouseMove);
});
}
$.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({
......
......@@ -69,16 +69,18 @@ Google Maps).
var urls = [], points = [];
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,42 +90,46 @@ 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 () {
--missing;
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;
for (var i = 0; i < points.length; i += ps) {
var img = points[i],
x1 = points[i + 1], y1 = points[i + 2],
......@@ -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;
......@@ -147,10 +154,10 @@ Google Maps).
y2 = y1;
y1 = tmp;
}
// if the anchor is at the center of the pixel, expand the
// 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;
......@@ -158,12 +165,13 @@ Google Maps).
y1 -= tmp;
y2 += tmp;
}
// 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) {
......@@ -185,12 +193,12 @@ Google Maps).
sy1 += (sy1 - sy2) * (yaxis.max - y2) / (y2 - y1);
y2 = yaxis.max;
}
x1 = xaxis.p2c(x1);
x2 = xaxis.p2c(x2);
y1 = yaxis.p2c(y1);
y2 = yaxis.p2c(y2);
// the transformation may have swapped us
if (x1 > x2) {
tmp = x2;
......@@ -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 = [
......@@ -226,16 +235,16 @@ Google Maps).
{ y: true, number: true, required: true }
];
}
function init(plot) {
plot.hooks.processRawData.push(processRawData);
plot.hooks.drawSeries.push(drawSeries);
}
$.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,8 +181,8 @@ 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) {
value = value[0];
if ($.isArray(value) && value.length === 1) {
value = value[0];
}
if ($.isArray(value)) {
......@@ -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,8 +721,9 @@ More detail and specific examples can be found in the included HTML file.
function indexOfHighlight(s) {
for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i];
if (h.series == s)
if (h.series === s) {
return i;
}
}
return -1;
}
......
......@@ -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,30 +20,31 @@ 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);
}
plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown);
}
$.plot.plugins.push({
init: init,
options: options,
name: 'resize',
version: '1.0'
name: "resize",
version: "1.0"
});
})(jQuery);
This diff is collapsed.
......@@ -39,28 +39,32 @@ charts or filled areas).
var options = {
series: { stack: null } // or number/string
};
function init(plot) {
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) {
} 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) {
} 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,77 +117,81 @@ 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;
}
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;
i += ps;
}
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];
}
}
datapoints.points = newpoints;
}
plot.hooks.processDatapoints.push(stackData);
}
$.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,17 +55,18 @@ 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);
}
$.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,45 +66,42 @@ 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;
......@@ -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);
This diff is collapsed.
/*! 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