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,8 +113,9 @@ as "categories" on the axis object, e.g. plot.getAxes().xaxis.categories. ...@@ -108,8 +113,9 @@ 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,16 +91,18 @@ shadowSize and lineWidth are derived as well from the points series. ...@@ -90,16 +91,18 @@ 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;
} }
else { if (lower < x - radius) {
if (upper < y - radius) drawPath(ctx, [[x,upper],[x,Math.min(y - radius,minmax[0])]] ); drawPath(ctx, [[Math.min(x - radius,minmax[1]),y],[lower,y]] );
else drawUpper = false; } else {
if (lower > y + radius) drawPath(ctx, [[x,Math.max(y + radius,minmax[1])],[x,lower]] ); drawLower = false;
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 = [
......
This diff is collapsed.
...@@ -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,10 +125,11 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -128,10 +125,11 @@ 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) {
...@@ -144,20 +142,23 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -144,20 +142,23 @@ 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;
} }
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,8 +341,9 @@ Licensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-L ...@@ -329,8 +341,9 @@ 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);
......
...@@ -181,7 +181,7 @@ More detail and specific examples can be found in the included HTML file. ...@@ -181,7 +181,7 @@ More detail and specific examples can be found in the included HTML file.
// that the user may have stored in higher indexes. // that the user may have stored in higher indexes.
if ($.isArray(value) && value.length == 1) { if ($.isArray(value) && value.length == 1) {
value = value[0]; value = value[0];
} }
if ($.isArray(value)) { if ($.isArray(value)) {
...@@ -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,8 +718,9 @@ More detail and specific examples can be found in the included HTML file. ...@@ -715,8 +718,9 @@ More detail and specific examples can be found in the included HTML file.
function indexOfHighlight(s) { function indexOfHighlight(s) {
for (var i = 0; i < highlights.length; ++i) { for (var i = 0; i < highlights.length; ++i) {
var h = highlights[i]; var h = highlights[i];
if (h.series == s) if (h.series == s) {
return i; return i;
}
} }
return -1; return -1;
} }
......
...@@ -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,8 +183,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -177,8 +183,9 @@ 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) {
...@@ -192,32 +199,36 @@ The plugin allso adds the following methods to the plot object: ...@@ -192,32 +199,36 @@ 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", [ ]);
}
} }
} }
...@@ -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,8 +295,9 @@ The plugin allso adds the following methods to the plot object: ...@@ -283,8 +295,9 @@ 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() {
...@@ -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,8 +170,9 @@ charts or filled areas). ...@@ -158,8 +170,9 @@ 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
...@@ -167,8 +180,9 @@ charts or filled areas). ...@@ -167,8 +180,9 @@ charts or filled areas).
&& 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,8 +55,9 @@ The symbols are accessed as strings through the standard symbol options: ...@@ -55,8 +55,9 @@ 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) {
......
...@@ -71,33 +71,38 @@ You may need to check for this in hover events. ...@@ -71,33 +71,38 @@ 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;
...@@ -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