<div class="wrap">
    
    <h1><?php echo e($__page->get('title')); ?> pour la ville de : <?php echo get_the_title( $_GET['ville'] ); ?></h1>

    <div class="row">
        <div class="col-12">
            <div class="tablenav top">
                <div class="actions">
                    <form action="admin.php?<?php echo createUrlFormAction( $_SERVER['QUERY_STRING'], array('filters') ); ?>">
                    <?php
                    echo generateHiddenFormElementsFromUrl($_SERVER['QUERY_STRING'], array('filters')); 
                    $journaux = JournalModel::allInArray();
                    echo View::make('admin._general.list.filters.journaux', ['journaux' => $journaux]);
                    ?>
                    <?php echo View::make('admin._general.list.filters.dates', []); ?>
                    <input type="submit" name="filter_action" id="post-query-submit" class="button" value="Filtrer">
                    </form>
                </div>
            </div>
        </div>
    </div>

    <?php 

    $journauxLast = JournalModel::last();

    ?>

    <div class="row">
        <div class="col-4">
            <h2><?php _e("Nombre de parutions", "farandole"); ?> : </h2>
            <canvas id="evenementsAlauneByVille" width="400" height="200" data-ischartjs="true"></canvas>
            <script type="text/javascript">

                <?php $parutionsAlaune =  count( EvenementModel::findEvenementsAlauneByVille( $_GET['ville'] ) ); ?>
                <?php $parutions = count( EvenementModel::findEvenementsAlauneByVille( $_GET['ville'], 0 ) ); ?>
                <?php $parutionsTotal = $parutionsAlaune + $parutions; ?>

                canvasData.evenementsAlauneByVille = {
                    data: {
                        labels: [ "Parutions (à la une)", "Parutions", "Parutions total" ],
                        datasets: [
                            {
                                fill: false,
                                lineTension: 0.1,
                                backgroundColor: "rgba(75,192,192,0.4)",
                                borderColor: "rgba(75,192,192,1)",
                                borderCapStyle: 'butt',
                                borderDash: [],
                                borderDashOffset: 0.0,
                                borderJoinStyle: 'miter',
                                pointBorderColor: "rgba(75,192,192,1)",
                                pointBackgroundColor: "#fff",
                                pointBorderWidth: 1,
                                pointHoverRadius: 5,
                                pointHoverBackgroundColor: "rgba(75,192,192,1)",
                                pointHoverBorderColor: "rgba(220,220,220,1)",
                                pointHoverBorderWidth: 2,
                                pointRadius: 1,
                                pointHitRadius: 10,
                                data: [<?php echo $parutionsAlaune; ?>, <?php echo $parutions; ?>, <?php echo $parutionsTotal; ?>],
                            }
                        ]
                    },
                    borderWidth: 0,
                    options: {
                        legend: {
                            display: false,
                        },
                        scales: {
                            yAxes: [{
                                ticks: {
                                    beginAtZero:true,
                                    unitStepSize: 1
                                }
                            }]
                        }
                    },
                    type: 'bar'
                };
            </script>
        </div>
    </div>

    <div class="row">
        <div class="col-6">
        <h2><?php _e("Nombre de caractères par journal", "farandole"); ?> :</h2>
        <canvas id="caracteresParJournal" width="400" height="200" data-ischartjs="true"></canvas>
        <script type="text/javascript">
            canvasData.caracteresParJournal = {
                data: {
                    labels: <?php echo json_encode( array_map( "getTitleFromPost", $journauxLast ) ); ?>,
                    datasets: [
                        {
                            fill: false,
                            lineTension: 0.1,
                            backgroundColor: "rgba(75,192,192,0.4)",
                            borderColor: "rgba(75,192,192,1)",
                            borderCapStyle: 'butt',
                            borderDash: [],
                            borderDashOffset: 0.0,
                            borderJoinStyle: 'miter',
                            pointBorderColor: "rgba(75,192,192,1)",
                            pointBackgroundColor: "#fff",
                            pointBorderWidth: 1,
                            pointHoverRadius: 5,
                            pointHoverBackgroundColor: "rgba(75,192,192,1)",
                            pointHoverBorderColor: "rgba(220,220,220,1)",
                            pointHoverBorderWidth: 2,
                            pointRadius: 1,
                            pointHitRadius: 10,
                            data: <?php echo json_encode( getCaracteresByJournauxAndVille( $journauxLast, $_GET['ville'] ) ) ; ?>,
                        }
                    ]
                },
                options: {
                    legend: {
                        display: false,
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero:true,
                                unitStepSize: 1
                            }
                        }]
                    }
                },
                type: 'line'
            };
        </script>
        </div>
        <div class="col-6">
        <h2><?php _e("Nombre d'évènement par journal", "farandole"); ?> :</h2>
        <canvas id="evenementsParJournal" width="400" height="200" data-ischartjs="true"></canvas>
        <script type="text/javascript">
            canvasData.evenementsParJournal = {
                data: {
                    labels: <?php echo json_encode( array_map( "getTitleFromPost", $journauxLast ) ); ?>,
                    datasets: [
                        {
                            fill: false,
                            lineTension: 0.1,
                            backgroundColor: "rgba(75,192,192,0.4)",
                            borderColor: "rgba(75,192,192,1)",
                            borderCapStyle: 'butt',
                            borderDash: [],
                            borderDashOffset: 0.0,
                            borderJoinStyle: 'miter',
                            pointBorderColor: "rgba(75,192,192,1)",
                            pointBackgroundColor: "#fff",
                            pointBorderWidth: 1,
                            pointHoverRadius: 5,
                            pointHoverBackgroundColor: "rgba(75,192,192,1)",
                            pointHoverBorderColor: "rgba(220,220,220,1)",
                            pointHoverBorderWidth: 2,
                            pointRadius: 1,
                            pointHitRadius: 10,
                            data: <?php echo json_encode( getCountByJournauxAndVille( $journauxLast, $_GET['ville'] ) ) ; ?>,
                        }
                    ]
                },
                options: {
                    legend: {
                        display: false,
                    },
                    scales: {
                        yAxes: [{
                            ticks: {
                                beginAtZero:true,
                                unitStepSize: 1
                            }
                        }]
                    }
                },
                type: 'bar'
            };
        </script>
        </div>
    </div>

</div>