Hybrid View

  1. #1
    Ext GWT Premium Member dardison's Avatar
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    168
    Vote Rating
    1
    dardison is on a distinguished road

      0  

    Default ScaleProvider that supports negative scale values for BarCharts

    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
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


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

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar