-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-bar.js
More file actions
135 lines (127 loc) · 5 KB
/
progress-bar.js
File metadata and controls
135 lines (127 loc) · 5 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
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
125
126
127
128
129
130
131
132
133
134
135
import { Visualizer } from "./visualizer.js";
export class ProgressBar {
constructor(visualizer, snapshotObject, window, width = 50, height = 20) {
this.container = d3.select('#slider-container')
.style('position', 'relative')
.style('box-sizing', 'border-box')
.attr('width', 300)
.attr('height', 30);
this.visualizer = visualizer;
this.snapshots = snapshotObject.snapshots;
this.selectedMap = snapshotObject.selectedMap;
this.selectedSnapshots = snapshotObject.selectedSnapshots;
console.log('blah2', this.selectedSnapshots);
this.value = 1;
this.maxValue = snapshotObject.snapshots.length;
this.window = window;
this.label = this.container.append('div')
.style('position', 'absolute')
.style('left', '50%')
.style('top', '50%')
.style('transform', 'translate(-50%, -50%)')
.text(`${this.value}/${this.maxValue}`);
this.svg = this.container
.append('svg')
.attr('width', 300)
.attr('height', 30)
.attr('id', 'sliderSvg');
this.progressBarBackground = this.svg.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', 300)
.attr('height', 30)
.attr('fill', 'lightgray');
this.progressBarFill = this.svg.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('height', 30)
.attr('fill', 'steelblue')
.attr('width', 0/*Math.max(0, Math.min(300, clickedX))*/);
this.progressBarBackground.call(d3.drag()
.on('start drag', (event) => {
this.updateProgressBar(event.x);
console.log('val', this.value);
})
).on('click', (event) => {
this.updateProgressBar(event.x);
console.log('val', this.value);
});
this.progressBarFill.call(d3.drag()
.on('start drag', (event) => {
this.updateProgressBar(event.x);
})
).on('click', (event) => {
this.updateProgressBar(event.x);
});
}
updateSnapshotDisplay(snapshotIndex) {
const currentSnapshot = snapshots[snapshotIndex];
if (currentSnapshot && currentSnapshot.line) {
this.window.highlightLine(currentSnapshot.line);
}
}
visualizeValueChange() {
console.log('snapshots3', this.snapshots[this.value - 1].data);
console.log('heyo', this.selectedSnapshots, this.value);
this.visualizer.clear();
console.log(this.selectedSnapshots, this.value -1);
const selectedValueMap = this.getSelectedSnapshot(this.selectedSnapshots[this.value - 1].data)
this.visualizer.visualizeAll(this.snapshots[this.value - 1].data, selectedValueMap);
if (this.snapshots[this.value - 1].data && this.snapshots[this.value - 1].line) {
this.window.highlightLine(this.snapshots[this.value - 1].line);
}
}
getSelectedSnapshot(selectedSnapshot) {
let snapshotMap = new Map();
console.log("selectedSnapshot", selectedSnapshot)
selectedSnapshot.forEach((value) => snapshotMap.set(value.name, value.value));
let valueMap = new Map();
this.selectedMap.forEach((value, key) => {
const selectedList = value;
const valueList = selectedList.map((name) => {
if (snapshotMap.has(name)) {
return snapshotMap.get(name);
}
});
valueMap.set(key, valueList);
});
console.log('valueMap', valueMap);
return valueMap;
}
updateProgressBar(clickedX) {
//console.log('val2', this.value);
//console.log(clickedX, 'click');
const newWidth = Math.max(0, Math.min(300, clickedX));
this.progressBarFill.attr('width', newWidth);
let oldValue = this.value;
this.value = Math.round(newWidth / 300 * (this.maxValue - 1)) + 1;
this.label.text(`${this.value}/${this.maxValue}`);
if (oldValue != this.value) {
this.visualizeValueChange();
}
//console.log("currval", this.value)
}
iterateProgressBar() {
console.log('here4')
console.log('firstVal', this.value);
if (this.value < this.maxValue) {
this.value += 1;
this.visualizeValueChange();
}
console.log(this.value);
this.progressBarFill.attr('width', this.value * (300/this.maxValue));
this.label.text(`${this.value}/${this.maxValue}`);
}
deterateProgressBar() {
console.log('lastVal', this.value);
if (this.value > 1) {
this.value -= 1;
this.visualizeValueChange();
}
this.progressBarFill.attr('width', this.value * (300/this.maxValue));
this.label.text(`${this.value}/${this.maxValue}`);
}
clearContainer() {
this.container.html('');
}
}