people.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query){
  14. queryURL = prepareQueryURL(query);
  15. response = $.ajax({//OGGETTO
  16. url: queryURL,
  17. dataType: "json",
  18. success: function (data){},
  19. error: function (e) {}
  20. });
  21. return response;
  22. }
  23. // Funzioni per raccattare + stringhificare l'output
  24. queryStringOutput = "";
  25. function stringifyResponse(val){
  26. resultArray = val['results']['bindings'];
  27. out = "";
  28. for(i = 0; i < resultArray.length; i++){
  29. out = out + JSON.stringify(resultArray[i])
  30. }
  31. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  32. }
  33. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  34. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  35. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  36. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  37. PREFIX schema: <http://schema.org/> \
  38. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  39. PREFIX person: <http://www.w3.org/ns/person#>"
  40. query = prefixes + " SELECT DISTINCT ?place ?label ?coordinates \
  41. WHERE { \
  42. {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  43. ?event_from crm:P01_has_domain ?pc ; \
  44. rdf:type crm:EL3_Receive_Letter; \
  45. crm:P26_moved_to ?place_from . \
  46. ?place_from rdf:type crm:E53_Place ; \
  47. owl:sameAs ?place . \
  48. ?place rdfs:label ?label ; \
  49. crm:P168_place_is_defined_by ?coordinates . \
  50. } UNION { \
  51. ?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  52. ?event_from crm:P01_has_domain ?pc ; \
  53. rdf:type crm:EL2_Send_Letter; \
  54. crm:P27_moved_from ?place_from . \
  55. ?place_from rdf:type crm:E53_Place ; \
  56. owl:sameAs ?place . \
  57. ?place rdfs:label ?label ; \
  58. crm:P168_place_is_defined_by ?coordinates . \
  59. } \
  60. }"
  61. queryInfo = prefixes + " SELECT DISTINCT ?graph ?label ?identifier ?name ?givenName ?familyName ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation (group_concat(distinct ?relative1 ;separator=', ') as ?relatives) ?qualification ?group \
  62. WHERE { \
  63. VALUES ?uri {<" + thisUrlParams.link + ">} \
  64. GRAPH ?graph {?uri rdfs:label ?label} \
  65. ?uri foaf:name ?name . \
  66. OPTIONAL {?uri crm:P1_is_identified_by ?id . \
  67. ?id rdfs:label ?identifier } \
  68. OPTIONAL {?uri foaf:givenName ?givenName} \
  69. OPTIONAL {?uri foaf:familyName ?familyName} \
  70. OPTIONAL {?uri foaf:gender ?gender} \
  71. OPTIONAL {?uri person:patronymicName ?patronymic } \
  72. OPTIONAL {?uri schema:hasOccupation ?uriOccupation . \
  73. ?uriOccupation rdf:type schema:Occupation; \
  74. rdfs:label ?occupation } \
  75. OPTIONAL {?uri schema:honorificPrefix ?qualification} \
  76. OPTIONAL {?uri schema:relatedTo ?uriRel1 . \
  77. ?uriRel1 rdfs:label ?relative1} \
  78. OPTIONAL {?uri crm:P100i_died_in ?Death . \
  79. ?Death crm:P4_has_time-span ?Death_TS; \
  80. crm:P7_took_place_at ?Place_D .\
  81. ?Death_TS rdfs:label ?Death_Date . \
  82. ?Place_D rdfs:label ?Death_Place } \
  83. OPTIONAL {?uri crm:P98i_was_born ?Birth . \
  84. ?Birth crm:P4_has_time-span ?Birth_TS; \
  85. crm:P7_took_place_at ?Place_B . \
  86. ?Birth_TS rdfs:label ?Birth_Date . \
  87. ?Place_B rdfs:label ?Birth_Place } \
  88. OPTIONAL {?uri crm:P107i_is_current_or_former_member_of ?uriGroup . \
  89. ?uriGroup rdfs:label ?group } \
  90. } \
  91. GROUP BY ?graph ?label ?identifier ?name ?givenName ?familyName ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation ?qualification ?group "
  92. queryLetters = prefixes + " SELECT DISTINCT ?type ?segnatura ?document_uri ?document_name ?time_span ?InfObj \
  93. WHERE {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  94. ?ev_move crm:P01_has_domain ?pc ; \
  95. rdfs:label ?type ; \
  96. rdfs:subClassOf ?event . \
  97. ?document_uri crm:P25i_moved_by ?event ; \
  98. rdfs:label ?document_name . \
  99. ?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  100. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  101. rdfs:label ?segnatura . \
  102. OPTIONAL {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?document_uri crm:P128_carries ?InfObj . \
  103. ?InfObj rdf:type crm:E73_Information_Object} }. \
  104. OPTIONAL {?ev_move crm:P4_has_time-span ?uri_ts . \
  105. ?uri_ts rdfs:label ?time_span . } \
  106. }"
  107. queryNetwork = prefixes + " SELECT DISTINCT COUNT(?event) AS ?count ?uri2 SAMPLE(?label2) AS ?text \
  108. WHERE { \
  109. {?event rdf:type crm:EL1_Exchange_Letters . \
  110. ?event_to rdfs:subClassOf ?event; \
  111. rdf:type crm:EL2_Send_Letter ; \
  112. crm:P01_has_domain ?pc_to . \
  113. ?pc_to crm:P02_has_range ?uri . \
  114. ?uri rdfs:label ?label . \
  115. ?event_from rdfs:subClassOf ?event; \
  116. rdf:type crm:EL3_Receive_Letter; \
  117. crm:P01_has_domain ?pc_from . \
  118. ?pc_from crm:P02_has_range ?uri2 . \
  119. ?uri2 rdfs:label ?label2 . \
  120. FILTER (?uri = <" + thisUrlParams.link + ">) \
  121. } UNION { \
  122. ?event rdf:type crm:EL1_Exchange_Letters . \
  123. ?event_to rdfs:subClassOf ?event; \
  124. rdf:type crm:EL3_Receive_Letter ; \
  125. crm:P01_has_domain ?pc_from . \
  126. ?pc_from crm:P02_has_range ?uri . \
  127. ?uri rdfs:label ?label . \
  128. ?event_from rdfs:subClassOf ?event; \
  129. rdf:type crm:EL2_Send_Letter; \
  130. crm:P01_has_domain ?pc_to . \
  131. ?pc_to crm:P02_has_range ?uri2 . \
  132. ?uri2 rdfs:label ?label2 . \
  133. FILTER (?uri = <" + thisUrlParams.link + ">) \
  134. } \
  135. } ORDER BY DESC (?count)"
  136. queryURL = prepareQueryURL(query);
  137. queryNet = prepareQueryURL(queryNetwork);
  138. query = prepareQueryURL(queryInfo);
  139. queryEx = prepareQueryURL(queryLetters);
  140. response = $.ajax({
  141. url: query,
  142. dataType: "json",
  143. success: function (data){
  144. handle_data(data);
  145. },
  146. error: function (e) {}
  147. });
  148. response = $.ajax({
  149. url: queryURL,
  150. dataType: "json",
  151. success: function (data){
  152. handle_map(data);
  153. },
  154. error: function (e) {}
  155. });
  156. responseNet = $.ajax({
  157. url: queryNet,
  158. dataType: "json",
  159. success: function (data){
  160. handle_network(data);
  161. },
  162. error: function (e) {}
  163. });
  164. responseLet = $.ajax({
  165. url: queryEx,
  166. dataType: "json",
  167. success: function (data){
  168. handle_Letters(data);
  169. },
  170. error: function (e) {}
  171. });
  172. function handle_data(json) {
  173. console.log(json['results']['bindings']);
  174. var graph = "";
  175. var label = "";
  176. if ("givenName" in json.results.bindings) {
  177. givenName = value['givenName']['value'];
  178. alert(givenName);
  179. }
  180. $.each(
  181. json['results']['bindings'],
  182. function (index, value) {
  183. var graph = value['graph']['value'];
  184. var label = value['label']['value'];
  185. var name = value['name']['value'];
  186. var givenName = "";
  187. var familyName = "";
  188. var gender = "";
  189. var patronymic = "";
  190. var occupation = "";
  191. var relative = "";
  192. var identifier = "";
  193. var birth_date = "";
  194. var birth_place = "";
  195. var death_date = "";
  196. var death_place = "";
  197. var qualification = "";
  198. var group = "";
  199. if (value.hasOwnProperty('givenName')) {
  200. $("#givenName").css("display", "flex");
  201. givenName = value['givenName']['value'];
  202. }
  203. if (value.hasOwnProperty('familyName')) {
  204. $("#familyName").css("display", "flex");
  205. familyName = value['familyName']['value'].toLowerCase();
  206. familyName = familyName.charAt(0).toUpperCase() + familyName.slice(1)
  207. }
  208. if (value.hasOwnProperty('gender')) {
  209. $("#gender").css("display", "flex");
  210. gender = value['gender']['value'];
  211. }
  212. if (value.hasOwnProperty('patronymic')) {
  213. $("#patronymic").css("display", "flex");
  214. patronymic = value['patronymic']['value'];
  215. }
  216. if (value.hasOwnProperty('occupation')) {
  217. $("#occupation").css("display", "flex");
  218. occupation = value['occupation']['value'];
  219. }
  220. if (value.hasOwnProperty('relatives')) {
  221. if (value['relatives']['value'] != "") {
  222. relative = value['relatives']['value'];
  223. }
  224. }
  225. if (value.hasOwnProperty('qualification')) {
  226. $("#honorific").css("display", "flex");
  227. qualification = value['qualification']['value'];
  228. }
  229. if (value.hasOwnProperty('Birth_Date')) {
  230. $("#BirthDate").css("display", "flex");
  231. birth_date = value['Birth_Date']['value'];
  232. }
  233. if (value.hasOwnProperty('Birth_Place')) {
  234. $("#BirthPlace").css("display", "flex");
  235. birth_place = value['Birth_Place']['value'];
  236. }
  237. if (value.hasOwnProperty('Death_Date')) {
  238. $("#DeathDate").css("display", "flex");
  239. death_date = value['Death_Date']['value'];
  240. }
  241. if (value.hasOwnProperty('Death_Place')) {
  242. $("#DeathPlace").css("display", "flex");
  243. death_place = value['Death_Place']['value'];
  244. }
  245. if (value.hasOwnProperty('group')) {
  246. $("#groups").css("display", "flex");
  247. group = value['group']['value'];
  248. }
  249. var dataset = get_dataset_name(graph);
  250. var second_name = patronymic + " " + relative;
  251. var first_name = givenName + " " + second_name + " " + familyName;
  252. document.getElementById("grafo").innerHTML = dataset;
  253. document.getElementById("nome_persona").innerHTML = first_name;
  254. document.getElementById("nome").innerHTML = name;
  255. document.getElementById("genere").innerHTML = gender;
  256. document.getElementById("nome_proprio").innerHTML = givenName;
  257. document.getElementById("nome_famiglia").innerHTML = familyName;
  258. document.getElementById("patronimico").innerHTML = second_name;
  259. document.getElementById("qualifica").innerHTML = qualification;
  260. document.getElementById("occupazione").innerHTML = occupation;
  261. document.getElementById("data_nascita").innerHTML = birth_date;
  262. document.getElementById("data_morte").innerHTML = death_date;
  263. document.getElementById("luogo_nascita").innerHTML = birth_place;
  264. document.getElementById("luogo_morte").innerHTML = death_place;
  265. document.getElementById("gruppi_appartenenza").innerHTML = group;
  266. const collection = document.getElementsByClassName("PN");
  267. for (var i=0; i<collection.length; i++) {
  268. collection[i].innerHTML = first_name;
  269. }
  270. });
  271. }
  272. function get_dataset_name(graph) {
  273. var string = "Scheda Onomastica";
  274. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica") {
  275. string = string + " / Onomastica Datini";
  276. }
  277. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/authors"){
  278. string = string + " / Artisti";
  279. }
  280. else {
  281. string = string;
  282. }
  283. return (string);
  284. }
  285. function handle_Letters(json) {
  286. console.log(json);
  287. const send = [];
  288. const receive = [];
  289. var i=0;
  290. var j=0;
  291. $.each(
  292. json['results']['bindings'],
  293. function (index, value) {
  294. type = value['type']['value'];
  295. uri = value['document_uri']['value'];
  296. title = value['document_name']['value'];
  297. segnatura = value['segnatura']['value'];
  298. var data = "";
  299. var InfObj = "";
  300. if (value.hasOwnProperty('time_span')) {
  301. data = value['time_span']['value'];
  302. }
  303. if (value.hasOwnProperty('InfObj')) {
  304. InfObj = value['InfObj']['value'];
  305. }
  306. if (type == "Invio") {
  307. send.push([uri, title, segnatura, data, InfObj]);
  308. i++;
  309. } else {
  310. receive.push([uri, title, segnatura, data, InfObj]);
  311. j++;
  312. }
  313. });
  314. var Send_Letters = "";
  315. var Receive_Letters = "";
  316. //POPULATE SEND LETTERS BOX
  317. for (var i=0; i<send.length; i++) {
  318. var letter = '<a href=' + send[i][0] + ' target="_blank">' + send[i][1] + '</a>';
  319. var infObject_button = "";
  320. if (send[i][2] != "") {
  321. letter = letter + "<br />Segnatura: " + send[i][2];
  322. }
  323. if (send[i][3] != "") {
  324. letter = letter + "<br />Data invio: " + send[i][3];
  325. }
  326. if (send[i][4] != "") {
  327. infObject_button += '<button type="button" id="' + send[i][4] +
  328. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  329. } else {
  330. infObject_button += '<button type="button" id="' + send[i][0] +
  331. '" class="object btn btn-default" alt="oggetto" title="' + send[i][1] +
  332. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  333. }
  334. Send_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  335. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  336. '<button type="button" id="' + send[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  337. '<button type="button" id="' + send[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  338. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + send[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  339. }
  340. //POPULATE RECEIVE LETTERS BOX
  341. for (var i=0; i<receive.length; i++) {
  342. var letter = '<a href=' + receive[i][0] + ' target="_blank">' + receive[i][1] + '</a>';
  343. var infObject_button = "";
  344. if (receive[i][2] != "") {
  345. letter = letter + "<br />Segnatura: " + receive[i][2];
  346. }
  347. if (receive[i][3] != "") {
  348. letter = letter + "<br />Data ricezione: " + receive[i][3];
  349. }
  350. if (receive[i][4] != "") {
  351. infObject_button += '<button type="button" id="' + receive[i][4] +
  352. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  353. } else {
  354. infObject_button += '<button type="button" id="' + receive[i][0] +
  355. '" class="object btn btn-default" alt="oggetto" title="' + receive[i][1] +
  356. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  357. }
  358. Receive_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  359. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  360. '<button type="button" id="' + receive[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  361. '<button type="button" id="' + receive[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  362. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + receive[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  363. }
  364. document.getElementById("l_send").innerHTML = send.length;
  365. document.getElementById("l_receive").innerHTML = receive.length;
  366. document.getElementById("letters_send").innerHTML = Send_Letters;
  367. document.getElementById("letters_receive").innerHTML = Receive_Letters;
  368. if (i==0) {
  369. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  370. document.getElementById("letters_send").innerHTML = messaggio;
  371. }
  372. if (j==0) {
  373. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  374. document.getElementById("letters_receive").innerHTML = messaggio;
  375. }
  376. }
  377. function handle_map(json) {
  378. console.log(json);
  379. const locations = [];
  380. const place_names = [];
  381. var lat = 0;
  382. var long = 0;
  383. var i=0;
  384. var myPlaces = "";
  385. $.each(
  386. json['results']['bindings'],
  387. function (index, value) {
  388. const loc = []
  389. var uri = value['place']['value'];
  390. var label = value['label']['value'];
  391. var coord = value['coordinates']['value'];
  392. const coordinates = coord.split(", ");
  393. loc.push(label);
  394. myPlaces += "<div class='item-place-person'><div class='clickPlace item-place-person-label' data-point='"+ coordinates + "'>" + label + "</div><div class='item-place-person-action'><div class='luogo' id='" +
  395. uri + "'><i class='far fa-map' style='cursor:pointer'></i></div></div></div>";
  396. loc.push(coordinates[0]);
  397. lat += parseInt(coordinates[0]);
  398. loc.push(coordinates[1]);
  399. long += parseInt(coordinates[1].replace(/^(\.)/,"0.").replace("-.", "-0."));
  400. locations.push(loc);
  401. i++;
  402. });
  403. var latitude = lat/i;
  404. var longitude = long/i;
  405. document.getElementById("list_places_person").innerHTML = myPlaces;
  406. var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
  407. cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade, Points &copy 2012 LINZ',
  408. cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
  409. latlng = new L.LatLng(latitude, longitude);
  410. var map = new L.Map('map', {center: latlng, zoom: 5, layers: [cloudmade]});
  411. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  412. var markers = new L.MarkerClusterGroup();
  413. var markerList = [];
  414. var geo = new L.tileLayer(
  415. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  416. attribution: '&copy; ' + mapLink + ' Contributors',
  417. maxZoom: 18,
  418. }).addTo(map);
  419. function populate() {
  420. for (var i = 0; i < locations.length; i++) {
  421. var a = locations[i];
  422. var title = a[0];
  423. var marker = new L.Marker(new L.LatLng(a[1], a[2]), { title: title });
  424. marker.bindPopup(title);
  425. markers.addLayer(marker);
  426. markerList.push(marker);
  427. }
  428. }
  429. populate();
  430. map.addLayer(markers);
  431. $('.clickPlace').on('click', function(){
  432. // parse lat and lng from the divs data attribute
  433. var latlng = $(this).data().point.split(',');
  434. var lat = latlng[0];
  435. var lng = latlng[1];
  436. var zoom = 10;
  437. // set the view
  438. map.setView([lat, lng], zoom);
  439. });
  440. }
  441. function handle_network(json) {
  442. console.log(json);
  443. const words = [];
  444. const tempArray = [];
  445. var listwords = "";
  446. var ArrayNames = "";
  447. var temp = 0;
  448. var sum = 0;
  449. var i=0;
  450. var j=0;
  451. $.each(
  452. json['results']['bindings'],
  453. function (index, value) {
  454. text = value['text']['value'];
  455. link = value['uri2']['value'];
  456. num = parseInt(value['count']['value']);
  457. /*count = 0;
  458. if ((num - temp) > 50) {
  459. count = temp + 12;
  460. } else {
  461. count = num;
  462. }
  463. words.push([text, count]);
  464. temp = count;
  465. sum += temp;*/
  466. tempArray.push([text, num]);
  467. ArrayNames += "<div class='item-place-person'><div class='item-place-person-label'>" +
  468. text + "<br /><span class='num_occ'>[Co-occorrenze: " + num + "]</span></div><div class='item-place-person-action'><div><a target='_blank' href='" +
  469. link + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div><div class='persona' id='" +
  470. link + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div></div>";
  471. });
  472. if (tempArray.length < 8) {
  473. for (var k=0; k<tempArray.length; k++) {
  474. text = tempArray[k][0];
  475. count = tempArray[k][1] + 36;
  476. words.push([text, count]);
  477. }
  478. } else {
  479. for (var k=tempArray.length-1; k>=0; k--) {
  480. text = tempArray[k][0];
  481. num = tempArray[k][1];
  482. count = 0;
  483. if ((num - temp) > 50) {
  484. count = temp + 12;
  485. } else {
  486. count = num;
  487. }
  488. words.push([text, count]);
  489. temp = count;
  490. sum += temp;
  491. }
  492. }
  493. document.getElementById("list_person_network").innerHTML = ArrayNames;
  494. /*var tot = parseInt(words[0][1]);*/
  495. for (var i in words) {
  496. var text = words[i][0]
  497. var count = words[i][1];
  498. listwords += '{ "word": \"' + text + '\", "size": \"' + count + '\"},';
  499. }
  500. let listL = ('[' + listwords + ']').replace(',]', ']');
  501. const links = JSON.parse(listL);
  502. console.log(links);
  503. // List of words
  504. var myWords = links;
  505. // set the dimensions and margins of the graph
  506. var margin = {top: 10, right: 10, bottom: 10, left: 10},
  507. width = 850 - margin.left - margin.right,
  508. height = 500 - margin.top - margin.bottom;
  509. // append the svg object to the body of the page
  510. var svg = d3.select("#myWordCloud").append("svg")
  511. .attr("width", width + margin.left + margin.right)
  512. .attr("height", height + margin.top + margin.bottom)
  513. .append("g")
  514. .attr("transform",
  515. "translate(" + (width/2-50) + "," + (height/2+20) + ")");
  516. // Constructs a new cloud layout instance. It run an algorithm to find the position of words that suits your requirements
  517. // Wordcloud features that are different from one word to the other must be here
  518. var layout = d3.layout.cloud()
  519. .size([width, height])
  520. .words(myWords.map(function(d) { return {text: d.word, size:d.size/2}; }))
  521. .padding(5) //space between words
  522. .rotate(function() { return ~~(Math.random() * 2);})
  523. .fontSize(function(d) { return d.size + 6; }) // font size of words
  524. .on("end", draw);
  525. layout.start();
  526. // This function takes the output of 'layout' above and draw the words
  527. // Wordcloud features that are THE SAME from one word to the other can be here
  528. function draw(words) {
  529. var cloud = svg.selectAll("g text")
  530. .data(words, function(d) { return d.text; })
  531. //Entering words
  532. cloud.enter()
  533. .append("text")
  534. .style("font-family", "Impact")
  535. .attr("text-anchor", "middle")
  536. .attr('font-size', 1)
  537. .text(function(d) { return d.text; });
  538. //Entering and existing words
  539. cloud
  540. .transition()
  541. .duration(600)
  542. .style("font-size", function(d) { return d.size + "px"; })
  543. .attr("transform", function(d) {
  544. return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
  545. })
  546. .style("fill-opacity", 1);
  547. //Exiting words
  548. cloud.exit()
  549. .transition()
  550. .duration(200)
  551. .style('fill-opacity', 1e-6)
  552. .attr('font-size', 1)
  553. .remove();
  554. }
  555. }
  556. $(document).on("click", ".luogo", function (ev) {
  557. var link = this.id;
  558. //alert(nome_autore);
  559. //$('#myModal').text("");
  560. window.open("Luogo.html?link="+this.id);
  561. });
  562. $(document).on("click", ".persona", function (ev) {
  563. var link = this.id;
  564. //alert(nome_autore);
  565. //$('#myModal').text("");
  566. window.open("Persona.html?link="+this.id);
  567. });
  568. $(document).on("click", ".lettera", function (ev) {
  569. var link = this.id;
  570. //alert(nome_autore);
  571. //$('#myModal').text("");
  572. window.open("lettera.html?link="+this.id);
  573. });
  574. $(document).on("click", ".object", function (ev) {
  575. var link = this.id;
  576. //alert(nome_autore);
  577. //$('#myModal').text("");
  578. window.open("object.html?link="+this.id);
  579. });
  580. $(document).on("click", ".hyp", function (ev) {
  581. var link = this.id;
  582. $("#myModal").empty();
  583. $("#myModal").css("display", "block");
  584. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  585. link + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  586. });
  587. $(document).on("click", ".close", function (ev) {
  588. var link = this.id;
  589. //alert(nome_autore);
  590. //$('#myModal').text("");
  591. $("#myModal").css("display", "none");
  592. });
  593. $(document).on("click", ".back", function (ev) {
  594. $("#myTab").css("display", "none");
  595. });
  596. $(document).on("click", ".cit", function (ev) {
  597. var author ="RESTORE. smart access to digital heritage and memory"
  598. var year = new Date().getFullYear()
  599. var today = new Date();
  600. var dd = String(today.getDate()).padStart(2, '0');
  601. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  602. var yyyy = today.getFullYear();
  603. today = dd + '/' + mm + '/' + yyyy;
  604. var link = this.id;
  605. //alert(nome_autore);
  606. //$('#myModal').text("");
  607. $("#myModal").empty();
  608. $("#myModal").css("display", "block");
  609. $('#myModal').append("<div class='modal-content'><span class='close'>&times;</span><div id='myInput'>" +
  610. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  611. });
  612. function copyToClipboard(text) {
  613. var sampleTextarea = document.createElement("textarea");
  614. document.body.appendChild(sampleTextarea);
  615. sampleTextarea.value = text; //save main text in it
  616. sampleTextarea.select(); //select textarea contenrs
  617. document.execCommand("copy");
  618. document.body.removeChild(sampleTextarea);
  619. }
  620. function myFunction(){
  621. var copy = document.getElementById("myInput");
  622. copyText = copy.textContent;
  623. copyToClipboard(copyText);
  624. //copyToClipboard(copyText.value);
  625. }