-
Notifications
You must be signed in to change notification settings - Fork 747
/
chartjs.template
102 lines (97 loc) · 4.51 KB
/
chartjs.template
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<h3>{{xlabel}}/{{ylabel}}</h3>
<div id="{{ xlabel }}{{ ylabel }}{{ label }}">
<canvas id="chart{{ xlabel }}{{ ylabel }}{{ label }}" width="800" height="600"></canvas>
<script>
var ctx = document.getElementById("chart{{ xlabel }}{{ ylabel }}{{ label }}");
var chart = new Chart(ctx, {
{% if not render_all_points %}
type: "line",
{% else %}
type: "bubble",
{% endif %}
data: { datasets: [
{% for run in data_points %}
{
label: "{{ run["name"] }}",
fill: false,
pointStyle: "{{ linestyle[run["name"]][3] }}",
borderColor: "{{ linestyle[run["name"]][0] }}",
data: [
{% for (x, y), l in zip(run["coords"], run["labels"]) %}
{ x: {{ x }} , y: {{ y }}, label: "{{ l }}" },
{% endfor %}
]
},
{% endfor %}
]},
options: {
responsive: false,
title:{
display:true,
text: '{{ plot_label }}'
},
scales: {
xAxes: [{
display: true,
type: 'linear',
max: '1',
position: 'bottom',
scaleLabel: {
display: true,
labelString: ' {{ xlabel }} '
}
}],
yAxes: [{
display: true,
type: 'logarithmic',
scaleLabel: {
display: true,
labelString: ' {{ ylabel }} '
}
}]
}
}
});
function pushOrConcat(base, toPush) {
if (toPush) {
if (Chart.helpers.isArray(toPush)) {
// base = base.concat(toPush);
Array.prototype.push.apply(base, toPush);
} else {
base.push(toPush);
}
}
return base;
}
Chart.Tooltip.prototype.getFooter = function(tooltipItem, data) {
var me = this;
var callbacks = me._options.callbacks;
var item = tooltipItem[0];
var beforeFooter = callbacks.beforeFooter.apply(me, arguments);
var footer = "Parameters: " + data.datasets[item.datasetIndex].data[item.index].label || '';
var afterFooter = callbacks.afterFooter.apply(me, arguments);
var lines = [];
lines = pushOrConcat(lines, beforeFooter);
lines = pushOrConcat(lines, footer);
lines = pushOrConcat(lines, afterFooter);
return lines;
}
</script>
</div>
{% if args.latex %}
<div class="row">
<div class="col-md-4 text-center">
<button type="button" id="button_{{button_label}}" class="btn btn-default" >Toggle latex code</button>
</div>
</div>
<script>
$("#button_{{button_label}}").click(function() {
$("#plot_{{button_label}}").toggle();
});
</script>
<div id="plot_{{button_label}}" style="display:none">
<pre>
{{latex_code}}
</pre>
</div>
{% endif %}