From d14b9eed5b7ee0fc3935cbdb2c9a66cf881fd87a Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 13 Sep 2010 18:31:07 -0700 Subject: [PATCH] support attachAtBottom --- dygraph-canvas.js | 15 ++++++++++++--- tests/annotation.html | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 123fa83..a8ec2b3 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -554,7 +554,11 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { div.appendChild(document.createTextNode(p.annotation.shortText)); } div.style.left = (p.canvasx - width / 2) + "px"; - div.style.top = (p.canvasy - height - tick_height) + "px"; + if (a.attachAtBottom) { + div.style.top = (this.area.h - height - tick_height) + "px"; + } else { + div.style.top = (p.canvasy - height - tick_height) + "px"; + } div.style.width = width + "px"; div.style.height = height + "px"; div.title = p.annotation.text; @@ -577,8 +581,13 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { var ctx = this.element.getContext("2d"); ctx.strokeStyle = this.colors[p.name]; ctx.beginPath(); - ctx.moveTo(p.canvasx, p.canvasy); - ctx.lineTo(p.canvasx, p.canvasy - 2 - tick_height); + if (!a.attachAtBottom) { + ctx.moveTo(p.canvasx, p.canvasy); + ctx.lineTo(p.canvasx, p.canvasy - 2 - tick_height); + } else { + ctx.moveTo(p.canvasx, this.area.h); + ctx.lineTo(p.canvasx, this.area.h - 2 - tick_height); + } ctx.closePath(); ctx.stroke(); } diff --git a/tests/annotation.html b/tests/annotation.html index 60062bc..f4191df 100644 --- a/tests/annotation.html +++ b/tests/annotation.html @@ -14,7 +14,10 @@ +

Annotations Demo

+

Click any point to add an annotation to it or click "Add Annotation".

+
@@ -99,6 +102,23 @@ g.setAnnotations(annotations); } + function bottom(el) { + var to_bottom = true; + if (el.value != 'Shove to bottom') to_bottom = false; + + var anns = g.annotations(); + for (var i = 0; i < anns.length; i++) { + anns[i].attachAtBottom = to_bottom; + } + g.setAnnotations(anns); + + if (to_bottom) { + el.value = 'Lift back up'; + } else { + el.value = 'Shove to bottom'; + } + } + var saveBg = ''; var num = 0; g.updateOptions( { -- 2.7.4