<?
function panel_pp_fusion_charts($pp_key,$eye='',$options=[]) {
    $parent_panel_id=($options['parent_panel_id']?'#'.$options['parent_panel_id']:'#panel_PP_preview_'.$pp_key);
    $width=($options['width']?$options['width']:'500');
    $height=($options['height']?$options['height']:'300');
    $rec=execSQL_van("select * from obj_site_narko_data narko where pkey=".$pp_key);
    if (!$rec['leftEye']) $rec['leftEye']=PP()->get_pp_value($rec['pkey'],'left');
    if (!$rec['rightEye']) $rec['rightEye']=PP()->get_pp_value($rec['pkey'],'right');

    $rec_norm=execSQL_van('select pp_id from obj_site_narko_data_out_303 where user_id='.$rec['personal_id']);
    if ($rec_norm['pp_id'])
    {   $pp_norm=execSQL_van('select * from obj_site_narko_data where pkey='.$rec_norm['pp_id']);
        if (!$pp_norm['leftEye']) $pp_norm['leftEye']=PP()->get_pp_value($pp_norm['pkey'],'left');
        if (!$pp_norm['rightEye']) $pp_norm['rightEye']=PP()->get_pp_value($pp_norm['pkey'],'right');
        if ($pp_norm['pkey'])
        {   $analyzer=new Analyzer();
            if (!$eye or $eye=='l')
            { $analyzer->stringToArrays($pp_norm['leftEye']);
                $dataMassiveNorm=[
                    'type'=>'NORM',
                    'data'=>$analyzer->getMassive()
                ];
            }
            if (!$eye or $eye=='r')
            { $analyzer->stringToArrays($pp_norm['rightEye']);
                $dataMassiveNorm=[
                    'type'=>'NORM',
                    'data'=>$analyzer->getMassive()
                ];
            }
        }
    }
    $analyzer=new Analyzer();
    if (!$eye or $eye=='l')
    {
        if (!$options['no_approximate']) $analyzer->stringToArrays($rec['leftEye']);
        else $analyzer->stringToArrays($rec['leftEye'],'',array('no_approximate'=>1));
        $dataMassive=[
            'type'=>'LEFT',
            'data'=>$analyzer->getMassive()
        ];
    }
    if (!$eye or $eye=='r')
    {
        if (!$options['no_approximate']) $analyzer->stringToArrays($rec['rightEye']);
        else $analyzer->stringToArrays($rec['rightEye'],'',array('no_approximate'=>1));
        $dataMassive=[
            'type'=>'RIGHT',
            'data'=>$analyzer->getMassive()
        ];
    }

    if (_sizeof($dataMassive['data'])) {
        $categorySetArray=[];
        if (_sizeof($dataMassiveNorm['data'])>_sizeof($dataMassive['data'])) {
            foreach ($dataMassiveNorm['data'] as $key=>$value) {
                $categorySetArray[]='{"label":"'.$key.'"}';
            }
        } else {
            foreach ($dataMassive['data'] as $key=>$value) {
                $categorySetArray[]='{"label":"'.$key.'"}';
            }
        }
        $categorySet=implode(',',$categorySetArray);
        foreach ($dataMassive['data'] as $key=>$value) {
            $dataSetValueArray[]='{"value":"'.$value.'"}';
        }
        $dataSetArray=[];
        if (_sizeof($dataSetValueArray)) {
            $dataSetArray[]='{"seriesname":"'.$dataMassive['type'].'","color":"#bce02e","data":['.implode(',',$dataSetValueArray).']}';
        }

        if (_sizeof($dataMassiveNorm)) {
            foreach ($dataMassiveNorm['data'] as $key=>$value) {
                $dataSetNormArray[]='{"value":"'.$value.'"}';
            }
            if (_sizeof($dataSetNormArray)) {
                $dataSetArray[]='{"seriesname":"NORM","color":"#e0642e","data":['.implode(',',$dataSetNormArray).']}';
            }

        }

        $dataSet=implode(',',$dataSetArray);
    }

    ?>
    <div id="dryEye_<?echo $eye.$pp_key?>" class="dryPPEye">Подождите, идет построение графика</div>
    <script type="text/javascript">
        FusionCharts.ready(function(){
            var revenueChart_<?echo $eye.$pp_key?> = new FusionCharts({
                type: 'msline',
                renderAt: 'dryEye_<?echo $eye.$pp_key?>',
                width: "<?echo $width?>",
                height: "<?echo $height?>",
                dataFormat: "json",
                dataSource: {
                    "chart": {
                        "showhovereffect": "1",
                        "showvalues": "0",
                        "theme": "candy",
                        "drawAnchors": "0",
                        "canvasBgColor" : "#ffffff",
                        "canvasBorderAlpha" : "0",
                        "showBorder" : "0",
                        "bgColor" : "#ffffff",
                        "showShadow" : "0",
                        "showAlternateHGridColor": "0",
                        "divLineDashed": "1",
                        "divLineDashLen": "5",
                        "divLineDashGap": "6",
                        "labelStep": "100",
                        // "animation": "0"
                        // "showZeroPlane": "0"
                    },
                    "categories": [
                        {
                            "category": [
                                <?echo $categorySet?>
                            ]
                        }
                    ],
                    "dataset": [
                        <?echo $dataSet?>
                    ]
                }
            }).render(function() {
            });
        });
        $j('<?echo $parent_panel_id?>').css('background-image', 'none');
    </script>
    <?
}
?>