ScaleProvider.java :  » Ajax » ext-gwt » com » extjs » gxt » charts » client » model » Java Open Source

Java Open Source » Ajax » ext gwt 
ext gwt » com » extjs » gxt » charts » client » model » ScaleProvider.java
/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package com.extjs.gxt.charts.client.model;

/**
 * Provides the chart scale given a minimum and maximum value.
 */
public interface ScaleProvider {

  public static ScaleProvider DEFAULT_SCALE_PROVIDER = new ScaleProvider() {
    public Scale calcScale(double min, double max) {
      if (min == 0 && max == 0) {
        return new Scale(-1, 1, 1);
      }
      min = Math.floor(min * (min > 0 ? .9 : 1.1));
      max = Math.round(max * (max > 0 ? 1.1 : .9));
      return new Scale(min, max, Math.max(min > 0 ? min : min * -1, max > 0 ? max : max * -1) / 10);
    }
  };

  public static ScaleProvider ROUNDED_NEAREST_SCALE_PROVIDER = new ScaleProvider() {
    public Scale calcScale(double min, double max) {
      Scale scale = DEFAULT_SCALE_PROVIDER.calcScale(min, max);
      scale.setInterval(Math.round(scale.getInterval()));
      return scale;
    }
  };

  /**
   * Returns the scale for the given minimum and maximum value.
   * 
   * @param min the minimum value
   * @param max the maximum value
   * @return the scale
   */
  public Scale calcScale(double min, double max);

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.