bug on legend position Top with a long legend title

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Jonathan
Newbie
Newbie
Posts: 60
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin

bug on legend position Top with a long legend title

Post by Jonathan » Thu Feb 17, 2011 11:06 pm

Hi,

Bug 1)
I don't have a problem with a legend whose position is either Left or Right. When I change the legend position to either Top or Bottom with a long legend title, the width of the legend bounds isn't correctly rendered. In other words, the long legend title can't fit into the legend whose position is either Top or Bottom. The following is a sample code of what i am talking about. Is there a way to make the legend width suitable with the legend title when the position is Top or Bottom, just like when the position is either Right or Left?

Bug 2)
I noticed that the icon for the legend item gets smaller when the position is Top/Bottom when compared to the position of Left/Right? Is there a way to have a same size of the icon for the legend item when its position is either Top or Bottom? You will see the different size of the icon within the legend when you change the position from Left/Right to Top/Bottom.

Code: Select all

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		JPanel panel = new JPanel();
		panel.setSize(600, 600);
		TChart chart = new TChart();
		
		panel.add(chart);
		Bar b = new Bar(chart.getChart());
		b.add(0, 10, Color.BLACK);
		b.add(1, 20, Color.BLACK);
		b.add(2, 30, Color.BLACK);
		b.setTitle("first series");
		
		Bar b1 = new Bar(chart.getChart());
		b1.add(0, 10, Color.RED);
		b1.add(1, 10, Color.RED);
		b1.add(2, 10, Color.RED);
		b1.setMultiBar(MultiBars.STACKED);
		b1.setTitle("second series");
		
		String title = "here is a quite long legend title to see if this can fit into legend top";
		chart.getLegend().getTitle().setText(title);
		chart.getLegend().setAlignment(LegendAlignment.TOP);
//		chart.getLegend().setAlignment(LegendAlignment.BOTTOM);
	
		frame.add(panel);
		frame.setSize(600, 600);
		frame.setVisible(true);
	}

Yeray
Site Admin
Site Admin
Posts: 8726
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: bug on legend position Top with a long legend title

Post by Yeray » Mon Feb 21, 2011 12:16 pm

Hi Jonathan,

I can see the Bug #1 you reported so I've added it to the defect list to be fixed in future releases (TJ71015403).
Regarding the Bug #2, I don't see any difference between default alignment (right) and top alignment. Here is my result with NetBeans 6.9.1:
Legends.png
Legends.png (3.26 KiB) Viewed 3262 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Jonathan
Newbie
Newbie
Posts: 60
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin

Re: bug on legend position Top with a long legend title

Post by Jonathan » Mon Feb 21, 2011 3:44 pm

1) Is there any workaround I can do now for the Bug #1 ?

2) The size of blue and orange images got a bit smaller when the position is top/bottom, when compared to left/right. I can even see the a little difference on the image you posted.

Thanks

Yeray
Site Admin
Site Admin
Posts: 8726
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: bug on legend position Top with a long legend title

Post by Yeray » Mon Feb 21, 2011 5:56 pm

Hi Jonathan,
Jonathan wrote:1) Is there any workaround I can do now for the Bug #1 ?
You could use the LegendResolver to manually modify the legend rect:

Code: Select all

        tChart1.setLegendResolver(new LegendResolver() {

            @Override
            public Rectangle getBounds(Legend legend, Rectangle rectangle) {
                return new Rectangle(200,20,400,legend.getHeight());
            }

            @Override
            public LegendItemCoordinates getItemCoordinates(Legend legend, LegendItemCoordinates coordinates) {
                return coordinates;
            }

            @Override
            public String getItemText(Legend legend, LegendStyle legendStyle, int index, String text) {
                return text;
            }
        });
Jonathan wrote:2) The size of blue and orange images got a bit smaller when the position is top/bottom, when compared to left/right. I can even see the a little difference on the image you posted.
You are right. I can see a difference of about two pixels. I've added it to the defect list to be fixed in future releases (TJ71015407).
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Jonathan
Newbie
Newbie
Posts: 60
Joined: Tue Mar 11, 2008 12:00 am
Location: Austin

Re: bug on legend position Top with a long legend title

Post by Jonathan » Wed Feb 23, 2011 11:23 pm

Hi Yeray,

Thanks for your answers. However, I found 2 problems on the temp solution you provided for the Bug #1.

Problem1) I can't set a hard code of '400' for the legend width because the legend title can vary. There should be a way to convert the legend string title to pixel.

Problem 2) I can't set a hard code of '200' for the legend x coordinates because the legend won't be in center and because the legend would be cropped off. (ditto: y coordinate) There should be a way to calculate x and y into right positions.

Thanks.

Yeray
Site Admin
Site Admin
Posts: 8726
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: bug on legend position Top with a long legend title

Post by Yeray » Fri Feb 25, 2011 5:20 pm

Hi Jonathan,

You can always the code suggested with textWidth function to calculate the Legend title width. For example this works fine for me:

Code: Select all

public Rectangle getBounds(Legend legend, Rectangle rectangle) {
                int lwidth = Utils.round(tChart1.getGraphics3D().textWidth(tChart1.getLegend().getTitle().getText())) + 10;
                int leftPos = (tChart1.getWidth()/2) - (lwidth/2);
                return new Rectangle(leftPos,legend.getTop(),lwidth,legend.getHeight());
            }
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply