Commit 4fc5340d authored by David Schnur's avatar David Schnur

Merge pull request #880 from kswedberg/border-object-fix

Fix setting border color/width as an object.
parents 559a39ee 198a6015
...@@ -200,8 +200,8 @@ ...@@ -200,8 +200,8 @@
plot.triggerRedrawOverlay = triggerRedrawOverlay; plot.triggerRedrawOverlay = triggerRedrawOverlay;
plot.pointOffset = function(point) { plot.pointOffset = function(point) {
return { return {
left: parseInt(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left), left: parseInt(xaxes[axisNumber(point, "x") - 1].p2c(+point.x) + plotOffset.left, 10),
top: parseInt(yaxes[axisNumber(point, "y") - 1].p2c(+point.y) + plotOffset.top) top: parseInt(yaxes[axisNumber(point, "y") - 1].p2c(+point.y) + plotOffset.top, 10)
}; };
}; };
plot.shutdown = shutdown; plot.shutdown = shutdown;
...@@ -507,7 +507,8 @@ ...@@ -507,7 +507,8 @@
bottomSentry = Number.NEGATIVE_INFINITY, bottomSentry = Number.NEGATIVE_INFINITY,
fakeInfinity = Number.MAX_VALUE, fakeInfinity = Number.MAX_VALUE,
i, j, k, m, length, i, j, k, m, length,
s, points, ps, x, y, axis, val, f, p; s, points, ps, x, y, axis, val, f, p,
data, format;
function updateAxis(axis, min, max) { function updateAxis(axis, min, max) {
if (min < axis.datamin && min != -fakeInfinity) if (min < axis.datamin && min != -fakeInfinity)
...@@ -534,7 +535,8 @@ ...@@ -534,7 +535,8 @@
for (i = 0; i < series.length; ++i) { for (i = 0; i < series.length; ++i) {
s = series[i]; s = series[i];
var data = s.data, format = s.datapoints.format; data = s.data;
format = s.datapoints.format;
if (!format) { if (!format) {
format = []; format = [];
...@@ -1002,7 +1004,7 @@ ...@@ -1002,7 +1004,7 @@
axisMargin = options.grid.axisMargin, axisMargin = options.grid.axisMargin,
padding = options.grid.labelMargin, padding = options.grid.labelMargin,
all = axis.direction == "x" ? xaxes : yaxes, all = axis.direction == "x" ? xaxes : yaxes,
index; index, innermost;
// determine axis margin // determine axis margin
var samePosition = $.grep(all, function (a) { var samePosition = $.grep(all, function (a) {
...@@ -1017,7 +1019,7 @@ ...@@ -1017,7 +1019,7 @@
return a && a.reserveSpace; return a && a.reserveSpace;
}); });
var innermost = $.inArray(axis, sameDirection) == 0; innermost = $.inArray(axis, sameDirection) == 0;
if (innermost) if (innermost)
tickLength = "full"; tickLength = "full";
else else
...@@ -1474,7 +1476,7 @@ ...@@ -1474,7 +1476,7 @@
} }
function drawGrid() { function drawGrid() {
var i; var i, axes, bw, bc;
ctx.save(); ctx.save();
ctx.translate(plotOffset.left, plotOffset.top); ctx.translate(plotOffset.left, plotOffset.top);
...@@ -1483,7 +1485,7 @@ ...@@ -1483,7 +1485,7 @@
var markings = options.grid.markings; var markings = options.grid.markings;
if (markings) { if (markings) {
if ($.isFunction(markings)) { if ($.isFunction(markings)) {
var axes = plot.getAxes(); axes = plot.getAxes();
// xmin etc. is backwards compatibility, to be // xmin etc. is backwards compatibility, to be
// removed in the future // removed in the future
axes.xmin = axes.xaxis.min; axes.xmin = axes.xaxis.min;
...@@ -1548,7 +1550,8 @@ ...@@ -1548,7 +1550,8 @@
} }
// draw the ticks // draw the ticks
var axes = allAxes(), bw = options.grid.borderWidth; axes = allAxes();
bw = options.grid.borderWidth;
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,
...@@ -1644,34 +1647,49 @@ ...@@ -1644,34 +1647,49 @@
// line by line instead of as one rectangle // line by line instead of as one rectangle
bc = options.grid.borderColor; bc = options.grid.borderColor;
if(typeof bw == "object" || typeof bc == "object") { if(typeof bw == "object" || typeof bc == "object") {
if (typeof bw !== "object") {
bw = {top: bw, right: bw, bottom: bw, left: bw};
}
if (typeof bc !== "object") {
bc = {top: bc, right: bc, bottom: bc, left: bc};
}
if (bw.top > 0) {
ctx.strokeStyle = bc.top;
ctx.lineWidth = bw.top;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = (typeof bc == "object" ? bc.top : bc);
ctx.lineWidth = (typeof bw == "object" ? bw.top : bw);
ctx.moveTo(0 - bw.left, 0 - bw.top/2); ctx.moveTo(0 - bw.left, 0 - bw.top/2);
ctx.lineTo(plotWidth, 0 - bw.top/2); ctx.lineTo(plotWidth, 0 - bw.top/2);
ctx.stroke(); ctx.stroke();
}
if (bw.right > 0) {
ctx.strokeStyle = bc.right;
ctx.lineWidth = bw.right;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = (typeof bc == "object" ? bc.right : bc);
ctx.lineWidth = (typeof bw == "object" ? bw.right : bw);
ctx.moveTo(plotWidth + bw.right / 2, 0 - bw.top); ctx.moveTo(plotWidth + bw.right / 2, 0 - bw.top);
ctx.lineTo(plotWidth + bw.right / 2, plotHeight); ctx.lineTo(plotWidth + bw.right / 2, plotHeight);
ctx.stroke(); ctx.stroke();
}
if (bw.bottom > 0) {
ctx.strokeStyle = bc.bottom;
ctx.lineWidth = bw.bottom;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = (typeof bc == "object" ? bc.bottom : bc);
ctx.lineWidth = (typeof bw == "object" ? bw.bottom : bw);
ctx.moveTo(plotWidth + bw.right, plotHeight + bw.bottom / 2); ctx.moveTo(plotWidth + bw.right, plotHeight + bw.bottom / 2);
ctx.lineTo(0, plotHeight + bw.bottom / 2); ctx.lineTo(0, plotHeight + bw.bottom / 2);
ctx.stroke(); ctx.stroke();
}
if (bw.left > 0) {
ctx.strokeStyle = bc.left;
ctx.lineWidth = bw.left;
ctx.beginPath(); ctx.beginPath();
ctx.strokeStyle = (typeof bc == "object" ? bc.left : bc);
ctx.lineWidth = (typeof bw == "object" ? bw.left : bw);
ctx.moveTo(0 - bw.left/2, plotHeight + bw.bottom); ctx.moveTo(0 - bw.left/2, plotHeight + bw.bottom);
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;
...@@ -2344,7 +2362,7 @@ ...@@ -2344,7 +2362,7 @@
function findNearbyItem(mouseX, mouseY, seriesFilter) { function findNearbyItem(mouseX, mouseY, seriesFilter) {
var maxDistance = options.grid.mouseActiveRadius, var maxDistance = options.grid.mouseActiveRadius,
smallestDistance = maxDistance * maxDistance + 1, smallestDistance = maxDistance * maxDistance + 1,
item = null, foundPoint = false, i, j; 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]))
...@@ -2354,12 +2372,12 @@ ...@@ -2354,12 +2372,12 @@
axisx = s.xaxis, axisx = s.xaxis,
axisy = s.yaxis, axisy = s.yaxis,
points = s.datapoints.points, points = s.datapoints.points,
ps = s.datapoints.pointsize,
mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster mx = axisx.c2p(mouseX), // precompute some stuff to make the loop faster
my = axisy.c2p(mouseY), my = axisy.c2p(mouseY),
maxx = maxDistance / axisx.scale, maxx = maxDistance / axisx.scale,
maxy = maxDistance / axisy.scale; maxy = maxDistance / axisy.scale;
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)
...@@ -2431,7 +2449,7 @@ ...@@ -2431,7 +2449,7 @@
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"]; });
} }
function onMouseLeave(e) { function onMouseLeave(e) {
...@@ -2442,7 +2460,7 @@ ...@@ -2442,7 +2460,7 @@
function onClick(e) { function onClick(e) {
triggerClickHoverEvent("plotclick", e, triggerClickHoverEvent("plotclick", e,
function (s) { return s["clickable"] != false; }); function (s) { return !!s["clickable"]; });
} }
// trigger click or hover event (they send the same parameters // trigger click or hover event (they send the same parameters
...@@ -2460,8 +2478,8 @@ ...@@ -2460,8 +2478,8 @@
if (item) { if (item) {
// fill in mouse pos for any listeners out there // fill in mouse pos for any listeners out there
item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left); item.pageX = parseInt(item.series.xaxis.p2c(item.datapoint[0]) + offset.left + plotOffset.left, 10);
item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top); item.pageY = parseInt(item.series.yaxis.p2c(item.datapoint[1]) + offset.top + plotOffset.top, 10);
} }
if (options.grid.autoHighlight) { if (options.grid.autoHighlight) {
...@@ -2575,8 +2593,8 @@ ...@@ -2575,8 +2593,8 @@
var pointRadius = series.points.radius + series.points.lineWidth / 2; var pointRadius = series.points.radius + series.points.lineWidth / 2;
octx.lineWidth = pointRadius; octx.lineWidth = pointRadius;
octx.strokeStyle = highlightColor; octx.strokeStyle = highlightColor;
var radius = 1.5 * pointRadius, var radius = 1.5 * pointRadius;
x = axisx.p2c(x), x = axisx.p2c(x);
y = axisy.p2c(y); y = axisy.p2c(y);
octx.beginPath(); octx.beginPath();
......
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