google-code-export / tatami

Automatically exported from code.google.com/p/tatami
1 stars 1 forks source link

Bug charting and resizing. #19

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Here's an interesting bug for you guys. Just to start out with, you
should know I'm using what I checked out from subversion so that it
would have those bug fixes that you put in for the setWidth() and
setMajorTicks() methods.

So, here's the thing. If you call the setWidth() or setHeight() method
in Chart2D and specify a value that is larger than the current height/
width, the chart will correctly resize. However, if you try to specify
a height/width that is smaller than the current size, it won't do
anything, the dimensions will stay exactly the same.

I tried to figure out why this would happen, but I couldn't really get
to the root of the problem. From what I can tell it has something to
do with this:

        private void setWidth(String width , boolean resizeDojo) {
        super.setWidth(width);
        if(resizeDojo && dojoWidget != null){
            dojoUpdateSize(dojoWidget,getOffsetWidth(),getOffsetHeight());
        }
    }

For example, if I increase the width by 10 pixels
dojoWidget.getOffsetWidth() returns a width that is increased by 10
pixels so that the underlying dojo widget will be resized correctly.
But when I pass in a width that is reduced by 10 pixels, the
offsetWidth doesn't change. I don't know if this somehow means that
super.setWidth(width) isn't working correctly, or getOffsetWidth isn't
reading the DOM element correctly, or something else completely
different.

This is what I wrote to try and figure out what was going on.

      int width = 400;
      int height = 400;
      Chart2D chart;

      chart = new Chart2D(width+"px", height+"px");
      BarPlot plot = new BarPlot();
      Serie serie = new Serie();

      serie.addData(10);
      serie.addData(20);
      serie.addData(30);

      plot.addSerie(serie);
      chart.addPlot(plot);

      Button buttonUp = new Button("Up");
      Button buttonDown = new Button("Down");

      buttonUp.addClickListener(new ClickListener(){

         public void onClick(Widget sender)
         {
            System.out.print(chart.getOffsetWidth() + " " +
chart.getOffsetHeight() +" : ");
            width+=10;
            chart.setWidth(width+"px");
            System.out.println(chart.getOffsetWidth() + " " +
chart.getOffsetHeight());
         }

      });

      buttonDown.addClickListener(new ClickListener(){

         public void onClick(Widget sender)
         {
            System.out.print(chart.getOffsetWidth() + " " +
chart.getOffsetHeight() +" : ");
            width-=10;
            chart.setWidth(width+"px");
            System.out.println(chart.getOffsetWidth() + " " +
chart.getOffsetHeight());
         }

      });

      RootPanel.get().add(chart);
      RootPanel.get().add(buttonUp);
      RootPanel.get().add(buttonDown);

Original issue reported on code.google.com by vgrass...@gmail.com on 31 Mar 2009 at 8:22

GoogleCodeExporter commented 9 years ago
I think that I know why there is a problem.
Calling the methods getOffsetWidth() or getOffsetHeight() is not a good idea 
because
these methods use the property offsetWidth respectively offsetHeight of the DOM 
Element.
When you call the method setWidth() or setHeight, you change the height or width
property of the Style Element.

Original comment by vgrass...@gmail.com on 31 Mar 2009 at 8:34