whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
SUPPORT
whitespace
FORUM
whitespace
FAQS
whitespace
SUBSCRIPTION
whitespace
REQUEST ON-LINE
whitespace
whitespace

Technical Support Forum

Welcome Guest Search | Active Topics | Log In | Register

[SOLVED] Implementation of a ChartAxisScale Listenner Options · View
olivier
#1 Posted : Thursday, March 17, 2011 6:40:28 PM
Rank: Newbie

Groups: Registered

Joined: 3/16/2011
Posts: 3
Location: France
Hello,

I draw some stuff on the graph area but i wound need a clean way to know when the scale has been changed.

I thaught of implementing like a ChartAxisScaleListenner, but maybe there are some already existing features that I can use, i don"t really know where to start.

I thaught maybe if i extend the ChartAxisScale i could know when the scale is changed, but then how would I force the aiChart to use my class and not the original one ?

Thanks a lot for you help on this matter.
Baydalka Volodymyr
#2 Posted : Thursday, March 17, 2011 6:57:51 PM
Rank: Developers Team


Groups: Registered, Administrators

Joined: 7/28/2009
Posts: 447
Hi,

Unfortunately, there is no way like to know when the scale has been changed. We have plans to add some listener like this in future version. Also you can change the ChartAxisScale class.

There is workaround how to detect scale changes. Try to use ChartView.getChart().addInvalidateListener(). IInvalidateListener interface contains onInvalidate method, that will be called each time when chart need to be redrawn. You may check scale values there and handle changes.

Also you may ChartArea.refresh() method to update scale manually.

Best regards,
Volodymyr Baydalka
Andriod development and support team
olivier
#3 Posted : Friday, March 18, 2011 10:57:13 AM
Rank: Newbie

Groups: Registered

Joined: 3/16/2011
Posts: 3
Location: France
I have tried with this code, but I get a StackOverFlow Exception, wich i tried to avoid by using the "ignoreNextCall" variable, but I still get the exception :(


Code:

public class ScaleChangeListener implements IInvalidateListener {

    ChartAxisScale oldScaleY;
    ChartAxisScale oldScaleX;
    ChartView chart;

    boolean ignoreNextCall;

    public ScaleChangeListener(ChartView view) {
        chart = view;
        oldScaleX = chart.getAreas().get(0).getDefaultXAxis().getScale();
        oldScaleY = chart.getAreas().get(0).getDefaultYAxis().getScale();
    }


    @Override
    public void onInvalidate() {
        if(! ignoreNextCall) {
            ChartAxisScale currentScaleX = chart.getAreas().get(0).getDefaultXAxis().getScale();
            ChartAxisScale currentScaleY = chart.getAreas().get(0).getDefaultYAxis().getScale();


            if(currentScaleX.getRealMaximum() != oldScaleX.getRealMaximum() ||
                    currentScaleY.getRealMaximum() != oldScaleY.getRealMaximum()) {

                oldScaleX = currentScaleX;
                oldScaleY = currentScaleY;

                onScaleChanged(currentScaleX, currentScaleY);
            }
        }
        else {
            ignoreNextCall = false;
        }

    }


    public void onScaleChanged(ChartAxisScale newScaleX, ChartAxisScale newScaleY)  {
        ignoreNextCall = true;
                //drawing stuff
        ChartUtilities.displayHistoricArea();

    }


Baydalka Volodymyr
#4 Posted : Friday, March 18, 2011 12:08:54 PM
Rank: Developers Team


Groups: Registered, Administrators

Joined: 7/28/2009
Posts: 447
Hi,

Make notice that any changes that you made may call onInvalidate() method again. Also make notice that ChartAxisScale methods may compute values when getXXX() method is called and call onInvalidate() method too.

Check following code

Code:
public static class ScaleChangeListener implements IInvalidateListener
{
    double xMin, xMax;
    double yMin, yMax;
    
  ChartView chart;
  boolean isBusy = false;

  public ScaleChangeListener(ChartView view)
  {
      chart = view;
  }

  @Override
  public void onInvalidate()
  {
      if(!isBusy)
      {
          isBusy = true;
       
          ChartAxisScale xScale = chart.getAreas().get(0).getDefaultXAxis().getScale();
        ChartAxisScale yScale = chart.getAreas().get(0).getDefaultYAxis().getScale();

        if(xScale.getRealMinimum() != xMin || xScale.getRealMaximum() != xMax
                || yScale.getRealMinimum() != yMin || yScale.getRealMaximum() != yMax)
        {
            xMin = xScale.getRealMinimum();
            xMax = xScale.getRealMaximum();
            yMin = yScale.getRealMinimum();
            yMax = yScale.getRealMaximum();
            
          onScaleChanged(xScale, xScale);
        }
       
        isBusy = false;
      }
  }

  public void onScaleChanged(ChartAxisScale newScaleX, ChartAxisScale newScaleY)
  {
      // TODO
  }
}


P.S. ChartAxis.getScale() method always returns the same instance.
Volodymyr Baydalka
Andriod development and support team
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.