Add set name label to graph on history page

This commit is contained in:
2021-10-03 18:03:06 +01:00
parent 4c2f1613ff
commit 31ebbc2d65
2 changed files with 7 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ export default class History extends Component {
totalPercentage: 0, totalPercentage: 0,
totalCompleteTests: 0, totalCompleteTests: 0,
userMarkHistory: [], userMarkHistory: [],
userSetHistory: [],
personalSetsCount: 0, personalSetsCount: 0,
}; };
@@ -67,6 +68,7 @@ export default class History extends Component {
let totalTime = 0; let totalTime = 0;
let totalPercentage = 0; let totalPercentage = 0;
let userMarkHistory = []; let userMarkHistory = [];
let userSetHistory = [];
querySnapshot.docs.map((doc) => { querySnapshot.docs.map((doc) => {
const data = doc.data(); const data = doc.data();
@@ -92,6 +94,7 @@ export default class History extends Component {
x: new Date(data.start_time), x: new Date(data.start_time),
y: (data.correct.length / data.questions.length * 100), y: (data.correct.length / data.questions.length * 100),
}); });
userSetHistory.push(data.set_title);
return complete.push(pushData); return complete.push(pushData);
} else { } else {
return incomplete.push(pushData); return incomplete.push(pushData);
@@ -108,6 +111,7 @@ export default class History extends Component {
totalPercentage: totalPercentage, totalPercentage: totalPercentage,
totalCompleteTests: complete.length, totalCompleteTests: complete.length,
userMarkHistory: userMarkHistory, userMarkHistory: userMarkHistory,
userSetHistory: userSetHistory,
personalSetsCount: (await userSets).docs.length, personalSetsCount: (await userSets).docs.length,
}); });
this.props.page.load(); this.props.page.load();
@@ -186,7 +190,7 @@ export default class History extends Component {
</div> </div>
{ this.state.userMarkHistory && this.state.userMarkHistory.length > 1 && { this.state.userMarkHistory && this.state.userMarkHistory.length > 1 &&
<LineChart data={this.state.userMarkHistory} /> <LineChart data={this.state.userMarkHistory} sets={this.state.userSetHistory} />
} }
{ {

View File

@@ -38,7 +38,8 @@ export default function LineChart (props) {
tooltip: { tooltip: {
theme: "dark", theme: "dark",
x: { x: {
show: false, show: typeof props.sets !== "undefined",
formatter: (value, opt) => typeof props.sets !== "undefined" ? props.sets[opt.dataPointIndex] : null,
}, },
}, },
stroke: { stroke: {