Commit 6522b5e0 authored by wuqinghua's avatar wuqinghua

2021/12/7 吴卿华 1修改一级关系图展示形状为圆形 2修改颜色生成算法

parent 9f85871b
package com.example.gajz.transferrelationship;
import org.junit.Test;
import java.awt.*;
import java.util.Random;
public class TEST {
public static void main(String[] args) {
}
@Test
public void RandomHexColor_test() {
Random random = new Random();
float hue = random.nextFloat();
float saturation = (random.nextInt(7000) + 4000) / 10000f;
float luminance = 1f;
Color color = Color.getHSBColor(hue, saturation, luminance);
System.out.println(color);
System.out.println("#" + Integer.toHexString((color.getRGB() & 0xffffff) | 0x1000000).substring(1));
//红色
String red;
//绿色
String green;
//蓝色
String blue;
//生成红色颜色代码
red = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成绿色颜色代码
green = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成蓝色颜色代码
blue = Integer.toHexString(random.nextInt(256)).toUpperCase();
//判断红色代码的位数
red = red.length()==1 ? "0" + red : red ;
//判断绿色代码的位数
green = green.length()==1 ? "0" + green : green ;
//判断蓝色代码的位数
blue = blue.length()==1 ? "0" + blue : blue ;
//生成十六进制颜色值
String color1 = "0x"+red+green+blue;
System.out.println(color1);
}
}
package com.example.gajz.transferrelationship.neo4j;
import java.awt.*;
import java.util.Random;
public class Colour {
public String getColour(){
//红色
String red;
//绿色
String green;
//蓝色
String blue;
// //红色
// String red;
// //绿色
// String green;
// //蓝色
// String blue;
//生成随机对象
Random random = new Random();
//生成红色颜色代码
red = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成绿色颜色代码
green = Integer.toHexString(random.nextInt(256)).toUpperCase();
//生成蓝色颜色代码
blue = Integer.toHexString(random.nextInt(256)).toUpperCase();
//判断红色代码的位数
red = red.length()==1 ? "0" + red : red ;
//判断绿色代码的位数
green = green.length()==1 ? "0" + green : green ;
//判断蓝色代码的位数
blue = blue.length()==1 ? "0" + blue : blue ;
//生成十六进制颜色值
String color = "0x"+red+green+blue;
return color;
// //生成红色颜色代码
// red = Integer.toHexString(random.nextInt(256)).toUpperCase();
// //生成绿色颜色代码
// green = Integer.toHexString(random.nextInt(256)).toUpperCase();
// //生成蓝色颜色代码
// blue = Integer.toHexString(random.nextInt(256)).toUpperCase();
// //判断红色代码的位数
// red = red.length()==1 ? "0" + red : red ;
// //判断绿色代码的位数
// green = green.length()==1 ? "0" + green : green ;
// //判断蓝色代码的位数
// blue = blue.length()==1 ? "0" + blue : blue ;
// //生成十六进制颜色值
// String color = "0x"+red+green+blue;
float hue = random.nextFloat();
float saturation = (random.nextInt(7000) + 4000) / 10000f;
float luminance = 1f;
Color color1= Color.getHSBColor(hue, saturation, luminance);
String cos="0x" + Integer.toHexString((color1.getRGB() & 0xffffff) | 0x1000000).substring(1);
return cos;
}
}
......@@ -2,22 +2,35 @@ package com.example.gajz.transferrelationship.neo4j;
import com.example.gajz.redis.ConFigRedis;
import redis.clients.jedis.Jedis;
import java.util.HashMap;
import java.util.Set;
import java.util.*;
public class test {
public static void main(String[] args) {
int START = 1;
int END = 100;
Random random = new Random();
for (int idx = 1; idx <= 1; ++idx){
showRandomInteger(START, END, random);
}
}
HashMap hashMap=new HashMap();
hashMap.put("1","111");
hashMap.put("2","222");
hashMap.put("3","333");
hashMap.put("4","444");
private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
if ( aStart > aEnd ) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("Generated : " + randomNumber);
}
private static void log(String aMessage){
System.out.println(aMessage);
}
System.out.println(hashMap.size());
}
}
......@@ -273,8 +273,8 @@ public class CalculationCenterPoint {
CenterPointVo centerPointVo1=new CenterPointVo();
centerPointVo1.setBankCardNo(transferCardVoList.get(p).getBankCardNo());
centerPointVo1.setName(transferCardVoList.get(p).getName());
centerPointVo1.setX((int)(Math.random()*2000));
centerPointVo1.setY((int)(Math.random()*2000));
centerPointVo1.setX((int)(Math.random()*1000));
centerPointVo1.setY((int)(Math.random()*1000));
temporaryList.add(centerPointVo1);
repeat.put(transferCardVoList.get(p).getBankCardNo(),1);
}
......@@ -294,11 +294,8 @@ public class CalculationCenterPoint {
subordinateList.add(temporary.get(x));
}
}
}
return centerPointVoList;
}
......
......@@ -36,6 +36,7 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
/**HugeGraph*/
@Autowired
HugeCollectionProperties hugeCollectionProperties;
@Autowired
CalculationCenterPoint calculationCenterPoint;
......@@ -85,48 +86,50 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
public List diagramSpot() {
// Jedis conn = ConFigRedis.getConn();
/**已经存在的点 会存储到map里面*/
HashMap hashMap = new HashMap();
/**存储已经查找到的中心点下级 防止重复*/
HashMap centerPointMap = new HashMap();
HashMap hashMap=new HashMap();
//查询转账人(中心点)信息
List<TransferCardVo> transferCardVos = transferRelationshipMapper.selectTransferCard();
/**----------------------------------计算中心点位置 开始------------------------------------*/
/**计算中心点方法*/
List<CenterPointVo> centerPointVoList = calculationCenterPoint.CenterPointMethod(transferCardVos);
// System.out.println(centerPointVoList.size());
/**----------------------------------计算中心点位置 结束------------------------------------*/
List list=new ArrayList();
int centerPointX = 0;
int centerPointY = 0;
//重复次数
int repeatFrequency = 0;
//存储所有大圆的四角X Y轴数据
HashMap xyMap = new HashMap();
/** 中心点*/
for (int i=0;i<centerPointVoList.size();i++){
for (int i=0;i<transferCardVos.size();i++){
//是否重叠
boolean overlap=false;
if (!overlap){
centerPointVoList.get(i).setX(centerPointVoList.get(i).getX()+20);
centerPointVoList.get(i).setY(centerPointVoList.get(i).getY()+20);
centerPointVoList.get(i).setY(centerPointVoList.get(i).getY());
}
//生成颜色
Colour colour=new Colour();
String code=colour.getColour();
Test test=new Test();
test.setId(centerPointVoList.get(i).getBankCardNo());
test.setX(centerPointVoList.get(i).getX());
test.setY(centerPointVoList.get(i).getY());
test.setName(centerPointVoList.get(i).getName());
test.setId(transferCardVos.get(i).getBankCardNo());
test.setX((int)(Math.random()*5000));
test.setY((int)(Math.random()*5000));
test.setName(transferCardVos.get(i).getName());
test.setColor(code);
centerPointX=test.getX();
centerPointY=test.getY();
/** -----------------------------去掉被转账人对应中心点重复出现点 代码--------------------------------*/
/**查询被转账人全部信息*/
List<com.example.gajz.transferrelationship.bean.param.data> transfer = transferRelationshipMapper.transferRelationship(centerPointVoList.get(i).getBankCardNo());
List<com.example.gajz.transferrelationship.bean.param.data> transfer = transferRelationshipMapper.transferRelationship(transferCardVos.get(i).getBankCardNo());
/**将没有重复的值 存储到这个list里面*/
List<com.example.gajz.transferrelationship.bean.param.data> dataList=new ArrayList<>();
for (int p=0;p<transfer.size();p++){
Object target = hashMap.get(transfer.get(p).getTarget());
/**判断此中心点是否是因为碰撞第一次生成下级数据 如果不是第一次就设置防重复map失效*/
if (repeatFrequency!=0){
target = null;
}
if (target==null){
com.example.gajz.transferrelationship.bean.param.data data=new com.example.gajz.transferrelationship.bean.param.data();
data.setName(transfer.get(p).getName());
......@@ -144,7 +147,7 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
}
/**每圈点数 动态变化 */
int base = 8;
int base = 40;
/**总数*/
int total = dataList.size();
/**循环次数*/
......@@ -154,10 +157,10 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
/**算大圈半径专用 总数*/
int bigTotal = dataList.size();
/**算大圈半径专用 每圈点数*/
int bigBase = 8;
int bigBase = 20;
for (int n=1;bigTotal>0;n++){
bigTotal = bigTotal-bigBase;
bigBase = bigBase+20;
bigBase = bigBase+50;
}
/** 大圆最后一圈半径 每份多少点数 */
int bigPointsPerShare = bigBase/4;
......@@ -181,8 +184,12 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
}else {
for (int p=0;p<i;p++){
int zX = (int) xyMap.get(p + "zX");
int zY = (int) xyMap.get(p + "zY");
int yX = (int) xyMap.get(p + "yX");
int yY = (int) xyMap.get(p + "yY");
int sX = (int) xyMap.get(p + "sX");
int sY = (int) xyMap.get(p + "sY");
int xX = (int) xyMap.get(p + "xX");
int xY = (int) xyMap.get(p + "xY");
if(((zX>(centerPointX-fullCircleRadius)&&zX>(centerPointX+fullCircleRadius)) ||(yX<(centerPointX-fullCircleRadius)&&yX<(centerPointX+fullCircleRadius)))
||
......@@ -201,8 +208,12 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
// conn.set(test.getId(),position);
list.add(test);
overlap=true;
repeatFrequency=0;
}
}else {
//设置碰撞次数
repeatFrequency++;
//设置已经碰撞
overlap=false;
break;
}
......@@ -213,15 +224,17 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
continue;
}
/**圆圈层数 每循环一次 就是一圈*/
for (int y=1;total>0;y++){
/**点之间 x轴y轴间隔距离*/
int distance=2;
/**圆分成四份 每份多少点数*/
int pointsPerShare = base/4;
float pointsPerShare = base/4;
/**每份点数 / 90度 算出每个点数的度数*/
float number=90/pointsPerShare;
int eachDegree = (int)Math.ceil(number);
/**小圆半径 点数X距离*/
int circleRadius = pointsPerShare * distance;
int circleRadius = (int) (pointsPerShare * distance);
/**右下角逐渐递减*/
int lowerRight = 0;
/**左下角逐渐递减*/
......@@ -234,33 +247,57 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
for (int t=0;t<base;t++){
Test test1=new Test();
if (t<pointsPerShare){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((distance*t)+centerPointX);
test1.setY((centerPointY-circleRadius)+(distance*t));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
}else if (t<=pointsPerShare*2){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((centerPointX+circleRadius)-(distance*lowerRight));
test1.setY(centerPointY+(lowerRight*distance));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
lowerRight++;
}else if (t<=pointsPerShare*3){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((centerPointX-circleRadius)+(distance*lowerLeft));
test1.setY(centerPointY+(distance*lowerLeft));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
lowerLeft++;
}else if (t<=pointsPerShare*4){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX(centerPointX-(distance*upperLeft));
test1.setY((centerPointY-circleRadius)+(distance*upperLeft));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
upperLeft++;
......@@ -272,40 +309,64 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
numberCycles++;
}
total=total-base;
base = base+20;
base = base+(y*45);
continue;
}
if (base>0){
for (int t=0;numberCycles<dataList.size();t++){
Test test1=new Test();
if (t<pointsPerShare){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((distance*t)+centerPointX);
test1.setY((centerPointY-circleRadius)+(distance*t));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
}else if (t<=pointsPerShare*2){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((centerPointX+circleRadius)-(distance*lowerRight));
test1.setY(centerPointY+(lowerRight*distance));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
lowerRight++;
}else if (t<=pointsPerShare*3){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX((centerPointX-circleRadius)+(distance*lowerLeft));
test1.setY(centerPointY+(distance*lowerLeft));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
lowerLeft++;
}else if (t<=pointsPerShare*4){
//算出A角度数 (每份点数-t)* 每点度数
int Adegrees = (int) ((pointsPerShare-t) * eachDegree);
//Y轴
int a= (int) (circleRadius*Math.sin(Adegrees));
//X轴
int b= (int) (circleRadius*Math.cos(Adegrees));
test1.setId(dataList.get(numberCycles).getTarget());
test1.setName(dataList.get(numberCycles).getName());
test1.setX(centerPointX-(distance*upperLeft));
test1.setY((centerPointY-circleRadius)+(distance*upperLeft));
test1.setX(centerPointX+b);
test1.setY(centerPointY-a);
test1.setColor(code);
test1.setSize(pointSize);
upperLeft++;
......@@ -313,7 +374,7 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
// /** 将其他点 X Y轴拼接 并存入Redis中*/
// String position=test1.getX()+"Y"+test1.getY();
// conn.set(test1.getId(),position);
list.add(test1);
// list.add(test1);
numberCycles++;
}
break;
......@@ -321,6 +382,7 @@ public class TransferRelationshipServiceImpl implements TransferRelationshipServ
}
}
// conn.close();
// System.out.println(list.size());
return list;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment