Newer
Older
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
// Copyright 2017 Istituto Nazionale di Fisica Nucleare
//
// Licensed under the EUPL
import * as $ from "jquery";
import G = require("./globals");
import * as fs from "./fs";
import * as img from "./draw";
//INIZIO DELLO SCRIPT
$(document).ready(function ()
{
// skip the tooltip for the moment; it generates an apparently fatal error
// $('[data-toggle="tooltip"]').tooltip();
//creazione dell'albero e gestione barre laterali
setImportFile();
compressingSidenav();
// enable drag&drop
/* let droppableArea: any = document.querySelector('.droppable');
makeDroppable(droppableArea, callback);
*/
G.zPixel1 = { x: 0, y: 0 };
G.zPixel2 = { x: 0, y: 0 };
});
//funzione che definisce tutti gli elementi responsabili dell'apertura di un file.
//Sono definiti quindi l'albero e il bottone per l'importazione da locale
export function setImportFile()
{
console.log("here");
// genero e leggo il contenuto della directory "filesystem"
// comment out waiting to properly address the request
/* let xmlDoc: Document;
let xmlListingFile: any = new XMLHttpRequest();
xmlListingFile.open("PROPFIND", "CHNET/", false);
xmlListingFile.setRequestHeader("Depth", "infinity");
xmlListingFile.onreadystatechange = function ()
{
if (xmlListingFile.readyState === 4) {
if (xmlListingFile.status === 207) {
let parser = new DOMParser();
xmlDoc = parser.parseFromString(xmlListingFile.responseText, "text/xml");
}
}
}
xmlListingFile.send(null);
*/
/*
//ora genero l'albero e definisco l'evento in caso di selezione di un nodo
$('#FileTreeview').treeview({ data: generateTree(xmlDoc) });
$('#FileTreeview').on('nodeSelected', function (e, node)
{
if (node['url'] != undefined) {
$("#load-spinner").css("display", "inline");
openFileFromServer(node['url']);
}
});
*/
// import a local file
let fileInputButton: any = document.getElementById('myImport');
fileInputButton.onchange = function ()
{
$("#load-spinner").css("display", "inline");
let file: File = fileInputButton.files[0];
let readerObject = new FileReader();
readerObject.onload = function ()
{
let content: string = readerObject.result;
let image = fs.readImage(content);
console.log(image.width);
img.drawImg(image, { x: 0, y: 0 }, { x: image.width - 1, y: image.height - 1 }, 0, G.channelDepth);
img.drawChart(image, { x: 0, y: 0 }, { x: image.width - 1, y: image.height - 1 }, 0, G.channelDepth);
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// install callbacks for the canvas and chart?
}
readerObject.readAsText(file);
}
}
//funzione per la compressione della sidenav sx
function compressingSidenav()
{
let fsLabel = $('.sidebar-label');
let isClosedfs = false;
fsLabel.click(function () { fsLabel_cross(); });
function fsLabel_cross()
{
if (isClosedfs == true) {
isClosedfs = false;
$('.w3-bar-block').css('width', "65px");
$('.text-sidenav').css('display', 'none');
$('#collapse-symbol').attr('title', 'Open Sidebar');
$("#collapse-symbol").removeClass("fa-angle-double-left");
$("#collapse-symbol").addClass("fa-angle-double-right");
} else {
isClosedfs = true;
$('.w3-bar-block').css('width', "200px");
$('.text-sidenav').css('display', 'inline');
$('#collapse-symbol').attr('title', 'Close Sidebar');
$("#collapse-symbol").removeClass("fa-angle-double-right");
$("#collapse-symbol").addClass("fa-angle-double-left");
}
}
}
//funzione che definisce l'area su cui si può eseguire il drag&drop
function makeDroppable(droppableArea, callback)
{
//creo l'elemento "input type file" non visibile e lo aggiungo a "droppableArea"
let input: any = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('multiple', true);
input.style.display = 'none';
droppableArea.appendChild(input);
//questo evento è chiamato quando i file sono trascinati ma non ancora lasciati
droppableArea.addEventListener('dragover', function (e)
{
e.preventDefault(); //impediamo l'apertura del file
e.stopPropagation();
e.dataTransfer.dropEffect = 'copy';
droppableArea.classList.add('dragover');
});
//l'evento è chiamato quando un file lascia la zona predefinita per il drag&drop
droppableArea.addEventListener('dragleave', function (e)
{
e.preventDefault();
e.stopPropagation();
droppableArea.classList.remove('dragover');
});
//questo evento si innesca quando il drop è effettivamente avvenuto
droppableArea.addEventListener('drop', function (e)
{
e.preventDefault();
e.stopPropagation();
droppableArea.classList.remove('dragover');
callback.call(null, e.dataTransfer.files);
});
}
//funzione chiamata in caso di drag&drop responsabile dell'apertura del file droppato,
//della sua lettura e del passaggio del suo contenuto alla funzione readData()
function callback(files)
{
$("#load-spinner").css("display", "inline");
let file: File = files[files.length - 1];
console.log("Try to open " + file.name + " ...");
let readerObject = new FileReader();
let content: string = readerObject.result;
fs.readImage(content);
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
}
//la funzione findPosition definisce la posizione del cursore del mouse
//relativa al canvas nel momento in cui avviene l'evento passato in input
function findPosition(event: any, pixel: G.coordinates)
{
let scrollTOP: number = (document.documentElement.scrollTop) ?
document.documentElement.scrollTop : document.body.scrollTop;
let scrollLEFT: number = (document.documentElement.scrollLeft) ?
document.documentElement.scrollLeft : document.body.scrollLeft;
let allX: number = event.clientX + scrollLEFT;
let allY: number = event.clientY + scrollTOP;
let elParent: any = document.getElementById('myCanvas');
let objX: number = 0, objY: number = 0;
while (elParent) {
objX += elParent.offsetLeft;
objY += elParent.offsetTop;
elParent = elParent.offsetParent;
}
pixel.x = Math.floor((allX - objX - 1) / G.pixelDim) + G.newOrigin.x;
pixel.y = Math.floor((allY - objY - 1) / G.pixelDim) + G.newOrigin.y;
}
//la funzione findPosDown memorizza la posizione del pixel cliccato
function findPosDown(event: any)
{
findPosition(event, G.zPixel1);
}
//la funzione findPosUp memorizza la posizione del pixel quando il mouse viene
//rilasciato, ordina le coordinate, aggiorna l'origine e la pagina.
function findPosUp(event: any)
{
findPosition(event, G.zPixel2);
let tmp: number;
if (G.zPixel1.x > G.zPixel2.x) {
tmp = G.zPixel1.x;
G.zPixel1.x = G.zPixel2.x;
G.zPixel2.x = tmp;
}
if (G.zPixel1.y > G.zPixel2.y) {
tmp = G.zPixel1.y;
G.zPixel1.y = G.zPixel2.y;
G.zPixel2.y = tmp;
}
//se è stato cliccato un punto disegno il grafico, altrimenti disegno anche il
//canvas e aggiorno l'origine
//alert(G.zPixel1.xp + ", " + G.zPixel1.yp + " - " + G.zPixel2.xp + ", " + G.zPixel2.yp);
if (G.zPixel1.x != G.zPixel2.x || G.zPixel1.y != G.zPixel2.y) {
G.newOrigin = { x: G.zPixel1.x, y: G.zPixel1.y };
// comment out waiting to manage correctly callbacks
// img.drawImg(image, G.zPixel1, G.zPixel2, G.globalxMinRange, G.globalxMaxRange);
}
// comment out waiting to manage correctly callbacks
/* img.drawChart(image, G.zPixel1, G.zPixel2, G.globalxMinRange, G.globalxMaxRange);
*/
}