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 .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))) all: $(patsubst %.js,%.min.js,$(filter-out %.min.js,$(wildcard *.js)))
%.min.js: %.js %.min.js: %.js
yui-compressor $< -o $@ yui-compressor $< -o $@
# Flot's Travis test suite runs JSHint with the options in .jshintrc
test: test:
./node_modules/.bin/jshint *jquery.flot.js ./node_modules/.bin/jshint jquery.flot*.js
/* Plugin for jQuery for working with colors. /* Plugin for jQuery for working with colors.
* *
* Version 1.1. * Version 1.1.
* *
* Inspiration from jQuery color animation plugin by John Resig. * Inspiration from jQuery color animation plugin by John Resig.
* *
* Released under the MIT license by Ole Laursen, October 2009. * Released under the MIT license by Ole Laursen, October 2009.
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* V. 1.1: Fix error handling so e.g. parsing an empty string does * V. 1.1: Fix error handling so e.g. parsing an empty string does
* produce a color rather than just crashing. * produce a color rather than just crashing.
*/ */
(function($) { (function($) {
$.color = {}; $.color = {};
...@@ -32,17 +32,19 @@ ...@@ -32,17 +32,19 @@
o.a = a != null ? a : 1; o.a = a != null ? a : 1;
o.add = function (c, d) { 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; o[c.charAt(i)] += d;
}
return o.normalize(); return o.normalize();
}; };
o.scale = function (c, f) { 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; o[c.charAt(i)] *= f;
}
return o.normalize(); return o.normalize();
}; };
o.toString = function () { o.toString = function () {
if (o.a >= 1.0) { if (o.a >= 1.0) {
return "rgb("+[o.r, o.g, o.b].join(",")+")"; return "rgb("+[o.r, o.g, o.b].join(",")+")";
...@@ -55,10 +57,10 @@ ...@@ -55,10 +57,10 @@
function clamp(min, value, max) { function clamp(min, value, max) {
return value < min ? min: (value > max ? max: value); return value < min ? min: (value > max ? max: value);
} }
o.r = clamp(0, parseInt(o.r), 255); o.r = clamp(0, parseInt(o.r, 10), 255);
o.g = clamp(0, parseInt(o.g), 255); o.g = clamp(0, parseInt(o.g, 10), 255);
o.b = clamp(0, parseInt(o.b), 255); o.b = clamp(0, parseInt(o.b, 10), 255);
o.a = clamp(0, o.a, 1); o.a = clamp(0, o.a, 1);
return o; return o;
}; };
...@@ -68,7 +70,7 @@ ...@@ -68,7 +70,7 @@
}; };
return o.normalize(); return o.normalize();
} };
// extract CSS color property from element, going up in the DOM // extract CSS color property from element, going up in the DOM
// if it's "transparent" // if it's "transparent"
...@@ -78,18 +80,20 @@ ...@@ -78,18 +80,20 @@
c = elem.css(css).toLowerCase(); c = elem.css(css).toLowerCase();
// keep going until we find an element that has color, or // keep going until we find an element that has color, or
// we hit the body // we hit the body
if (c != '' && c != 'transparent') if (c !== "" && c !== "transparent") {
break; break;
}
elem = elem.parent(); elem = elem.parent();
} while (!$.nodeName(elem.get(0), "body")); } while (!$.nodeName(elem.get(0), "body"));
// catch Safari's way of signalling transparent // catch Safari's way of signalling transparent
if (c == "rgba(0, 0, 0, 0)") if (c === "rgba(0, 0, 0, 0)") {
c = "transparent"; c = "transparent";
}
return $.color.parse(c); return $.color.parse(c);
} };
// parse CSS color string (like "rgb(10, 32, 43)" or "#fff"), // parse CSS color string (like "rgb(10, 32, 43)" or "#fff"),
// returns color object, if parsing failed, you get black (0, 0, // returns color object, if parsing failed, you get black (0, 0,
// 0) out // 0) out
...@@ -97,40 +101,52 @@ ...@@ -97,40 +101,52 @@
var res, m = $.color.make; var res, m = $.color.make;
// Look for rgb(num,num,num) // 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)); return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
}
// Look for rgba(num,num,num,num) // 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])); return m(parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10), parseFloat(res[4]));
}
// Look for rgb(num%,num%,num%) // 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); return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55);
}
// Look for rgba(num%,num%,num%,num) // 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])); return m(parseFloat(res[1])*2.55, parseFloat(res[2])*2.55, parseFloat(res[3])*2.55, parseFloat(res[4]));
}
// Look for #a0b1c2 // 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)); return m(parseInt(res[1], 16), parseInt(res[2], 16), parseInt(res[3], 16));
}
// Look for #fff // 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)); 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 // Otherwise, we're most likely dealing with a named color
var name = $.trim(str).toLowerCase(); var name = $.trim(str).toLowerCase();
if (name == "transparent") if (name === "transparent") {
return m(255, 255, 255, 0); return m(255, 255, 255, 0);
else { } else {
// default to black // default to black
res = lookupColors[name] || [0, 0, 0]; res = lookupColors[name] || [0, 0, 0];
return m(res[0], res[1], res[2]); return m(res[0], res[1], res[2]);
} }
} };
var lookupColors = { var lookupColors = {
aqua:[0,255,255], aqua:[0,255,255],
azure:[240,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. ...@@ -35,10 +35,6 @@ browser, but needs to redraw with canvas text when exporting as an image.
var render, getTextInfo, addText; var render, getTextInfo, addText;
// Cache the prototype hasOwnProperty for faster access
var hasOwnProperty = Object.prototype.hasOwnProperty;
function init(plot, classes) { function init(plot, classes) {
var Canvas = classes.Canvas; var Canvas = classes.Canvas;
...@@ -70,14 +66,14 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -70,14 +66,14 @@ browser, but needs to redraw with canvas text when exporting as an image.
context.textBaseline = "middle"; context.textBaseline = "middle";
for (var layerKey in cache) { for (var layerKey in cache) {
if (hasOwnProperty.call(cache, layerKey)) { if (Object.prototype.hasOwnProperty.call(cache, layerKey)) {
var layerCache = cache[layerKey]; var layerCache = cache[layerKey];
for (var styleKey in layerCache) { for (var styleKey in layerCache) {
if (hasOwnProperty.call(layerCache, styleKey)) { if (Object.prototype.hasOwnProperty.call(layerCache, styleKey)) {
var styleCache = layerCache[styleKey], var styleCache = layerCache[styleKey],
updateStyles = true; updateStyles = true;
for (var key in styleCache) { for (var key in styleCache) {
if (hasOwnProperty.call(styleCache, key)) { if (Object.prototype.hasOwnProperty.call(styleCache, key)) {
var info = styleCache[key], var info = styleCache[key],
positions = info.positions, positions = info.positions,
...@@ -103,7 +99,7 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -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]; delete styleCache[key];
} }
} }
...@@ -280,9 +276,9 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -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 // Tweak the initial y-position to match vertical alignment
if (valign == "middle") { if (valign === "middle") {
y = Math.round(y - info.height / 2); y = Math.round(y - info.height / 2);
} else if (valign == "bottom") { } else if (valign === "bottom") {
y = Math.round(y - info.height); y = Math.round(y - info.height);
} else { } else {
y = Math.round(y); y = Math.round(y);
...@@ -302,7 +298,7 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -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. // If so, mark it for inclusion in the next render pass.
for (var i = 0, position; position = positions[i]; i++) { 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; position.active = true;
return; return;
} }
...@@ -322,10 +318,10 @@ browser, but needs to redraw with canvas text when exporting as an image. ...@@ -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 // Fill in the x & y positions of each line, adjusting them
// individually for horizontal alignment. // individually for horizontal alignment.
for (var i = 0, line; line = lines[i]; i++) { for (var j = 0, line; line = lines[j]; j++) {
if (halign == "center") { if (halign === "center") {
position.lines.push([Math.round(x - line.width / 2), y]); 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]); position.lines.push([Math.round(x - line.width), y]);
} else { } else {
position.lines.push([Math.round(x), y]); position.lines.push([Math.round(x), y]);
......
...@@ -52,17 +52,18 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -52,17 +52,18 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
categories: null categories: null
} }
}; };
function processRawData(plot, series, data, datapoints) { function processRawData(plot, series, data, datapoints) {
// if categories are enabled, we need to disable // if categories are enabled, we need to disable
// auto-transformation to numbers so the strings are intact // auto-transformation to numbers so the strings are intact
// for later processing // for later processing
var xCategories = series.xaxis.options.mode == "categories", var xCategories = series.xaxis.options.mode === "categories",
yCategories = series.yaxis.options.mode == "categories"; yCategories = series.yaxis.options.mode === "categories";
if (!(xCategories || yCategories)) if (!(xCategories || yCategories)) {
return; return;
}
var format = datapoints.format; var format = datapoints.format;
...@@ -81,68 +82,81 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -81,68 +82,81 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
format[format.length - 1].x = true; format[format.length - 1].x = true;
} }
} }
datapoints.format = format; datapoints.format = format;
} }
for (var m = 0; m < format.length; ++m) { for (var m = 0; m < format.length; ++m) {
if (format[m].x && xCategories) if (format[m].x && xCategories) {
format[m].number = false; format[m].number = false;
}
if (format[m].y && yCategories)
if (format[m].y && yCategories) {
format[m].number = false; format[m].number = false;
}
} }
} }
function getNextIndex(categories) { function getNextIndex(categories) {
var index = -1; var index = -1;
for (var v in categories) for (var v in categories) {
if (categories[v] > index) if (categories[v] > index) {
index = categories[v]; index = categories[v];
}
}
return index + 1; return index + 1;
} }
function categoriesTickGenerator(axis) { function categoriesTickGenerator(axis) {
var res = []; var res = [],
for (var label in axis.categories) { categories = axis.categories;
var v = axis.categories[label]; for (var label in categories) {
if (v >= axis.min && v <= axis.max) if (Object.prototype.hasOwnProperty.call(categories, label)) {
res.push([v, 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]; }); res.sort(function (a, b) { return a[0] - b[0]; });
return res; return res;
} }
function setupCategoriesForAxis(series, axis, datapoints) { function setupCategoriesForAxis(series, axis, datapoints) {
if (series[axis].options.mode != "categories") if (series[axis].options.mode !== "categories") {
return; return;
}
if (!series[axis].categories) { if (!series[axis].categories) {
// parse options // parse options
var c = {}, o = series[axis].options.categories || {}; var c = {}, o = series[axis].options.categories || {};
if ($.isArray(o)) { if ($.isArray(o)) {
for (var i = 0; i < o.length; ++i) for (var i = 0; i < o.length; ++i) {
c[o[i]] = 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; series[axis].categories = c;
} }
// fix ticks // fix ticks
if (!series[axis].options.ticks) if (!series[axis].options.ticks) {
series[axis].options.ticks = categoriesTickGenerator; series[axis].options.ticks = categoriesTickGenerator;
}
transformPointsOnAxis(datapoints, axis, series[axis].categories); transformPointsOnAxis(datapoints, axis, series[axis].categories);
} }
function transformPointsOnAxis(datapoints, axis, categories) { function transformPointsOnAxis(datapoints, axis, categories) {
// go through the points, transforming them // go through the points, transforming them
var points = datapoints.points, var points = datapoints.points,
...@@ -152,20 +166,22 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -152,20 +166,22 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
index = getNextIndex(categories); index = getNextIndex(categories);
for (var i = 0; i < points.length; i += ps) { for (var i = 0; i < points.length; i += ps) {
if (points[i] == null) if (points[i] == null) {
continue; continue;
}
for (var m = 0; m < ps; ++m) { for (var m = 0; m < ps; ++m) {
var val = points[i + m]; var val = points[i + m];
if (val == null || !format[m][formatColumn]) if (val == null || !format[m][formatColumn]) {
continue; continue;
}
if (!(val in categories)) { if (!(val in categories)) {
categories[val] = index; categories[val] = index;
++index; ++index;
} }
points[i + m] = categories[val]; points[i + m] = categories[val];
} }
} }
...@@ -180,11 +196,11 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -180,11 +196,11 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
plot.hooks.processRawData.push(processRawData); plot.hooks.processRawData.push(processRawData);
plot.hooks.processDatapoints.push(processDatapoints); plot.hooks.processDatapoints.push(processDatapoints);
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'categories', name: "categories",
version: '1.0' version: "1.0"
}); });
})(jQuery); })(jQuery);
...@@ -59,6 +59,7 @@ The plugin also adds four public methods: ...@@ -59,6 +59,7 @@ The plugin also adds four public methods:
*/ */
(function ($) { (function ($) {
var options = { var options = {
crosshair: { crosshair: {
mode: null, // one of null, "x", "y" or "xy", mode: null, // one of null, "x", "y" or "xy",
...@@ -66,28 +67,29 @@ The plugin also adds four public methods: ...@@ -66,28 +67,29 @@ The plugin also adds four public methods:
lineWidth: 1 lineWidth: 1
} }
}; };
function init(plot) { function init(plot) {
// position of crosshair in pixels // position of crosshair in pixels
var crosshair = { x: -1, y: -1, locked: false }; var crosshair = { x: -1, y: -1, locked: false };
plot.setCrosshair = function setCrosshair(pos) { plot.setCrosshair = function setCrosshair(pos) {
if (!pos) if (!pos) {
crosshair.x = -1; crosshair.x = -1;
else { } else {
var o = plot.p2c(pos); var o = plot.p2c(pos);
crosshair.x = Math.max(0, Math.min(o.left, plot.width())); crosshair.x = Math.max(0, Math.min(o.left, plot.width()));
crosshair.y = Math.max(0, Math.min(o.top, plot.height())); crosshair.y = Math.max(0, Math.min(o.top, plot.height()));
} }
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
}; };
plot.clearCrosshair = plot.setCrosshair; // passes null for pos plot.clearCrosshair = plot.setCrosshair; // passes null for pos
plot.lockCrosshair = function lockCrosshair(pos) { plot.lockCrosshair = function lockCrosshair(pos) {
if (pos) if (pos) {
plot.setCrosshair(pos); plot.setCrosshair(pos);
}
crosshair.locked = true; crosshair.locked = true;
}; };
...@@ -95,34 +97,37 @@ The plugin also adds four public methods: ...@@ -95,34 +97,37 @@ The plugin also adds four public methods:
crosshair.locked = false; crosshair.locked = false;
}; };
function onMouseOut(e) { function onMouseOut() {
if (crosshair.locked) if (crosshair.locked) {
return; return;
}
if (crosshair.x != -1) { if (crosshair.x !== -1) {
crosshair.x = -1; crosshair.x = -1;
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} }
} }
function onMouseMove(e) { function onMouseMove(e) {
if (crosshair.locked) if (crosshair.locked) {
return; return;
}
if (plot.getSelection && plot.getSelection()) { if (plot.getSelection && plot.getSelection()) {
crosshair.x = -1; // hide the crosshair while selecting crosshair.x = -1; // hide the crosshair while selecting
return; return;
} }
var offset = plot.offset(); var offset = plot.offset();
crosshair.x = Math.max(0, Math.min(e.pageX - offset.left, plot.width())); 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())); crosshair.y = Math.max(0, Math.min(e.pageY - offset.top, plot.height()));
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} }
plot.hooks.bindEvents.push(function (plot, eventHolder) { plot.hooks.bindEvents.push(function (plot, eventHolder) {
if (!plot.getOptions().crosshair.mode) if (!plot.getOptions().crosshair.mode) {
return; return;
}
eventHolder.mouseout(onMouseOut); eventHolder.mouseout(onMouseOut);
eventHolder.mousemove(onMouseMove); eventHolder.mousemove(onMouseMove);
...@@ -130,15 +135,16 @@ The plugin also adds four public methods: ...@@ -130,15 +135,16 @@ The plugin also adds four public methods:
plot.hooks.drawOverlay.push(function (plot, ctx) { plot.hooks.drawOverlay.push(function (plot, ctx) {
var c = plot.getOptions().crosshair; var c = plot.getOptions().crosshair;
if (!c.mode) if (!c.mode) {
return; return;
}
var plotOffset = plot.getPlotOffset(); var plotOffset = plot.getPlotOffset();
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); 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; var adj = plot.getOptions().crosshair.lineWidth % 2 === 0 ? 0 : 0.5;
ctx.strokeStyle = c.color; ctx.strokeStyle = c.color;
...@@ -146,12 +152,12 @@ The plugin also adds four public methods: ...@@ -146,12 +152,12 @@ The plugin also adds four public methods:
ctx.lineJoin = "round"; ctx.lineJoin = "round";
ctx.beginPath(); ctx.beginPath();
if (c.mode.indexOf("x") != -1) { if (c.mode.indexOf("x") !== -1) {
var drawX = Math.round(crosshair.x) + adj; var drawX = Math.round(crosshair.x) + adj;
ctx.moveTo(drawX, 0); ctx.moveTo(drawX, 0);
ctx.lineTo(drawX, plot.height()); ctx.lineTo(drawX, plot.height());
} }
if (c.mode.indexOf("y") != -1) { if (c.mode.indexOf("y") !== -1) {
var drawY = Math.round(crosshair.y) + adj; var drawY = Math.round(crosshair.y) + adj;
ctx.moveTo(0, drawY); ctx.moveTo(0, drawY);
ctx.lineTo(plot.width(), drawY); ctx.lineTo(plot.width(), drawY);
...@@ -166,11 +172,12 @@ The plugin also adds four public methods: ...@@ -166,11 +172,12 @@ The plugin also adds four public methods:
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
}); });
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'crosshair', name: "crosshair",
version: '1.0' version: "1.0"
}); });
})(jQuery); })(jQuery);
This diff is collapsed.
...@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -29,7 +29,7 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
*/ */
(function ( $ ) { (function ($) {
var options = { var options = {
series: { series: {
...@@ -37,37 +37,37 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -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; var i;
for ( i = 0; i < allseries.length; ++i ) { for (i = 0; i < allseries.length; ++i) {
if ( allseries[ i ].id === s.fillBetween ) { if (allseries[i].id === s.fillBetween) {
return allseries[ i ]; return allseries[i];
} }
} }
if ( typeof s.fillBetween === "number" ) { if (typeof s.fillBetween === "number") {
if ( s.fillBetween < 0 || s.fillBetween >= allseries.length ) { if (s.fillBetween < 0 || s.fillBetween >= allseries.length) {
return null; return null;
} }
return allseries[ s.fillBetween ]; return allseries[s.fillBetween];
} }
return null; return null;
} }
function computeFillBottoms( plot, s, datapoints ) { function computeFillBottoms(plot, s, datapoints) {
if ( s.fillBetween == null ) { if (s.fillBetween == null) {
return; return;
} }
var other = findBottomSeries( s, plot.getData() ); var other = findBottomSeries(s, plot.getData());
if ( !other ) { if (!other) {
return; return;
} }
...@@ -85,42 +85,42 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -85,42 +85,42 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
j = 0, j = 0,
l, m; l, m;
while ( true ) { while (true) {
if ( i >= points.length ) { if (i >= points.length) {
break; break;
} }
l = newpoints.length; l = newpoints.length;
if ( points[ i ] == null ) { if (points[i] == null) {
// copy gaps // copy gaps
for ( m = 0; m < ps; ++m ) { for (m = 0; m < ps; ++m) {
newpoints.push( points[ i + m ] ); newpoints.push(points[i + m]);
} }
i += ps; i += ps;
} else if ( j >= otherpoints.length ) { } else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points // for lines, we can't use the rest of the points
if ( !withlines ) { if (!withlines) {
for ( m = 0; m < ps; ++m ) { for (m = 0; m < ps; ++m) {
newpoints.push( points[ i + m ] ); newpoints.push(points[i + m]);
} }
} }
i += ps; i += ps;
} else if ( otherpoints[ j ] == null ) { } else if (otherpoints[j] == null) {
// oops, got a gap // oops, got a gap
for ( m = 0; m < ps; ++m ) { for (m = 0; m < ps; ++m) {
newpoints.push( null ); newpoints.push(null);
} }
fromgap = true; fromgap = true;
...@@ -130,35 +130,35 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -130,35 +130,35 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
// cases where we actually got two points // cases where we actually got two points
px = points[ i ]; px = points[i];
py = points[ i + 1 ]; py = points[i + 1];
qx = otherpoints[ j ]; qx = otherpoints[j];
qy = otherpoints[ j + 1 ]; qy = otherpoints[j + 1];
bottom = 0; bottom = 0;
if ( px === qx ) { if (px === qx) {
for ( m = 0; m < ps; ++m ) { for (m = 0; m < ps; ++m) {
newpoints.push( points[ i + m ] ); newpoints.push(points[i + m]);
} }
//newpoints[ l + 1 ] += qy; //newpoints[l + 1] += qy;
bottom = qy; bottom = qy;
i += ps; i += ps;
j += otherps; j += otherps;
} else if ( px > qx ) { } else if (px > qx) {
// we got past point below, might need to // we got past point below, might need to
// insert interpolated extra point // insert interpolated extra point
if ( withlines && i > 0 && points[ i - ps ] != null ) { if (withlines && i > 0 && points[i - ps] != null) {
intery = py + ( points[ i - ps + 1 ] - py ) * ( qx - px ) / ( points[ i - ps ] - px ); intery = py + (points[i - ps + 1] - py) * (qx - px) / (points[i - ps] - px);
newpoints.push( qx ); newpoints.push(qx);
newpoints.push( intery ); newpoints.push(intery);
for ( m = 2; m < ps; ++m ) { for (m = 2; m < ps; ++m) {
newpoints.push( points[ i + m ] ); newpoints.push(points[i + m]);
} }
bottom = qy; bottom = qy;
} }
...@@ -169,20 +169,20 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -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 we come from a gap, we just skip this point
if ( fromgap && withlines ) { if (fromgap && withlines) {
i += ps; i += ps;
continue; continue;
} }
for ( m = 0; m < ps; ++m ) { for (m = 0; m < ps; ++m) {
newpoints.push( points[ i + m ] ); newpoints.push(points[i + m]);
} }
// we might be able to interpolate a point below, // we might be able to interpolate a point below,
// this can give us a better y // 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 + 1 ] - qy ) * ( px - qx ) / ( otherpoints[ j - otherps ] - qx ); bottom = qy + (otherpoints[j - otherps + 1] - qy) * (px - qx) / (otherpoints[j - otherps] - qx);
} }
//newpoints[l + 1] += bottom; //newpoints[l + 1] += bottom;
...@@ -192,28 +192,28 @@ jquery.flot.stack.js plugin, possibly some code could be shared. ...@@ -192,28 +192,28 @@ jquery.flot.stack.js plugin, possibly some code could be shared.
fromgap = false; fromgap = false;
if ( l !== newpoints.length && withbottom ) { if (l !== newpoints.length && withbottom) {
newpoints[ l + 2 ] = bottom; newpoints[l + 2] = bottom;
} }
} }
// maintain the line steps invariant // maintain the line steps invariant
if ( withsteps && l !== newpoints.length && l > 0 && if (withsteps && l !== newpoints.length && l > 0 &&
newpoints[ l ] !== null && newpoints[l] !== null &&
newpoints[ l ] !== newpoints[ l - ps ] && newpoints[l] !== newpoints[ l - ps ] &&
newpoints[ l + 1 ] !== newpoints[ l - ps + 1 ] ) { newpoints[l + 1] !== newpoints[l - ps + 1] ) {
for (m = 0; m < ps; ++m) { 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; datapoints.points = newpoints;
} }
plot.hooks.processDatapoints.push( computeFillBottoms ); plot.hooks.processDatapoints.push(computeFillBottoms);
} }
$.plot.plugins.push({ $.plot.plugins.push({
......
...@@ -69,16 +69,18 @@ Google Maps). ...@@ -69,16 +69,18 @@ Google Maps).
var urls = [], points = []; var urls = [], points = [];
var defaultShow = options.series.images.show; var defaultShow = options.series.images.show;
$.each(series, function (i, s) { $.each(series, function (i, s) {
if (!(defaultShow || s.images.show)) if (!(defaultShow || s.images.show)) {
return; return;
}
if (s.data)
if (s.data) {
s = s.data; s = s.data;
}
$.each(s, function (i, p) { $.each(s, function (i, p) {
if (typeof p[0] == "string") { if (typeof p[0] === "string") {
urls.push(p[0]); urls.push(p[0]);
points.push(p); points.push(p);
} }
...@@ -88,42 +90,46 @@ Google Maps). ...@@ -88,42 +90,46 @@ Google Maps).
$.plot.image.load(urls, function (loadedImages) { $.plot.image.load(urls, function (loadedImages) {
$.each(points, function (i, p) { $.each(points, function (i, p) {
var url = p[0]; var url = p[0];
if (loadedImages[url]) if (loadedImages[url]) {
p[0] = loadedImages[url]; p[0] = loadedImages[url];
}
}); });
callback(); callback();
}); });
} };
$.plot.image.load = function (urls, callback) { $.plot.image.load = function (urls, callback) {
var missing = urls.length, loaded = {}; var missing = urls.length, loaded = {};
if (missing == 0) if (missing === 0) {
callback({}); callback({});
}
$.each(urls, function (i, url) { $.each(urls, function (i, url) {
var handler = function () { var handler = function () {
--missing; --missing;
loaded[url] = this; loaded[url] = this;
if (missing == 0) if (missing === 0) {
callback(loaded); callback(loaded);
}
}; };
$('<img />').load(handler).error(handler).attr('src', url); $("<img />").load(handler).error(handler).attr("src", url);
}); });
}; };
function drawSeries(plot, ctx, series) { function drawSeries(plot, ctx, series) {
var plotOffset = plot.getPlotOffset(); var plotOffset = plot.getPlotOffset();
if (!series.images || !series.images.show) if (!series.images || !series.images.show) {
return; return;
}
var points = series.datapoints.points, var points = series.datapoints.points,
ps = series.datapoints.pointsize; ps = series.datapoints.pointsize;
for (var i = 0; i < points.length; i += ps) { for (var i = 0; i < points.length; i += ps) {
var img = points[i], var img = points[i],
x1 = points[i + 1], y1 = points[i + 2], x1 = points[i + 1], y1 = points[i + 2],
...@@ -134,8 +140,9 @@ Google Maps). ...@@ -134,8 +140,9 @@ Google Maps).
// actually we should check img.complete, but it // actually we should check img.complete, but it
// appears to be a somewhat unreliable indicator in // appears to be a somewhat unreliable indicator in
// IE6 (false even after load event) // IE6 (false even after load event)
if (!img || img.width <= 0 || img.height <= 0) if (!img || img.width <= 0 || img.height <= 0) {
continue; continue;
}
if (x1 > x2) { if (x1 > x2) {
tmp = x2; tmp = x2;
...@@ -147,10 +154,10 @@ Google Maps). ...@@ -147,10 +154,10 @@ Google Maps).
y2 = y1; y2 = y1;
y1 = tmp; 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 // 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); tmp = 0.5 * (x2-x1) / (img.width - 1);
x1 -= tmp; x1 -= tmp;
x2 += tmp; x2 += tmp;
...@@ -158,12 +165,13 @@ Google Maps). ...@@ -158,12 +165,13 @@ Google Maps).
y1 -= tmp; y1 -= tmp;
y2 += tmp; y2 += tmp;
} }
// clip // clip
if (x1 == x2 || y1 == y2 || if (x1 === x2 || y1 === y2 ||
x1 >= xaxis.max || x2 <= xaxis.min || x1 >= xaxis.max || x2 <= xaxis.min ||
y1 >= yaxis.max || y2 <= yaxis.min) y1 >= yaxis.max || y2 <= yaxis.min) {
continue; continue;
}
var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height; var sx1 = 0, sy1 = 0, sx2 = img.width, sy2 = img.height;
if (x1 < xaxis.min) { if (x1 < xaxis.min) {
...@@ -185,12 +193,12 @@ Google Maps). ...@@ -185,12 +193,12 @@ Google Maps).
sy1 += (sy1 - sy2) * (yaxis.max - y2) / (y2 - y1); sy1 += (sy1 - sy2) * (yaxis.max - y2) / (y2 - y1);
y2 = yaxis.max; y2 = yaxis.max;
} }
x1 = xaxis.p2c(x1); x1 = xaxis.p2c(x1);
x2 = xaxis.p2c(x2); x2 = xaxis.p2c(x2);
y1 = yaxis.p2c(y1); y1 = yaxis.p2c(y1);
y2 = yaxis.p2c(y2); y2 = yaxis.p2c(y2);
// the transformation may have swapped us // the transformation may have swapped us
if (x1 > x2) { if (x1 > x2) {
tmp = x2; tmp = x2;
...@@ -214,8 +222,9 @@ Google Maps). ...@@ -214,8 +222,9 @@ Google Maps).
} }
function processRawData(plot, series, data, datapoints) { function processRawData(plot, series, data, datapoints) {
if (!series.images.show) if (!series.images.show) {
return; return;
}
// format is Image, x1, y1, x2, y2 (opposite corners) // format is Image, x1, y1, x2, y2 (opposite corners)
datapoints.format = [ datapoints.format = [
...@@ -226,16 +235,16 @@ Google Maps). ...@@ -226,16 +235,16 @@ Google Maps).
{ y: true, number: true, required: true } { y: true, number: true, required: true }
]; ];
} }
function init(plot) { function init(plot) {
plot.hooks.processRawData.push(processRawData); plot.hooks.processRawData.push(processRawData);
plot.hooks.drawSeries.push(drawSeries); plot.hooks.drawSeries.push(drawSeries);
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'image', name: "image",
version: '1.1' version: "1.1"
}); });
})(jQuery); })(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. ...@@ -88,7 +88,7 @@ More detail and specific examples can be found in the included HTML file.
// set labels.show // set labels.show
if (options.series.pie.label.show == "auto") { if (options.series.pie.label.show === "auto") {
if (options.legend.show) { if (options.legend.show) {
options.series.pie.label.show = false; options.series.pie.label.show = false;
} else { } else {
...@@ -98,7 +98,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -98,7 +98,7 @@ More detail and specific examples can be found in the included HTML file.
// set radius // set radius
if (options.series.pie.radius == "auto") { if (options.series.pie.radius === "auto") {
if (options.series.pie.label.show) { if (options.series.pie.label.show) {
options.series.pie.radius = 3/4; options.series.pie.radius = 3/4;
} else { } else {
...@@ -149,7 +149,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -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) { if (!processed) {
processed = true; processed = true;
canvas = plot.getCanvas(); canvas = plot.getCanvas();
...@@ -165,13 +165,14 @@ More detail and specific examples can be found in the included HTML file. ...@@ -165,13 +165,14 @@ More detail and specific examples can be found in the included HTML file.
combined = 0, combined = 0,
numCombined = 0, numCombined = 0,
color = options.series.pie.combine.color, color = options.series.pie.combine.color,
newdata = []; newdata = [],
i, value;
// Fix up the raw data from Flot, ensuring the data is numeric // 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 // 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. // 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. ...@@ -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 // new one; this is more efficient and preserves any extra data
// that the user may have stored in higher indexes. // that the user may have stored in higher indexes.
if ($.isArray(value) && value.length == 1) { if ($.isArray(value) && value.length === 1) {
value = value[0]; value = value[0];
} }
if ($.isArray(value)) { if ($.isArray(value)) {
...@@ -202,15 +203,15 @@ More detail and specific examples can be found in the included HTML file. ...@@ -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 // 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]; total += data[i].data[0][1];
} }
// Count the number of slices with percentages below the combine // Count the number of slices with percentages below the combine
// threshold; if it turns out to be just one, we won't combine. // threshold; if it turns out to be just one, we won't combine.
for (var i = 0; i < data.length; ++i) { for (i = 0; i < data.length; ++i) {
var value = data[i].data[0][1]; value = data[i].data[0][1];
if (value / total <= options.series.pie.combine.threshold) { if (value / total <= options.series.pie.combine.threshold) {
combined += value; combined += value;
numCombined++; numCombined++;
...@@ -220,8 +221,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -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) { for (i = 0; i < data.length; ++i) {
var value = data[i].data[0][1]; value = data[i].data[0][1];
if (numCombined < 2 || value / total > options.series.pie.combine.threshold) { if (numCombined < 2 || value / total > options.series.pie.combine.threshold) {
newdata.push({ newdata.push({
data: [[1, value]], data: [[1, value]],
...@@ -287,7 +288,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -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; centerTop = canvasHeight / 2 + options.series.pie.offset.top;
centerLeft = canvasWidth / 2; centerLeft = canvasWidth / 2;
if (options.series.pie.offset.left == "auto") { if (options.series.pie.offset.left === "auto") {
if (options.legend.position.match("w")) { if (options.legend.position.match("w")) {
centerLeft += legendWidth / 2; centerLeft += legendWidth / 2;
} else { } else {
...@@ -318,7 +319,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -318,7 +319,7 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.tilt <= 0.8) { if (options.series.pie.tilt <= 0.8) {
drawShadow(); drawShadow();
} }
} while (!drawPie() && attempts < REDRAW_ATTEMPTS) } while (!drawPie() && attempts < REDRAW_ATTEMPTS);
if (attempts >= REDRAW_ATTEMPTS) { if (attempts >= REDRAW_ATTEMPTS) {
clear(); clear();
...@@ -373,8 +374,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -373,8 +374,9 @@ More detail and specific examples can be found in the included HTML file.
function drawPie() { function drawPie() {
var startAngle = Math.PI * options.series.pie.startAngle; var startAngle = Math.PI * options.series.pie.startAngle,
var radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius; radius = options.series.pie.radius > 1 ? options.series.pie.radius : maxRadius * options.series.pie.radius,
i;
// center and rotate to starting position // center and rotate to starting position
...@@ -387,7 +389,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -387,7 +389,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save(); ctx.save();
var currentAngle = startAngle; var currentAngle = startAngle;
for (var i = 0; i < slices.length; ++i) { for (i = 0; i < slices.length; ++i) {
slices[i].startAngle = currentAngle; slices[i].startAngle = currentAngle;
drawSlice(slices[i].angle, slices[i].color, true); 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. ...@@ -399,7 +401,7 @@ More detail and specific examples can be found in the included HTML file.
ctx.save(); ctx.save();
ctx.lineWidth = options.series.pie.stroke.width; ctx.lineWidth = options.series.pie.stroke.width;
currentAngle = startAngle; 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); drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
} }
ctx.restore(); ctx.restore();
...@@ -415,7 +417,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -415,7 +417,9 @@ More detail and specific examples can be found in the included HTML file.
if (options.series.pie.label.show) { if (options.series.pie.label.show) {
return drawLabels(); return drawLabels();
} else return true; } else {
return true;
}
function drawSlice(angle, color, fill) { function drawSlice(angle, color, fill) {
...@@ -467,7 +471,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -467,7 +471,7 @@ More detail and specific examples can be found in the included HTML file.
function drawLabel(slice, startAngle, index) { function drawLabel(slice, startAngle, index) {
if (slice.data[0][1] == 0) { if (slice.data[0][1] === 0) {
return true; return true;
} }
...@@ -505,7 +509,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -505,7 +509,7 @@ More detail and specific examples can be found in the included HTML file.
return false; 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 // 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. ...@@ -561,10 +565,12 @@ More detail and specific examples can be found in the included HTML file.
//-- Additional Interactive related functions -- //-- Additional Interactive related functions --
function isPointInPoly(poly, pt) { function isPointInPoly(poly, pt) {
for(var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) 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])) ((poly[i][1] <= pt[1] && pt[1] < poly[j][1]) ||
&& (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0]) (poly[j][1] <= pt[1] && pt[1]< poly[i][1])) &&
&& (c = !c); (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; return c;
} }
...@@ -651,8 +657,8 @@ More detail and specific examples can be found in the included HTML file. ...@@ -651,8 +657,8 @@ More detail and specific examples can be found in the included HTML file.
function triggerClickHoverEvent(eventname, e) { function triggerClickHoverEvent(eventname, e) {
var offset = plot.offset(); var offset = plot.offset();
var canvasX = parseInt(e.pageX - offset.left); var canvasX = parseInt(e.pageX - offset.left, 10);
var canvasY = parseInt(e.pageY - offset.top); var canvasY = parseInt(e.pageY - offset.top, 10);
var item = findNearbySlice(canvasX, canvasY); var item = findNearbySlice(canvasX, canvasY);
if (options.grid.autoHighlight) { if (options.grid.autoHighlight) {
...@@ -661,7 +667,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -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) { for (var i = 0; i < highlights.length; ++i) {
var h = highlights[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); unhighlight(h.series);
} }
} }
...@@ -686,7 +692,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -686,7 +692,7 @@ More detail and specific examples can be found in the included HTML file.
var i = indexOfHighlight(s); var i = indexOfHighlight(s);
if (i == -1) { if (i === -1) {
highlights.push({ series: s, auto: auto }); highlights.push({ series: s, auto: auto });
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} else if (!auto) { } else if (!auto) {
...@@ -706,7 +712,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -706,7 +712,7 @@ More detail and specific examples can be found in the included HTML file.
var i = indexOfHighlight(s); var i = indexOfHighlight(s);
if (i != -1) { if (i !== -1) {
highlights.splice(i, 1); highlights.splice(i, 1);
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} }
...@@ -715,8 +721,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -715,8 +721,9 @@ More detail and specific examples can be found in the included HTML file.
function indexOfHighlight(s) { function indexOfHighlight(s) {
for (var i = 0; i < highlights.length; ++i) { for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i]; var h = highlights[i];
if (h.series == s) if (h.series === s) {
return i; return i;
}
} }
return -1; return -1;
} }
......
...@@ -11,17 +11,6 @@ can just fix the size of their placeholders. ...@@ -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 ($) { (function ($) {
var options = { }; // no options var options = { }; // no options
...@@ -31,30 +20,31 @@ can just fix the size of their placeholders. ...@@ -31,30 +20,31 @@ can just fix the size of their placeholders.
// somebody might have hidden us and we can't plot // somebody might have hidden us and we can't plot
// when we don't have the dimensions // when we don't have the dimensions
if (placeholder.width() == 0 || placeholder.height() == 0) if (placeholder.width() === 0 || placeholder.height() === 0) {
return; return;
}
plot.resize(); plot.resize();
plot.setupGrid(); plot.setupGrid();
plot.draw(); plot.draw();
} }
function bindEvents(plot, eventHolder) { function bindEvents(plot) {
plot.getPlaceholder().resize(onResize); plot.getPlaceholder().resize(onResize);
} }
function shutdown(plot, eventHolder) { function shutdown(plot) {
plot.getPlaceholder().unbind("resize", onResize); plot.getPlaceholder().unbind("resize", onResize);
} }
plot.hooks.bindEvents.push(bindEvents); plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown); plot.hooks.shutdown.push(shutdown);
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'resize', name: "resize",
version: '1.0' version: "1.0"
}); });
})(jQuery); })(jQuery);
This diff is collapsed.
...@@ -39,28 +39,32 @@ charts or filled areas). ...@@ -39,28 +39,32 @@ charts or filled areas).
var options = { var options = {
series: { stack: null } // or number/string series: { stack: null } // or number/string
}; };
function init(plot) { function init(plot) {
function findMatchingSeries(s, allseries) { function findMatchingSeries(s, allseries) {
var res = null; var res = null;
for (var i = 0; i < allseries.length; ++i) { for (var i = 0; i < allseries.length; ++i) {
if (s == allseries[i]) if (s === allseries[i]) {
break; break;
}
if (allseries[i].stack == s.stack)
if (allseries[i].stack === s.stack) {
res = allseries[i]; res = allseries[i];
}
} }
return res; return res;
} }
function stackData(plot, s, datapoints) { function stackData(plot, s, datapoints) {
if (s.stack == null || s.stack === false) if (s.stack == null || s.stack === false) {
return; return;
}
var other = findMatchingSeries(s, plot.getData()); var other = findMatchingSeries(s, plot.getData());
if (!other) if (!other) {
return; return;
}
var ps = datapoints.pointsize, var ps = datapoints.pointsize,
points = datapoints.points, points = datapoints.points,
...@@ -78,33 +82,34 @@ charts or filled areas). ...@@ -78,33 +82,34 @@ charts or filled areas).
i = 0, j = 0, l, m; i = 0, j = 0, l, m;
while (true) { while (true) {
if (i >= points.length) if (i >= points.length) {
break; break;
}
l = newpoints.length; l = newpoints.length;
if (points[i] == null) { if (points[i] == null) {
// copy gaps // copy gaps
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
}
i += ps; i += ps;
} } else if (j >= otherpoints.length) {
else if (j >= otherpoints.length) {
// for lines, we can't use the rest of the points // for lines, we can't use the rest of the points
if (!withlines) { if (!withlines) {
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
}
} }
i += ps; i += ps;
} } else if (otherpoints[j] == null) {
else if (otherpoints[j] == null) {
// oops, got a gap // oops, got a gap
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
newpoints.push(null); newpoints.push(null);
}
fromgap = true; fromgap = true;
j += otherps; j += otherps;
} } else {
else {
// cases where we actually got two points // cases where we actually got two points
px = points[i + keyOffset]; px = points[i + keyOffset];
py = points[i + accumulateOffset]; py = points[i + accumulateOffset];
...@@ -112,77 +117,81 @@ charts or filled areas). ...@@ -112,77 +117,81 @@ charts or filled areas).
qy = otherpoints[j + accumulateOffset]; qy = otherpoints[j + accumulateOffset];
bottom = 0; bottom = 0;
if (px == qx) { if (px === qx) {
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
}
newpoints[l + accumulateOffset] += qy; newpoints[l + accumulateOffset] += qy;
bottom = qy; bottom = qy;
i += ps; i += ps;
j += otherps; j += otherps;
} } else if (px > qx) {
else if (px > qx) {
// we got past point below, might need to // we got past point below, might need to
// insert interpolated extra point // insert interpolated extra point
if (withlines && i > 0 && points[i - ps] != null) { if (withlines && i > 0 && points[i - ps] != null) {
intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px); intery = py + (points[i - ps + accumulateOffset] - py) * (qx - px) / (points[i - ps + keyOffset] - px);
newpoints.push(qx); newpoints.push(qx);
newpoints.push(intery + qy); newpoints.push(intery + qy);
for (m = 2; m < ps; ++m) for (m = 2; m < ps; ++m) {
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
bottom = qy; }
bottom = qy;
} }
j += otherps; j += otherps;
} } else { // px < qx
else { // px < qx
if (fromgap && withlines) { if (fromgap && withlines) {
// if we come from a gap, we just skip this point // if we come from a gap, we just skip this point
i += ps; i += ps;
continue; continue;
} }
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
newpoints.push(points[i + m]); newpoints.push(points[i + m]);
}
// we might be able to interpolate a point below, // we might be able to interpolate a point below,
// this can give us a better y // 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); bottom = qy + (otherpoints[j - otherps + accumulateOffset] - qy) * (px - qx) / (otherpoints[j - otherps + keyOffset] - qx);
}
newpoints[l + accumulateOffset] += bottom; newpoints[l + accumulateOffset] += bottom;
i += ps; i += ps;
} }
fromgap = false; fromgap = false;
if (l != newpoints.length && withbottom) if (l !== newpoints.length && withbottom) {
newpoints[l + 2] += bottom; newpoints[l + 2] += bottom;
}
} }
// maintain the line steps invariant // maintain the line steps invariant
if (withsteps && l != newpoints.length && l > 0 if (withsteps && l !== newpoints.length && l > 0 &&
&& newpoints[l] != null newpoints[l] != null &&
&& newpoints[l] != newpoints[l - ps] newpoints[l] !== newpoints[l - ps] &&
&& newpoints[l + 1] != newpoints[l - ps + 1]) { newpoints[l + 1] !== newpoints[l - ps + 1]) {
for (m = 0; m < ps; ++m) 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; datapoints.points = newpoints;
} }
plot.hooks.processDatapoints.push(stackData); plot.hooks.processDatapoints.push(stackData);
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'stack', name: "stack",
version: '1.2' version: "1.2"
}); });
})(jQuery); })(jQuery);
...@@ -14,17 +14,17 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -14,17 +14,17 @@ The symbols are accessed as strings through the standard symbol options:
*/ */
(function ($) { (function ($) {
function processRawData(plot, series, datapoints) { function processRawData(plot, series) {
// we normalize the area of each symbol so it is approximately the // we normalize the area of each symbol so it is approximately the
// same as a circle of the given radius // same as a circle of the given radius
var handlers = { 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 // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2; var size = radius * Math.sqrt(Math.PI) / 2;
ctx.rect(x - size, y - size, size + size, size + size); 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) // pi * r^2 = 2s^2 => s = r * sqrt(pi/2)
var size = radius * Math.sqrt(Math.PI / 2); var size = radius * Math.sqrt(Math.PI / 2);
ctx.moveTo(x - size, y); ctx.moveTo(x - size, y);
...@@ -44,7 +44,7 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -44,7 +44,7 @@ The symbols are accessed as strings through the standard symbol options:
ctx.lineTo(x - size/2, y + height/2); 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 // pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI) / 2; var size = radius * Math.sqrt(Math.PI) / 2;
ctx.moveTo(x - size, y - size); ctx.moveTo(x - size, y - size);
...@@ -55,17 +55,18 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -55,17 +55,18 @@ The symbols are accessed as strings through the standard symbol options:
}; };
var s = series.points.symbol; var s = series.points.symbol;
if (handlers[s]) if (handlers[s]) {
series.points.symbol = handlers[s]; series.points.symbol = handlers[s];
}
} }
function init(plot) { function init(plot) {
plot.hooks.processDatapoints.push(processRawData); plot.hooks.processDatapoints.push(processRawData);
} }
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
name: 'symbols', name: "symbols",
version: '1.0' version: "1.0"
}); });
})(jQuery); })(jQuery);
...@@ -50,8 +50,14 @@ You may need to check for this in hover events. ...@@ -50,8 +50,14 @@ You may need to check for this in hover events.
function init(plot) { function init(plot) {
function thresholdData(plot, s, datapoints, below, above, color) { 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.datapoints = { points: [], pointsize: ps, format: datapoints.format };
thresholded.label = null; thresholded.label = null;
...@@ -60,45 +66,42 @@ You may need to check for this in hover events. ...@@ -60,45 +66,42 @@ You may need to check for this in hover events.
thresholded.originSeries = s; thresholded.originSeries = s;
thresholded.data = []; thresholded.data = [];
var origpoints = datapoints.points,
addCrossingPoints = s.lines.show;
var threspoints = [];
var newpoints = [];
var m;
for (i = 0; i < origpoints.length; i += ps) { for (i = 0; i < origpoints.length; i += ps) {
x = origpoints[i]; x = origpoints[i];
y = origpoints[i + 1]; y = origpoints[i + 1];
prevp = p; prevp = p;
if (y < below || y > above) if (y < below || y > above) {
p = threspoints; p = threspoints;
else } else {
p = newpoints; p = newpoints;
}
if (addCrossingPoints && prevp != p && x != null if (addCrossingPoints && prevp !== p && x != null && i > 0 && origpoints[i - ps] != null) {
&& i > 0 && origpoints[i - ps] != null) {
var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]); var interx = x + (below - y) * (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]);
prevp.push(interx); prevp.push(interx);
prevp.push(below); prevp.push(below);
for (m = 2; m < ps; ++m) for (m = 2; m < ps; ++m) {
prevp.push(origpoints[i + m]); prevp.push(origpoints[i + m]);
}
p.push(null); // start new segment p.push(null); // start new segment
p.push(null); p.push(null);
for (m = 2; m < ps; ++m) for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]); p.push(origpoints[i + m]);
}
p.push(interx); p.push(interx);
p.push(below); p.push(below);
for (m = 2; m < ps; ++m) for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]); p.push(origpoints[i + m]);
}
} }
p.push(x); p.push(x);
p.push(y); p.push(y);
for (m = 2; m < ps; ++m) for (m = 2; m < ps; ++m) {
p.push(origpoints[i + m]); p.push(origpoints[i + m]);
}
} }
datapoints.points = newpoints; datapoints.points = newpoints;
...@@ -114,8 +117,9 @@ You may need to check for this in hover events. ...@@ -114,8 +117,9 @@ You may need to check for this in hover events.
} }
function processThresholds(plot, s, datapoints) { function processThresholds(plot, s, datapoints) {
if (!s.threshold) if (!s.threshold) {
return; return;
}
if (s.threshold instanceof Array) { if (s.threshold instanceof Array) {
s.threshold.sort(function(a, b) { s.threshold.sort(function(a, b) {
...@@ -125,8 +129,7 @@ You may need to check for this in hover events. ...@@ -125,8 +129,7 @@ You may need to check for this in hover events.
$(s.threshold).each(function(i, th) { $(s.threshold).each(function(i, th) {
thresholdData(plot, s, datapoints, th.below, th.above, th.color); 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); 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. ...@@ -137,7 +140,7 @@ You may need to check for this in hover events.
$.plot.plugins.push({ $.plot.plugins.push({
init: init, init: init,
options: options, options: options,
name: 'threshold', name: "threshold",
version: '1.3' version: "1.3"
}); });
})(jQuery); })(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