From 41ee764f8a4eca14b72c66116b6cca0084b82b77 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Fri, 9 Dec 2011 13:24:05 -0500 Subject: [PATCH] Add jsdoc for setAnnotations() and an example of how to use them with native-format dates. --- docs/annotations.html | 2 ++ dygraph.js | 3 +++ tests/annotation-native.html | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/annotation-native.html diff --git a/docs/annotations.html b/docs/annotations.html index b0281f6..d69dd29 100644 --- a/docs/annotations.html +++ b/docs/annotations.html @@ -142,6 +142,8 @@

Annotations are JavaScript dictionaries. The series and x fields are required: they indicate which point the annotation should be attached to. If specified, shortText will appear on the annotation "flag". If you don't specify shortText, you can specify icon instead to display a small picture. The text parameter specifies hovertext. If you highlight the annotation and leave the mouse still, it will appear.

+

If you are using native format, you need to pass in a numeric value for the x field. For a numeric x-axis, simply pass in the x-value of the data point on which you wish to attach the annotation. For a date axis, pass in Date.parse('YYYY/MM/DD'). This returns milliseconds since epoch for the date.

+

Modifying Annotations

To remove or modify existing annotations, call the annotations method to get an array of annotations. Modify that diff --git a/dygraph.js b/dygraph.js index ff05507..f90f461 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2969,6 +2969,9 @@ Dygraph.prototype.size = function() { /** * Update the list of annotations and redraw the chart. + * See dygraphs.com/annotations.html for more info on how to use annotations. + * @param ann {Array} An array of annotation objects. + * @param suppressDraw {Boolean} Set to "true" to block chart redraw (optional). */ Dygraph.prototype.setAnnotations = function(ann, suppressDraw) { // Only add the annotation CSS rule once we know it will be used. diff --git a/tests/annotation-native.html b/tests/annotation-native.html new file mode 100644 index 0000000..f71f71d --- /dev/null +++ b/tests/annotation-native.html @@ -0,0 +1,42 @@ + + + + + Native format annotations + + + + +

This test demonstrates how annotations can be used with native-format data.

+ +
+ + + + -- 2.7.4