This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathimage.js
More file actions
106 lines (89 loc) · 2.4 KB
/
Copy pathimage.js
File metadata and controls
106 lines (89 loc) · 2.4 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
const nrows = 4;
const ncols = 8;
const size = {width: ncols * 100, height: nrows * 100}
const nums = 400;
function createRandomMapping(num){
var ar = [];
while(ar.length < num){
var r = Math.floor(Math.random() * 400);
if(ar.indexOf(r) === -1) ar.push(r);
}
return ar;
}
row.style.width = `${size.width}px`;
row.style.height =`${size.height}px`;
images = []
const arr = createRandomMapping( nrows * ncols);
for (let i = 0; i < arr.length; i++) {
src = `https://raw.githubusercontent.com/manavmahan/image/main/Images/${leadingZeros(arr[i], 3)}.png`
img = {
"type": "image",
"source": src,
"xref": "x",
"yref": "y",
"x": i%ncols,
"y": Math.floor(i/ncols),
"sizex": 0.85,
"sizey": 0.85,
"xanchor": "center",
"yanchor": "middle"
};
images.push(img)
}
const layout = {
autosize: false,
xaxis: {visible: false, range: [-.5, ncols - .5]},
yaxis: {visible: false, range: [-.5, nrows - .5]},
hovermode:'closest',
width: size.width,
height: size.height,
images:images,
margin: {l: 0, r: 0, b: 0, t: 0},
paper_bgcolor: '#00000000',
plot_bgcolor: '#00000000'
};
function range(start, stop, inc){
var ar = []
for (let i = start; i < stop; i += inc) {
ar.push(i);
}
return ar;
}
function getMatrix(nrows, ncols){
var x = [];
var y = [];
range(0, ncols, 1).forEach(x1 => {
range(0, nrows, 1).forEach(y1 =>{
x.push(x1);
y.push(y1);
})
});
return {x: x, y: y, type: 'line', line: {color: 'rgba(0, 0, 0, 1)'}, mode: 'markers', hoverinfo:'none'}
}
function plotData(num){
var src = `https://raw.githubusercontent.com/manavmahan/image/main/data/b_${leadingZeros(num, 3)}.json`;
$.getJSON(src, function(building){
closeLoader();
createScreen();
plotBuilding(building);
plotAnalysis(building);
});
}
var config = {displayModeBar:false, responsive: true};
var plot = Plotly.newPlot('container', [getMatrix(nrows, ncols)], layout, config);
var myPlot = document.getElementById("container");
myPlot.on('plotly_click', function(data){
// screen.style.visibility = "unset";
var x = data.points[0].x;
var y = data.points[0].y;
var num = x + y * ncols;
plotData(arr[num]);
});
myPlot.on('plotly_hover', function(data){
var x = data.points[0].x;
var y = data.points[0].y;
createLoader(- (ncols - x) * 100, (nrows -y - 1) * 100);
})
// myPlot.on('plotly_unhover', function(data){
// closeLoader();
// });