package com.ddChat.graphic;
public class TickInfo
{
GData min, max,len;
GData alignMin, alignMax,alignLen;
TickProp tickProp,alignTickProp;
public TickInfo(GData min, GData max)
{
super();
this.min = min;
this.max = max;
this.len = new GData();
len.setValue(max.getValue() - min.getValue());
len.setResolution(min.getResolution());
calculateAlignData();
System.out.println("alignMin="+alignMin);
System.out.println("alignMax="+alignMax);
}
private void calculateAlignData()
{
tickProp = getTickProp();
System.out.println(tickProp);
alignMin = new GData(min.getValue(),min.getResolution());
alignMax = new GData(max.getValue(),max.getResolution());
alignLen = new GData();
GData base = new GData(tickProp.getTickInterval(),min.getResolution());
alignMin = alignMin.floor(base);
alignMax = alignMax.ceil(base);
alignLen.setValue(alignMax.getValue() - alignMin.getValue());
alignLen.setResolution(alignMin.getResolution());
alignTickProp = getAlignedTickProp();
System.out.println(alignTickProp);
}
public int pickNextInterval(double currentInterval)
{
int result = -1;
int intervalBase[] = Config.TICK_INTERVAL_BASE;
if((intervalBase == null) ||(intervalBase.length == 0))
{
return result;
}
double log10base = Math.log10(currentInterval);
//放大倍数
int scale = (int) Math.pow(10, Math.floor(log10base));
int scaleInterval = 0;
if (currentInterval < 1)
{
result = intervalBase[0];
return result;
}
for(int i = 0 ; i < intervalBase.length; i++)
{
//将基准intervalBase放大resolution对应幅度
scaleInterval = intervalBase[i] * scale;
if( scaleInterval > currentInterval)
{
result = scaleInterval;
return result;
}
}
//找遍全部,都没有找到,则将intervalBase[0] 多放大10作为返回值
result = intervalBase[0] * scale * 10;
return result;
}
public TickProp getTickProp()
{
TickProp tickObj = new TickProp();
int result = -1;
int lenInt = len.toInt();
double scale = Math.pow(10, len.getResolution());
int interval = 0;
double tickCount = 0d;
while(true)
{
interval = pickNextInterval(interval);
tickCount = 1.0 * lenInt / interval;
if(( tickCount >= Config.MIN_TICK_COUNT ) && ( tickCount <= Config.MAX_TICK_COUNT ))
{
result = (int) Math.ceil(tickCount);
tickObj.setTickCount(result);
tickObj.setTickInterval(interval/scale);
return tickObj;
}
else if( tickCount < Config.MIN_TICK_COUNT )
{
result = Config.MIN_TICK_COUNT;
tickObj.setTickCount(result);
tickObj.setTickInterval(interval/scale);
return tickObj;
}
}
}
public TickProp getAlignedTickProp()
{
TickProp tickObj = new TickProp();
int result = -1;
int lenInt = alignLen.toInt();
double scale = Math.pow(10, alignLen.getResolution());
int interval = 0;
double tickCount = 0d;
while(true)
{
interval = pickNextInterval(interval);
tickCount = 1.0 * lenInt / interval;
if(( tickCount >= Config.MIN_TICK_COUNT ) && ( tickCount <= Config.MAX_TICK_COUNT ))
{
result = (int) Math.ceil(tickCount);
tickObj.setTickCount(result);
tickObj.setTickInterval(interval/scale);
return tickObj;
}
else if( tickCount < Config.MIN_TICK_COUNT )
{
result = Config.MIN_TICK_COUNT;
tickObj.setTickCount(result);
tickObj.setTickInterval(interval/scale);
return tickObj;
}
}
}
public GData getAlignMin()
{
return alignMin;
}
public void setAlignMin(GData alignMin)
{
this.alignMin = alignMin;
}
public GData getAlignMax()
{
return alignMax;
}
public void setAlignMax(GData alignMax)
{
this.alignMax = alignMax;
}
public GData getAlignLen()
{
return alignLen;
}
public void setAlignLen(GData alignLen)
{
this.alignLen = alignLen;
}
public GData getMin()
{
return min;
}
public void setMin(GData min)
{
this.min = min;
}
public GData getMax()
{
return max;
}
public void setMax(GData max)
{
this.max = max;
}
}