1.2.3-SNAPSHOT Arrow_down_16x16
  • (slider updater-fn slider-values)
  • (slider updater-fn slider-values slider-label)


Examples:
(use '(incanter core stats charts))

(def pdf-chart (function-plot pdf-normal -3 3))
(view pdf-chart)
(add-function pdf-chart pdf-normal -3 3)

(let [x (range -3 3 0.1)]
(slider #(set-data pdf-chart [x (pdf-normal x :sd %)]) (range 0.1 10 0.1)))

(let [x (range -3 3 0.1)]
(slider #(set-data pdf-chart [x (pdf-normal x :sd %)]) (range 0.1 10 0.1) "sd"))

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:2784 top

(defn slider 
"

  Examples:
    (use '(incanter core stats charts))

    (def pdf-chart (function-plot pdf-normal -3 3))
    (view pdf-chart)
    (add-function pdf-chart pdf-normal -3 3)

    (let [x (range -3 3 0.1)] 
      (slider #(set-data pdf-chart [x (pdf-normal x :sd %)]) (range 0.1 10 0.1)))

    (let [x (range -3 3 0.1)] 
      (slider #(set-data pdf-chart [x (pdf-normal x :sd %)]) (range 0.1 10 0.1) \"sd\"))
"
  ([updater-fn slider-values]
     (slider updater-fn slider-values nil))
  ([updater-fn slider-values slider-label]
     (let [max-idx (count slider-values)
	   label-txt (fn [v] (str (when slider-label (str slider-label " = ")) v))
	   label (JLabel. (label-txt (first slider-values)) JLabel/CENTER)
	   slider (doto (JSlider. JSlider/HORIZONTAL 0 max-idx 0)
		    (.addChangeListener (proxy [javax.swing.event.ChangeListener] []
					  (stateChanged [^javax.swing.event.ChangeEvent event]
							(let [source (.getSource event)
							      value (nth slider-values (.getValue source))]
							  (do
							    (.setText label (label-txt value))
							    (updater-fn value)))))))
	   panel (doto (JPanel. (BorderLayout.))
		   (.add label BorderLayout/NORTH)
		   (.add slider BorderLayout/CENTER))
	   frame (JFrame. "Slider Control")
	   width 500
	   height 70] 
       (doto frame
	 (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
	 (.add panel BorderLayout/CENTER)
	 (.setSize width height)
	 ;; (.setVisible true)
	 (.setVisible true))
       frame)))
Vars in incanter.charts/slider: defn doto let
Used in 0 other vars

Comments top

No comments for slider. Log in to add a comment.