
let dataMap={
    0:[0, 0, 0, 0, 0, 0, 0,0,0,0],
    1:[0, 0, 0, 0, 0, 0, 0,0,0,0],
    2:[0, 0, 0, 0, 0, 0, 0,0,0,0]
}

let tempList= [
    'rgba(255, 99, 132, 0.7)',
    'rgba(54, 162, 235, 0.7)',
    'rgba(255, 206, 86, 0.7)',
    'rgba(75, 192, 192, 0.7)',
    'rgba(153, 102, 255, 0.7)',
    'rgba(255, 159, 64, 0.7)'
]
let tempbList=[]

function update(line,tag)
{
    let cur=line.data.datasets[tag]
    let obj=cur.data

    for (let key in dataMap[tag]) 
    {
        obj[key].value=dataMap[tag][key]
    }
    
}

function updateAll(line,tagList)
{
    for (let index = 0; index < tagList.length; index++) 
    {
        let cur=tagList[index]
        update(line,cur)
    }
    line.update();
}



await $M.include("/public/default/js/Chart.js")
var data = {
    labels: ["tag1", "tag2", "tag3", "tag4", "tag5", "tag6", "tag7", "tag8", "tag9", "tag10"],
    datasets: [
        {
            label: "正态分布",
            backgroundColor: 'rgba(54, 162, 235, 0.4)',
            borderColor: tempbList,
            data: dataMap[0],
            borderColor:'rgba(255,255,255,0.2)'
        },
        {
            label: "自带随机数",
            backgroundColor: 'rgba(255, 30, 100, 0.4)',
            borderColor: tempbList,
            data: dataMap[1],
            borderColor:'rgba(255,255,255,0.2)'
        },
        {
            label: "线性同余",
            backgroundColor: 'rgba(75, 192, 192, 0.5)',
            borderColor: tempbList,
            data: dataMap[2],
            borderColor:'rgba(255,255,255,0.2)'
        }
    ]
};

var ctx = $M.find("#myChart").getContext("2d");

var line = new Chart(ctx, {
    type: 'line',
    data
});


function gen(tag,arr)
{
    if(!arr.length)return
    let count=dataMap[tag].length
    for (let index = 0; index < count; index++) 
    {
        dataMap[tag][index]+=arr[index]
    }
}


$M.find('#myChart').rely
(
    'html','content-com-statis-update',(event)=>
    {
        let obj=event.detail
        gen(0,obj.sho)
        gen(1,obj.rand)
        gen(2,obj.seed)
        updateAll(line,[0,1,2])
        $M.dispatch('html','content-com-code-update',obj)
    }
)
