-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinteractions.js
124 lines (110 loc) · 4.01 KB
/
interactions.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* Dashboard interactions
*
* Copyright Robert Monfera
*/
function setTableSortOrder(sortVariable) {
//if(d3.event) d3.event.stopPropagation()
var sortSettings = dashboardSettings.table.sort
if(sortSettings.lastTimedSort) {
window.clearTimeout(sortSettings.lastTimedSort)
sortSettings.lastTimedSort = null
}
if(sortVariable && sortVariable !== sortSettings.sortVariable) { // fixme this doesn't detect identical sortings based on template based variables
sortSettings.sortVariable = sortVariable
render()
sortSettings.lastSortTime = new Date()
}
}
function setDelayedTableSortOrder(variable, d) {
d.delayed = window.setTimeout(function() {
setTableSortOrder(variable)
}, 300)
}
function setGroupHeaderTableSortOrder(className, d) {
var variable = findWhere('groupAlias', className)(dashboardSettings.variables)
setDelayedTableSortOrder(variable, d)
}
function setPetiteHeaderTableSortOrder(headerName, d) {
var variable = findWhere('petiteHeaderAlias', headerName)(dashboardSettings.variables)
setDelayedTableSortOrder(variable, d)
}
function resetTableSortOrder(d) {
setTableSortOrder(defaultSortVariable)
if(d.delayed) {
window.clearTimeout(d.delayed)
delete d.delayed
}
}
function setGroupLegendTableSortOrder(legendName) {
var variable = findWhere('legendAlias', legendName)(dashboardSettings.variables)
setTableSortOrder(variable)
}
function rowMouseDown(d) {
var e = d3.event
var studentSelection = dashboardSettings.table.studentSelection
if(!studentSelection.brushable) {
studentSelection.brushable = true
}
var cond = studentSelection.selectedStudents[d.key]
studentSelection.currentSelectedStudents = {}
if(cond) {
studentSelection.selectedStudents = {}
cancelSelection()
} else {
studentSelection.currentSelectedStudents.from = d.key
studentSelection.currentSelectedStudents.to = d.key
studentSelection.brushInProgress = true
if(!(e.metaKey || e.ctrlKey) ) {
studentSelection.selectedStudents = {}
}
studentSelection.selectedStudents[d.key] = true
render()
}
}
function rowMouseOver(d) {
var studentSelection = dashboardSettings.table.studentSelection
var selectedStudents = studentSelection.selectedStudents
var currentSelectedStudents = studentSelection.currentSelectedStudents
if(!studentSelection.brushable) {
return
}
if(!studentSelection.brushInProgress) {
if(Object.keys(selectedStudents).length > 0) {
return;
}
currentSelectedStudents.from = d.key
currentSelectedStudents.to = d.key
}
currentSelectedStudents.to = d.key
var names = dashboardData['Student Data'].map(key)
var indices = [studentSelection.currentSelectedStudents.from, studentSelection.currentSelectedStudents.to].map(function(name) {return names.indexOf(name)})
var extent = d3.extent(indices)
Object.keys(selectedStudents).forEach(function(key) {if(selectedStudents[key] === 'maybe') delete selectedStudents[key]})
for(var i = extent[0]; i <= extent[1]; i++) {studentSelection.selectedStudents[names[i]] = 'maybe'}
render()
}
function rowMouseUp() {
var studentSelection = dashboardSettings.table.studentSelection
var selectedStudents = studentSelection.selectedStudents
Object.keys(selectedStudents).forEach(function(key) {selectedStudents[key] = true})
if(!studentSelection.brushable) {
return
}
if(studentSelection.brushInProgress) {
studentSelection.brushInProgress = false
}
}
function cancelSelection() {
var studentSelection = dashboardSettings.table.studentSelection
d3.event.preventDefault(); d3.event.stopPropagation();
studentSelection.selectedStudents = {}
studentSelection.brushInProgress = false
studentSelection.brushable = false
render()
}
var rowInteractions = {
mousedown: rowMouseDown,
mouseover: rowMouseOver,
mouseup: rowMouseUp
}