fusionCharts dragnode demo
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<ChartTreeItem> calculateItemXY( int totalLevel, int currLevel, List<OperationLog> list, TreeMap<Integer,List<OperationLog>> treemap, Map map){ String currentRecordId = (String)map.get("currentRecordId"); List<ChartTreeItem> listitem = new ArrayList<ChartTreeItem>(); 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<currSize;i++){ OperationLog log = list.get(i); ChartTreeItem item = new ChartTreeItem(log); item.setColor(getItemBgColor(log,currentRecordId)); //设置节点背景颜色 item.setTo(getParentId(log.getPreviousRecordId(),treemap)); x = eachWidth *(i+1); if(isNeedLadder){ //每层的高度为:(1+n)*n/2 *d // y = eachHeight * (1+calculatLevvel)*calculatLevvel/2 + ITEM_HEIGHT*(i%heightCount); y = eachHeight * ( currLevel-1) + ITEM_HEIGHT*(i%heightCount) + ITEM_HEIGHT*3; }else{ y = eachHeight * ( currLevel-1) + ITEM_HEIGHT; //y = eachHeight * (1+calculatLevvel)*calculatLevvel/2; } if(y<ITEM_HEIGHT){ y = ITEM_HEIGHT; } item.setX(x); // item.setY(y); item.setY(PAGE_HEIGHT - y); listitem.add(item); } } return listitem; } /** * 计算树的位置,以便于展现 * @return */ public static List<ChartTreeItem> calculateTree(int totalLevel,int eachLevelCount,Map paraMap){ List<ChartTreeItem> listitem = new ArrayList<ChartTreeItem>(); TreeMap<Integer,List<OperationLog>> treemap = makeTree(totalLevel,eachLevelCount); Iterator it = treemap.keySet().iterator(); while(it.hasNext()){ Integer level = Integer.valueOf(it.next().toString()); List<OperationLog> list = treemap.get(level); if(list!=null){ listitem.addAll(calculateItemXY(treemap.size(),level,list,treemap,paraMap)); } } return listitem; } /** * 将获取到的数据链表整理成树状map * @return */ public static TreeMap<Integer,List<OperationLog>> makeTree(int totalLevel,int eachLevelCount){ TreeMap<Integer,List<OperationLog>> map = new TreeMap<Integer,List<OperationLog>>(); List<OperationLog> list = generatTestData(totalLevel,eachLevelCount); for(OperationLog log : list){ String parentId = log.getPreviousRecordId(); //无父节点 if(parentId==null || "".equals(parentId) || "null".equals(parentId)){ List<OperationLog> levelList = map.get(1); if(levelList==null){ levelList = new ArrayList<OperationLog>(); } levelList.add(log); map.put(1, levelList); }else{//有父节点 Integer parentLevel = getParentLevel(parentId,map); Integer level = parentLevel +1;//父级再加一级 List<OperationLog> levelList = map.get(level); if(levelList==null){ levelList = new ArrayList<OperationLog>(); } levelList.add(log); map.put(level, levelList); } } logger.info(map.toString()); return map; } /** * 生成测试数据 * @return */ public static List<OperationLog> generatTestData(int level,int eachLevelCount){ List<OperationLog> ret = new ArrayList<OperationLog>(); TreeMap<Integer,List<OperationLog>> genMap = new TreeMap<Integer,List<OperationLog>>(); String id = "id1"; OperationLog log1 = new OperationLog(); log1.setId(id); log1.setTargetNum("13011112222"); log1.setRecordId(id); log1.setOpDescription(id); List<OperationLog> list = new ArrayList<OperationLog>(); list.add(log1); genMap.put(1, list); // int level = 3; // int eachLevelCount = 2; for(int i = 2; i<=level; i++){ List<OperationLog> levelList = genMap.get(i-1); //上一层的所有节点 for(int j=0;j<levelList.size();j++){ for(int k=0;k<eachLevelCount;k++){ OperationLog parent = levelList.get(j); OperationLog log = new OperationLog(); String thisId = "id"+i+String.valueOf(j)+String.valueOf(k); log.setId(thisId); log.setTargetNum("18922269"+i+String.valueOf(j)+String.valueOf(k)); log.setRecordId(thisId); log.setPreviousRecordId(parent.getRecordId()); log.setOpDescription(thisId); List<OperationLog> list2 = genMap.get(i); //本层的所有节点 if(list2==null || list2.size()<1){ list2 = new ArrayList<OperationLog>(); } 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<OperationLog> 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<ChartTreeItem> list = calculateTree(totalLevel,eachLevelCount,paraMap); String xml = ""; xml = "<chart"; xml += " bgcolor=\"FFFFFF\""; xml += " baseFontSize=\"12\""; xml += " charttopmargin=\"0\""; xml += " chartleftmargin=\"0\""; xml += " chartrightmargin=\"0\""; xml += " bordercolor=\"FFFFFF\""; xml += " canvasbordercolor=\"DFBAAD\""; xml += " xAxisMinValue=\"0\""; xml += " xAxisMaxValue=\""+FusionChartsUtil.PAGE_WIDTH+"\""; xml += " yAxisMinValue=\"0\""; xml += " yAxisMaxValue=\""+FusionChartsUtil.PAGE_HEIGHT+"\""; xml += " bubbleScale=\"3\""; xml += " is3D=\"1\""; xml += " numDivLines=\"0\""; xml += " showFormBtn=\"0\""; xml += " viewMode=\"1\""; xml += " restoreBtnTitle=\"重新加载\""; xml += " showrestorebtn=\"1\""; xml += " toolTipBorderColor =\""+COLOR_RED+"\""; xml += " toolTipBgColor=\"F0FFF0\""; xml += "> "; xml += "<dataset plotborderAlpha=\"0\">"; for(ChartTreeItem item : list){ xml += item.toSetString(); } // xml += "<set"; // xml += " x=\"43\""; // xml += " y=\"43\""; // xml += " width=\"90\""; // xml += " height=\"40\""; // xml += " name=\"13500001111\""; // xml += " color=\"4EC745\""; // xml += " link=\"n-http://www.fusioncharts.com\""; // xml += " id=\"AM1\""; // xml += " />"; // // xml += "<set"; // xml += " x=\"43\""; // xml += " y=\"93\""; // xml += " width=\"90\""; // xml += " height=\"30\""; // xml += " name=\"13300002222\""; // xml += " color=\"4EC745\""; // xml += " link=\"n-http://www.fusioncharts.com\""; // xml += " id=\"AM2\""; // xml += " />"; xml += " </dataset>"; xml += "<connectors color=\"83C6E1\" stdThickness=\"8\">"; for(ChartTreeItem item : list){ xml += item.toConnectorString(); } //xml += "<connector strength=\"0.45\" from=\"AM1\" to=\"AM2\" arrowAtStart=\"0\" arrowAtEnd=\"0\"/>"; xml += "</connectors>"; // xml += "<styles>"; // xml += " <definition>"; // xml += " <style name=\"dataLabelFontStyle\" type=\"font\" size=\"15\" color=\"FFFFFF\" bold=\"1\"/>"; // xml += " </definition>"; // xml += " <application>"; // xml += " <apply toObject=\"DATALABELS\" styles=\"dataLabelFontStyle\"/>"; // xml += " </application>"; // xml += " </styles>"; xml += "</chart>"; logger.info(xml); return xml; } /** * 通过parentId获取父节点的级别,若未找到,则返回0 * @param parentId * @param map * @return */ public static Integer getParentLevel(String parentId,TreeMap<Integer,List<OperationLog>> map) { logger.info("parentId="+parentId); Integer level = 0; Iterator it = map.keySet().iterator(); while(it.hasNext()){ String key = it.next().toString(); List<OperationLog> 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<Integer,List<OperationLog>> 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<OperationLog> 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; } }
- 1
- 粉丝: 34
- 资源: 7
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 农村信用社联合社计算机信息系统投产与变更管理办.docx
- 农村信用社联合社计算机信息系统数据管理办法.docx
- 利用SPSS作临床效度分析线上计算网站介绍-医学研究部统计谘.(医学PPT课件).ppt
- 利用Zabbix监控mysqldump定时备份数据库状态.docx
- 利用计算机解决问题的基本过程.doc
- 化工铁路通信工程总结.doc
- 北京大学网络教育软件工程作业.docx
- 医药公司(连锁店)计算机操作规程未新系统的自行按照旧制修改-新系统过制的编号加修模版.doc
- 医药公司(连锁店)计算机系统操作规程模版.doc
- 医药连锁门店计算机系统的操作和管理程序未新系统的自行按照旧制修改-新系统过制的编号加修模版.docx
- 1
- 2
前往页