server actix for cannabinieri website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
5.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. let graph = {
  2. nodes : [
  3. {id : "hemp", index: 0, x: 719.1790913580512, y: 326.11409230900296, vy: 0.0009665554475078223, vx: 0.00044710537175425926},
  4. {id : "permapp", index: 1, x: 473.51321690437135, y: 317.1181430586339, vy: 0.0005811239352358496, vx: 0.0005105059544352408 },
  5. {id : "offgrid", index: 2, x: 495.66982580572676, y: 18.53, vy: 0.0007713356454593206, vx: 0.0007887999665437037 },
  6. {id : "cyberpreneur", index: 3, x: 457.9995206323447, y: 277.13445200140694, vy: 0.0004637678594351416, vx: 0.0007441570379881761 },
  7. {id : "kaoscube", index: 4, x: 428.05791236956037, y: 237.65121337678465, vy: 0.00037483669542696317, vx: 0.00039028860355878376 },
  8. {id : "spider", index: 5, x: 461.65464520161396, y: 189.18158017082138, vy: -0.00023265081878199873, vx: 0.00006278089396472572 }
  9. ],
  10. links : [
  11. {source: 0, target: 1, index: 0 },
  12. {source: 0, target: 2, index: 1 },
  13. {source: 0, target: 3, index: 2 },
  14. {source: 0, target: 4, index: 3 },
  15. {source: 1, target: 2, index: 4 },
  16. {source: 1, target: 4, index: 5 },
  17. {source: 2, target: 3 ,index: 6 },
  18. {source: 2, target: 4 ,index: 7 },
  19. {source: 2, target: 5 ,index: 8 },
  20. {source: 4, target: 5 ,index: 9 }
  21. ],
  22. }
  23. // mobile network
  24. let width = 100;
  25. let height = 200;
  26. let radius = 15;
  27. const svg = d3.select("#mobile_network").append("svg").attr("viewBox", "0, 0, 100, 200").attr("preserveAspectRatio", "xMidYMid meet"),
  28. link = svg
  29. .selectAll(".link")
  30. .data(graph.links)
  31. .join("line")
  32. .classed("link", true),
  33. node = svg
  34. .selectAll(".node")
  35. .data(graph.nodes)
  36. .join("circle")
  37. .attr("id", d => d.id)
  38. .attr("r", 15)
  39. .classed("node", true)
  40. .classed("fixed", d => d.fx !== undefined);
  41. const node1 = svg.select("#hemp")
  42. .attr("fill", "url(#imgHemp)")
  43. .append("a")
  44. .attr("xlink:href", "/hemp");
  45. const node2 = svg.select("#permapp")
  46. .attr("fill", "url(#imgPermapp)");
  47. const node3 = svg.select("#spider")
  48. .attr("fill", "url(#imgSpider)");
  49. const node4 = svg.select("#cyberpreneur")
  50. .attr("fill", "url(#imgCyber)");
  51. const node5 = svg.select("#kaoscube")
  52. .attr("fill", "url(#imgKaos)");
  53. const node6 = svg.select("#offgrid")
  54. .attr("fill", "url(#imgOff)");
  55. const defs = svg.append("svg:defs");
  56. defs.append("svg:pattern")
  57. .attr("width", "100%")
  58. .attr("height", "100%")
  59. .attr("id", "imgHemp")
  60. .append("svg:image")
  61. .attr("xlink:href", "/assets/img/hemp.webp")
  62. .attr("width", 45)
  63. .attr("height", 45)
  64. .attr("x", -7 )
  65. .attr("y", 0);
  66. defs.append("svg:pattern")
  67. .attr("width", "100%")
  68. .attr("height", "100%")
  69. .attr("id", "imgPermapp")
  70. .append("svg:image")
  71. .attr("xlink:href", "/assets/img/v1-permapp.webp")
  72. .attr("width", 35)
  73. .attr("height", 35)
  74. .attr("x", 0 )
  75. .attr("y", 0);
  76. defs.append("svg:pattern")
  77. .attr("width", "100%")
  78. .attr("height", "100%")
  79. .attr("id", "imgSpider")
  80. .append("svg:image")
  81. .attr("xlink:href", "/assets/img/spider_out.webp")
  82. .attr("width", 45)
  83. .attr("height", 45)
  84. .attr("x", -4 )
  85. .attr("y", -7);
  86. defs.append("svg:pattern")
  87. .attr("width", "100%")
  88. .attr("height", "100%")
  89. .attr("id", "imgCyber")
  90. .append("svg:image")
  91. .attr("xlink:href", "/assets/img/3d_greenhouse.webp")
  92. .attr("width", 50)
  93. .attr("height", 50)
  94. .attr("x", -5 )
  95. .attr("y", -10);
  96. defs.append("svg:pattern")
  97. .attr("width", "100%")
  98. .attr("height", "100%")
  99. .attr("id", "imgKaos")
  100. .append("svg:image")
  101. .attr("xlink:href", "/assets/img/cube_space.webp")
  102. .attr("width", 40)
  103. .attr("height", 40)
  104. .attr("x", -6 )
  105. .attr("y", -6);
  106. defs.append("svg:pattern")
  107. .attr("width", "100%")
  108. .attr("height", "100%")
  109. .attr("id", "imgOff")
  110. .append("svg:image")
  111. .attr("xlink:href", "/assets/img/boat_construction.webp")
  112. .attr("width", 40)
  113. .attr("height", 40)
  114. .attr("x", -5 )
  115. .attr("y", -6);
  116. const simulation = d3
  117. .forceSimulation()
  118. .nodes(graph.nodes)
  119. .force("charge", d3.forceManyBody().strength(-300))
  120. .force("center", d3.forceCenter(width / 2.5, height / 2.25))
  121. .force("link", d3.forceLink(graph.links).distance(30))
  122. .force("collide", d3.forceCollide(22))
  123. .force("x", d3.forceX(-30))
  124. .on("tick", tick);
  125. const drag = d3
  126. .drag()
  127. .on("start", dragstart)
  128. .on("drag", dragged);
  129. // invokes regiserd callback
  130. node.call(drag).on("click", click);
  131. function tick() {
  132. link
  133. .attr("x1", d => d.source.x)
  134. .attr("y1", d => d.source.y)
  135. .attr("x2", d => d.target.x)
  136. .attr("y2", d => d.target.y);
  137. node
  138. .attr("cx", d => d.x = Math.max(radius, Math.min(width - radius, d.x)))
  139. .attr("cy", d => d.y = Math.max(radius, Math.min(height - radius, d.y)));
  140. }
  141. // make this work on touch as well
  142. function click(event, d) {
  143. delete d.fx;
  144. delete d.fy;
  145. // remove fixed position on click
  146. d3.select(this).classed("fixed", false);
  147. simulation.alpha(1).restart();
  148. // on this click display html text box
  149. }
  150. function dragstart() {
  151. d3.select(this).classed("fixed", true);
  152. }
  153. function dragged(event, d) {
  154. console.log("dragged",d.id);
  155. // set x position of dragged node
  156. d.fx = clamp(event.x, 0, width);
  157. // set x position of dragged node
  158. d.fy = clamp(event.y, 0, height);
  159. // sets duration of animation before restart
  160. simulation.alpha(1).restart();
  161. }
  162. function clamp(x, lo, hi) {
  163. return x < lo ? lo : x > hi ? hi : x;
  164. }
  165. // desktop network