-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_all.js
More file actions
139 lines (133 loc) · 4.38 KB
/
plot_all.js
File metadata and controls
139 lines (133 loc) · 4.38 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
136
137
138
139
d3.csv('https://raw.githubusercontent.com/ErronLLP/plotly/main/data/mds_all.csv', function(err, rows) {
function unpack(rows, key) {
return rows.map(function(row) { return row[key]; });
}
var valence = unpack(rows, 'valence').map(Number); // Ensure valence is numeric
var arousal = unpack(rows, 'arousal').map(Number); // Ensure arousal is numeric
var videoName = unpack(rows, 'videoName'); // Extract video names
var hovertextValence = videoName.map((name, i) => `Video: ${name}<br>Valence: ${valence[i]}`);
var hovertextArousal = videoName.map((name, i) => `Video: ${name}<br>Arousal: ${arousal[i]}`);
// Determine the min and max values for both variables to set a consistent color scale range
var minValue = -5;
var maxValue = 5;
var data = [{
x: unpack(rows, 'MDS1'),
y: unpack(rows, 'MDS2'),
z: unpack(rows, 'MDS3'),
mode: 'markers',
type: 'scatter3d',
marker: {
color: valence,
colorscale: [
[0, '#0571b0'],
[0.25, '#92c5de'],
[0.5, '#f7f7f7'],
[0.75, '#f4a582'],
[1, '#ca0020']
],
cmin: minValue, // Set minimum value
cmax: maxValue, // Set maximum value
size: 5,
symbol: 'circle',
colorbar: {
title: 'Valence',
titleside: 'right',
x: 1,
xpad: 20
}
},
customdata: videoName, // Ensure 'videoName' matches the CSV column name for videos
hovertext: hovertextValence,
hoverinfo: 'text'
}];
var layout = {
autosize: true,
height: 800, // Reduced height
width: 800, // Reduced width
scene: {
aspectratio: {
x: 1,
y: 1,
z: 1
},
camera: {
center: {
x: 0,
y: 0,
z: 0
},
eye: {
x: 1.25,
y: 1.25,
z: 1.25
},
up: {
x: 0,
y: 0,
z: 1
}
},
xaxis: {
type: 'linear',
zeroline: false
},
yaxis: {
type: 'linear',
zeroline: false
},
zaxis: {
type: 'linear',
zeroline: false
}
},
hovermode: 'closest', // Ensure hovermode is set to 'closest'
title: '',
updatemenus: [{
buttons: [
{
args: [{
'marker.color': [valence],
'marker.colorscale': [
[0, '#0571b0'],
[0.25, '#92c5de'],
[0.5, '#f7f7f7'],
[0.75, '#f4a582'],
[1, '#ca0020']
],
'marker.cmin': minValue,
'marker.cmax': maxValue,
'marker.colorbar.title': 'Valence',
'hovertext': [hovertextValence]
}],
label: 'Valence',
method: 'restyle'
},
{
args: [{
'marker.color': [arousal],
'marker.colorscale': [
[0, '#0571b0'],
[0.25, '#92c5de'],
[0.5, '#f7f7f7'],
[0.75, '#f4a582'],
[1, '#ca0020']
],
'marker.cmin': minValue,
'marker.cmax': maxValue,
'marker.colorbar.title': 'Arousal',
'hovertext': [hovertextArousal]
}],
label: 'Arousal',
method: 'restyle'
}
],
direction: 'down',
showactive: true,
x: 0.17,
xanchor: 'left',
y: 0.9,
yanchor: 'top'
}]
};
Plotly.newPlot('myDiv', data, layout);
});