生成测试用例

<!DOCUMENTTYPE>
<html>
<head>
<script>
var right ;
var posx = 0;
var posy = 0;
var isFirst = false;
var stepSzie = 200;
var heightSize = 50;
function generate(){
    right = document.getElementById("right");
    var value = document.getElementById("input").value;
    var jsonObj = JSON.parse(value);
    analize(jsonObj,0);
}
//递归遍历json
function analize(jsonObj,level){
    for(var p in jsonObj){
        var cell = jsonObj[p];
        if(typeof(cell) == 'object'){
            isFirst = true;
            posy+=heightSize;
            posx = stepSzie * (level);
            right.appendChild(generateCell(p,posx,posy,level));
            
            analize(cell,level+1);
        }else{
            if(isFirst){
                posx = stepSzie * (level);
            }
            posy+=heightSize;
            right.appendChild(generateCell(p,posx,posy,level));
            right.appendChild(generateCell(cell,posx+stepSzie,posy,level));
        }
    }
}
function generateCell(text,x,y,type){
    var div = document.createElement("div");
    div.textContent = text;
    div.style.backgroundColor = "rgb(42, 125, 171)";
    div.style.position = "absolute";
    div.style.top = y + "px";
    div.style.left = x + "px";
    div.style.color = "#fff";
    div.style.paddingLeft = "2px";
    div.style.paddingRight = "2px";
    div.style.borderRadius = "5px";
    div.style.boxShadow = "5px 5px 5px #000";
    div.id = type;
    return div;
}
function getById(id){
    return document.getElementById(id);
}
</script>
<style>
.left{
    border:1px solid #f00;
    width:500px;
    height:800px;
    position:absolute;
    left:1px;

}
.right{
    border:1px solid #f00;
    width:1300px;
    height:800px;
    position:absolute;
    right:1px;
}
.inputStyle{
    width: 400px;
    height: 400px;
}
</style>
</head>
<body>
</body>

<div class="left">
<textarea  id="input" class="inputStyle"></textarea>
<button onclick="generate();">生成</button>
<svg  height="400" width="450" style="border:1px solid #f00;">
 
    <path d="M 10 200 C50 100  300 50 300 200" stroke="blue" stroke-width="5" fill="none" />
    <g stroke="black" stroke-width="3" fill="black">
    <circle id="pointA" cx="10" cy="200" r="3" />
    <circle id="pointB" cx="50" cy="100" r="3" />
    <circle id="pointC" cx="300" cy="50" r="3" />
    <circle id="pointC" cx="300" cy="200" r="3" />
  </g>

</svg>
</div>
<div id="right" class="right">
</div>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值