Commit f24a67e7 authored by David Schnur's avatar David Schnur

Wrap one-statement if and for blocks in braces.

parent 05dfea77
...@@ -32,14 +32,16 @@ ...@@ -32,14 +32,16 @@
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();
}; };
...@@ -78,14 +80,16 @@ ...@@ -78,14 +80,16 @@
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);
}; };
...@@ -98,39 +102,45 @@ ...@@ -98,39 +102,45 @@
// Look for rgb(num,num,num) // Look for rgb(num,num,num)
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) 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)
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) 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%)
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) 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)
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) 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
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) 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
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) 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]);
......
...@@ -61,8 +61,9 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -61,8 +61,9 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
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;
...@@ -86,20 +87,24 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -86,20 +87,24 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
} }
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;
} }
...@@ -108,9 +113,10 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -108,9 +113,10 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
var res = []; var res = [];
for (var label in axis.categories) { for (var label in axis.categories) {
var v = axis.categories[label]; var v = axis.categories[label];
if (v >= axis.min && v <= axis.max) if (v >= axis.min && v <= axis.max) {
res.push([v, label]); res.push([v, label]);
} }
}
res.sort(function (a, b) { return a[0] - b[0]; }); res.sort(function (a, b) { return a[0] - b[0]; });
...@@ -118,27 +124,31 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -118,27 +124,31 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories.
} }
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 { else {
for (var v in o) for (var v in o) {
c[v] = o[v]; 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);
} }
...@@ -152,14 +162,16 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -152,14 +162,16 @@ 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;
......
...@@ -72,9 +72,9 @@ The plugin also adds four public methods: ...@@ -72,9 +72,9 @@ The plugin also adds four public methods:
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()));
...@@ -86,8 +86,9 @@ The plugin also adds four public methods: ...@@ -86,8 +86,9 @@ The plugin also adds four public methods:
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;
}; };
...@@ -96,8 +97,9 @@ The plugin also adds four public methods: ...@@ -96,8 +97,9 @@ The plugin also adds four public methods:
}; };
function onMouseOut(e) { function onMouseOut(e) {
if (crosshair.locked) if (crosshair.locked) {
return; return;
}
if (crosshair.x != -1) { if (crosshair.x != -1) {
crosshair.x = -1; crosshair.x = -1;
...@@ -106,8 +108,9 @@ The plugin also adds four public methods: ...@@ -106,8 +108,9 @@ The plugin also adds four public methods:
} }
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
...@@ -121,8 +124,9 @@ The plugin also adds four public methods: ...@@ -121,8 +124,9 @@ The plugin also adds four public methods:
} }
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,8 +134,9 @@ The plugin also adds four public methods: ...@@ -130,8 +134,9 @@ 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();
......
...@@ -74,8 +74,9 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -74,8 +74,9 @@ shadowSize and lineWidth are derived as well from the points series.
}; };
function processRawData(plot, series, data, datapoints){ function processRawData(plot, series, data, datapoints){
if (!series.points.errorbars) if (!series.points.errorbars) {
return; return;
}
// x,y values // x,y values
var format = [ var format = [
...@@ -90,17 +91,19 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -90,17 +91,19 @@ shadowSize and lineWidth are derived as well from the points series.
if (series.points.xerr.asymmetric) { if (series.points.xerr.asymmetric) {
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
} else } else {
format.push({ x: true, number: true, required: true }); format.push({ x: true, number: true, required: true });
} }
}
if (errors == "y" || errors == "xy") { if (errors == "y" || errors == "xy") {
// lower / upper error // lower / upper error
if (series.points.yerr.asymmetric) { if (series.points.yerr.asymmetric) {
format.push({ y: true, number: true, required: true }); format.push({ y: true, number: true, required: true });
format.push({ y: true, number: true, required: true }); format.push({ y: true, number: true, required: true });
} else } else {
format.push({ y: true, number: true, required: true }); format.push({ y: true, number: true, required: true });
} }
}
datapoints.format = format; datapoints.format = format;
} }
...@@ -122,29 +125,42 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -122,29 +125,42 @@ shadowSize and lineWidth are derived as well from the points series.
if (xerr.asymmetric) { if (xerr.asymmetric) {
exl = points[i + 2]; exl = points[i + 2];
exu = points[i + 3]; exu = points[i + 3];
if (eb == "xy") if (eb == "xy") {
if (yerr.asymmetric){ if (yerr.asymmetric){
eyl = points[i + 4]; eyl = points[i + 4];
eyu = points[i + 5]; eyu = points[i + 5];
} else eyl = points[i + 4]; } else {
eyl = points[i + 4];
}
}
} else { } else {
exl = points[i + 2]; exl = points[i + 2];
if (eb == "xy") if (eb == "xy") {
if (yerr.asymmetric) { if (yerr.asymmetric) {
eyl = points[i + 3]; eyl = points[i + 3];
eyu = points[i + 4]; eyu = points[i + 4];
} else eyl = points[i + 3]; } else {
eyl = points[i + 3];
}
}
} }
// only Y // only Y
} else if (eb == "y") } else if (eb == "y") {
if (yerr.asymmetric) { if (yerr.asymmetric) {
eyl = points[i + 2]; eyl = points[i + 2];
eyu = points[i + 3]; eyu = points[i + 3];
} else eyl = points[i + 2]; } else {
eyl = points[i + 2];
}
}
// symmetric errors? // symmetric errors?
if (exu == null) exu = exl; if (exu == null) {
if (eyu == null) eyu = eyl; exu = exl;
}
if (eyu == null) {
eyu = eyl;
}
var errRanges = [exl, exu, eyl, eyu]; var errRanges = [exl, exu, eyl, eyu];
// nullify if not showing // nullify if not showing
...@@ -206,12 +222,16 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -206,12 +222,16 @@ shadowSize and lineWidth are derived as well from the points series.
lower = [x, y][e] - errRanges[e * err.length]; lower = [x, y][e] - errRanges[e * err.length];
//points outside of the canvas //points outside of the canvas
if (err[e].err == "x") if (err[e].err == "x") {
if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max) if (y > ax[1].max || y < ax[1].min || upper < ax[0].min || lower > ax[0].max) {
continue; continue;
if (err[e].err == "y") }
if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max) }
if (err[e].err == "y") {
if (x > ax[0].max || x < ax[0].min || upper < ax[1].min || lower > ax[1].max) {
continue; continue;
}
}
// prevent errorbars getting out of the canvas // prevent errorbars getting out of the canvas
var drawUpper = true, var drawUpper = true,
...@@ -281,16 +301,27 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -281,16 +301,27 @@ shadowSize and lineWidth are derived as well from the points series.
// error bar - avoid plotting over circles // error bar - avoid plotting over circles
if (err.err == "x"){ if (err.err == "x"){
if (upper > x + radius) drawPath(ctx, [[upper,y],[Math.max(x + radius,minmax[0]),y]]); if (upper > x + radius) {
else drawUpper = false; drawPath(ctx, [[upper,y],[Math.max(x + radius,minmax[0]),y]]);
if (lower < x - radius) drawPath(ctx, [[Math.min(x - radius,minmax[1]),y],[lower,y]] ); } else {
else drawLower = false; drawUpper = false;
}
if (lower < x - radius) {
drawPath(ctx, [[Math.min(x - radius,minmax[1]),y],[lower,y]] );
} else {
drawLower = false;
}
} else {
if (upper < y - radius) {
drawPath(ctx, [[x,upper],[x,Math.min(y - radius,minmax[0])]] );
} else {
drawUpper = false;
}
if (lower > y + radius) {
drawPath(ctx, [[x,Math.max(y + radius,minmax[1])],[x,lower]] );
} else {
drawLower = false;
} }
else {
if (upper < y - radius) drawPath(ctx, [[x,upper],[x,Math.min(y - radius,minmax[0])]] );
else drawUpper = false;
if (lower > y + radius) drawPath(ctx, [[x,Math.max(y + radius,minmax[1])],[x,lower]] );
else drawLower = false;
} }
//internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps //internal radius value in errorbar, allows to plot radius 0 points and still keep proper sized caps
...@@ -300,21 +331,33 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -300,21 +331,33 @@ shadowSize and lineWidth are derived as well from the points series.
// upper cap // upper cap
if (drawUpper) { if (drawUpper) {
if (err.upperCap == "-"){ if (err.upperCap == "-"){
if (err.err=="x") drawPath(ctx, [[upper,y - radius],[upper,y + radius]] ); if (err.err=="x") {
else drawPath(ctx, [[x - radius,upper],[x + radius,upper]] ); drawPath(ctx, [[upper,y - radius],[upper,y + radius]] );
} else {
drawPath(ctx, [[x - radius,upper],[x + radius,upper]] );
}
} else if ($.isFunction(err.upperCap)){ } else if ($.isFunction(err.upperCap)){
if (err.err=="x") err.upperCap(ctx, upper, y, radius); if (err.err=="x") {
else err.upperCap(ctx, x, upper, radius); err.upperCap(ctx, upper, y, radius);
} else {
err.upperCap(ctx, x, upper, radius);
}
} }
} }
// lower cap // lower cap
if (drawLower) { if (drawLower) {
if (err.lowerCap == "-"){ if (err.lowerCap == "-"){
if (err.err=="x") drawPath(ctx, [[lower,y - radius],[lower,y + radius]] ); if (err.err=="x") {
else drawPath(ctx, [[x - radius,lower],[x + radius,lower]] ); drawPath(ctx, [[lower,y - radius],[lower,y + radius]] );
} else {
drawPath(ctx, [[x - radius,lower],[x + radius,lower]] );
}
} else if ($.isFunction(err.lowerCap)){ } else if ($.isFunction(err.lowerCap)){
if (err.err=="x") err.lowerCap(ctx, lower, y, radius); if (err.err=="x") {
else err.lowerCap(ctx, x, lower, radius); err.lowerCap(ctx, lower, y, radius);
} else {
err.lowerCap(ctx, x, lower, radius);
}
} }
} }
} }
...@@ -322,8 +365,9 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -322,8 +365,9 @@ shadowSize and lineWidth are derived as well from the points series.
function drawPath(ctx, pts){ function drawPath(ctx, pts){
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(pts[0][0], pts[0][1]); ctx.moveTo(pts[0][0], pts[0][1]);
for (var p=1; p < pts.length; p++) for (var p=1; p < pts.length; p++) {
ctx.lineTo(pts[p][0], pts[p][1]); ctx.lineTo(pts[p][0], pts[p][1]);
}
ctx.stroke(); ctx.stroke();
} }
...@@ -333,8 +377,9 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -333,8 +377,9 @@ shadowSize and lineWidth are derived as well from the points series.
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
$.each(plot.getData(), function (i, s) { $.each(plot.getData(), function (i, s) {
if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) if (s.points.errorbars && (s.points.xerr.show || s.points.yerr.show)) {
drawSeriesErrors(plot, ctx, s); drawSeriesErrors(plot, ctx, s);
}
}); });
ctx.restore(); ctx.restore();
} }
......
...@@ -71,11 +71,13 @@ Google Maps). ...@@ -71,11 +71,13 @@ Google Maps).
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") {
...@@ -88,8 +90,9 @@ Google Maps). ...@@ -88,8 +90,9 @@ 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();
...@@ -98,8 +101,9 @@ Google Maps). ...@@ -98,8 +101,9 @@ Google Maps).
$.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 () {
...@@ -107,8 +111,9 @@ Google Maps). ...@@ -107,8 +111,9 @@ Google Maps).
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);
...@@ -118,8 +123,9 @@ Google Maps). ...@@ -118,8 +123,9 @@ Google Maps).
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;
...@@ -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;
...@@ -162,8 +169,9 @@ Google Maps). ...@@ -162,8 +169,9 @@ Google Maps).
// 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) {
...@@ -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 = [
......
...@@ -638,8 +638,9 @@ Licensed under the MIT license. ...@@ -638,8 +638,9 @@ Licensed under the MIT license.
plot.getAxes = function () { plot.getAxes = function () {
var res = {}, i; var res = {}, i;
$.each(xaxes.concat(yaxes), function (_, axis) { $.each(xaxes.concat(yaxes), function (_, axis) {
if (axis) if (axis) {
res[axis.direction + (axis.n != 1 ? axis.n : "") + "axis"] = axis; res[axis.direction + (axis.n != 1 ? axis.n : "") + "axis"] = axis;
}
}); });
return res; return res;
}; };
...@@ -680,9 +681,10 @@ Licensed under the MIT license. ...@@ -680,9 +681,10 @@ Licensed under the MIT license.
function executeHooks(hook, args) { function executeHooks(hook, args) {
args = [plot].concat(args); args = [plot].concat(args);
for (var i = 0; i < hook.length; ++i) for (var i = 0; i < hook.length; ++i) {
hook[i].apply(this, args); hook[i].apply(this, args);
} }
}
function initPlugins() { function initPlugins() {
...@@ -695,10 +697,11 @@ Licensed under the MIT license. ...@@ -695,10 +697,11 @@ Licensed under the MIT license.
for (var i = 0; i < plugins.length; ++i) { for (var i = 0; i < plugins.length; ++i) {
var p = plugins[i]; var p = plugins[i];
p.init(plot, classes); p.init(plot, classes);
if (p.options) if (p.options) {
$.extend(true, options, p.options); $.extend(true, options, p.options);
} }
} }
}
function parseOptions(opts) { function parseOptions(opts) {
...@@ -713,20 +716,26 @@ Licensed under the MIT license. ...@@ -713,20 +716,26 @@ Licensed under the MIT license.
options.colors = opts.colors; options.colors = opts.colors;
} }
if (options.xaxis.color == null) if (options.xaxis.color == null) {
options.xaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString(); options.xaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString();
if (options.yaxis.color == null) }
if (options.yaxis.color == null) {
options.yaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString(); options.yaxis.color = $.color.parse(options.grid.color).scale("a", 0.22).toString();
}
if (options.xaxis.tickColor == null) // grid.tickColor for back-compatibility if (options.xaxis.tickColor == null) { // grid.tickColor for back-compatibility
options.xaxis.tickColor = options.grid.tickColor || options.xaxis.color; options.xaxis.tickColor = options.grid.tickColor || options.xaxis.color;
if (options.yaxis.tickColor == null) // grid.tickColor for back-compatibility }
if (options.yaxis.tickColor == null) { // grid.tickColor for back-compatibility
options.yaxis.tickColor = options.grid.tickColor || options.yaxis.color; options.yaxis.tickColor = options.grid.tickColor || options.yaxis.color;
}
if (options.grid.borderColor == null) if (options.grid.borderColor == null) {
options.grid.borderColor = options.grid.color; options.grid.borderColor = options.grid.color;
if (options.grid.tickColor == null) }
if (options.grid.tickColor == null) {
options.grid.tickColor = $.color.parse(options.grid.color).scale("a", 0.22).toString(); options.grid.tickColor = $.color.parse(options.grid.color).scale("a", 0.22).toString();
}
// Fill in defaults for axis options, including any unspecified // Fill in defaults for axis options, including any unspecified
// font-spec fields, if a font-spec was provided. // font-spec fields, if a font-spec was provided.
...@@ -784,10 +793,12 @@ Licensed under the MIT license. ...@@ -784,10 +793,12 @@ Licensed under the MIT license.
} }
// backwards compatibility, to be removed in future // backwards compatibility, to be removed in future
if (options.xaxis.noTicks && options.xaxis.ticks == null) if (options.xaxis.noTicks && options.xaxis.ticks == null) {
options.xaxis.ticks = options.xaxis.noTicks; options.xaxis.ticks = options.xaxis.noTicks;
if (options.yaxis.noTicks && options.yaxis.ticks == null) }
if (options.yaxis.noTicks && options.yaxis.ticks == null) {
options.yaxis.ticks = options.yaxis.noTicks; options.yaxis.ticks = options.yaxis.noTicks;
}
if (options.x2axis) { if (options.x2axis) {
options.xaxes[1] = $.extend(true, {}, options.xaxis, options.x2axis); options.xaxes[1] = $.extend(true, {}, options.xaxis, options.x2axis);
options.xaxes[1].position = "top"; options.xaxes[1].position = "top";
...@@ -796,31 +807,42 @@ Licensed under the MIT license. ...@@ -796,31 +807,42 @@ Licensed under the MIT license.
options.yaxes[1] = $.extend(true, {}, options.yaxis, options.y2axis); options.yaxes[1] = $.extend(true, {}, options.yaxis, options.y2axis);
options.yaxes[1].position = "right"; options.yaxes[1].position = "right";
} }
if (options.grid.coloredAreas) if (options.grid.coloredAreas) {
options.grid.markings = options.grid.coloredAreas; options.grid.markings = options.grid.coloredAreas;
if (options.grid.coloredAreasColor) }
if (options.grid.coloredAreasColor) {
options.grid.markingsColor = options.grid.coloredAreasColor; options.grid.markingsColor = options.grid.coloredAreasColor;
if (options.lines) }
if (options.lines) {
$.extend(true, options.series.lines, options.lines); $.extend(true, options.series.lines, options.lines);
if (options.points) }
if (options.points) {
$.extend(true, options.series.points, options.points); $.extend(true, options.series.points, options.points);
if (options.bars) }
if (options.bars) {
$.extend(true, options.series.bars, options.bars); $.extend(true, options.series.bars, options.bars);
if (options.shadowSize != null) }
if (options.shadowSize != null) {
options.series.shadowSize = options.shadowSize; options.series.shadowSize = options.shadowSize;
if (options.highlightColor != null) }
if (options.highlightColor != null) {
options.series.highlightColor = options.highlightColor; options.series.highlightColor = options.highlightColor;
}
// save options on axes for future reference // save options on axes for future reference
for (i = 0; i < options.xaxes.length; ++i) for (i = 0; i < options.xaxes.length; ++i) {
getOrCreateAxis(xaxes, i + 1).options = options.xaxes[i]; getOrCreateAxis(xaxes, i + 1).options = options.xaxes[i];
for (i = 0; i < options.yaxes.length; ++i) }
for (i = 0; i < options.yaxes.length; ++i) {
getOrCreateAxis(yaxes, i + 1).options = options.yaxes[i]; getOrCreateAxis(yaxes, i + 1).options = options.yaxes[i];
}
// add hooks from options // add hooks from options
for (var n in hooks) for (var n in hooks) {
if (options.hooks[n] && options.hooks[n].length) if (options.hooks[n] && options.hooks[n].length) {
hooks[n] = hooks[n].concat(options.hooks[n]); hooks[n] = hooks[n].concat(options.hooks[n]);
}
}
executeHooks(hooks.processOptions, [options]); executeHooks(hooks.processOptions, [options]);
} }
...@@ -843,9 +865,9 @@ Licensed under the MIT license. ...@@ -843,9 +865,9 @@ Licensed under the MIT license.
$.extend(true, s, d[i]); $.extend(true, s, d[i]);
d[i].data = s.data; d[i].data = s.data;
} } else {
else
s.data = d[i]; s.data = d[i];
}
res.push(s); res.push(s);
} }
...@@ -854,10 +876,12 @@ Licensed under the MIT license. ...@@ -854,10 +876,12 @@ Licensed under the MIT license.
function axisNumber(obj, coord) { function axisNumber(obj, coord) {
var a = obj[coord + "axis"]; var a = obj[coord + "axis"];
if (typeof a == "object") // if we got a real axis, extract number if (typeof a == "object") { // if we got a real axis, extract number
a = a.n; a = a.n;
if (typeof a != "number") }
if (typeof a != "number") {
a = 1; // default to first axis a = 1; // default to first axis
}
return a; return a;
} }
...@@ -871,20 +895,24 @@ Licensed under the MIT license. ...@@ -871,20 +895,24 @@ Licensed under the MIT license.
var res = {}, i, axis; var res = {}, i, axis;
for (i = 0; i < xaxes.length; ++i) { for (i = 0; i < xaxes.length; ++i) {
axis = xaxes[i]; axis = xaxes[i];
if (axis && axis.used) if (axis && axis.used) {
res["x" + axis.n] = axis.c2p(pos.left); res["x" + axis.n] = axis.c2p(pos.left);
} }
}
for (i = 0; i < yaxes.length; ++i) { for (i = 0; i < yaxes.length; ++i) {
axis = yaxes[i]; axis = yaxes[i];
if (axis && axis.used) if (axis && axis.used) {
res["y" + axis.n] = axis.c2p(pos.top); res["y" + axis.n] = axis.c2p(pos.top);
} }
}
if (res.x1 !== undefined) if (res.x1 !== undefined) {
res.x = res.x1; res.x = res.x1;
if (res.y1 !== undefined) }
if (res.y1 !== undefined) {
res.y = res.y1; res.y = res.y1;
}
return res; return res;
} }
...@@ -897,8 +925,9 @@ Licensed under the MIT license. ...@@ -897,8 +925,9 @@ Licensed under the MIT license.
axis = xaxes[i]; axis = xaxes[i];
if (axis && axis.used) { if (axis && axis.used) {
key = "x" + axis.n; key = "x" + axis.n;
if (pos[key] == null && axis.n == 1) if (pos[key] == null && axis.n == 1) {
key = "x"; key = "x";
}
if (pos[key] != null) { if (pos[key] != null) {
res.left = axis.p2c(pos[key]); res.left = axis.p2c(pos[key]);
...@@ -911,8 +940,9 @@ Licensed under the MIT license. ...@@ -911,8 +940,9 @@ Licensed under the MIT license.
axis = yaxes[i]; axis = yaxes[i];
if (axis && axis.used) { if (axis && axis.used) {
key = "y" + axis.n; key = "y" + axis.n;
if (pos[key] == null && axis.n == 1) if (pos[key] == null && axis.n == 1) {
key = "y"; key = "y";
}
if (pos[key] != null) { if (pos[key] != null) {
res.top = axis.p2c(pos[key]); res.top = axis.p2c(pos[key]);
...@@ -925,12 +955,13 @@ Licensed under the MIT license. ...@@ -925,12 +955,13 @@ Licensed under the MIT license.
} }
function getOrCreateAxis(axes, number) { function getOrCreateAxis(axes, number) {
if (!axes[number - 1]) if (!axes[number - 1]) {
axes[number - 1] = { axes[number - 1] = {
n: number, // save the number for future reference n: number, // save the number for future reference
direction: axes == xaxes ? "x" : "y", direction: axes == xaxes ? "x" : "y",
options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis) options: $.extend(true, {}, axes == xaxes ? options.xaxis : options.yaxis)
}; };
}
return axes[number - 1]; return axes[number - 1];
} }
...@@ -981,8 +1012,12 @@ Licensed under the MIT license. ...@@ -981,8 +1012,12 @@ Licensed under the MIT license.
if (variation >= 0) { if (variation >= 0) {
if (variation < 0.5) { if (variation < 0.5) {
variation = -variation - 0.2; variation = -variation - 0.2;
} else variation = 0; } else {
} else variation = -variation; variation = 0;
}
} else {
variation = -variation;
}
} }
colors[i] = c.scale("rgb", 1 + variation); colors[i] = c.scale("rgb", 1 + variation);
...@@ -999,20 +1034,23 @@ Licensed under the MIT license. ...@@ -999,20 +1034,23 @@ Licensed under the MIT license.
s.color = colors[colori].toString(); s.color = colors[colori].toString();
++colori; ++colori;
} }
else if (typeof s.color == "number") else if (typeof s.color == "number") {
s.color = colors[s.color].toString(); s.color = colors[s.color].toString();
}
// turn on lines automatically in case nothing is set // turn on lines automatically in case nothing is set
if (s.lines.show == null) { if (s.lines.show == null) {
var v, show = true; var v, show = true;
for (v in s) for (v in s) {
if (s[v] && s[v].show) { if (s[v] && s[v].show) {
show = false; show = false;
break; break;
} }
if (show) }
if (show) {
s.lines.show = true; s.lines.show = true;
} }
}
// If nothing was provided for lines.zero, default it to match // If nothing was provided for lines.zero, default it to match
// lines.fill, since areas by default should extend to zero. // lines.fill, since areas by default should extend to zero.
...@@ -1036,11 +1074,13 @@ Licensed under the MIT license. ...@@ -1036,11 +1074,13 @@ Licensed under the MIT license.
data, format; data, format;
function updateAxis(axis, min, max) { function updateAxis(axis, min, max) {
if (min < axis.datamin && min != -fakeInfinity) if (min < axis.datamin && min != -fakeInfinity) {
axis.datamin = min; axis.datamin = min;
if (max > axis.datamax && max != fakeInfinity) }
if (max > axis.datamax && max != fakeInfinity) {
axis.datamax = max; axis.datamax = max;
} }
}
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function (_, axis) {
// init axis // init axis
...@@ -1081,8 +1121,9 @@ Licensed under the MIT license. ...@@ -1081,8 +1121,9 @@ Licensed under the MIT license.
s.datapoints.format = format; s.datapoints.format = format;
} }
if (s.datapoints.pointsize != null) if (s.datapoints.pointsize != null) {
continue; // already filled in continue; // already filled in
}
s.datapoints.pointsize = format.length; s.datapoints.pointsize = format.length;
...@@ -1104,22 +1145,25 @@ Licensed under the MIT license. ...@@ -1104,22 +1145,25 @@ Licensed under the MIT license.
if (f) { if (f) {
if (f.number && val != null) { if (f.number && val != null) {
val = +val; // convert to number val = +val; // convert to number
if (isNaN(val)) if (isNaN(val)) {
val = null; val = null;
else if (val == Infinity) } else if (val == Infinity) {
val = fakeInfinity; val = fakeInfinity;
else if (val == -Infinity) } else if (val == -Infinity) {
val = -fakeInfinity; val = -fakeInfinity;
} }
}
if (val == null) { if (val == null) {
if (f.required) if (f.required) {
nullify = true; nullify = true;
}
if (f.defaultValue != null) if (f.defaultValue != null) {
val = f.defaultValue; val = f.defaultValue;
} }
} }
}
points[k + m] = val; points[k + m] = val;
} }
...@@ -1152,8 +1196,9 @@ Licensed under the MIT license. ...@@ -1152,8 +1196,9 @@ Licensed under the MIT license.
&& points[k - ps] != points[k] && points[k - ps] != points[k]
&& points[k - ps + 1] != points[k + 1]) { && points[k - ps + 1] != points[k + 1]) {
// copy the point to make room for a middle point // copy the point to make room for a middle point
for (m = 0; m < ps; ++m) for (m = 0; m < ps; ++m) {
points[k + ps + m] = points[k + m]; points[k + ps + m] = points[k + m];
}
// middle point has same y // middle point has same y
points[k + 1] = points[k - ps + 1]; points[k + 1] = points[k - ps + 1];
...@@ -1183,29 +1228,35 @@ Licensed under the MIT license. ...@@ -1183,29 +1228,35 @@ Licensed under the MIT license.
xmax = bottomSentry, ymax = bottomSentry; xmax = bottomSentry, ymax = bottomSentry;
for (j = 0; j < points.length; j += ps) { for (j = 0; j < points.length; j += ps) {
if (points[j] == null) if (points[j] == null) {
continue; continue;
}
for (m = 0; m < ps; ++m) { for (m = 0; m < ps; ++m) {
val = points[j + m]; val = points[j + m];
f = format[m]; f = format[m];
if (!f || f.autoscale === false || val == fakeInfinity || val == -fakeInfinity) if (!f || f.autoscale === false || val == fakeInfinity || val == -fakeInfinity) {
continue; continue;
}
if (f.x) { if (f.x) {
if (val < xmin) if (val < xmin) {
xmin = val; xmin = val;
if (val > xmax) }
if (val > xmax) {
xmax = val; xmax = val;
} }
}
if (f.y) { if (f.y) {
if (val < ymin) if (val < ymin) {
ymin = val; ymin = val;
if (val > ymax) }
if (val > ymax) {
ymax = val; ymax = val;
} }
} }
} }
}
if (s.bars.show) { if (s.bars.show) {
// make sure we got room for the bar on the dancing floor // make sure we got room for the bar on the dancing floor
...@@ -1228,8 +1279,7 @@ Licensed under the MIT license. ...@@ -1228,8 +1279,7 @@ Licensed under the MIT license.
if (s.bars.horizontal) { if (s.bars.horizontal) {
ymin += delta; ymin += delta;
ymax += delta + s.bars.barWidth; ymax += delta + s.bars.barWidth;
} } else {
else {
xmin += delta; xmin += delta;
xmax += delta + s.bars.barWidth; xmax += delta + s.bars.barWidth;
} }
...@@ -1240,10 +1290,12 @@ Licensed under the MIT license. ...@@ -1240,10 +1290,12 @@ Licensed under the MIT license.
} }
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function (_, axis) {
if (axis.datamin == topSentry) if (axis.datamin == topSentry) {
axis.datamin = null; axis.datamin = null;
if (axis.datamax == bottomSentry) }
if (axis.datamax == bottomSentry) {
axis.datamax = null; axis.datamax = null;
}
}); });
} }
...@@ -1255,8 +1307,9 @@ Licensed under the MIT license. ...@@ -1255,8 +1307,9 @@ Licensed under the MIT license.
placeholder.css("padding", 0) // padding messes up the positioning placeholder.css("padding", 0) // padding messes up the positioning
.children(":not(.flot-base,.flot-overlay)").remove(); .children(":not(.flot-base,.flot-overlay)").remove();
if (placeholder.css("position") == "static") if (placeholder.css("position") == "static") {
placeholder.css("position", "relative"); // for positioning labels and overlay placeholder.css("position", "relative"); // for positioning labels and overlay
}
surface = new Canvas("flot-base", placeholder); surface = new Canvas("flot-base", placeholder);
overlay = new Canvas("flot-overlay", placeholder); // overlay canvas for interactive features overlay = new Canvas("flot-overlay", placeholder); // overlay canvas for interactive features
...@@ -1294,15 +1347,17 @@ Licensed under the MIT license. ...@@ -1294,15 +1347,17 @@ Licensed under the MIT license.
eventHolder.bind("mouseleave", onMouseLeave); eventHolder.bind("mouseleave", onMouseLeave);
} }
if (options.grid.clickable) if (options.grid.clickable) {
eventHolder.click(onClick); eventHolder.click(onClick);
}
executeHooks(hooks.bindEvents, [eventHolder]); executeHooks(hooks.bindEvents, [eventHolder]);
} }
function shutdown() { function shutdown() {
if (redrawTimeout) if (redrawTimeout) {
clearTimeout(redrawTimeout); clearTimeout(redrawTimeout);
}
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mouseleave", onMouseLeave); eventHolder.unbind("mouseleave", onMouseLeave);
...@@ -1325,24 +1380,25 @@ Licensed under the MIT license. ...@@ -1325,24 +1380,25 @@ Licensed under the MIT license.
if (axis.direction == "x") { if (axis.direction == "x") {
s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min)); s = axis.scale = plotWidth / Math.abs(t(axis.max) - t(axis.min));
m = Math.min(t(axis.max), t(axis.min)); m = Math.min(t(axis.max), t(axis.min));
} } else {
else {
s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min)); s = axis.scale = plotHeight / Math.abs(t(axis.max) - t(axis.min));
s = -s; s = -s;
m = Math.max(t(axis.max), t(axis.min)); m = Math.max(t(axis.max), t(axis.min));
} }
// data point to canvas coordinate // data point to canvas coordinate
if (t == identity) // slight optimization if (t == identity) { // slight optimization
axis.p2c = function (p) { return (p - m) * s; }; axis.p2c = function (p) { return (p - m) * s; };
else } else {
axis.p2c = function (p) { return (t(p) - m) * s; }; axis.p2c = function (p) { return (t(p) - m) * s; };
}
// canvas coordinate to data point // canvas coordinate to data point
if (!it) if (!it) {
axis.c2p = function (c) { return m + c / s; }; axis.c2p = function (c) { return m + c / s; };
else } else {
axis.c2p = function (c) { return it(m + c / s); }; axis.c2p = function (c) { return it(m + c / s); };
} }
}
function measureTickLabels(axis) { function measureTickLabels(axis) {
...@@ -1359,8 +1415,9 @@ Licensed under the MIT license. ...@@ -1359,8 +1415,9 @@ Licensed under the MIT license.
var t = ticks[i]; var t = ticks[i];
if (!t.label) if (!t.label) {
continue; continue;
}
var info = surface.getTextInfo(layer, t.label, font, null, maxWidth); var info = surface.getTextInfo(layer, t.label, font, null, maxWidth);
...@@ -1392,8 +1449,9 @@ Licensed under the MIT license. ...@@ -1392,8 +1449,9 @@ Licensed under the MIT license.
var samePosition = $.grep(all, function (a) { var samePosition = $.grep(all, function (a) {
return a && a.options.position == pos && a.reserveSpace; return a && a.options.position == pos && a.reserveSpace;
}); });
if ($.inArray(axis, samePosition) == samePosition.length - 1) if ($.inArray(axis, samePosition) == samePosition.length - 1) {
axisMargin = 0; // outermost axisMargin = 0; // outermost
}
// Determine whether the axis is the first (innermost) on its side // Determine whether the axis is the first (innermost) on its side
...@@ -1402,14 +1460,16 @@ Licensed under the MIT license. ...@@ -1402,14 +1460,16 @@ Licensed under the MIT license.
// determine tick length - if we're innermost, we can use "full" // determine tick length - if we're innermost, we can use "full"
if (tickLength == null) { if (tickLength == null) {
if (innermost) if (innermost) {
tickLength = "full"; tickLength = "full";
else } else {
tickLength = 5; tickLength = 5;
} }
}
if (!isNaN(+tickLength)) if (!isNaN(+tickLength)) {
padding += +tickLength; padding += +tickLength;
}
// compute box // compute box
if (axis.direction == "x") { if (axis.direction == "x") {
...@@ -1418,20 +1478,17 @@ Licensed under the MIT license. ...@@ -1418,20 +1478,17 @@ Licensed under the MIT license.
if (pos == "bottom") { if (pos == "bottom") {
plotOffset.bottom += lh + axisMargin; plotOffset.bottom += lh + axisMargin;
axis.box = { top: surface.height - plotOffset.bottom, height: lh }; axis.box = { top: surface.height - plotOffset.bottom, height: lh };
} } else {
else {
axis.box = { top: plotOffset.top + axisMargin, height: lh }; axis.box = { top: plotOffset.top + axisMargin, height: lh };
plotOffset.top += lh + axisMargin; plotOffset.top += lh + axisMargin;
} }
} } else {
else {
lw += padding; lw += padding;
if (pos == "left") { if (pos == "left") {
axis.box = { left: plotOffset.left + axisMargin, width: lw }; axis.box = { left: plotOffset.left + axisMargin, width: lw };
plotOffset.left += lw + axisMargin; plotOffset.left += lw + axisMargin;
} } else {
else {
plotOffset.right += lw + axisMargin; plotOffset.right += lw + axisMargin;
axis.box = { left: surface.width - plotOffset.right, width: lw }; axis.box = { left: surface.width - plotOffset.right, width: lw };
} }
...@@ -1450,8 +1507,7 @@ Licensed under the MIT license. ...@@ -1450,8 +1507,7 @@ Licensed under the MIT license.
if (axis.direction == "x") { if (axis.direction == "x") {
axis.box.left = plotOffset.left - axis.labelWidth / 2; axis.box.left = plotOffset.left - axis.labelWidth / 2;
axis.box.width = surface.width - plotOffset.left - plotOffset.right + axis.labelWidth; axis.box.width = surface.width - plotOffset.left - plotOffset.right + axis.labelWidth;
} } else {
else {
axis.box.top = plotOffset.top - axis.labelHeight / 2; axis.box.top = plotOffset.top - axis.labelHeight / 2;
axis.box.height = surface.height - plotOffset.bottom - plotOffset.top + axis.labelHeight; axis.box.height = surface.height - plotOffset.bottom - plotOffset.top + axis.labelHeight;
} }
...@@ -1469,9 +1525,10 @@ Licensed under the MIT license. ...@@ -1469,9 +1525,10 @@ Licensed under the MIT license.
// customize) // customize)
if (minMargin == null) { if (minMargin == null) {
minMargin = 0; minMargin = 0;
for (i = 0; i < series.length; ++i) for (i = 0; i < series.length; ++i) {
minMargin = Math.max(minMargin, 2 * (series[i].points.radius + series[i].points.lineWidth/2)); minMargin = Math.max(minMargin, 2 * (series[i].points.radius + series[i].points.lineWidth/2));
} }
}
margins.x = margins.y = Math.ceil(minMargin); margins.x = margins.y = Math.ceil(minMargin);
...@@ -1480,8 +1537,9 @@ Licensed under the MIT license. ...@@ -1480,8 +1537,9 @@ Licensed under the MIT license.
// jump as much around with replots // jump as much around with replots
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function (_, axis) {
var dir = axis.direction; var dir = axis.direction;
if (axis.reserveSpace) if (axis.reserveSpace) {
margins[dir] = Math.ceil(Math.max(margins[dir], (dir == "x" ? axis.labelWidth : axis.labelHeight) / 2)); margins[dir] = Math.ceil(Math.max(margins[dir], (dir == "x" ? axis.labelWidth : axis.labelHeight) / 2));
}
}); });
plotOffset.left = Math.max(margins.x, plotOffset.left); plotOffset.left = Math.max(margins.x, plotOffset.left);
...@@ -1507,8 +1565,7 @@ Licensed under the MIT license. ...@@ -1507,8 +1565,7 @@ Licensed under the MIT license.
for (var a in plotOffset) { for (var a in plotOffset) {
if(typeof(options.grid.borderWidth) == "object") { if(typeof(options.grid.borderWidth) == "object") {
plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0; plotOffset[a] += showGrid ? options.grid.borderWidth[a] : 0;
} } else {
else {
plotOffset[a] += showGrid ? options.grid.borderWidth : 0; plotOffset[a] += showGrid ? options.grid.borderWidth : 0;
} }
} }
...@@ -1516,8 +1573,9 @@ Licensed under the MIT license. ...@@ -1516,8 +1573,9 @@ Licensed under the MIT license.
// init axes // init axes
$.each(axes, function (_, axis) { $.each(axes, function (_, axis) {
axis.show = axis.options.show; axis.show = axis.options.show;
if (axis.show == null) if (axis.show == null) {
axis.show = axis.used; // by default an axis is visible if it's got data axis.show = axis.used; // by default an axis is visible if it's got data
}
axis.reserveSpace = axis.show || axis.options.reserveSpace; axis.reserveSpace = axis.show || axis.options.reserveSpace;
...@@ -1540,8 +1598,9 @@ Licensed under the MIT license. ...@@ -1540,8 +1598,9 @@ Licensed under the MIT license.
// with all dimensions calculated, we can compute the // with all dimensions calculated, we can compute the
// axis bounding boxes, start from the outside // axis bounding boxes, start from the outside
// (reverse order) // (reverse order)
for (i = allocatedAxes.length - 1; i >= 0; --i) for (i = allocatedAxes.length - 1; i >= 0; --i) {
allocateAxisBoxFirstPhase(allocatedAxes[i]); allocateAxisBoxFirstPhase(allocatedAxes[i]);
}
// make sure we've got enough space for things that // make sure we've got enough space for things that
// might stick out // might stick out
...@@ -1577,14 +1636,15 @@ Licensed under the MIT license. ...@@ -1577,14 +1636,15 @@ Licensed under the MIT license.
// degenerate case // degenerate case
var widen = max == 0 ? 1 : 0.01; var widen = max == 0 ? 1 : 0.01;
if (opts.min == null) if (opts.min == null) {
min -= widen; min -= widen;
}
// always widen max if we couldn't widen min to ensure we // always widen max if we couldn't widen min to ensure we
// don't fall into min == max which doesn't work // don't fall into min == max which doesn't work
if (opts.max == null || opts.min != null) if (opts.max == null || opts.min != null) {
max += widen; max += widen;
} }
else { } else {
// consider autoscaling // consider autoscaling
var margin = opts.autoscaleMargin; var margin = opts.autoscaleMargin;
if (margin != null) { if (margin != null) {
...@@ -1592,16 +1652,18 @@ Licensed under the MIT license. ...@@ -1592,16 +1652,18 @@ Licensed under the MIT license.
min -= delta * margin; min -= delta * margin;
// make sure we don't go below zero if all values // make sure we don't go below zero if all values
// are positive // are positive
if (min < 0 && axis.datamin != null && axis.datamin >= 0) if (min < 0 && axis.datamin != null && axis.datamin >= 0) {
min = 0; min = 0;
} }
}
if (opts.max == null) { if (opts.max == null) {
max += delta * margin; max += delta * margin;
if (max > 0 && axis.datamax != null && axis.datamax <= 0) if (max > 0 && axis.datamax != null && axis.datamax <= 0) {
max = 0; max = 0;
} }
} }
} }
}
axis.min = min; axis.min = min;
axis.max = max; axis.max = max;
} }
...@@ -1611,12 +1673,13 @@ Licensed under the MIT license. ...@@ -1611,12 +1673,13 @@ Licensed under the MIT license.
// estimate number of ticks // estimate number of ticks
var noTicks; var noTicks;
if (typeof opts.ticks == "number" && opts.ticks > 0) if (typeof opts.ticks == "number" && opts.ticks > 0) {
noTicks = opts.ticks; noTicks = opts.ticks;
else } else {
// heuristic based on the model a*sqrt(x) fitted to // heuristic based on the model a*sqrt(x) fitted to
// some data points that seemed reasonable // some data points that seemed reasonable
noTicks = 0.3 * Math.sqrt(axis.direction == "x" ? surface.width : surface.height); noTicks = 0.3 * Math.sqrt(axis.direction == "x" ? surface.width : surface.height);
}
var delta = (axis.max - axis.min) / noTicks, var delta = (axis.max - axis.min) / noTicks,
dec = -Math.floor(Math.log(delta) / Math.LN10), dec = -Math.floor(Math.log(delta) / Math.LN10),
...@@ -1704,8 +1767,9 @@ Licensed under the MIT license. ...@@ -1704,8 +1767,9 @@ Licensed under the MIT license.
}; };
} }
if ($.isFunction(opts.tickFormatter)) if ($.isFunction(opts.tickFormatter)) {
axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); }; axis.tickFormatter = function (v, axis) { return "" + opts.tickFormatter(v, axis); };
}
if (opts.alignTicksWithAxis != null) { if (opts.alignTicksWithAxis != null) {
var otherAxis = (axis.direction == "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1]; var otherAxis = (axis.direction == "x" ? xaxes : yaxes)[opts.alignTicksWithAxis - 1];
...@@ -1713,11 +1777,13 @@ Licensed under the MIT license. ...@@ -1713,11 +1777,13 @@ Licensed under the MIT license.
// consider snapping min/max to outermost nice ticks // consider snapping min/max to outermost nice ticks
var niceTicks = axis.tickGenerator(axis); var niceTicks = axis.tickGenerator(axis);
if (niceTicks.length > 0) { if (niceTicks.length > 0) {
if (opts.min == null) if (opts.min == null) {
axis.min = Math.min(axis.min, niceTicks[0]); axis.min = Math.min(axis.min, niceTicks[0]);
if (opts.max == null && niceTicks.length > 1) }
if (opts.max == null && niceTicks.length > 1) {
axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]); axis.max = Math.max(axis.max, niceTicks[niceTicks.length - 1]);
} }
}
axis.tickGenerator = function (axis) { axis.tickGenerator = function (axis) {
// copy ticks, scaled to this axis // copy ticks, scaled to this axis
...@@ -1739,24 +1805,26 @@ Licensed under the MIT license. ...@@ -1739,24 +1805,26 @@ Licensed under the MIT license.
// only proceed if the tick interval rounded // only proceed if the tick interval rounded
// with an extra decimal doesn't give us a // with an extra decimal doesn't give us a
// zero at end // zero at end
if (!(ts.length > 1 && /\..*0$/.test((ts[1] - ts[0]).toFixed(extraDec)))) if (!(ts.length > 1 && /\..*0$/.test((ts[1] - ts[0]).toFixed(extraDec)))) {
axis.tickDecimals = extraDec; axis.tickDecimals = extraDec;
} }
} }
} }
} }
}
function setTicks(axis) { function setTicks(axis) {
var oticks = axis.options.ticks, ticks = []; var oticks = axis.options.ticks, ticks = [];
if (oticks == null || (typeof oticks == "number" && oticks > 0)) if (oticks == null || (typeof oticks == "number" && oticks > 0)) {
ticks = axis.tickGenerator(axis); ticks = axis.tickGenerator(axis);
else if (oticks) { } else if (oticks) {
if ($.isFunction(oticks)) if ($.isFunction(oticks)) {
// generate the ticks // generate the ticks
ticks = oticks(axis); ticks = oticks(axis);
else } else {
ticks = oticks; ticks = oticks;
} }
}
// clean up/labelify the supplied ticks, copy them over // clean up/labelify the supplied ticks, copy them over
var i, v; var i, v;
...@@ -1766,27 +1834,32 @@ Licensed under the MIT license. ...@@ -1766,27 +1834,32 @@ Licensed under the MIT license.
var t = ticks[i]; var t = ticks[i];
if (typeof t == "object") { if (typeof t == "object") {
v = +t[0]; v = +t[0];
if (t.length > 1) if (t.length > 1) {
label = t[1]; label = t[1];
} }
else } else {
v = +t; v = +t;
if (label == null) }
if (label == null) {
label = axis.tickFormatter(v, axis); label = axis.tickFormatter(v, axis);
if (!isNaN(v)) }
if (!isNaN(v)) {
axis.ticks.push({ v: v, label: label }); axis.ticks.push({ v: v, label: label });
} }
} }
}
function snapRangeToTicks(axis, ticks) { function snapRangeToTicks(axis, ticks) {
if (axis.options.autoscaleMargin && ticks.length > 0) { if (axis.options.autoscaleMargin && ticks.length > 0) {
// snap to ticks // snap to ticks
if (axis.options.min == null) if (axis.options.min == null) {
axis.min = Math.min(axis.min, ticks[0].v); axis.min = Math.min(axis.min, ticks[0].v);
if (axis.options.max == null && ticks.length > 1) }
if (axis.options.max == null && ticks.length > 1) {
axis.max = Math.max(axis.max, ticks[ticks.length - 1].v); axis.max = Math.max(axis.max, ticks[ticks.length - 1].v);
} }
} }
}
function draw() { function draw() {
...@@ -1797,8 +1870,9 @@ Licensed under the MIT license. ...@@ -1797,8 +1870,9 @@ Licensed under the MIT license.
var grid = options.grid; var grid = options.grid;
// draw background, if any // draw background, if any
if (grid.show && grid.backgroundColor) if (grid.show && grid.backgroundColor) {
drawBackground(); drawBackground();
}
if (grid.show && !grid.aboveData) { if (grid.show && !grid.aboveData) {
drawGrid(); drawGrid();
...@@ -1830,8 +1904,9 @@ Licensed under the MIT license. ...@@ -1830,8 +1904,9 @@ Licensed under the MIT license.
axis = axes[i]; axis = axes[i];
if (axis.direction == coord) { if (axis.direction == coord) {
key = coord + axis.n + "axis"; key = coord + axis.n + "axis";
if (!ranges[key] && axis.n == 1) if (!ranges[key] && axis.n == 1) {
key = coord + "axis"; // support x1axis as xaxis key = coord + "axis"; // support x1axis as xaxis
}
if (ranges[key]) { if (ranges[key]) {
from = ranges[key].from; from = ranges[key].from;
to = ranges[key].to; to = ranges[key].to;
...@@ -1893,27 +1968,33 @@ Licensed under the MIT license. ...@@ -1893,27 +1968,33 @@ Licensed under the MIT license.
yrange = extractRange(m, "y"); yrange = extractRange(m, "y");
// fill in missing // fill in missing
if (xrange.from == null) if (xrange.from == null) {
xrange.from = xrange.axis.min; xrange.from = xrange.axis.min;
if (xrange.to == null) }
if (xrange.to == null) {
xrange.to = xrange.axis.max; xrange.to = xrange.axis.max;
if (yrange.from == null) }
if (yrange.from == null) {
yrange.from = yrange.axis.min; yrange.from = yrange.axis.min;
if (yrange.to == null) }
if (yrange.to == null) {
yrange.to = yrange.axis.max; yrange.to = yrange.axis.max;
}
// clip // clip
if (xrange.to < xrange.axis.min || xrange.from > xrange.axis.max || if (xrange.to < xrange.axis.min || xrange.from > xrange.axis.max ||
yrange.to < yrange.axis.min || yrange.from > yrange.axis.max) yrange.to < yrange.axis.min || yrange.from > yrange.axis.max) {
continue; continue;
}
xrange.from = Math.max(xrange.from, xrange.axis.min); xrange.from = Math.max(xrange.from, xrange.axis.min);
xrange.to = Math.min(xrange.to, xrange.axis.max); xrange.to = Math.min(xrange.to, xrange.axis.max);
yrange.from = Math.max(yrange.from, yrange.axis.min); yrange.from = Math.max(yrange.from, yrange.axis.min);
yrange.to = Math.min(yrange.to, yrange.axis.max); yrange.to = Math.min(yrange.to, yrange.axis.max);
if (xrange.from == xrange.to && yrange.from == yrange.to) if (xrange.from == xrange.to && yrange.from == yrange.to) {
continue; continue;
}
// then draw // then draw
xrange.from = xrange.axis.p2c(xrange.from); xrange.from = xrange.axis.p2c(xrange.from);
...@@ -1929,8 +2010,7 @@ Licensed under the MIT license. ...@@ -1929,8 +2010,7 @@ Licensed under the MIT license.
ctx.moveTo(xrange.from, yrange.from); ctx.moveTo(xrange.from, yrange.from);
ctx.lineTo(xrange.to, yrange.to); ctx.lineTo(xrange.to, yrange.to);
ctx.stroke(); ctx.stroke();
} } else {
else {
// fill area // fill area
ctx.fillStyle = m.color || options.grid.markingsColor; ctx.fillStyle = m.color || options.grid.markingsColor;
ctx.fillRect(xrange.from, yrange.to, ctx.fillRect(xrange.from, yrange.to,
...@@ -1947,36 +2027,39 @@ Licensed under the MIT license. ...@@ -1947,36 +2027,39 @@ Licensed under the MIT license.
for (var j = 0; j < axes.length; ++j) { for (var j = 0; j < axes.length; ++j) {
var axis = axes[j], box = axis.box, var axis = axes[j], box = axis.box,
t = axis.tickLength, x, y, xoff, yoff; t = axis.tickLength, x, y, xoff, yoff;
if (!axis.show || axis.ticks.length == 0) if (!axis.show || axis.ticks.length == 0) {
continue; continue;
}
ctx.lineWidth = 1; ctx.lineWidth = 1;
// find the edges // find the edges
if (axis.direction == "x") { if (axis.direction == "x") {
x = 0; x = 0;
if (t == "full") if (t == "full") {
y = (axis.position == "top" ? 0 : plotHeight); y = (axis.position == "top" ? 0 : plotHeight);
else } else {
y = box.top - plotOffset.top + (axis.position == "top" ? box.height : 0); y = box.top - plotOffset.top + (axis.position == "top" ? box.height : 0);
} }
else { } else {
y = 0; y = 0;
if (t == "full") if (t == "full") {
x = (axis.position == "left" ? 0 : plotWidth); x = (axis.position == "left" ? 0 : plotWidth);
else } else {
x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0); x = box.left - plotOffset.left + (axis.position == "left" ? box.width : 0);
} }
}
// draw tick bar // draw tick bar
if (!axis.innermost) { if (!axis.innermost) {
ctx.strokeStyle = axis.options.color; ctx.strokeStyle = axis.options.color;
ctx.beginPath(); ctx.beginPath();
xoff = yoff = 0; xoff = yoff = 0;
if (axis.direction == "x") if (axis.direction == "x") {
xoff = plotWidth + 1; xoff = plotWidth + 1;
else } else {
yoff = plotHeight + 1; yoff = plotHeight + 1;
}
if (ctx.lineWidth == 1) { if (ctx.lineWidth == 1) {
if (axis.direction == "x") { if (axis.direction == "x") {
...@@ -2005,30 +2088,33 @@ Licensed under the MIT license. ...@@ -2005,30 +2088,33 @@ Licensed under the MIT license.
// skip those lying on the axes if we got a border // skip those lying on the axes if we got a border
|| (t == "full" || (t == "full"
&& ((typeof bw == "object" && bw[axis.position] > 0) || bw > 0) && ((typeof bw == "object" && bw[axis.position] > 0) || bw > 0)
&& (v == axis.min || v == axis.max))) && (v == axis.min || v == axis.max))) {
continue; continue;
}
if (axis.direction == "x") { if (axis.direction == "x") {
x = axis.p2c(v); x = axis.p2c(v);
yoff = t == "full" ? -plotHeight : t; yoff = t == "full" ? -plotHeight : t;
if (axis.position == "top") if (axis.position == "top") {
yoff = -yoff; yoff = -yoff;
} }
else { } else {
y = axis.p2c(v); y = axis.p2c(v);
xoff = t == "full" ? -plotWidth : t; xoff = t == "full" ? -plotWidth : t;
if (axis.position == "left") if (axis.position == "left") {
xoff = -xoff; xoff = -xoff;
} }
}
if (ctx.lineWidth == 1) { if (ctx.lineWidth == 1) {
if (axis.direction == "x") if (axis.direction == "x") {
x = Math.floor(x) + 0.5; x = Math.floor(x) + 0.5;
else } else {
y = Math.floor(y) + 0.5; y = Math.floor(y) + 0.5;
} }
}
ctx.moveTo(x, y); ctx.moveTo(x, y);
ctx.lineTo(x + xoff, y + yoff); ctx.lineTo(x + xoff, y + yoff);
...@@ -2086,8 +2172,7 @@ Licensed under the MIT license. ...@@ -2086,8 +2172,7 @@ Licensed under the MIT license.
ctx.lineTo(0- bw.left/2, 0); ctx.lineTo(0- bw.left/2, 0);
ctx.stroke(); ctx.stroke();
} }
} } else {
else {
ctx.lineWidth = bw; ctx.lineWidth = bw;
ctx.strokeStyle = options.grid.borderColor; ctx.strokeStyle = options.grid.borderColor;
ctx.strokeRect(-bw/2, -bw/2, plotWidth + bw, plotHeight + bw); ctx.strokeRect(-bw/2, -bw/2, plotWidth + bw, plotHeight + bw);
...@@ -2100,8 +2185,9 @@ Licensed under the MIT license. ...@@ -2100,8 +2185,9 @@ Licensed under the MIT license.
function drawAxisLabels() { function drawAxisLabels() {
$.each(allAxes(), function (_, axis) { $.each(allAxes(), function (_, axis) {
if (!axis.show || axis.ticks.length == 0) if (!axis.show || axis.ticks.length == 0) {
return; return;
}
var box = axis.box, var box = axis.box,
legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis", legacyStyles = axis.direction + "Axis " + axis.direction + axis.n + "Axis",
...@@ -2114,8 +2200,9 @@ Licensed under the MIT license. ...@@ -2114,8 +2200,9 @@ Licensed under the MIT license.
for (var i = 0; i < axis.ticks.length; ++i) { for (var i = 0; i < axis.ticks.length; ++i) {
tick = axis.ticks[i]; tick = axis.ticks[i];
if (!tick.label || tick.v < axis.min || tick.v > axis.max) if (!tick.label || tick.v < axis.min || tick.v > axis.max) {
continue; continue;
}
if (axis.direction == "x") { if (axis.direction == "x") {
halign = "center"; halign = "center";
...@@ -2143,13 +2230,16 @@ Licensed under the MIT license. ...@@ -2143,13 +2230,16 @@ Licensed under the MIT license.
} }
function drawSeries(series) { function drawSeries(series) {
if (series.lines.show) if (series.lines.show) {
drawSeriesLines(series); drawSeriesLines(series);
if (series.bars.show) }
if (series.bars.show) {
drawSeriesBars(series); drawSeriesBars(series);
if (series.points.show) }
if (series.points.show) {
drawSeriesPoints(series); drawSeriesPoints(series);
} }
}
function drawSeriesLines(series) { function drawSeriesLines(series) {
function plotLine(datapoints, xoffset, yoffset, axisx, axisy) { function plotLine(datapoints, xoffset, yoffset, axisx, axisy) {
...@@ -2162,68 +2252,74 @@ Licensed under the MIT license. ...@@ -2162,68 +2252,74 @@ Licensed under the MIT license.
var x1 = points[i - ps], y1 = points[i - ps + 1], var x1 = points[i - ps], y1 = points[i - ps + 1],
x2 = points[i], y2 = points[i + 1]; x2 = points[i], y2 = points[i + 1];
if (x1 == null || x2 == null) if (x1 == null || x2 == null) {
continue; continue;
}
// clip with ymin // clip with ymin
if (y1 <= y2 && y1 < axisy.min) { if (y1 <= y2 && y1 < axisy.min) {
if (y2 < axisy.min) if (y2 < axisy.min) {
continue; // line segment is outside continue; // line segment is outside
}
// compute new intersection point // compute new intersection point
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.min; y1 = axisy.min;
} } else if (y2 <= y1 && y2 < axisy.min) {
else if (y2 <= y1 && y2 < axisy.min) { if (y1 < axisy.min) {
if (y1 < axisy.min)
continue; continue;
}
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.min; y2 = axisy.min;
} }
// clip with ymax // clip with ymax
if (y1 >= y2 && y1 > axisy.max) { if (y1 >= y2 && y1 > axisy.max) {
if (y2 > axisy.max) if (y2 > axisy.max) {
continue; continue;
}
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.max; y1 = axisy.max;
} } else if (y2 >= y1 && y2 > axisy.max) {
else if (y2 >= y1 && y2 > axisy.max) { if (y1 > axisy.max) {
if (y1 > axisy.max)
continue; continue;
}
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.max; y2 = axisy.max;
} }
// clip with xmin // clip with xmin
if (x1 <= x2 && x1 < axisx.min) { if (x1 <= x2 && x1 < axisx.min) {
if (x2 < axisx.min) if (x2 < axisx.min) {
continue; continue;
}
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.min; x1 = axisx.min;
} } else if (x2 <= x1 && x2 < axisx.min) {
else if (x2 <= x1 && x2 < axisx.min) { if (x1 < axisx.min) {
if (x1 < axisx.min)
continue; continue;
}
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.min; x2 = axisx.min;
} }
// clip with xmax // clip with xmax
if (x1 >= x2 && x1 > axisx.max) { if (x1 >= x2 && x1 > axisx.max) {
if (x2 > axisx.max) if (x2 > axisx.max) {
continue; continue;
}
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.max; x1 = axisx.max;
} } else if (x2 >= x1 && x2 > axisx.max) {
else if (x2 >= x1 && x2 > axisx.max) { if (x1 > axisx.max) {
if (x1 > axisx.max)
continue; continue;
}
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.max; x2 = axisx.max;
} }
if (x1 != prevx || y1 != prevy) if (x1 != prevx || y1 != prevy) {
ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset); ctx.moveTo(axisx.p2c(x1) + xoffset, axisy.p2c(y1) + yoffset);
}
prevx = x2; prevx = x2;
prevy = y2; prevy = y2;
...@@ -2243,8 +2339,9 @@ Licensed under the MIT license. ...@@ -2243,8 +2339,9 @@ Licensed under the MIT license.
// direction to sketch out top, then once we hit the // direction to sketch out top, then once we hit the
// end we go backwards to sketch the bottom // end we go backwards to sketch the bottom
while (true) { while (true) {
if (ps > 0 && i > points.length + ps) if (ps > 0 && i > points.length + ps) {
break; break;
}
i += ps; // ps is negative if going backwards i += ps; // ps is negative if going backwards
...@@ -2272,35 +2369,40 @@ Licensed under the MIT license. ...@@ -2272,35 +2369,40 @@ Licensed under the MIT license.
} }
} }
if (x1 == null || x2 == null) if (x1 == null || x2 == null) {
continue; continue;
}
// clip x values // clip x values
// clip with xmin // clip with xmin
if (x1 <= x2 && x1 < axisx.min) { if (x1 <= x2 && x1 < axisx.min) {
if (x2 < axisx.min) if (x2 < axisx.min) {
continue; continue;
}
y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.min; x1 = axisx.min;
} }
else if (x2 <= x1 && x2 < axisx.min) { else if (x2 <= x1 && x2 < axisx.min) {
if (x1 < axisx.min) if (x1 < axisx.min) {
continue; continue;
}
y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = (axisx.min - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.min; x2 = axisx.min;
} }
// clip with xmax // clip with xmax
if (x1 >= x2 && x1 > axisx.max) { if (x1 >= x2 && x1 > axisx.max) {
if (x2 > axisx.max) if (x2 > axisx.max) {
continue; continue;
}
y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y1 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x1 = axisx.max; x1 = axisx.max;
} }
else if (x2 >= x1 && x2 > axisx.max) { else if (x2 >= x1 && x2 > axisx.max) {
if (x1 > axisx.max) if (x1 > axisx.max) {
continue; continue;
}
y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1; y2 = (axisx.max - x1) / (x2 - x1) * (y2 - y1) + y1;
x2 = axisx.max; x2 = axisx.max;
} }
...@@ -2317,8 +2419,7 @@ Licensed under the MIT license. ...@@ -2317,8 +2419,7 @@ Licensed under the MIT license.
ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max)); ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.max));
ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.max)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.max));
continue; continue;
} } else if (y1 <= axisy.min && y2 <= axisy.min) {
else if (y1 <= axisy.min && y2 <= axisy.min) {
ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.min)); ctx.lineTo(axisx.p2c(x1), axisy.p2c(axisy.min));
ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min)); ctx.lineTo(axisx.p2c(x2), axisy.p2c(axisy.min));
continue; continue;
...@@ -2337,8 +2438,7 @@ Licensed under the MIT license. ...@@ -2337,8 +2438,7 @@ Licensed under the MIT license.
if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) { if (y1 <= y2 && y1 < axisy.min && y2 >= axisy.min) {
x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.min; y1 = axisy.min;
} } else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) {
else if (y2 <= y1 && y2 < axisy.min && y1 >= axisy.min) {
x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = (axisy.min - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.min; y2 = axisy.min;
} }
...@@ -2347,8 +2447,7 @@ Licensed under the MIT license. ...@@ -2347,8 +2447,7 @@ Licensed under the MIT license.
if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) { if (y1 >= y2 && y1 > axisy.max && y2 <= axisy.max) {
x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x1 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y1 = axisy.max; y1 = axisy.max;
} } else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) {
else if (y2 >= y1 && y2 > axisy.max && y1 <= axisy.max) {
x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1; x2 = (axisy.max - y1) / (y2 - y1) * (x2 - x1) + x1;
y2 = axisy.max; y2 = axisy.max;
} }
...@@ -2400,8 +2499,9 @@ Licensed under the MIT license. ...@@ -2400,8 +2499,9 @@ Licensed under the MIT license.
plotLineArea(series.datapoints, series.xaxis, series.yaxis); plotLineArea(series.datapoints, series.xaxis, series.yaxis);
} }
if (lw > 0) if (lw > 0) {
plotLine(series.datapoints, 0, 0, series.xaxis, series.yaxis); plotLine(series.datapoints, 0, 0, series.xaxis, series.yaxis);
}
ctx.restore(); ctx.restore();
} }
...@@ -2411,16 +2511,18 @@ Licensed under the MIT license. ...@@ -2411,16 +2511,18 @@ Licensed under the MIT license.
for (var i = 0; i < points.length; i += ps) { for (var i = 0; i < points.length; i += ps) {
var x = points[i], y = points[i + 1]; var x = points[i], y = points[i + 1];
if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) if (x == null || x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) {
continue; continue;
}
ctx.beginPath(); ctx.beginPath();
x = axisx.p2c(x); x = axisx.p2c(x);
y = axisy.p2c(y) + offset; y = axisy.p2c(y) + offset;
if (symbol == "circle") if (symbol == "circle") {
ctx.arc(x, y, radius, 0, shadow ? Math.PI : Math.PI * 2, false); ctx.arc(x, y, radius, 0, shadow ? Math.PI : Math.PI * 2, false);
else } else {
symbol(ctx, x, y, radius, shadow); symbol(ctx, x, y, radius, shadow);
}
ctx.closePath(); ctx.closePath();
if (fillStyle) { if (fillStyle) {
...@@ -2444,8 +2546,9 @@ Licensed under the MIT license. ...@@ -2444,8 +2546,9 @@ Licensed under the MIT license.
// Doing the conditional here allows the shadow setting to still be // Doing the conditional here allows the shadow setting to still be
// optional even with a lineWidth of 0. // optional even with a lineWidth of 0.
if( lw == 0 ) if( lw == 0 ) {
lw = 0.0001; lw = 0.0001;
}
if (lw > 0 && sw > 0) { if (lw > 0 && sw > 0) {
// draw shadow in two steps // draw shadow in two steps
...@@ -2492,8 +2595,7 @@ Licensed under the MIT license. ...@@ -2492,8 +2595,7 @@ Licensed under the MIT license.
drawLeft = true; drawLeft = true;
drawRight = false; drawRight = false;
} }
} } else {
else {
drawLeft = drawRight = drawTop = true; drawLeft = drawRight = drawTop = true;
drawBottom = false; drawBottom = false;
left = x + barLeft; left = x + barLeft;
...@@ -2513,8 +2615,9 @@ Licensed under the MIT license. ...@@ -2513,8 +2615,9 @@ Licensed under the MIT license.
// clip // clip
if (right < axisx.min || left > axisx.max || if (right < axisx.min || left > axisx.max ||
top < axisy.min || bottom > axisy.max) top < axisy.min || bottom > axisy.max) {
return; return;
}
if (left < axisx.min) { if (left < axisx.min) {
left = axisx.min; left = axisx.min;
...@@ -2558,22 +2661,26 @@ Licensed under the MIT license. ...@@ -2558,22 +2661,26 @@ Licensed under the MIT license.
// FIXME: inline moveTo is buggy with excanvas // FIXME: inline moveTo is buggy with excanvas
c.moveTo(left, bottom + offset); c.moveTo(left, bottom + offset);
if (drawLeft) if (drawLeft) {
c.lineTo(left, top + offset); c.lineTo(left, top + offset);
else } else {
c.moveTo(left, top + offset); c.moveTo(left, top + offset);
if (drawTop) }
if (drawTop) {
c.lineTo(right, top + offset); c.lineTo(right, top + offset);
else } else {
c.moveTo(right, top + offset); c.moveTo(right, top + offset);
if (drawRight) }
if (drawRight) {
c.lineTo(right, bottom + offset); c.lineTo(right, bottom + offset);
else } else {
c.moveTo(right, bottom + offset); c.moveTo(right, bottom + offset);
if (drawBottom) }
if (drawBottom) {
c.lineTo(left, bottom + offset); c.lineTo(left, bottom + offset);
else } else {
c.moveTo(left, bottom + offset); c.moveTo(left, bottom + offset);
}
c.stroke(); c.stroke();
} }
} }
...@@ -2583,8 +2690,9 @@ Licensed under the MIT license. ...@@ -2583,8 +2690,9 @@ Licensed under the MIT license.
var points = datapoints.points, ps = datapoints.pointsize; var points = datapoints.points, ps = datapoints.pointsize;
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;
}
drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth); drawBar(points[i], points[i + 1], points[i + 2], barLeft, barRight, offset, fillStyleCallback, axisx, axisy, ctx, series.bars.horizontal, series.bars.lineWidth);
} }
} }
...@@ -2619,11 +2727,13 @@ Licensed under the MIT license. ...@@ -2619,11 +2727,13 @@ Licensed under the MIT license.
function getFillStyle(filloptions, seriesColor, bottom, top) { function getFillStyle(filloptions, seriesColor, bottom, top) {
var fill = filloptions.fill; var fill = filloptions.fill;
if (!fill) if (!fill) {
return null; return null;
}
if (filloptions.fillColor) if (filloptions.fillColor) {
return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor); return getColorOrGradient(filloptions.fillColor, bottom, top, seriesColor);
}
var c = $.color.parse(seriesColor); var c = $.color.parse(seriesColor);
c.a = typeof fill == "number" ? fill : 0.4; c.a = typeof fill == "number" ? fill : 0.4;
...@@ -2635,8 +2745,9 @@ Licensed under the MIT license. ...@@ -2635,8 +2745,9 @@ Licensed under the MIT license.
placeholder.find(".legend").remove(); placeholder.find(".legend").remove();
if (!options.legend.show) if (!options.legend.show) {
return; return;
}
var fragments = [], entries = [], rowStarted = false, var fragments = [], entries = [], rowStarted = false,
lf = options.legend.labelFormatter, s, label; lf = options.legend.labelFormatter, s, label;
...@@ -2680,8 +2791,9 @@ Licensed under the MIT license. ...@@ -2680,8 +2791,9 @@ Licensed under the MIT license.
var entry = entries[i]; var entry = entries[i];
if (i % options.legend.noColumns == 0) { if (i % options.legend.noColumns == 0) {
if (rowStarted) if (rowStarted) {
fragments.push("</tr>"); fragments.push("</tr>");
}
fragments.push("<tr>"); fragments.push("<tr>");
rowStarted = true; rowStarted = true;
} }
...@@ -2692,29 +2804,34 @@ Licensed under the MIT license. ...@@ -2692,29 +2804,34 @@ Licensed under the MIT license.
); );
} }
if (rowStarted) if (rowStarted) {
fragments.push("</tr>"); fragments.push("</tr>");
}
if (fragments.length == 0) if (fragments.length == 0) {
return; return;
}
var table = "<table style='font-size:smaller;color:" + options.grid.color + "'>" + fragments.join("") + "</table>"; var table = "<table style='font-size:smaller;color:" + options.grid.color + "'>" + fragments.join("") + "</table>";
if (options.legend.container != null) if (options.legend.container != null) {
$(options.legend.container).html(table); $(options.legend.container).html(table);
else { } else {
var pos = "", var pos = "",
p = options.legend.position, p = options.legend.position,
m = options.legend.margin; m = options.legend.margin;
if (m[0] == null) if (m[0] == null) {
m = [m, m]; m = [m, m];
if (p.charAt(0) == "n") }
if (p.charAt(0) == "n") {
pos += "top:" + (m[1] + plotOffset.top) + "px;"; pos += "top:" + (m[1] + plotOffset.top) + "px;";
else if (p.charAt(0) == "s") } else if (p.charAt(0) == "s") {
pos += "bottom:" + (m[1] + plotOffset.bottom) + "px;"; pos += "bottom:" + (m[1] + plotOffset.bottom) + "px;";
if (p.charAt(1) == "e") }
if (p.charAt(1) == "e") {
pos += "right:" + (m[0] + plotOffset.right) + "px;"; pos += "right:" + (m[0] + plotOffset.right) + "px;";
else if (p.charAt(1) == "w") } else if (p.charAt(1) == "w") {
pos += "left:" + (m[0] + plotOffset.left) + "px;"; pos += "left:" + (m[0] + plotOffset.left) + "px;";
}
var legend = $("<div class='legend'>" + table.replace("style='", "style='position:absolute;" + pos +";") + "</div>").appendTo(placeholder); var legend = $("<div class='legend'>" + table.replace("style='", "style='position:absolute;" + pos +";") + "</div>").appendTo(placeholder);
if (options.legend.backgroundOpacity != 0.0) { if (options.legend.backgroundOpacity != 0.0) {
// put in the transparent background // put in the transparent background
...@@ -2723,10 +2840,11 @@ Licensed under the MIT license. ...@@ -2723,10 +2840,11 @@ Licensed under the MIT license.
var c = options.legend.backgroundColor; var c = options.legend.backgroundColor;
if (c == null) { if (c == null) {
c = options.grid.backgroundColor; c = options.grid.backgroundColor;
if (c && typeof c == "string") if (c && typeof c == "string") {
c = $.color.parse(c); c = $.color.parse(c);
else } else {
c = $.color.extract(legend, "background-color"); c = $.color.extract(legend, "background-color");
}
c.a = 1; c.a = 1;
c = c.toString(); c = c.toString();
} }
...@@ -2749,8 +2867,9 @@ Licensed under the MIT license. ...@@ -2749,8 +2867,9 @@ Licensed under the MIT license.
item = null, foundPoint = false, i, j, ps; item = null, foundPoint = false, i, j, ps;
for (i = series.length - 1; i >= 0; --i) { for (i = series.length - 1; i >= 0; --i) {
if (!seriesFilter(series[i])) if (!seriesFilter(series[i])) {
continue; continue;
}
var s = series[i], var s = series[i],
axisx = s.xaxis, axisx = s.xaxis,
...@@ -2764,22 +2883,26 @@ Licensed under the MIT license. ...@@ -2764,22 +2883,26 @@ Licensed under the MIT license.
ps = s.datapoints.pointsize; ps = s.datapoints.pointsize;
// with inverse transforms, we can't use the maxx/maxy // with inverse transforms, we can't use the maxx/maxy
// optimization, sadly // optimization, sadly
if (axisx.options.inverseTransform) if (axisx.options.inverseTransform) {
maxx = Number.MAX_VALUE; maxx = Number.MAX_VALUE;
if (axisy.options.inverseTransform) }
if (axisy.options.inverseTransform) {
maxy = Number.MAX_VALUE; maxy = Number.MAX_VALUE;
}
if (s.lines.show || s.points.show) { if (s.lines.show || s.points.show) {
for (j = 0; j < points.length; j += ps) { for (j = 0; j < points.length; j += ps) {
var x = points[j], y = points[j + 1]; var x = points[j], y = points[j + 1];
if (x == null) if (x == null) {
continue; continue;
}
// For points and lines, the cursor must be within a // For points and lines, the cursor must be within a
// certain distance to the data point // certain distance to the data point
if (x - mx > maxx || x - mx < -maxx || if (x - mx > maxx || x - mx < -maxx ||
y - my > maxy || y - my < -maxy) y - my > maxy || y - my < -maxy) {
continue; continue;
}
// We have to calculate distances in pixels, not in // We have to calculate distances in pixels, not in
// data units, because the scales of the axes may be different // data units, because the scales of the axes may be different
...@@ -2802,19 +2925,21 @@ Licensed under the MIT license. ...@@ -2802,19 +2925,21 @@ Licensed under the MIT license.
for (j = 0; j < points.length; j += ps) { for (j = 0; j < points.length; j += ps) {
var x = points[j], y = points[j + 1], b = points[j + 2]; var x = points[j], y = points[j + 1], b = points[j + 2];
if (x == null) if (x == null) {
continue; continue;
}
// for a bar graph, the cursor must be inside the bar // for a bar graph, the cursor must be inside the bar
if (series[i].bars.horizontal ? if (series[i].bars.horizontal ?
(mx <= Math.max(b, x) && mx >= Math.min(b, x) && (mx <= Math.max(b, x) && mx >= Math.min(b, x) &&
my >= y + barLeft && my <= y + barRight) : my >= y + barLeft && my <= y + barRight) :
(mx >= x + barLeft && mx <= x + barRight && (mx >= x + barLeft && mx <= x + barRight &&
my >= Math.min(b, y) && my <= Math.max(b, y))) my >= Math.min(b, y) && my <= Math.max(b, y))) {
item = [i, j / ps]; item = [i, j / ps];
} }
} }
} }
}
if (item) { if (item) {
i = item[0]; i = item[0];
...@@ -2831,16 +2956,18 @@ Licensed under the MIT license. ...@@ -2831,16 +2956,18 @@ Licensed under the MIT license.
} }
function onMouseMove(e) { function onMouseMove(e) {
if (options.grid.hoverable) if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e, triggerClickHoverEvent("plothover", e,
function (s) { return s["hoverable"] != false; }); function (s) { return s["hoverable"] != false; });
} }
}
function onMouseLeave(e) { function onMouseLeave(e) {
if (options.grid.hoverable) if (options.grid.hoverable) {
triggerClickHoverEvent("plothover", e, triggerClickHoverEvent("plothover", e,
function (s) { return false; }); function (s) { return false; });
} }
}
function onClick(e) { function onClick(e) {
triggerClickHoverEvent("plotclick", e, triggerClickHoverEvent("plotclick", e,
...@@ -2873,13 +3000,15 @@ Licensed under the MIT license. ...@@ -2873,13 +3000,15 @@ Licensed under the MIT license.
if (h.auto == eventname && if (h.auto == eventname &&
!(item && h.series == item.series && !(item && h.series == item.series &&
h.point[0] == item.datapoint[0] && h.point[0] == item.datapoint[0] &&
h.point[1] == item.datapoint[1])) h.point[1] == item.datapoint[1])) {
unhighlight(h.series, h.point); unhighlight(h.series, h.point);
} }
}
if (item) if (item) {
highlight(item.series, item.datapoint, eventname); highlight(item.series, item.datapoint, eventname);
} }
}
placeholder.trigger(eventname, [ pos, item ]); placeholder.trigger(eventname, [ pos, item ]);
} }
...@@ -2891,9 +3020,10 @@ Licensed under the MIT license. ...@@ -2891,9 +3020,10 @@ Licensed under the MIT license.
return; return;
} }
if (!redrawTimeout) if (!redrawTimeout) {
redrawTimeout = setTimeout(drawOverlay, t); redrawTimeout = setTimeout(drawOverlay, t);
} }
}
function drawOverlay() { function drawOverlay() {
redrawTimeout = null; redrawTimeout = null;
...@@ -2907,19 +3037,21 @@ Licensed under the MIT license. ...@@ -2907,19 +3037,21 @@ Licensed under the MIT license.
for (i = 0; i < highlights.length; ++i) { for (i = 0; i < highlights.length; ++i) {
hi = highlights[i]; hi = highlights[i];
if (hi.series.bars.show) if (hi.series.bars.show) {
drawBarHighlight(hi.series, hi.point); drawBarHighlight(hi.series, hi.point);
else } else {
drawPointHighlight(hi.series, hi.point); drawPointHighlight(hi.series, hi.point);
} }
}
octx.restore(); octx.restore();
executeHooks(hooks.drawOverlay, [octx]); executeHooks(hooks.drawOverlay, [octx]);
} }
function highlight(s, point, auto) { function highlight(s, point, auto) {
if (typeof s == "number") if (typeof s == "number") {
s = series[s]; s = series[s];
}
if (typeof point == "number") { if (typeof point == "number") {
var ps = s.datapoints.pointsize; var ps = s.datapoints.pointsize;
...@@ -2931,10 +3063,10 @@ Licensed under the MIT license. ...@@ -2931,10 +3063,10 @@ Licensed under the MIT license.
highlights.push({ series: s, point: point, auto: auto }); highlights.push({ series: s, point: point, auto: auto });
triggerRedrawOverlay(); triggerRedrawOverlay();
} } else if (!auto) {
else if (!auto)
highlights[i].auto = false; highlights[i].auto = false;
} }
}
function unhighlight(s, point) { function unhighlight(s, point) {
if (s == null && point == null) { if (s == null && point == null) {
...@@ -2943,8 +3075,9 @@ Licensed under the MIT license. ...@@ -2943,8 +3075,9 @@ Licensed under the MIT license.
return; return;
} }
if (typeof s == "number") if (typeof s == "number") {
s = series[s]; s = series[s];
}
if (typeof point == "number") { if (typeof point == "number") {
var ps = s.datapoints.pointsize; var ps = s.datapoints.pointsize;
...@@ -2963,9 +3096,10 @@ Licensed under the MIT license. ...@@ -2963,9 +3096,10 @@ Licensed under the MIT license.
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 && h.point[0] == p[0] if (h.series == s && h.point[0] == p[0]
&& h.point[1] == p[1]) && h.point[1] == p[1]) {
return i; return i;
} }
}
return -1; return -1;
} }
...@@ -2974,8 +3108,9 @@ Licensed under the MIT license. ...@@ -2974,8 +3108,9 @@ Licensed under the MIT license.
axisx = series.xaxis, axisy = series.yaxis, axisx = series.xaxis, axisy = series.yaxis,
highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale("a", 0.5).toString(); highlightColor = (typeof series.highlightColor === "string") ? series.highlightColor : $.color.parse(series.color).scale("a", 0.5).toString();
if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) if (x < axisx.min || x > axisx.max || y < axisy.min || y > axisy.max) {
return; return;
}
var pointRadius = series.points.radius + series.points.lineWidth / 2; var pointRadius = series.points.radius + series.points.lineWidth / 2;
octx.lineWidth = pointRadius; octx.lineWidth = pointRadius;
...@@ -2985,10 +3120,11 @@ Licensed under the MIT license. ...@@ -2985,10 +3120,11 @@ Licensed under the MIT license.
y = axisy.p2c(y); y = axisy.p2c(y);
octx.beginPath(); octx.beginPath();
if (series.points.symbol == "circle") if (series.points.symbol == "circle") {
octx.arc(x, y, radius, 0, 2 * Math.PI, false); octx.arc(x, y, radius, 0, 2 * Math.PI, false);
else } else {
series.points.symbol(octx, x, y, radius, false); series.points.symbol(octx, x, y, radius, false);
}
octx.closePath(); octx.closePath();
octx.stroke(); octx.stroke();
} }
...@@ -3006,9 +3142,9 @@ Licensed under the MIT license. ...@@ -3006,9 +3142,9 @@ Licensed under the MIT license.
} }
function getColorOrGradient(spec, bottom, top, defaultColor) { function getColorOrGradient(spec, bottom, top, defaultColor) {
if (typeof spec == "string") if (typeof spec == "string") {
return spec; return spec;
else { } else {
// assume this is a gradient spec; IE currently only // assume this is a gradient spec; IE currently only
// supports a simple vertical gradient properly, so that's // supports a simple vertical gradient properly, so that's
// what we support too // what we support too
...@@ -3018,10 +3154,12 @@ Licensed under the MIT license. ...@@ -3018,10 +3154,12 @@ Licensed under the MIT license.
var c = spec.colors[i]; var c = spec.colors[i];
if (typeof c != "string") { if (typeof c != "string") {
var co = $.color.parse(defaultColor); var co = $.color.parse(defaultColor);
if (c.brightness != null) if (c.brightness != null) {
co = co.scale("rgb", c.brightness); co = co.scale("rgb", c.brightness);
if (c.opacity != null) }
if (c.opacity != null) {
co.a *= c.opacity; co.a *= c.opacity;
}
c = co.toString(); c = co.toString();
} }
gradient.addColorStop(i / (l - 1), c); gradient.addColorStop(i / (l - 1), c);
......
...@@ -100,10 +100,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -100,10 +100,7 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
* *
* Requires: 1.2.2+ * Requires: 1.2.2+
*/ */
//(function(d){function e(a){var b=a||window.event,c=[].slice.call(arguments,1),f=0,e=0,g=0,a=d.event.fix(b);a.type="mousewheel";b.wheelDelta&&(f=b.wheelDelta/120);b.detail&&(f=-b.detail/3);g=f;void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(g=0,e=-1*f);void 0!==b.wheelDeltaY&&(g=b.wheelDeltaY/120);void 0!==b.wheelDeltaX&&(e=-1*b.wheelDeltaX/120);c.unshift(a,f,e,g);return(d.event.dispatch||d.event.handle).apply(this,c)}var c=["DOMMouseScroll","mousewheel"];if(d.event.fixHooks)for(var h=c.length;h;)d.event.fixHooks[c[--h]]=d.event.mouseHooks;d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],e,!1);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery); (function(d){function e(a){var b=a||window.event,c=[].slice.call(arguments,1),f=0,e=0,g=0,a=d.event.fix(b);a.type="mousewheel";b.wheelDelta&&(f=b.wheelDelta/120);b.detail&&(f=-b.detail/3);g=f;void 0!==b.axis&&b.axis===b.HORIZONTAL_AXIS&&(g=0,e=-1*f);void 0!==b.wheelDeltaY&&(g=b.wheelDeltaY/120);void 0!==b.wheelDeltaX&&(e=-1*b.wheelDeltaX/120);c.unshift(a,f,e,g);return(d.event.dispatch||d.event.handle).apply(this,c)}var c=["DOMMouseScroll","mousewheel"];if(d.event.fixHooks)for(var h=c.length;h;)d.event.fixHooks[c[--h]]=d.event.mouseHooks;d.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=c.length;a;)this.addEventListener(c[--a],e,!1);else this.onmousewheel=e},teardown:function(){if(this.removeEventListener)for(var a=c.length;a;)this.removeEventListener(c[--a],e,!1);else this.onmousewheel=null}};d.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery);
(function ($) { (function ($) {
var options = { var options = {
...@@ -128,11 +125,12 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -128,11 +125,12 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
var c = plot.offset(); var c = plot.offset();
c.left = e.pageX - c.left; c.left = e.pageX - c.left;
c.top = e.pageY - c.top; c.top = e.pageY - c.top;
if (zoomOut) if (zoomOut) {
plot.zoomOut({ center: c }); plot.zoomOut({ center: c });
else } else {
plot.zoom({ center: c }); plot.zoom({ center: c });
} }
}
function onMouseWheel(e, delta) { function onMouseWheel(e, delta) {
e.preventDefault(); e.preventDefault();
...@@ -144,11 +142,13 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -144,11 +142,13 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
panTimeout = null; panTimeout = null;
function onDragStart(e) { function onDragStart(e) {
if (e.which != 1) // only accept left-click if (e.which != 1) { // only accept left-click
return false; return false;
}
var c = plot.getPlaceholder().css("cursor"); var c = plot.getPlaceholder().css("cursor");
if (c) if (c) {
prevCursor = c; prevCursor = c;
}
plot.getPlaceholder().css("cursor", plot.getOptions().pan.cursor); plot.getPlaceholder().css("cursor", plot.getOptions().pan.cursor);
prevPageX = e.pageX; prevPageX = e.pageX;
prevPageY = e.pageY; prevPageY = e.pageY;
...@@ -156,8 +156,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -156,8 +156,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
function onDrag(e) { function onDrag(e) {
var frameRate = plot.getOptions().pan.frameRate; var frameRate = plot.getOptions().pan.frameRate;
if (panTimeout || !frameRate) if (panTimeout || !frameRate) {
return; return;
}
panTimeout = setTimeout(function () { panTimeout = setTimeout(function () {
plot.pan({ left: prevPageX - e.pageX, plot.pan({ left: prevPageX - e.pageX,
...@@ -195,26 +196,30 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -195,26 +196,30 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
} }
plot.zoomOut = function (args) { plot.zoomOut = function (args) {
if (!args) if (!args) {
args = {}; args = {};
}
if (!args.amount) if (!args.amount) {
args.amount = plot.getOptions().zoom.amount; args.amount = plot.getOptions().zoom.amount;
}
args.amount = 1 / args.amount; args.amount = 1 / args.amount;
plot.zoom(args); plot.zoom(args);
}; };
plot.zoom = function (args) { plot.zoom = function (args) {
if (!args) if (!args) {
args = {}; args = {};
}
var c = args.center, var c = args.center,
amount = args.amount || plot.getOptions().zoom.amount, amount = args.amount || plot.getOptions().zoom.amount,
w = plot.width(), h = plot.height(); w = plot.width(), h = plot.height();
if (!c) if (!c) {
c = { left: w / 2, top: h / 2 }; c = { left: w / 2, top: h / 2 };
}
var xf = c.left / w, var xf = c.left / w,
yf = c.top / h, yf = c.top / h,
...@@ -236,8 +241,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -236,8 +241,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
zr = opts.zoomRange, zr = opts.zoomRange,
pr = opts.panRange; pr = opts.panRange;
if (zr === false) // no zooming on this axis if (zr === false) { // no zooming on this axis
return; return;
}
min = axis.c2p(min); min = axis.c2p(min);
max = axis.c2p(max); max = axis.c2p(max);
...@@ -261,8 +267,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -261,8 +267,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
var range = max - min; var range = max - min;
if (zr && if (zr &&
((zr[0] != null && range < zr[0]) || ((zr[0] != null && range < zr[0]) ||
(zr[1] != null && range > zr[1]))) (zr[1] != null && range > zr[1]))) {
return; return;
}
opts.min = min; opts.min = min;
opts.max = max; opts.max = max;
...@@ -271,8 +278,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -271,8 +278,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
plot.setupGrid(); plot.setupGrid();
plot.draw(); plot.draw();
if (!args.preventEvent) if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotzoom", [ plot, args ]); plot.getPlaceholder().trigger("plotzoom", [ plot, args ]);
}
}; };
plot.pan = function (args) { plot.pan = function (args) {
...@@ -281,10 +289,12 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -281,10 +289,12 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
y: +args.top y: +args.top
}; };
if (isNaN(delta.x)) if (isNaN(delta.x)) {
delta.x = 0; delta.x = 0;
if (isNaN(delta.y)) }
if (isNaN(delta.y)) {
delta.y = 0; delta.y = 0;
}
$.each(plot.getAxes(), function (_, axis) { $.each(plot.getAxes(), function (_, axis) {
var opts = axis.options, var opts = axis.options,
...@@ -294,8 +304,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -294,8 +304,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
max = axis.c2p(axis.p2c(axis.max) + d); max = axis.c2p(axis.p2c(axis.max) + d);
var pr = opts.panRange; var pr = opts.panRange;
if (pr === false) // no panning on this axis if (pr === false) { // no panning on this axis
return; return;
}
if (pr) { if (pr) {
// check whether we hit the wall // check whether we hit the wall
...@@ -319,8 +330,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -319,8 +330,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
plot.setupGrid(); plot.setupGrid();
plot.draw(); plot.draw();
if (!args.preventEvent) if (!args.preventEvent) {
plot.getPlaceholder().trigger("plotpan", [ plot, args ]); plot.getPlaceholder().trigger("plotpan", [ plot, args ]);
}
}; };
function shutdown(plot, eventHolder) { function shutdown(plot, eventHolder) {
...@@ -329,9 +341,10 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -329,9 +341,10 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L
eventHolder.unbind("dragstart", onDragStart); eventHolder.unbind("dragstart", onDragStart);
eventHolder.unbind("drag", onDrag); eventHolder.unbind("drag", onDrag);
eventHolder.unbind("dragend", onDragEnd); eventHolder.unbind("dragend", onDragEnd);
if (panTimeout) if (panTimeout) {
clearTimeout(panTimeout); clearTimeout(panTimeout);
} }
}
plot.hooks.bindEvents.push(bindEvents); plot.hooks.bindEvents.push(bindEvents);
plot.hooks.shutdown.push(shutdown); plot.hooks.shutdown.push(shutdown);
......
...@@ -415,7 +415,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -415,7 +415,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) {
...@@ -561,10 +563,11 @@ More detail and specific examples can be found in the included HTML file. ...@@ -561,10 +563,11 @@ 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]) || (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]) && (pt[0] < (poly[j][0] - poly[i][0]) * (pt[1] - poly[i][1]) / (poly[j][1] - poly[i][1]) + poly[i][0])
&& (c = !c); && (c = !c);
}
return c; return c;
} }
...@@ -715,9 +718,10 @@ More detail and specific examples can be found in the included HTML file. ...@@ -715,9 +718,10 @@ 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;
} }
......
...@@ -31,8 +31,9 @@ can just fix the size of their placeholders. ...@@ -31,8 +31,9 @@ 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();
......
...@@ -104,8 +104,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -104,8 +104,9 @@ The plugin allso adds the following methods to the plot object:
} }
function onMouseDown(e) { function onMouseDown(e) {
if (e.which != 1) // only accept left-click if (e.which != 1) { // only accept left-click
return; return;
}
// cancel out any text selections // cancel out any text selections
document.body.focus(); document.body.focus();
...@@ -135,18 +136,20 @@ The plugin allso adds the following methods to the plot object: ...@@ -135,18 +136,20 @@ The plugin allso adds the following methods to the plot object:
mouseUpHandler = null; mouseUpHandler = null;
// revert drag stuff for old-school browsers // revert drag stuff for old-school browsers
if (document.onselectstart !== undefined) if (document.onselectstart !== undefined) {
document.onselectstart = savedhandlers.onselectstart; document.onselectstart = savedhandlers.onselectstart;
if (document.ondrag !== undefined) }
if (document.ondrag !== undefined) {
document.ondrag = savedhandlers.ondrag; document.ondrag = savedhandlers.ondrag;
}
// no more dragging // no more dragging
selection.active = false; selection.active = false;
updateSelection(e); updateSelection(e);
if (selectionIsSane()) if (selectionIsSane()) {
triggerSelectedEvent(); triggerSelectedEvent();
else { } else {
// this counts as a clear // this counts as a clear
plot.getPlaceholder().trigger("plotunselected", [ ]); plot.getPlaceholder().trigger("plotunselected", [ ]);
plot.getPlaceholder().trigger("plotselecting", [ null ]); plot.getPlaceholder().trigger("plotselecting", [ null ]);
...@@ -156,10 +159,13 @@ The plugin allso adds the following methods to the plot object: ...@@ -156,10 +159,13 @@ The plugin allso adds the following methods to the plot object:
} }
function getSelection() { function getSelection() {
if (!selectionIsSane()) if (!selectionIsSane()) {
return null; return null;
}
if (!selection.show) return null; if (!selection.show) {
return null;
}
var r = {}, c1 = selection.first, c2 = selection.second; var r = {}, c1 = selection.first, c2 = selection.second;
$.each(plot.getAxes(), function (name, axis) { $.each(plot.getAxes(), function (name, axis) {
...@@ -177,9 +183,10 @@ The plugin allso adds the following methods to the plot object: ...@@ -177,9 +183,10 @@ The plugin allso adds the following methods to the plot object:
plot.getPlaceholder().trigger("plotselected", [ r ]); plot.getPlaceholder().trigger("plotselected", [ r ]);
// backwards-compat stuff, to be removed in future // backwards-compat stuff, to be removed in future
if (r.xaxis && r.yaxis) if (r.xaxis && r.yaxis) {
plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]); plot.getPlaceholder().trigger("selected", [ { x1: r.xaxis.from, y1: r.yaxis.from, x2: r.xaxis.to, y2: r.yaxis.to } ]);
} }
}
function clamp(min, value, max) { function clamp(min, value, max) {
return value < min ? min: (value > max ? max: value); return value < min ? min: (value > max ? max: value);
...@@ -192,34 +199,38 @@ The plugin allso adds the following methods to the plot object: ...@@ -192,34 +199,38 @@ The plugin allso adds the following methods to the plot object:
pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width()); pos.x = clamp(0, e.pageX - offset.left - plotOffset.left, plot.width());
pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height()); pos.y = clamp(0, e.pageY - offset.top - plotOffset.top, plot.height());
if (o.selection.mode == "y") if (o.selection.mode == "y") {
pos.x = pos == selection.first ? 0 : plot.width(); pos.x = pos == selection.first ? 0 : plot.width();
}
if (o.selection.mode == "x") if (o.selection.mode == "x") {
pos.y = pos == selection.first ? 0 : plot.height(); pos.y = pos == selection.first ? 0 : plot.height();
} }
}
function updateSelection(pos) { function updateSelection(pos) {
if (pos.pageX == null) if (pos.pageX == null) {
return; return;
}
setSelectionPos(selection.second, pos); setSelectionPos(selection.second, pos);
if (selectionIsSane()) { if (selectionIsSane()) {
selection.show = true; selection.show = true;
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
} } else {
else
clearSelection(true); clearSelection(true);
} }
}
function clearSelection(preventEvent) { function clearSelection(preventEvent) {
if (selection.show) { if (selection.show) {
selection.show = false; selection.show = false;
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
if (!preventEvent) if (!preventEvent) {
plot.getPlaceholder().trigger("plotunselected", [ ]); plot.getPlaceholder().trigger("plotunselected", [ ]);
} }
} }
}
// function taken from markings support in Flot // function taken from markings support in Flot
function extractRange(ranges, coord) { function extractRange(ranges, coord) {
...@@ -229,8 +240,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -229,8 +240,9 @@ The plugin allso adds the following methods to the plot object:
axis = axes[k]; axis = axes[k];
if (axis.direction == coord) { if (axis.direction == coord) {
key = coord + axis.n + "axis"; key = coord + axis.n + "axis";
if (!ranges[key] && axis.n == 1) if (!ranges[key] && axis.n == 1) {
key = coord + "axis"; // support x1axis as xaxis key = coord + "axis"; // support x1axis as xaxis
}
if (ranges[key]) { if (ranges[key]) {
from = ranges[key].from; from = ranges[key].from;
to = ranges[key].to; to = ranges[key].to;
...@@ -283,9 +295,10 @@ The plugin allso adds the following methods to the plot object: ...@@ -283,9 +295,10 @@ The plugin allso adds the following methods to the plot object:
selection.show = true; selection.show = true;
plot.triggerRedrawOverlay(); plot.triggerRedrawOverlay();
if (!preventEvent && selectionIsSane()) if (!preventEvent && selectionIsSane()) {
triggerSelectedEvent(); triggerSelectedEvent();
} }
}
function selectionIsSane() { function selectionIsSane() {
var minSize = plot.getOptions().selection.minSize; var minSize = plot.getOptions().selection.minSize;
...@@ -338,8 +351,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -338,8 +351,9 @@ The plugin allso adds the following methods to the plot object:
eventHolder.unbind("mousemove", onMouseMove); eventHolder.unbind("mousemove", onMouseMove);
eventHolder.unbind("mousedown", onMouseDown); eventHolder.unbind("mousedown", onMouseDown);
if (mouseUpHandler) if (mouseUpHandler) {
$(document).unbind("mouseup", mouseUpHandler); $(document).unbind("mouseup", mouseUpHandler);
}
}); });
} }
......
...@@ -44,23 +44,27 @@ charts or filled areas). ...@@ -44,23 +44,27 @@ charts or filled areas).
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,29 +82,33 @@ charts or filled areas). ...@@ -78,29 +82,33 @@ 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;
} }
...@@ -113,8 +121,9 @@ charts or filled areas). ...@@ -113,8 +121,9 @@ charts or filled areas).
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;
...@@ -129,8 +138,9 @@ charts or filled areas). ...@@ -129,8 +138,9 @@ charts or filled areas).
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;
} }
...@@ -143,13 +153,15 @@ charts or filled areas). ...@@ -143,13 +153,15 @@ charts or filled areas).
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;
...@@ -158,17 +170,19 @@ charts or filled areas). ...@@ -158,17 +170,19 @@ charts or filled areas).
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];
} }
} }
......
...@@ -55,9 +55,10 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -55,9 +55,10 @@ 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);
......
...@@ -71,34 +71,39 @@ You may need to check for this in hover events. ...@@ -71,34 +71,39 @@ You may need to check for this in hover events.
y = origpoints[i + 1]; y = origpoints[i + 1];
prevp = p; prevp = p;
if (y < below) if (y < below) {
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;
thresholded.datapoints.points = threspoints; thresholded.datapoints.points = threspoints;
...@@ -113,8 +118,9 @@ You may need to check for this in hover events. ...@@ -113,8 +118,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) {
......
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