Annotations

Annotations allow you to highlight particular parts of the data. There are two concepts in Chartreuse's annotation system:

Types of annotations

Annotation types are found within the chartreuse.component package. Currently, there are four different types of annotations:

An example of creating an AnnotationType:

val annotationType = AnnotationType.CircleWithText(15, "Something interesting happened here")

Positioning the annotations

Each annotation in Chartreuse uses AnnotationPosition for positioning.

AnnotationPosition uses Landmark, Angle and (Point, Double) => Point to place an annotation:

Most users will use predefined annotation positioning options for ease of use (e.g. AnnotationPosition.topLeft). But for more precise positioning it is possible to define all the parameters manually.

Creating annotations

To create an annotation, it's enough to use the apply method of Annotation, which takes the point of interest and the AnnotationType:

Annotation(
  Point(1950, 81651),
  AnnotationType.Text("Rapid growth began here")
)

Annotations can be added to a plot with the addAnnotation method:

val annotatedPlot = plot
      .addAnnotation(annotation)

By default, each annotation is placed in the center of the point of interest:

But the position can be adjusted using the withAnnotationPosition method:

Annotation(
  Point(1950, 81651),
  AnnotationType.Text("Rapid growth began here")
)
  .withAnnotationPosition(AnnotationPosition.bottomRight)

Which will produce

In addition, it's possible to draw an arrow between the text and the point of interest. withArrow method is used for this. Arrows are placed automatically:

Annotation(
  Point(1950, 81651),
  AnnotationType.Text("Rapid growth began here")
)
  .withAnnotationPosition(AnnotationPosition.bottomRight)
  .withArrow()

Which will produce