<?php assert($object instanceof \PhpBench\Report\Model\BarChart) ?>
<div id="<?php echo $id ?>" width="400" height="100"></div>
<script>
var data = [
    <?php foreach ($object->dataSets() as $setName => $dataSet): ?>
    {
        x: <?php echo json_encode($dataSet->xSeries()) ?>,
        name: '<?php echo $dataSet->name() ?>',
        y: <?php echo json_encode($dataSet->ySeries()) ?>,
        type: 'bar',
        <?php if ($dataSet->errorMargins() !== null): ?>
        error_y: {
            type: 'data',
            array: <?php echo json_encode($dataSet->errorMargins()) ?>,
            visible: true,
        }
        <?php endif ?>
    },
    <?php endforeach ?>
]
var layout = {
    barmode: 'group',
    yaxis: {
        tickmode: 'array',
        tickvals: <?php echo json_encode($object->yAxisLabelRange(10)) ?>,
        ticktext: <?php echo json_encode(array_map(function ($value) use ($object) {
            return $this->nodePrinter->print($this->nodeEvaluator->evaluate($object->yAxesLabelExpression(), ['yValue' => $value]));
        }, $object->yAxisLabelRange(10))) ?>
    },
    xaxis: {
        tickmode: 'array',
        tickvals: <?php echo json_encode($object->xAxes()) ?>,
        ticktext: <?php echo json_encode($object->xLabels()) ?>,
    }
};
<?php if ($object->title()): ?>
layout.title = <?php echo json_encode($object->title()) ?>;
<?php endif ?>
Plotly.newPlot(document.getElementById('<?php echo $id ?>'), data, layout);
</script>
