Results 1 to 2 of 2

Thread: ScaleProvider that supports negative scale values for BarCharts

  1. #1
    Ext GWT Premium Member dardison's Avatar
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    180
    Vote Rating
    1
      0  

    Default ScaleProvider that supports negative scale values for BarCharts

    Hi,

    You can use this ScaleProvider to manage BarChart scale to graph not only positive but negative figures, and generates integer adhoc intervals.

    Code:
    public class BarScaleProvider implements ScaleProvider {
    
    	public Scale calcScale(double min, double max) {
    		Scale result=null;
    		int divideCount=0;
    		boolean found=false;
    		Double interval;
    		Double minValue;
    		Double maxValue;
    		
    		double offset=max - min;
    		if(offset>1000){
    			while(!found){
    				offset=offset / 1000;
    				divideCount++;
    				if(offset<1000)
    					found=true;
    			}
    		}
    		interval=this.getInterval(offset);
    		for(int i=0; i<divideCount;i++){
    			interval=interval*1000;
    		}
    		interval=interval.intValue()*1.0;
    		minValue=min;
    		minValue=minValue.intValue()*1.0;
    		maxValue=max;
    		maxValue=maxValue.intValue()*1.0;
    		Double remainder=maxValue / interval;
    		remainder=remainder.intValue()*1.0;
    		maxValue=maxValue+interval-remainder;
    		if(min<0.0){
    			minValue=0.0;
    			while(minValue>min){
    				minValue=minValue-interval;
    			}
    		}
    		result=new Scale();
    		result.setMin(minValue);
    		result.setMax(maxValue);
    		result.setInterval(interval);
    		return result;
    	}
    	
    	protected double getInterval(double value){
    		Range[] ranges={ new Range(500, 1000, 100), new Range(200, 500, 50),
    						 new Range(100, 200, 20)  , new Range(50, 100, 10),
    						 new Range(20, 50, 5)     , new Range(10, 20, 2),
    						 new Range(5, 10, 1)      , new Range(2, 5, 0.5), 
    						 new Range(1, 2, 0.2)};
    		double interval=0;
    		for(Range r : ranges){
    			if(value>=r.left && value<r.right){
    				interval=r.interval;
    				break;
    			}
    		}
    		return interval;
    		
    	}
    	
    	protected class Range {
    		double left;
    		double right;
    		double interval;
    		
    		protected Range(double left, double right, double interval){
    			this.left=left;
    			this.right=right;
    			this.interval=interval;
    		}
    	}
    
    }

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    132
      0  

    Default

    I fixed the GXT scaleprovider to support also negative values the correct way. The fix will be part of M2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •