Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1502958
  • 博文数量: 108
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2013-06-29 09:58
个人简介

兴趣是坚持一件事永不衰竭的动力

文章分类

全部博文(108)

文章存档

2021年(1)

2020年(10)

2019年(19)

2018年(9)

2016年(23)

2015年(43)

2013年(3)

我的朋友

分类: Java

2015-11-24 23:48:50

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;
}



}

阅读(1078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~