NOTICE! This is a static HTML version of a legacy Fiji BugZilla bug.

The Fiji project now uses GitHub Issues for issue tracking.

Please file all new issues there.

Bug 18 - Can't add text label to ij.gui.Plot instance
Can't add text label to ij.gui.Plot instance
Status: RESOLVED WONTFIX
Product: Fiji
Classification: Unclassified
Component: ImageJ1
unspecified
PC Linux
: P2 normal
Assigned To: Mark Longair
Depends on:
Blocks:
 
Reported: 2008-10-29 22:13 CDT by Albert Cardona
Modified: 2008-12-15 11:26 CST
0 users

See Also:

Description Albert Cardona 2008-10-29 22:13:32 CDT
 
Comment 1 Albert Cardona 2008-10-29 22:15:40 CDT
This code generates a plot with random values:


(import '(ij.gui Plot))
(let [plot (Plot. "The plot" "The X" "The Y"
                  (float-array (range 30))
                  (float-array (map (fn [x] (rand))
                                    (range 30))))]
  (doto plot
    (setSize 700 300)
    (setLimits 0 30 0 1)
    (setLineWidth 2)                                          
    (show)))


This other block does so but adding a text label: FAILS
(import '(ij.gui Plot))
(let [plot (Plot. "The plot" "The X" "The Y"
                  (float-array (range 30))
                  (float-array (map (fn [x] (rand))
                                    (range 30))))]
  (doto plot
    (setSize 700 300)
    (setLimits 0 30 0 1)
    (setLineWidth 2)
    (addLabel 10 295 "Some label")                                        
    (show)))


... with this exception:

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0 (NO_SOURCE_FILE:0)
	at clojure.lang.Compiler.eval(Compiler.java:4008)
	at Clojure.Clojure_Interpreter$LispThread.parse(Clojure_Interpreter.java:331)
	at Clojure.Clojure_Interpreter$LispThread.run(Clojure_Interpreter.java:273)
Caused by: java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
	at java.awt.image.SampleModel.<init>(SampleModel.java:108)
	at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:128)
	at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:69)
	at java.awt.image.PixelInterleavedSampleModel.createCompatibleSampleModel(PixelInterleavedSampleModel.java:126)
	at ij.process.ImageProcessor.getIndexSampleModel(ImageProcessor.java:1724)
	at ij.process.ByteProcessor.createBufferedImage(ByteProcessor.java:98)
	at ij.process.ByteProcessor.createImage(ByteProcessor.java:82)
	at ij.process.ImageProcessor.drawString2(ImageProcessor.java:1007)
	at ij.process.ImageProcessor.drawString(ImageProcessor.java:978)
	at ij.process.ImageProcessor.drawString(ImageProcessor.java:1045)
	at ij.gui.Plot.addLabel(Plot.java:263)
	at user.eval__2477.invoke(Unknown Source)
	at clojure.lang.Compiler.eval(Compiler.java:3997)
	... 2 more


From outside Clojure, same behaviour.

Trying to add the label after calling 'show' on the plot has the same behaviour.
Comment 2 Johannes Schindelin 2008-12-15 11:26:14 CST
The trick is to specify x and y between 0 and 1, i.e. relative to the image size.  IOW if you call (addLabel 0.1 0.2 "Some label") it will work.  Yes, this is counterintuitive.  But it is existing ImageJ behavior (http://pacific.mpi-cbg.de/cgi-bin/gitweb.cgi?p=ImageJA.git;a=blob;f=ij/gui/Plot.java;h=b9df08a3cbde564201c48da6e9f69a1e7e268d0b;hb=HEAD#l261), so we cannot change it.