Highlight selected progress record on graphs

This commit is contained in:
2021-10-08 18:54:32 +01:00
parent 9875f505e8
commit e6bd026f72
2 changed files with 42 additions and 22 deletions

View File

@@ -2,6 +2,19 @@ import React from 'react';
import Chart from "react-apexcharts"; import Chart from "react-apexcharts";
export default function LineChart (props) { export default function LineChart (props) {
const themeColor = getComputedStyle(
document.querySelector("#root > div")
).getPropertyValue("--primary-color")
.trim();
const overlayColor = getComputedStyle(
document.querySelector("#root > div")
).getPropertyValue("--overlay-color")
.trim();
const textColor = getComputedStyle(
document.querySelector("#root > div")
).getPropertyValue("--text-color")
.trim();
const options = { const options = {
xaxis: { xaxis: {
type: "datetime", type: "datetime",
@@ -18,11 +31,7 @@ export default function LineChart (props) {
tickAmount: 5, tickAmount: 5,
}, },
chart: { chart: {
foreColor: foreColor: textColor,
getComputedStyle(
document.querySelector("#root > div")
).getPropertyValue("--text-color")
.trim(),
toolbar: { toolbar: {
show: false, show: false,
}, },
@@ -33,10 +42,7 @@ export default function LineChart (props) {
}, },
}, },
colors: [ colors: [
getComputedStyle( themeColor
document.querySelector("#root > div")
).getPropertyValue("--primary-color")
.trim()
], ],
tooltip: { tooltip: {
theme: "dark", theme: "dark",
@@ -50,10 +56,7 @@ export default function LineChart (props) {
curve: 'smooth', curve: 'smooth',
}, },
grid: { grid: {
borderColor: getComputedStyle( borderColor: overlayColor,
document.querySelector("#root > div")
).getPropertyValue("--overlay-color")
.trim(),
xaxis: { xaxis: {
lines: { lines: {
show: true show: true
@@ -71,6 +74,16 @@ export default function LineChart (props) {
}, },
}, },
}], }],
annotations:
props.currentPointX ? {
xaxis: [
{
x: new Date(props.currentPointX).getTime(),
strokeDashArray: 5,
borderColor: themeColor,
}
],
} : {},
}; };
const series = [ const series = [
{ {

View File

@@ -72,6 +72,7 @@ export default withRouter(class Progress extends React.Component {
setComplete: false, setComplete: false,
averagePercentage: null, averagePercentage: null,
pageLoaded: false, pageLoaded: false,
startTime: null,
}; };
let isMounted = true; let isMounted = true;
@@ -163,10 +164,13 @@ export default withRouter(class Progress extends React.Component {
newState.attemptNumber = querySnapshot.docs.map((doc) => doc.id).indexOf(this.props.match.params.progressId) + 1; newState.attemptNumber = querySnapshot.docs.map((doc) => doc.id).indexOf(this.props.match.params.progressId) + 1;
if (querySnapshot.docs.length > 1) if (querySnapshot.docs.length > 1)
newState.attemptHistory = querySnapshot.docs.filter((doc) => doc.data().duration !== null) newState.attemptHistory = querySnapshot.docs.filter((doc) => doc.data().duration !== null)
.map((doc) => ({ .map((doc) => {
if (doc.id === this.props.match.params.progressId) newState.startTime = doc.data().start_time;
return {
x: new Date(doc.data().start_time), x: new Date(doc.data().start_time),
y: (doc.data().correct.length / doc.data().questions.length * 100), y: (doc.data().correct.length / doc.data().questions.length * 100),
})); }
});
})); }));
promises.push(this.state.db.collection("completed_progress") promises.push(this.state.db.collection("completed_progress")
@@ -391,10 +395,13 @@ export default withRouter(class Progress extends React.Component {
newState.attemptNumber = querySnapshot.docs.map((doc) => doc.id).indexOf(this.props.match.params.progressId) + 1; newState.attemptNumber = querySnapshot.docs.map((doc) => doc.id).indexOf(this.props.match.params.progressId) + 1;
if (querySnapshot.docs.length > 1) if (querySnapshot.docs.length > 1)
newState.attemptHistory = querySnapshot.docs.filter((doc) => doc.data().duration !== null) newState.attemptHistory = querySnapshot.docs.filter((doc) => doc.data().duration !== null)
.map((doc) => ({ .map((doc) => {
if (doc.id === this.props.match.params.progressId) newState.startTime = doc.data().start_time;
return {
x: new Date(doc.data().start_time), x: new Date(doc.data().start_time),
y: (doc.data().correct.length / doc.data().questions.length * 100), y: (doc.data().correct.length / doc.data().questions.length * 100),
})); }
});
})); }));
} }
@@ -641,7 +648,7 @@ export default withRouter(class Progress extends React.Component {
{Object.keys(this.state.attemptHistory).length > 1 && {Object.keys(this.state.attemptHistory).length > 1 &&
<> <>
<h2 className="chart-title">History</h2> <h2 className="chart-title">History</h2>
<LineChart data={this.state.attemptHistory} /> <LineChart data={this.state.attemptHistory} currentPointX={this.state.startTime} />
</> </>
} }