Files
CTFd/assets/js/utils/graphs/echarts/userscore.js
Kevin Chung a64e7d51ef Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1
c9887cb1 Fix team template

git-subtree-dir: CTFd/themes/core-beta
git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
2023-06-11 15:56:28 -04:00

103 lines
1.8 KiB
JavaScript

import { colorHash } from "@ctfdio/ctfd-js/ui";
import { cumulativeSum } from "./scoreboard";
import dayjs from "dayjs";
export function getOption(id, name, solves, awards) {
let option = {
title: {
left: "center",
text: "Score over Time",
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "cross",
},
},
legend: {
type: "scroll",
orient: "horizontal",
align: "left",
bottom: 0,
data: [name],
},
toolbox: {
feature: {
saveAsImage: {},
},
},
grid: {
containLabel: true,
},
xAxis: [
{
type: "category",
boundaryGap: false,
data: [],
},
],
yAxis: [
{
type: "value",
},
],
dataZoom: [
{
id: "dataZoomX",
type: "slider",
xAxisIndex: [0],
filterMode: "filter",
height: 20,
top: 35,
fillerColor: "rgba(233, 236, 241, 0.4)",
},
],
series: [],
};
const times = [];
const scores = [];
const total = solves.concat(awards);
total.sort((a, b) => {
return new Date(a.date) - new Date(b.date);
});
for (let i = 0; i < total.length; i++) {
const date = dayjs(total[i].date);
times.push(date.toDate());
try {
scores.push(total[i].challenge.value);
} catch (e) {
scores.push(total[i].value);
}
}
times.forEach(time => {
option.xAxis[0].data.push(time);
});
option.series.push({
name: name,
type: "line",
label: {
normal: {
show: true,
position: "top",
},
},
areaStyle: {
normal: {
color: colorHash(name + id),
},
},
itemStyle: {
normal: {
color: colorHash(name + id),
},
},
data: cumulativeSum(scores),
});
return option;
}