import QtQuick 2.11

Rectangle {
    id:root
    z:-1

    width:900
    height:460

    color: "white"
    visible: false
    property string fileName
    property int  delayms:300

    property  real m_maxY: 0.0
    property  real m_minY: 0.0

   // property var pointList:[]


    function generatePicture(filename, dataArray){
        var current_step = 0

        for(var i=0; i<dataArray.length;i++){
            m_maxY = (m_maxY < dataArray[i].pressure)? dataArray[i].pressure:m_maxY
            m_minY = (m_minY > dataArray[i].pressure)? dataArray[i].pressure:m_minY
            //console.log("dataArray  ",i,dataArray[i])
        }

        curveDisplay_pic.spline.clear()
        curveDisplay_pic.scatter_clear()

        //m_minY = (m_minY-2) < 0?  0:(m_minY-2)
        //m_maxY = m_maxY+2
        console.log("generatePicture dataArray.length:"+dataArray.length)

        curveDisplay_pic.setRange_Y(m_minY-1.0, m_maxY+1.0)
        curveDisplay_pic.setRange_X(0, dataArray.length-1)

        for(var j=0; j<dataArray.length; j++){

            curveDisplay_pic.spline.append(j,dataArray[j].pressure)

            if(current_step !== dataArray[j].step){

                if(2 == current_step ){
                    curveDisplay_pic.scatter_add(j, dataArray[j].pressure)
                    console.log("generatePicture keep end j:"+j)
                }

                current_step = dataArray[j].step

                if(2 == current_step ){
                    curveDisplay_pic.scatter_add(j, dataArray[j].pressure)
                    console.log("generatePicture keep begin j:"+j)
                }
            }
        }

        //dataSource.update(curveDisplay.charView.series(0),root.pointList)

        root.fileName = "D:/tmp/"+filename +".jpg"
        timer.start()
    }


    Timer{
        id:timer
        repeat: false
        interval: delayms
        onTriggered: {
            root.grabToImage(function(result) {
                result.saveToFile(root.fileName);
            });
        }
    }


    CurveDisplay{
        id:curveDisplay_pic
        anchors.fill: parent
        name: "横轴时间（秒） 纵轴压力(kPa)"
    }





}
