1.2.3-SNAPSHOT Arrow_down_16x16

add-pointer

incanter.charts

  • (add-pointer chart x y & options)
Adds an arrow annotation to the given chart.

Arguments:
chart -- the chart to annotate
x, y -- the coordinate to add the annotation


Options:
:text -- (default "") text to include at the end of the arrow
:angle -- (default :nw) either a number indicating the angle of the arrow
or a keyword indicating a direction (:north :nw :west :sw :south
:se :east :ne)


Examples:

(use '(incanter core charts))
(def x (range (* -2 Math/PI) (* 2 Math/PI) 0.01))
(def plot (xy-plot x (sin x)))
(view plot)
;; annotate the plot
(doto plot
(add-pointer (- Math/PI) (sin (- Math/PI)) :text "(-pi, (sin -pi))")
(add-pointer Math/PI (sin Math/PI) :text "(pi, (sin pi))" :angle :ne)
(add-pointer (* 1/2 Math/PI) (sin (* 1/2 Math/PI)) :text "(pi/2, (sin pi/2))" :angle :south))

;; try the different angle options
(add-pointer plot 0 0 :text "north" :angle :north)
(add-pointer plot 0 0 :text "nw" :angle :nw)
(add-pointer plot 0 0 :text "ne" :angle :ne)
(add-pointer plot 0 0 :text "west" :angle :west)
(add-pointer plot 0 0 :text "east" :angle :east)
(add-pointer plot 0 0 :text "south" :angle :south)
(add-pointer plot 0 0 :text "sw" :angle :sw)
(add-pointer plot 0 0 :text "se" :angle :se)


0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/charts.clj:2365 top

(defn add-pointer
" Adds an arrow annotation to the given chart.

  Arguments:
    chart -- the chart to annotate
    x, y -- the coordinate to add the annotation


  Options:
      :text -- (default \"\") text to include at the end of the arrow
      :angle -- (default :nw) either a number indicating the angle of the arrow
                or a keyword indicating a direction (:north :nw :west :sw :south
                :se :east :ne)


  Examples:

    (use '(incanter core charts))
    (def x (range (* -2 Math/PI) (* 2 Math/PI) 0.01))
    (def plot (xy-plot x (sin x)))
    (view plot)
    ;; annotate the plot
    (doto plot
      (add-pointer (- Math/PI) (sin (- Math/PI)) :text \"(-pi, (sin -pi))\")
      (add-pointer Math/PI (sin Math/PI) :text \"(pi, (sin pi))\" :angle :ne)
      (add-pointer (* 1/2 Math/PI) (sin (* 1/2 Math/PI)) :text \"(pi/2, (sin pi/2))\" :angle :south))

    ;; try the different angle options
    (add-pointer plot 0 0 :text \"north\" :angle :north)
    (add-pointer plot 0 0 :text \"nw\" :angle :nw)
    (add-pointer plot 0 0 :text \"ne\" :angle :ne)
    (add-pointer plot 0 0 :text \"west\" :angle :west)
    (add-pointer plot 0 0 :text \"east\" :angle :east)
    (add-pointer plot 0 0 :text \"south\" :angle :south)
    (add-pointer plot 0 0 :text \"sw\" :angle :sw)
    (add-pointer plot 0 0 :text \"se\" :angle :se)


"
  ([chart x y & options]
    (let [opts (when options (apply assoc {} options))
          text (or (:text opts) "")
          n (* -1/2 Math/PI)
          s (* 1/2 Math/PI)
          w Math/PI
          e 0
          nw (* -3/4 Math/PI)
          ne (* -1/4 Math/PI)
          se (* 1/4 Math/PI)
          sw (* 3/4 Math/PI)
          angle (if (nil? (:angle opts))
                    nw
                    (if (keyword? (:angle opts))
                      (cond
                        (= (:angle opts) :north) n
                        (= (:angle opts) :south) s
                        (= (:angle opts) :west) w
                        (= (:angle opts) :east) e
                        (= (:angle opts) :nw) nw
                        (= (:angle opts) :ne) ne
                        (= (:angle opts) :sw) sw
                        (= (:angle opts) :se) se)
                      (:angle opts)))
          anno (XYPointerAnnotation. text x y angle)]
      (do
        (cond
          (= angle n)
            (.setTextAnchor anno TextAnchor/BASELINE_CENTER)
          (= angle s)
            (.setTextAnchor anno TextAnchor/CENTER)
          (= angle w)
            (.setTextAnchor anno TextAnchor/CENTER_RIGHT)
          (= angle e)
            (.setTextAnchor anno TextAnchor/CENTER_LEFT)
          (= angle nw)
            (.setTextAnchor anno TextAnchor/CENTER_RIGHT)
          (= angle ne)
            (.setTextAnchor anno TextAnchor/CENTER_LEFT)
          (= angle sw)
            (.setTextAnchor anno TextAnchor/CENTER_RIGHT)
          (= angle se)
            (.setTextAnchor anno TextAnchor/CENTER_LEFT))
        (.addAnnotation (.getPlot chart) anno)))))
Vars in incanter.charts/add-pointer: = cond defn let
Used in 0 other vars

Comments top

No comments for add-pointer. Log in to add a comment.