From f56ca35493f46759e317ee1c2d093ae7c1cdd60c Mon Sep 17 00:00:00 2001 From: n-gist <58081918+n-gist@users.noreply.github.com> Date: Tue, 16 May 2023 15:12:32 +0600 Subject: [PATCH 1/3] crosshair out of bounds selection filter --- src/extras/crosshair.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/extras/crosshair.js b/src/extras/crosshair.js index 108403778..697008f55 100644 --- a/src/extras/crosshair.js +++ b/src/extras/crosshair.js @@ -66,12 +66,15 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() { ctx.clearRect(0, 0, width, height); ctx.strokeStyle = this.strokeStyle_; ctx.beginPath(); - - var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering - - if (this.direction_ === "vertical" || this.direction_ === "both") { - ctx.moveTo(canvasx, 0); - ctx.lineTo(canvasx, height); + + var point = e.dygraph.selPoints_[0]; + if (point.x >= 0 && point.x <= 1) { + var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering + + if (this.direction_ === "vertical" || this.direction_ === "both") { + ctx.moveTo(canvasx, 0); + ctx.lineTo(canvasx, height); + } } if (this.direction_ === "horizontal" || this.direction_ === "both") { From 8246591cfc4087e271f4a79bc05b94c79958a1e0 Mon Sep 17 00:00:00 2001 From: n-gist <58081918+n-gist@users.noreply.github.com> Date: Sat, 20 May 2023 19:22:14 +0600 Subject: [PATCH 2/3] check horizontal lines also --- src/extras/crosshair.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/extras/crosshair.js b/src/extras/crosshair.js index 697008f55..6ec7ad33e 100644 --- a/src/extras/crosshair.js +++ b/src/extras/crosshair.js @@ -67,8 +67,8 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() { ctx.strokeStyle = this.strokeStyle_; ctx.beginPath(); - var point = e.dygraph.selPoints_[0]; - if (point.x >= 0 && point.x <= 1) { + var p_x = e.dygraph.selPoints_[0]; + if (p_x.x >= 0 && p_x.x <= 1) { var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering if (this.direction_ === "vertical" || this.direction_ === "both") { @@ -79,7 +79,9 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() { if (this.direction_ === "horizontal" || this.direction_ === "both") { for (var i = 0; i < e.dygraph.selPoints_.length; i++) { - var canvasy = Math.floor(e.dygraph.selPoints_[i].canvasy) + 0.5; // crisper rendering + var p_y = e.dygraph.selPoints_[i]; + if (p_y.y < 0 || p_y > 1) continue; + var canvasy = Math.floor(p_y.canvasy) + 0.5; // crisper rendering ctx.moveTo(0, canvasy); ctx.lineTo(width, canvasy); } From 7d7955b4c425163e62816a92fa66197cd9552d43 Mon Sep 17 00:00:00 2001 From: n-gist <58081918+n-gist@users.noreply.github.com> Date: Sat, 20 May 2023 19:25:17 +0600 Subject: [PATCH 3/3] use created variable --- src/extras/crosshair.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extras/crosshair.js b/src/extras/crosshair.js index 6ec7ad33e..e74a55764 100644 --- a/src/extras/crosshair.js +++ b/src/extras/crosshair.js @@ -69,7 +69,7 @@ Dygraph.Plugins.Crosshair = (function _extras_crosshair_closure() { var p_x = e.dygraph.selPoints_[0]; if (p_x.x >= 0 && p_x.x <= 1) { - var canvasx = Math.floor(e.dygraph.selPoints_[0].canvasx) + 0.5; // crisper rendering + var canvasx = Math.floor(p_x.canvasx) + 0.5; // crisper rendering if (this.direction_ === "vertical" || this.direction_ === "both") { ctx.moveTo(canvasx, 0);