mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-19 18:21:00 +02:00
Server Preference Pie creation
This commit is contained in:
parent
403c17e681
commit
786b8045ef
@ -0,0 +1,30 @@
|
|||||||
|
package main.java.com.djrapitops.plan.utilities.html.graphs;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ServerPreferencePieCreator {
|
||||||
|
|
||||||
|
private ServerPreferencePieCreator() {
|
||||||
|
throw new IllegalStateException("Utility Class");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createSeriesData(Map<String, Long> serverPlaytimes) {
|
||||||
|
StringBuilder seriesBuilder = new StringBuilder("[");
|
||||||
|
int i = 0;
|
||||||
|
int size = serverPlaytimes.size();
|
||||||
|
for (Map.Entry<String, Long> server : serverPlaytimes.entrySet()) {
|
||||||
|
String serverName = server.getKey();
|
||||||
|
seriesBuilder.append("{name:'").append(serverName)
|
||||||
|
.append("',y:").append(server.getValue()).append("'");
|
||||||
|
|
||||||
|
seriesBuilder.append("}");
|
||||||
|
if (i < size - 1) {
|
||||||
|
seriesBuilder.append(",");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
seriesBuilder.append("]");
|
||||||
|
|
||||||
|
return seriesBuilder.toString();
|
||||||
|
}
|
||||||
|
}
|
53
Plan/src/main/resources/js/serverPie.js
Normal file
53
Plan/src/main/resources/js/serverPie.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
function serverPie(id, serverSeries) {
|
||||||
|
Highcharts.chart(id, {
|
||||||
|
chart: {
|
||||||
|
plotBackgroundColor: null,
|
||||||
|
plotBorderWidth: null,
|
||||||
|
plotShadow: false,
|
||||||
|
type: 'pie'
|
||||||
|
},
|
||||||
|
title: {text: ''},
|
||||||
|
plotOptions: {
|
||||||
|
pie: {
|
||||||
|
allowPointSelect: true,
|
||||||
|
cursor: 'pointer',
|
||||||
|
dataLabels: {
|
||||||
|
enabled: false
|
||||||
|
},
|
||||||
|
showInLegend: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
formatter: function() {
|
||||||
|
return '<b>'+this.point.name+':</b> ' + formatTimeAmount(this.y) + ' ('+this.percentage.toFixed(2)+'%)';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
series: [serverSeries]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTimeAmount(ms) {
|
||||||
|
var out = "";
|
||||||
|
|
||||||
|
var seconds = Math.floor(ms / 1000);
|
||||||
|
|
||||||
|
var dd = Math.floor(seconds / 86400);
|
||||||
|
seconds -= (dd * 86400);
|
||||||
|
var dh = Math.floor(seconds / 3600);
|
||||||
|
seconds -= (dh * 3600);
|
||||||
|
var dm = Math.floor(seconds / 60);
|
||||||
|
seconds -= (dm * 60);
|
||||||
|
seconds = Math.floor(seconds);
|
||||||
|
if (dd !== 0) {
|
||||||
|
out += dd.toString() + "d ";
|
||||||
|
}
|
||||||
|
if (dh !== 0) {
|
||||||
|
out += dh.toString() + "h ";
|
||||||
|
}
|
||||||
|
if (dm !== 0) {
|
||||||
|
out += dm.toString() + "m ";
|
||||||
|
}
|
||||||
|
out += seconds.toString() + "s ";
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user