Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit ded0218

Browse files
committed
Basic Charts
1 parent a4252d6 commit ded0218

File tree

7 files changed

+91
-23
lines changed

7 files changed

+91
-23
lines changed

β€Ž.gitignoreβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/data/*.json
22
/data/*/*/*.json
3-
*.json.lock
3+
*.json.lock
4+
.DS_Store

β€Žphp/core/templates/stats_en.htmlβ€Ž

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ <h3>Tables</h3>
6060

6161
<h3>Graph</h3>
6262
<select id="graphselect">
63-
6463
</select>
6564
<button id="displaygraph">Display Graph</button>
6665

67-
<div id="maingraph"></div>
66+
<div style="width: 99%;">
67+
<canvas id="maingraph"></canvas>
68+
</div>
6869
<script>
6970
var combiData = %%COMBIDATA%%;
7071
var graphes = %%GRAPHES%%;
@@ -74,12 +75,19 @@ <h3>Graph</h3>
7475
graphes.forEach( (g) => {
7576
$("select#graphselect").append('<option value="'+g+'">'+g+'</option>');
7677
});
78+
var chart = null;
7779

7880
$("button#displaygraph").click( () => {
7981
var url = loadUrl + $("select#graphselect").val() + '.js';
8082
$.getScript( url, () => {
8183
if( typeof createGraph === "function" && combiData.length > 0 ){
82-
createGraph(combiData, "div#maingraph");
84+
if(chart !== null){
85+
chart.destroy();
86+
}
87+
chart = createGraph(
88+
combiData,
89+
document.getElementById('maingraph').getContext('2d')
90+
);
8391
}
8492
});
8593
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function createGraph(data, canvas){
2+
/**
3+
* The DOM has jQuery as $ and the ChartJS library.
4+
* The data can be found in data and canvas is the canvas for the chart.
5+
* The function should return the ChartJS object.
6+
*/
7+
8+
var plotdata = {}
9+
data.forEach( (v) => {
10+
if( !plotdata.hasOwnProperty(v.category)){
11+
plotdata[v.category] = 0
12+
}
13+
plotdata[v.category] += v.duration;
14+
});
15+
16+
/**
17+
* Colors from
18+
* chartjs-plugin-colorschemes MIT License
19+
* Copyright (c) 2019 Akihiko Kusanagi
20+
* https://github.com/nagix/chartjs-plugin-colorschemes/blob/master/src/colorschemes/colorschemes.tableau.js
21+
*/
22+
const colors = ['#4E79A7', '#A0CBE8', '#F28E2B', '#FFBE7D', '#59A14F', '#8CD17D', '#B6992D', '#F1CE63', '#499894', '#86BCB6', '#E15759', '#FF9D9A', '#79706E', '#BAB0AC', '#D37295', '#FABFD2', '#B07AA1', '#D4A6C8', '#9D7660', '#D7B5A6']; //['#9999ff', '#993366', '#ffffcc', '#ccffff', '#660066', '#ff8080', '#0066cc', '#ccccff', '#000080', '#ff00ff', '#ffff00', '#0000ff', '#800080', '#800000', '#008080', '#0000ff'];
23+
24+
var config = {
25+
type: 'pie',
26+
data: {
27+
datasets: [{
28+
data: Object.values(plotdata),
29+
backgroundColor: colors
30+
}],
31+
labels: Object.keys(plotdata)
32+
},
33+
options: {
34+
responsive: true
35+
}
36+
};
37+
return new Chart(canvas, config);
38+
}

β€Žphp/load/graphs/PieTask.jsβ€Ž

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function createGraph(data, canvas){
2+
/**
3+
* The DOM has jQuery as $ and the ChartJS library.
4+
* The data can be found in data and canvas is the canvas for the chart.
5+
* The function should return the ChartJS object.
6+
*/
7+
8+
var plotdata = {}
9+
data.forEach( (v) => {
10+
if( !plotdata.hasOwnProperty(v.name)){
11+
plotdata[v.name] = 0
12+
}
13+
plotdata[v.name] += v.duration;
14+
});
15+
16+
/**
17+
* Colors from
18+
* chartjs-plugin-colorschemes MIT License
19+
* Copyright (c) 2019 Akihiko Kusanagi
20+
* https://github.com/nagix/chartjs-plugin-colorschemes/blob/master/src/colorschemes/colorschemes.tableau.js
21+
*/
22+
const colors = ['#4E79A7', '#A0CBE8', '#F28E2B', '#FFBE7D', '#59A14F', '#8CD17D', '#B6992D', '#F1CE63', '#499894', '#86BCB6', '#E15759', '#FF9D9A', '#79706E', '#BAB0AC', '#D37295', '#FABFD2', '#B07AA1', '#D4A6C8', '#9D7660', '#D7B5A6']; //['#9999ff', '#993366', '#ffffcc', '#ccffff', '#660066', '#ff8080', '#0066cc', '#ccccff', '#000080', '#ff00ff', '#ffff00', '#0000ff', '#800080', '#800000', '#008080', '#0000ff'];
23+
24+
var config = {
25+
type: 'pie',
26+
data: {
27+
datasets: [{
28+
data: Object.values(plotdata),
29+
backgroundColor: colors
30+
}],
31+
labels: Object.keys(plotdata)
32+
},
33+
options: {
34+
responsive: true
35+
}
36+
};
37+
return new Chart(canvas, config);
38+
}

β€Žphp/load/graphs/simple.jsβ€Ž

Lines changed: 0 additions & 9 deletions
This file was deleted.

β€Žphp/load/graphs/test.jsβ€Ž

Lines changed: 0 additions & 9 deletions
This file was deleted.

β€Žphp/load/main.cssβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ input[type=text]{
2525
div#main{
2626
border: 1px solid black;
2727
margin:auto;
28-
max-width: 800px;
28+
min-width: 400px;
29+
max-width: 1600px;
2930
background-color: white;
3031
padding: 5px;
3132
border-radius: 4px;

0 commit comments

Comments
Β (0)