[O] Optimize course-scatter with course.assignmentTypes
This commit is contained in:
@@ -4,6 +4,7 @@ import {FormatUtils} from '@/logic/utils/format-utils';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import Course, {Assignment} from '@/logic/course';
|
import Course, {Assignment} from '@/logic/course';
|
||||||
import GraphUtils from '@/logic/utils/graph-utils';
|
import GraphUtils from '@/logic/utils/graph-utils';
|
||||||
|
import {CourseUtils} from '@/logic/utils/course-utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
})
|
})
|
||||||
@@ -109,13 +110,12 @@ export default class CourseScatter extends Vue
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create scatter plots
|
// Create scatter plots
|
||||||
let map = this.mapAssignments();
|
let series: any[] = this.course.assignmentTypes.map(type =>
|
||||||
let series: any[] = Array.from(map, ([type, assignments]) =>
|
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
name: type,
|
name: type.name,
|
||||||
data: CourseScatter.assignmentsData(assignments),
|
data: CourseScatter.assignmentsData(this.course.assignments.filter(a => a.typeId == type.id)),
|
||||||
itemStyle: itemStyle
|
itemStyle: itemStyle
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -131,27 +131,6 @@ export default class CourseScatter extends Vue
|
|||||||
return series;
|
return series;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Map assignments to {assignmentType, [assignment]} format.
|
|
||||||
*/
|
|
||||||
private mapAssignments(): Map<string, Assignment[]>
|
|
||||||
{
|
|
||||||
// Define map
|
|
||||||
let map = new Map();
|
|
||||||
|
|
||||||
// Move data to map
|
|
||||||
this.course.assignments.forEach(a =>
|
|
||||||
{
|
|
||||||
// Null case, create empty array
|
|
||||||
if (!map.has(a.type)) map.set(a.type, []);
|
|
||||||
|
|
||||||
// Put data
|
|
||||||
map.get(a.type).push(a);
|
|
||||||
});
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert assignments to series data
|
* Convert assignments to series data
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user