-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
61 lines (54 loc) · 2.29 KB
/
helpers.js
File metadata and controls
61 lines (54 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
function getTranslation(transform) {
// Create a dummy g for calculation purposes only. This will never
// be appended to the DOM and will be discarded once this function
// returns.
var g = document.createElementNS("http://www.w3.org/2000/svg", "g");
// Set the transform attribute to the provided string value.
g.setAttributeNS(null, "transform", transform);
// consolidate the SVGTransformList containing all transformations
// to a single SVGTransform of type SVG_TRANSFORM_MATRIX and get
// its SVGMatrix.
var matrix = g.transform.baseVal.consolidate().matrix;
// As per definition values e and f are the ones for the translation.
return [matrix.e, matrix.f];
}
function assign_colors(list, color_list) {
for(let i = 0; i < list.length; i++) {
list[i].color = color_list[Math.floor(Math.random() * color_list.length)];
let random_color = Math.floor(Math.random() * color_list.length);
list[i].color = color_list[random_color];
color_list.splice(random_color, 1); // remove color so its not selected again
}
}
function set_duration(list) {
for(let i = 0; i < list.length; i++) {
list[i].duration = (format(list[i].time.end) - format(list[i].time.start)) / 60000;
}
}
function isColliding(course, otherCourses, trans) {
return _.chain(otherCourses).map(function(otherCourse) {
if (course.id != otherCourse.id) {
if (_.intersection(course.day, otherCourse.day).length > 0){
var otherStart = hourScale(format(otherCourse.time.start))+20;
var otherEnd = hourScale(format(otherCourse.time.end));
var thisStart = trans[1];
var thisEnd = trans[1] + course.duration;
//var thisEnd = trans[1] + (hourScale(format(course.time.end)) - hourScale(format(course.time.start)));
return ((thisStart < otherStart && thisEnd > otherStart) || (thisStart > otherStart && thisStart < otherEnd));
}
else {
return false;
}
}
else {
return false;
}
}).contains(true).value();
}