map.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. query = prefixes + " SELECT DISTINCT ?graph ?name_place ?coordinates {\
  38. GRAPH ?graph {<" + thisUrlParams.link + "> crm:P168_place_is_defined_by ?coordinates;\
  39. rdfs:label ?name_place .\
  40. }\
  41. }"
  42. queryRiferimenti = prefixes + " SELECT DISTINCT ?references {\
  43. <" + thisUrlParams.link + "> owl:sameAs ?references\
  44. }"
  45. queryToponimi = prefixes + " SELECT DISTINCT ?toponimi {\
  46. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri_toponym .\
  47. ?uri_toponym rdfs:label ?toponimi\
  48. }"
  49. queryRicezione = prefixes + " SELECT DISTINCT ?object ?label {\
  50. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  51. ?event_to crm:P26_moved_to ?place ;\
  52. rdf:type crm:EL3_Receive_Letter ;\
  53. rdfs:subClassOf ?event .\
  54. ?object crm:P25i_moved_by ?event ; \
  55. rdfs:label ?label .\
  56. } "
  57. queryInvio = prefixes + " SELECT DISTINCT ?object ?label {\
  58. <" + thisUrlParams.link + "> owl:sameAs ?place .\
  59. ?event_to crm:P27_moved_from ?place ;\
  60. rdf:type crm:EL2_Send_Letter ;\
  61. rdfs:subClassOf ?event .\
  62. ?object crm:P25i_moved_by ?event ; \
  63. rdfs:label ?label .\
  64. }"
  65. queryCitazione = prefixes + " SELECT DISTINCT ?object ?label\
  66. {<" + thisUrlParams.link + "> crm:P1_is_identified_by ?toponym .\
  67. ?object crm:P67_refers_to ?toponym ;\
  68. rdfs:label ?label\
  69. }"
  70. queryPersone = prefixes + " SELECT DISTINCT ?range ?label \
  71. WHERE{ \
  72. {?place owl:sameAs <" + thisUrlParams.link + "> .\
  73. ?event_to crm:P26_moved_to ?place ;\
  74. rdf:type crm:EL3_Receive_Letter ;\
  75. crm:P01_has_domain ?domain .\
  76. ?domain crm:P02_has_range ?range .\
  77. ?range rdfs:label ?label .\
  78. } UNION {\
  79. ?place owl:sameAs <" + thisUrlParams.link + "> .\
  80. ?event_to crm:P27_moved_from ?place ;\
  81. rdf:type crm:EL2_Send_Letter ;\
  82. crm:P01_has_domain ?domain .\
  83. ?domain crm:P02_has_range ?range .\
  84. ?range rdfs:label ?label .\
  85. }\
  86. }"
  87. queryCount = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  88. WHERE{ \
  89. ?place_to owl:sameAs <" + thisUrlParams.link + "> . \
  90. ?event_to crm:P26_moved_to ?place_to ; \
  91. rdf:type crm:EL3_Receive_Letter ; \
  92. rdfs:subClassOf ?event . \
  93. ?event_from rdfs:subClassOf ?event ; \
  94. rdf:type crm:EL2_Send_Letter ; \
  95. crm:P27_moved_from ?place . \
  96. ?place rdfs:label ?label \
  97. } \
  98. ORDER BY DESC (?Count)"
  99. queryCount2 = prefixes + " SELECT ?place ?label COUNT(?label) AS ?Count \
  100. WHERE{ \
  101. ?place_from owl:sameAs <" + thisUrlParams.link + "> . \
  102. ?event_from crm:P27_moved_from ?place_from ; \
  103. rdf:type crm:EL2_Send_Letter ; \
  104. rdfs:subClassOf ?event . \
  105. ?event_to rdfs:subClassOf ?event ; \
  106. rdf:type crm:EL2_Send_Letter ; \
  107. crm:P27_moved_from ?place . \
  108. ?place rdfs:label ?label . \
  109. } \
  110. ORDER BY DESC (?Count) "
  111. queryCountLuogo = prefixes + " SELECT DISTINCT COUNT(?luogo) AS ?occorrenze \
  112. WHERE { \
  113. ?document crm:P67_refers_to ?luogo . \
  114. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?luogo . \
  115. } "
  116. queryCountDataset = prefixes + " SELECT DISTINCT COUNT(?uri) AS ?documenti \
  117. WHERE {\
  118. ?uri crm:P2_has_type 'Testo Lemmatizzato' } "
  119. querySupportCount = prefixes + " SELECT ?uri_antroponym ?antroponimo COUNT(DISTINCT ?document) AS ?occorrenze COUNT(DISTINCT ?letter) AS ?count \
  120. WHERE { \
  121. ?document crm:P67_refers_to ?uri . \
  122. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri . \
  123. ?document crm:P67_refers_to ?uri_antroponym . \
  124. ?uri_antroponym crm:P2_has_type 'Antroponimo'; \
  125. rdfs:label ?antroponimo . \
  126. ?letter crm:P67_refers_to ?uri_antroponym . \
  127. } \
  128. GROUP BY ?uri_antroponym ?antroponimo \
  129. ORDER BY DESC (?occorrenze) "
  130. querySupportLemma = prefixes + " SELECT ?uri_lemma ?lemma COUNT(DISTINCT ?document) AS ?occorrenze COUNT(DISTINCT ?letter) AS ?count \
  131. WHERE { \
  132. ?document crm:P67_refers_to ?uri . \
  133. <" + thisUrlParams.link + "> crm:P1_is_identified_by ?uri . \
  134. ?document crm:P67_refers_to ?uri_object . \
  135. ?uri_object crm:P128_carries ?uri_lemma . \
  136. ?uri_lemma rdf:type ?uri_type; \
  137. rdfs:label ?lemma . \
  138. ?uri_type rdfs:label 'Lemma' . \
  139. ?letter crm:P67_refers_to ?uri_object . \
  140. } \
  141. GROUP BY ?uri_lemma ?lemma \
  142. ORDER BY DESC (?occorrenze) "
  143. /*
  144. queryCountAntroponym = SELECT DISTINCT ?antroponimi COUNT(?uri) AS ?occorrenze
  145. WHERE {
  146. ?document crm:P67_refers_to ?uri .
  147. ?uri crm:P2_has_type "Antroponimo" ;
  148. rdfs:label ?antroponimi .
  149. }
  150. GROUP BY ?antroponimi ?uri
  151. ORDER BY DESC (?occorrenze)
  152. queryCountLuogo = SELECT DISTINCT COUNT(?luogo) AS ?occorrenze
  153. WHERE {
  154. ?document crm:P67_refers_to ?luogo .
  155. <http://dev.restore.ovi.cnr.it/vocabularies/places/161> crm:P1_is_identified_by ?luogo .
  156. }
  157. queryCountDataset = SELECT DISTINCT COUNT(?uri) AS ?documenti
  158. WHERE {
  159. ?uri crm:P2_has_type "Testo Lemmatizzato" }
  160. querySupportCount = SELECT DISTINCT ?uri_antroponym ?antroponimo COUNT(?antroponimo) AS ?occorrenze
  161. WHERE {
  162. ?document crm:P67_refers_to ?uri .
  163. <http://dev.restore.ovi.cnr.it/vocabularies/places/257> crm:P1_is_identified_by ?uri .
  164. ?document crm:P67_refers_to ?uri_antroponym .
  165. ?uri_antroponym crm:P2_has_type "Antroponimo";
  166. rdfs:label ?antroponimo .
  167. }
  168. GROUP BY ?uri_antroponym ?antroponimo
  169. ORDER BY DESC (?occorrenze)
  170. */
  171. queryURL = prepareQueryURL(query);
  172. queryRef = prepareQueryURL(queryRiferimenti);
  173. queryTopo = prepareQueryURL(queryToponimi);
  174. queryRec = prepareQueryURL(queryRicezione);
  175. querySend = prepareQueryURL(queryInvio);
  176. queryCit = prepareQueryURL(queryCitazione);
  177. queryPer = prepareQueryURL(queryPersone);
  178. queryCon1 = prepareQueryURL(queryCount);
  179. queryCon2 = prepareQueryURL(queryCount2);
  180. queryDataset = prepareQueryURL(queryCountDataset);
  181. querySup = prepareQueryURL(querySupportCount);
  182. queryLem = prepareQueryURL(querySupportLemma);
  183. queryOcc = prepareQueryURL(queryCountLuogo);
  184. response = $.ajax({//OGGETTO
  185. url: queryURL,
  186. dataType: "json",
  187. success: function (data){
  188. handle_data(data);
  189. },
  190. error: function (e) {}
  191. });
  192. response_ref = $.ajax({//OGGETTO
  193. url: queryRef,
  194. dataType: "json",
  195. success: function (data){
  196. handle_ref(data);
  197. },
  198. error: function (e) {}
  199. });
  200. response_top = $.ajax({//OGGETTO
  201. url: queryTopo,
  202. dataType: "json",
  203. success: function (data){
  204. handle_toponym(data);
  205. },
  206. error: function (e) {}
  207. });
  208. response_receive = $.ajax({//OGGETTO
  209. url: queryRec,
  210. dataType: "json",
  211. success: function (data){
  212. handle_receive(data);
  213. },
  214. error: function (e) {}
  215. });
  216. response_send = $.ajax({//OGGETTO
  217. url: querySend,
  218. dataType: "json",
  219. success: function (data){
  220. handle_send(data);
  221. },
  222. error: function (e) {}
  223. });
  224. response_cit = $.ajax({//OGGETTO
  225. url: queryCit,
  226. dataType: "json",
  227. success: function (data){
  228. handle_cit(data);
  229. },
  230. error: function (e) {}
  231. });
  232. response_per = $.ajax({//OGGETTO
  233. url: queryPer,
  234. dataType: "json",
  235. success: function (data){
  236. handle_persons(data);
  237. },
  238. error: function (e) {}
  239. });
  240. responseCountA = $.ajax({//OGGETTO
  241. url: queryCon1,
  242. dataType: "json",
  243. success: function (data){
  244. handle_count(data);
  245. },
  246. error: function (e) {}
  247. });
  248. responseCountP = $.ajax({//OGGETTO
  249. url: queryCon2,
  250. dataType: "json",
  251. success: function (data){
  252. handle_count2(data);
  253. },
  254. error: function (e) {}
  255. });
  256. responseDataset = $.ajax({//OGGETTO
  257. url: queryDataset,
  258. dataType: "json",
  259. success: function (data){
  260. get_dataset(data);
  261. },
  262. error: function (e) {}
  263. });
  264. responseOcc = $.ajax({//OGGETTO
  265. url: queryOcc,
  266. dataType: "json",
  267. success: function (data){
  268. get_occurrence(data);
  269. },
  270. error: function (e) {}
  271. });
  272. responseSupp = $.ajax({//OGGETTO
  273. url: querySup,
  274. dataType: "json",
  275. success: function (data){
  276. get_support(data);
  277. },
  278. error: function (e) {}
  279. });
  280. responseLemm = $.ajax({//OGGETTO
  281. url: queryLem,
  282. dataType: "json",
  283. success: function (data){
  284. get_support(data);
  285. },
  286. error: function (e) {}
  287. });
  288. function handle_data(json) {
  289. console.log(json);
  290. const locations = [];
  291. $.each(
  292. json['results']['bindings'],
  293. function (index, value) {
  294. const loc = []
  295. var graph = value['graph']['value'];
  296. var label = value['name_place']['value'];
  297. var coord = value['coordinates']['value'];
  298. const coordinates = coord.split(", ");
  299. loc.push(label);
  300. loc.push(coordinates[0]);
  301. loc.push(coordinates[1]);
  302. locations.push(loc);
  303. document.getElementById("grafo").innerHTML = graph;
  304. document.getElementById("nome_luogo").innerHTML = label;
  305. document.getElementById("nome_lu").innerHTML = label;
  306. document.getElementById("nome_lp").innerHTML = label;
  307. document.getElementById("nome_ll").innerHTML = label;
  308. document.getElementById("nome_lg").innerHTML = label;
  309. });
  310. var map = L.map('map').setView([locations[0][1], locations[0][2]], 7);
  311. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  312. L.tileLayer(
  313. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  314. attribution: '&copy; ' + mapLink + ' Contributors',
  315. maxZoom: 18,
  316. }).addTo(map);
  317. for (var i = 0; i < locations.length; i++) {
  318. marker = new L.marker([locations[i][1], locations[i][2]])
  319. .bindPopup(locations[i][0])
  320. .addTo(map);
  321. }
  322. }
  323. function handle_ref(json) {
  324. console.log(json);
  325. const references = [];
  326. var list_ref = "";
  327. $.each(
  328. json['results']['bindings'],
  329. function (index, value) {
  330. var ref = value['references']['value'];
  331. references.push(ref);
  332. });
  333. for (i=0; i<references.length; i++) {
  334. list_ref += "<a target='_blank' href='" + references[i] + "'>" + references[i] + "</a>";
  335. }
  336. document.getElementById("riferimenti").innerHTML = list_ref;
  337. }
  338. function handle_toponym(json) {
  339. console.log(json);
  340. const toponym = [];
  341. $.each(
  342. json['results']['bindings'],
  343. function (index, value) {
  344. var topo = value['toponimi']['value'];
  345. toponym.push(" " + topo);
  346. });
  347. document.getElementById("toponimi").innerHTML = toponym;
  348. }
  349. function handle_receive(json) {
  350. console.log(json);
  351. const received = {};
  352. var i=0;
  353. $.each(
  354. json['results']['bindings'],
  355. function (index, value) {
  356. key = value['object']['value'];
  357. data = value['label']['value'];
  358. received[key] = data;
  359. i++;
  360. });
  361. var myArray = "";
  362. for (var key in received) {
  363. myArray += "<div class='row res'><div class='col-10'>" + received[key] + "</div><div class='col d-flex align-items-start justify-content-end'><a class='btn-icon' target='_blank' href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  364. }
  365. document.getElementById("n_receive").innerHTML = i;
  366. document.getElementById("object_receive").innerHTML = myArray;
  367. if (i==0) {
  368. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  369. document.getElementById("object_receive").innerHTML = messaggio;
  370. }
  371. }
  372. function handle_send(json) {
  373. console.log(json);
  374. const sent = {};
  375. var i=0;
  376. $.each(
  377. json['results']['bindings'],
  378. function (index, value) {
  379. key = value['object']['value'];
  380. data = value['label']['value'];
  381. sent[key] = data;
  382. i++;
  383. });
  384. var myArray = "";
  385. for (var key in sent) {
  386. myArray += "<div class='row res'><div class='col-10'>" + sent[key] + "</div><div class='col d-flex align-items-start justify-content-end'><a class='btn-icon' target='_blank' href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  387. }
  388. document.getElementById("n_send").innerHTML = i;
  389. document.getElementById("object_send").innerHTML = myArray;
  390. if (i==0) {
  391. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  392. document.getElementById("object_send").innerHTML = messaggio;
  393. }
  394. }
  395. function handle_cit(json) {
  396. console.log(json);
  397. const citations = {};
  398. var i=0;
  399. $.each(
  400. json['results']['bindings'],
  401. function (index, value) {
  402. key = value['object']['value'];
  403. data = value['label']['value'];
  404. citations[key] = data;
  405. i++;
  406. });
  407. var myArray = "";
  408. for (var key in citations) {
  409. myArray += "<div class='row res'><div class='col-10'>" + citations[key] + "</div><div class='col d-flex align-items-start justify-content-end'><a class='btn-icon' target='_blank' href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  410. }
  411. document.getElementById("n_cit").innerHTML = i;
  412. document.getElementById("object_cit").innerHTML = myArray;
  413. if (i==0) {
  414. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  415. document.getElementById("object_cit").innerHTML = messaggio;
  416. }
  417. }
  418. function handle_persons(json) {
  419. console.log(json);
  420. const people = {};
  421. var i=0;
  422. $.each(
  423. json['results']['bindings'],
  424. function (index, value) {
  425. key = value['range']['value'];
  426. data = value['label']['value'];
  427. people[key] = data;
  428. i++;
  429. });
  430. var myArray = "";
  431. for (var key in people) {
  432. myArray += "<div class='row res'><div class='col-10'>" + people[key] + "</div><div class='col d-flex align-items-center justify-content-end'><div class='persona' id='" +
  433. key + "'><i class='fa fa-user' style='cursor: pointer'></i></div><div class='ml-3'><a class='btn-icon' target='_blank' href='" +
  434. key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div></div>";
  435. }
  436. document.getElementById("n_per").innerHTML = i;
  437. document.getElementById("object_per").innerHTML = myArray;
  438. if (i==0) {
  439. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  440. document.getElementById("object_per").innerHTML = messaggio;
  441. }
  442. }
  443. function handle_count(json) {
  444. console.log(json);
  445. const toponimi = [];
  446. const dataToponimi = [];
  447. var max = 0;
  448. $.each(
  449. json['results']['bindings'],
  450. function (index, value) {
  451. const topo = [];
  452. var toponimo = value['label']['value'];
  453. var count = value['Count']['value'];
  454. var temp = parseInt(count);
  455. toponimi.push(toponimo);
  456. dataToponimi.push([toponimo, count]);
  457. if (temp>max) {
  458. max = temp;
  459. }
  460. });
  461. // set the dimensions and margins of the graph
  462. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  463. width = 460 - margin.left - margin.right,
  464. height = 400 - margin.top - margin.bottom;
  465. // append the svg object to the body of the page
  466. var svg = d3.select("#my_dataviz")
  467. .append("svg")
  468. .attr("width", width + margin.left + margin.right)
  469. .attr("height", height + margin.top + margin.bottom)
  470. .append("g")
  471. .attr("transform",
  472. "translate(" + margin.left + "," + margin.top + ")");
  473. // Parse the Data
  474. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  475. // Add X axis
  476. var x = d3.scaleLinear()
  477. .domain([0, max])
  478. .range([ 0, width]);
  479. svg.append("g")
  480. .attr("transform", "translate(0," + height + ")")
  481. .call(d3.axisBottom(x))
  482. .selectAll("text")
  483. .attr("transform", "translate(-10,0)rotate(-45)")
  484. .style("text-anchor", "end");
  485. // Y axis
  486. var y = d3.scaleBand()
  487. .range([ 0, height ])
  488. .domain(toponimi)
  489. .padding(.1);
  490. svg.append("g")
  491. .call(d3.axisLeft(y))
  492. //Bars
  493. svg.selectAll("myRect")
  494. .data(dataToponimi)
  495. .enter()
  496. .append("rect")
  497. .attr("x", x(0) )
  498. .attr("y", function(d) { return y(d[0]); })
  499. .attr("width", function(d) { return x(d[1]); })
  500. .attr("height", y.bandwidth() )
  501. .attr("fill", "#69b3a2")
  502. /*var texts = svg.selectAll("myRect")
  503. .data(dataToponimi)
  504. .enter()
  505. .append("text");
  506. texts.attr("x", function(d){ return d[1] / 4 - 20})
  507. .attr("y", function(d,i){ return 22.26*i +20})
  508. .attr("text-anchor", "middle")
  509. .attr("fill", "#fff")
  510. .text(function(d){ return d[1]});*/
  511. }
  512. function handle_count2(json) {
  513. console.log(json);
  514. const toponimi = [];
  515. const dataToponimi = [];
  516. const values = [];
  517. var max = 0;
  518. $.each(
  519. json['results']['bindings'],
  520. function (index, value) {
  521. const topo = [];
  522. var toponimo = value['label']['value'];
  523. var count = value['Count']['value'];
  524. var temp = parseInt(count);
  525. toponimi.push(toponimo);
  526. dataToponimi.push([toponimo, count]);
  527. if (temp>max) {
  528. max = temp;
  529. }
  530. });
  531. // set the dimensions and margins of the graph
  532. var margin = {top: 20, right: 30, bottom: 40, left: 90},
  533. width = 460 - margin.left - margin.right,
  534. height = 400 - margin.top - margin.bottom;
  535. // append the svg object to the body of the page
  536. var svg = d3.select("#my_dataviz2")
  537. .append("svg")
  538. .attr("width", width + margin.left + margin.right)
  539. .attr("height", height + margin.top + margin.bottom)
  540. .append("g")
  541. .attr("transform",
  542. "translate(" + margin.left + "," + margin.top + ")");
  543. // Parse the Data
  544. //d3.csv("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/7_OneCatOneNum_header.csv", function(data) {
  545. // Add X axis
  546. var x = d3.scaleLinear()
  547. .domain([0, max])
  548. .range([ 0, width]);
  549. svg.append("g")
  550. .attr("transform", "translate(0," + height + ")")
  551. .call(d3.axisBottom(x))
  552. .selectAll("text")
  553. .attr("transform", "translate(-10,0)rotate(-45)")
  554. .style("text-anchor", "end");
  555. // Y axis
  556. var y = d3.scaleBand()
  557. .range([ 0, height ])
  558. .domain(toponimi)
  559. .padding(.1);
  560. svg.append("g")
  561. .call(d3.axisLeft(y))
  562. //Bars
  563. svg.selectAll("myRect")
  564. .data(dataToponimi)
  565. .enter()
  566. .append("rect")
  567. .attr("x", x(0) )
  568. .attr("y", function(d) { return y(d[0]); })
  569. .attr("width", function(d) { return x(d[1]); })
  570. .attr("height", y.bandwidth() )
  571. .attr("fill", "#69b3a2")
  572. svg.selectAll("text2")
  573. .data(dataToponimi)
  574. .enter().append("text2")
  575. .text(function(d) {return d[1]})
  576. .attr("class", "text")
  577. }
  578. function get_dataset(json) {
  579. console.log(json);
  580. data = json.results.bindings[0].documenti.value;
  581. console.log(data);
  582. }
  583. function get_occurrence(json) {
  584. }
  585. function get_support(json) {
  586. }
  587. function open_info() {
  588. document.getElementById("info_luogo").style.display = "block";
  589. document.getElementById("place_info").style.display = "block";
  590. document.getElementById("topo").style.display = "none";
  591. document.getElementById("rif").style.display = "none";
  592. }
  593. function open_toponimi() {
  594. document.getElementById("info_luogo").style.display = "block";
  595. document.getElementById("place_info").style.display = "none";
  596. document.getElementById("topo").style.display = "block";
  597. document.getElementById("rif").style.display = "none";
  598. }
  599. function open_riferimenti() {
  600. document.getElementById("info_luogo").style.display = "block";
  601. document.getElementById("place_info").style.display = "none";
  602. document.getElementById("topo").style.display = "none";
  603. document.getElementById("rif").style.display = "block";
  604. }
  605. function open_collegamenti() {
  606. document.getElementById("references").style.display = "flex";
  607. document.getElementById("statistiche").style.display = "none";
  608. document.getElementById("regole_associazione").style.display = "none";
  609. }
  610. function open_statistiche() {
  611. document.getElementById("references").style.display = "none";
  612. document.getElementById("statistiche").style.display = "flex";
  613. document.getElementById("regole_associazione").style.display = "none";
  614. }
  615. function open_correlazioni() {
  616. document.getElementById("references").style.display = "none";
  617. document.getElementById("statistiche").style.display = "none";
  618. document.getElementById("regole_associazione").style.display = "flex";
  619. }
  620. var header = document.getElementById("ref_buttons");
  621. var btns = header.getElementsByClassName("btn");
  622. for (var i = 0; i < btns.length; i++) {
  623. btns[i].addEventListener("click", function() {
  624. var current = document.getElementsByClassName("active");
  625. current[0].className = current[0].className.replace(" active", "");
  626. this.className += " active";
  627. });
  628. }
  629. //out = "";
  630. //for(i = 0; i < resultArray.length; i++){
  631. // out = out + JSON.stringify(resultArray[i])
  632. //}
  633. //queryStringOutput = (queryStringOutput + out).replace("}{",",");
  634. /*
  635. var locations = [
  636. ["LOCATION_1", 11.8166, 122.0942],
  637. ["LOCATION_2", 11.9804, 121.9189],
  638. ["LOCATION_3", 10.7202, 122.5621],
  639. ["LOCATION_4", 11.3889, 122.6277],
  640. ["LOCATION_5", 10.5929, 122.6325]
  641. ];
  642. var map = L.map('map').setView([11.206051, 122.447886], 8);
  643. mapLink =
  644. '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  645. L.tileLayer(
  646. 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  647. attribution: '&copy; ' + mapLink + ' Contributors',
  648. maxZoom: 18,
  649. }).addTo(map);
  650. for (var i = 0; i < locations.length; i++) {
  651. marker = new L.marker([locations[i][1], locations[i][2]])
  652. .bindPopup(locations[i][0])
  653. .addTo(map);
  654. }
  655. */
  656. $(document).on("click", ".persona", function (ev) {
  657. var link = this.id;
  658. //alert(nome_autore);
  659. //$('#myModal').text("");
  660. window.open("Persona.html?link="+this.id);
  661. });