forked from madalinoprea/magneto-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.phtml
80 lines (65 loc) · 3.45 KB
/
analytics.phtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<script>
//<![CDATA[
var options = {
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : true,
//String - The colour of each segment stroke
segmentStrokeColor : "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth : 1,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout : 50, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps : 100,
//String - Animation easing effect
animationEasing : "easeOutQuart",
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
tooltipTemplate: "<%= value %>", // override in loop
//String - A legend template OVERRIDE IN LOOP
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\" class=\"picto-<%=name.toLowerCase()%>-legend\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
};
function randomColor(brightness){
function randomChannel(brightness){
var r = 255-brightness;
var n = 0|((Math.random() * r) + brightness);
var s = n.toString(16);
return (s.length==1) ? '0'+s : s;
}
return '#' + randomChannel(brightness) + randomChannel(brightness) + randomChannel(brightness);
}
function generateObjectDatas(dataBrut){
var datas = [];
for(var key in dataBrut){
var data = {};
data.color = randomColor(50);
data.highlight = '#9e9e9e';
data.value = dataBrut[key];
data.label = key;
datas.push(data);
}
return datas;
}
//]]>
</script>
<?php foreach ($this->getList() as $type => $info) : ?>
<?php $sumCurrentType = array_sum($this->getResume($type)); ?>
<div id="container-myChart-<?php echo $type; ?>" class="debug-container-analytics">
<h4><?php echo $info['label']; ?></h4>
<div class="container-myChart-total"><?php echo $sumCurrentType; ?><?php echo $info['unit']; ?></div>
<canvas id="myChart-<?php echo $type; ?>" width="250" height="250"></canvas>
</div>
<script>
//<![CDATA[
var ctx_<?php echo $type; ?> = document.getElementById("myChart-<?php echo $type; ?>").getContext("2d");
var sumCurrentType = <?php echo $sumCurrentType ?>;
options.tooltipTemplate = "<%= value %> <?php echo $info['unit']; ?>";
options.legendTemplate = "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\" class=\"picto-<%=name.toLowerCase()%>-legend\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%> - <%= Math.round(segments[i].value*1000/sumCurrentType)/10 %>%</li><%}%> </ul>";
var myChart_<?php echo $type; ?> = new Chart(ctx_<?php echo $type; ?>).Doughnut(generateObjectDatas(<?php echo json_encode($this->getResume($type)); ?>),options);
var legend_<?php echo $type; ?> = myChart_<?php echo $type; ?>.generateLegend();
$('container-myChart-<?php echo $type; ?>').insert(legend_<?php echo $type; ?>);
//]]>
</script>
<?php endforeach; ?>