【文件属性】:
文件名称:fusionCharts dragnode demo
文件大小:701KB
文件格式:RAR
更新时间:2017-01-18 11:44:36
fusionCharts V3.3 破解版本 dragnode.swf 可拖动
fusionCharts V3.3 破解版本 dragnode.swf 可拖动
自动生成树形拓扑结构节点,根据生成的节点计算展现位置
package com;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Logger;
public class FusionChartsUtil {
protected static Logger logger = Logger.getLogger(FusionChartsUtil.class.getName());
public static Integer PAGE_HEIGHT = 1000;
public static Integer PAGE_WIDTH = 600;
public static Integer ITEM_HEIGHT = 30;
public static Integer ITEM_WIDTH = 90;
public static String COLOR_GREEN = "4EC745"; //基本色,默认颜色
public static String COLOR_RED = "FF0000";
public static String COLOR_GOLD = "FFD700";
public static String COLOR_PURPLE= "800080";
public static String COLOR_BLUE = "0000FF";
public static void main(String arg[])
{
Map paraMap = new HashMap();
paraMap.put("currentRecordId", "");
String xml = com.FusionChartsUtil.makeXml(2,2,paraMap);
}
/**
* 获取背景颜色
* @param log
* @param currentRecordId
* @return
*/
public static String getItemBgColor(OperationLog log,String currentRecordId){
String color = FusionChartsUtil.COLOR_GREEN;
if(currentRecordId!=null && currentRecordId.equals(log.getRecordId())){
color = FusionChartsUtil.COLOR_RED;
}
if("id301".equals(log.getRecordId())){
color = FusionChartsUtil.COLOR_GOLD;
}
if("id431".equals(log.getRecordId())){
color = FusionChartsUtil.COLOR_PURPLE;
}
if("id200".equals(log.getRecordId())){
color = FusionChartsUtil.COLOR_BLUE;
}
// if("id452".equals(log.getRecordId())){
// color = "B0C4DE";
// }
return color;
}
/**
* 计算结节的X,Y值
* @param totalLevel 总共的层数
* @param currLevel 当前的层数
* @param list 当前层的所有节点
* @return
*/
public static List calculateItemXY(
int totalLevel,
int currLevel,
List list,
TreeMap> treemap,
Map map){
String currentRecordId = (String)map.get("currentRecordId");
List listitem = new ArrayList();
if(list==null || list.size()<1) return listitem;
int x = 0;
int y = 0;
int currSize = list.size();
if(totalLevel==1){ //如果只有一层
y = PAGE_HEIGHT/2;
x = PAGE_WIDTH/2;
OperationLog log = list.get(0);
ChartTreeItem item = new ChartTreeItem(log);
item.setColor(getItemBgColor(log,currentRecordId)); //设置节点背景颜色
item.setX(x);
item.setY(y);
listitem.add(item);
}else{
boolean isNeedLadder = false;
//每层高度为等差数列,每层高度eachHeight为d,层数为n,总高度为total: (1+n)*n/2 * d = total ==> d = total*2/(1+n)*n ==>PAGE_HEIGHT *2 / ((totalLevel-1)*totalLevel);
//PAGE_HEIGHT/(totalLevel*2+2);
int eachHeight = PAGE_HEIGHT/(totalLevel+1);
int eachWidth = PAGE_WIDTH/(currSize+1);
int heightCount = eachHeight/ITEM_HEIGHT; //每个高度区间能显示多少个节点
logger.info("eachHeight="+eachHeight+",eachWidth="+eachWidth+",heightCount="+heightCount);
if(eachWidth <= ITEM_WIDTH){ //每节点的计算宽度小于设置的宽度,则需要梯度显示
isNeedLadder = true;
}
int calculatLevvel = currLevel -1;
for(int i=0;i calculateTree(int totalLevel,int eachLevelCount,Map paraMap){
List listitem = new ArrayList();
TreeMap> treemap = makeTree(totalLevel,eachLevelCount);
Iterator it = treemap.keySet().iterator();
while(it.hasNext()){
Integer level = Integer.valueOf(it.next().toString());
List list = treemap.get(level);
if(list!=null){
listitem.addAll(calculateItemXY(treemap.size(),level,list,treemap,paraMap));
}
}
return listitem;
}
/**
* 将获取到的数据链表整理成树状map
* @return
*/
public static TreeMap> makeTree(int totalLevel,int eachLevelCount){
TreeMap> map = new TreeMap>();
List list = generatTestData(totalLevel,eachLevelCount);
for(OperationLog log : list){
String parentId = log.getPreviousRecordId();
//无父节点
if(parentId==null || "".equals(parentId) || "null".equals(parentId)){
List levelList = map.get(1);
if(levelList==null){
levelList = new ArrayList();
}
levelList.add(log);
map.put(1, levelList);
}else{//有父节点
Integer parentLevel = getParentLevel(parentId,map);
Integer level = parentLevel +1;//父级再加一级
List levelList = map.get(level);
if(levelList==null){
levelList = new ArrayList();
}
levelList.add(log);
map.put(level, levelList);
}
}
logger.info(map.toString());
return map;
}
/**
* 生成测试数据
* @return
*/
public static List generatTestData(int level,int eachLevelCount){
List ret = new ArrayList();
TreeMap> genMap = new TreeMap>();
String id = "id1";
OperationLog log1 = new OperationLog();
log1.setId(id);
log1.setTargetNum("13011112222");
log1.setRecordId(id);
log1.setOpDescription(id);
List list = new ArrayList();
list.add(log1);
genMap.put(1, list);
// int level = 3;
// int eachLevelCount = 2;
for(int i = 2; i<=level; i++){
List levelList = genMap.get(i-1); //上一层的所有节点
for(int j=0;j list2 = genMap.get(i); //本层的所有节点
if(list2==null || list2.size()<1){
list2 = new ArrayList();
}
list2.add(log);
genMap.put(i, list2);
}
}
}
System.out.println("genMap.size = "+genMap.size());
Iterator it = genMap.keySet().iterator();
while(it.hasNext()){
String key = it.next().toString();
System.out.println("level = "+key);
List list2 = genMap.get(Integer.valueOf(key)); //本层的所有节点
if(list2!=null){
for(OperationLog log : list2){
ret.add(log);
System.out.println(">>level = "+key+",log: "+log.toString());
}
}
}
System.out.println("logs: "+ret.toString());
return ret;
}
public static String makeXml(int totalLevel,int eachLevelCount,Map paraMap){
String pageHeight = (String)paraMap.get("pageHeight");
String pageWidth = (String)paraMap.get("pageWidth");
FusionChartsUtil.PAGE_HEIGHT = Integer.valueOf(pageHeight);
FusionChartsUtil.PAGE_WIDTH = Integer.valueOf(pageWidth);
List list = calculateTree(totalLevel,eachLevelCount,paraMap);
String xml = "";
xml = " ";
xml += "";
for(ChartTreeItem item : list){
xml += item.toSetString();
}
// xml += "";
//
// xml += "";
xml += " ";
xml += "";
for(ChartTreeItem item : list){
xml += item.toConnectorString();
}
//xml += "";
xml += "";
// xml += "";
// xml += " ";
// xml += " ";
xml += "";
logger.info(xml);
return xml;
}
/**
* 通过parentId获取父节点的级别,若未找到,则返回0
* @param parentId
* @param map
* @return
*/
public static Integer getParentLevel(String parentId,TreeMap> map)
{
logger.info("parentId="+parentId);
Integer level = 0;
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = it.next().toString();
List list2 = map.get(Integer.valueOf(key)); //本层的所有节点
if(list2!=null){
for(OperationLog log : list2){
if(parentId.equals(log.getRecordId())){
level = Integer.valueOf(key);
logger.info(">>level = "+key+",log: "+log.toString());
return level;
}
}
}
}
return level;
}
/**
* 通过parentId获取父节点的级别,若未找到,则返回0
* @param parentId
* @param map
* @return
*/
public static String getParentId(String parentRecordId,TreeMap> map)
{
logger.info("parentRecordId="+parentRecordId);
if(parentRecordId==null) return "";
String parentId = "";
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String key = it.next().toString();
List list2 = map.get(Integer.valueOf(key)); //本层的所有节点
if(list2!=null){
for(OperationLog log : list2){
if(parentRecordId.equals(log.getRecordId())){
logger.info(">>level = "+key+",log: "+log.toString());
parentId = log.getId();
return parentId;
}
}
}
}
return parentId;
}
}
【文件预览】:
dragNode
----.settings()
--------org.eclipse.core.resources.prefs(88B)
----src()
--------com()
----.project(1KB)
----WebRoot()
--------META-INF()
--------WEB-INF()
--------resources()
--------node.html(2KB)
--------index.jsp(4KB)
--------test.jsp(841B)
----.mymetadata(285B)
----.classpath(340B)
----.myeclipse()