c3.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. var unityName = "C3Dev";
  2. var errorTable;
  3. var sites = {};
  4. $.ajaxSettings.async = false;
  5. var jqxhr = $.getJSON("/BIM-Monitor/assets/errorTable.json", function (json) {
  6. errorTable = json;
  7. });
  8. var C3Json = $.getJSON("/BIM-Monitor/assets/json/c3-monitorList.json", function (json) {
  9. sites["c3"] = json;
  10. });
  11. var R03Json = $.getJSON("/BIM-Monitor/assets/json/r03-monitorList.json", function (json) {
  12. sites["r03"] = json;
  13. });
  14. $.ajaxSettings.async = true;
  15. var lastNode;
  16. var errorArray = [];
  17. var switchNumber = 0;
  18. passString('OW');
  19. var wellTBA = [];
  20. var wellNameLists = [];
  21. var isAll = true;
  22. var isCompare = false;
  23. var saveCheckCompare = "";
  24. $(document).ready(function () {
  25. GetCheckAllAJAXValue();
  26. LoadPage();
  27. $(".monitor").on('click', function () {
  28. let site = $(this).parent().parent().parent().attr("monitor");
  29. if (site != 'c3') {
  30. location.href = `../${site}/Index.php`;
  31. } else {
  32. let option = $(this).attr("monitor");
  33. isAll = true;
  34. isCompare = false;
  35. passString(option);
  36. document.getElementById("monitorName").innerHTML = option + "監測儀器";
  37. if (lastNode != null) {
  38. lastNode.style = "color:#abb4be;";
  39. }
  40. document.getElementById("errorCheck").checked = false;
  41. document.getElementById("compareCheck").checked = false;
  42. lastNode = document.getElementById(option).parentNode;
  43. lastNode.style = "color:#0088cc;";
  44. LoadPage();
  45. }
  46. });
  47. })
  48. //Pass monitor equipment's name to index.php select form
  49. function passString(option) {
  50. window.localStorage.setItem("option", option);
  51. }
  52. //unity選擇到一個監測儀器後,在selectWell.cs會給一個監測儀器名稱(例:OW-1)給網頁
  53. function GetWellName(wellName) {
  54. showWell(wellName, true);
  55. }
  56. function submitForm() {
  57. document.getElementById("CSVform").submit();
  58. }
  59. //網頁用SendMessage()傳Initialization()給unity時,unity會回傳一個所有監測儀器名稱(例:OW-1,OW-2 ...)給網頁
  60. function GetWellNameList(wellNameList) {
  61. window.localStorage.setItem("wellNameList", wellNameList);
  62. }
  63. //display well name and send its name to showWell function
  64. function displayWellInfo2(equipment) {
  65. $.ajaxSettings.async = false;
  66. $.ajax({
  67. url: '/BIM-Monitor/script/php/getEquipmentName.php',
  68. type: "GET",
  69. data: {
  70. equipment: equipment,
  71. }
  72. }).success(function (data) {
  73. GetWellNameList(data);
  74. }).error(function (error) {
  75. console.log("錯誤");
  76. });
  77. $.ajaxSettings.async = true;
  78. }
  79. var sparklinePieData = [];
  80. //unity載入後會先跑LoadPage();
  81. function LoadPage() {
  82. var option = window.localStorage.getItem("option");
  83. displayWellInfo2(option);
  84. $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
  85. document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
  86. if (option == "ELP" || option == "OW")
  87. document.getElementById("displayCompareChart").style.display = 'block';
  88. else
  89. document.getElementById("displayCompareChart").style.display = 'none';
  90. if (isLoad) {
  91. if (option == "HM" || option == "SIS" || option == "RS" || option == "VG" || option == "SID") {
  92. //把B1的模型改成透明的
  93. myGameInstance.SendMessage("Monitor", "ChangeTransparent");
  94. //把樓上的模型隱形
  95. myGameInstance.SendMessage("Monitor", "RemoveModel", "true");
  96. } else {
  97. //把B1的模型改成白色
  98. myGameInstance.SendMessage("Monitor", "ChangeWhite");
  99. //把樓上的模型變回來
  100. myGameInstance.SendMessage("Monitor", "RemoveModel", "false");
  101. }
  102. }
  103. if (option != "ELP" && option != "SIS" && option != "SID") {
  104. document.getElementById("phase").style.display = "none";
  105. } else {
  106. document.getElementById("phase").style.display = "block";
  107. }
  108. var wellTBALocal = getCheckValue();
  109. var dataValue = option;
  110. for (i = 0; i < wellTBALocal.length; i++) {
  111. dataValue = dataValue.concat(',', wellTBALocal[i]);
  112. }
  113. if (isLoad) {
  114. //dataValue = 監測儀器代號,超出警戒值的儀器名稱
  115. //AddDataTable會存option:監測儀器代號(string)
  116. // abnormal:超出警戒值的儀器名稱(array)
  117. // gameObjects:所有監測儀器名稱(array)
  118. // optionGameObjects:包含監測儀器代號的所有監測儀器名稱(array)
  119. // 到unity的DataTable.cs裡面
  120. myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
  121. //原本的模型牆被挖空,SID、RS、VG都有建各自的牆,若選擇一種監測儀器則另外兩種隱藏掉
  122. //addData(DataTable.option);
  123. //依照DataTable的option將所有optionGameObjects改成normal的顏色
  124. //Search(DataTable.option, DataTable.abnormal);
  125. //將所有abnormal的儀器改成abnormal的顏色
  126. myGameInstance.SendMessage("Monitor", "Initialization");
  127. }
  128. var wellNameList = window.localStorage.getItem("wellNameList");
  129. var wellNameListsLocal = wellNameList.split(",");
  130. var order = new Array(wellNameListsLocal.length);
  131. for (i = 0; i < wellNameListsLocal.length; i++) {
  132. order[i] = wellNameListsLocal[i].match(/\d+/g);
  133. }
  134. for (i = 0; i < order.length; i++) {
  135. for (j = 0; j < order.length; j++) {
  136. if (order[j] > order[j + 1]) {
  137. let temp = order[j];
  138. order[j] = order[j + 1];
  139. order[j + 1] = temp;
  140. let temp2 = wellNameListsLocal[j];
  141. wellNameListsLocal[j] = wellNameListsLocal[j + 1];
  142. wellNameListsLocal[j + 1] = temp2;
  143. }
  144. }
  145. }
  146. wellNameLists = wellNameListsLocal;
  147. wellTBA = wellTBALocal;
  148. SetList();
  149. ResetCamera();
  150. showWell(wellNameLists[0], false);
  151. }
  152. //get well info from sql server
  153. function showWell(str, changeCamera) {
  154. var strLocal = "";
  155. var executed = false;
  156. var xhttp;
  157. isCompare = false;
  158. document.getElementById("compareCheck").checked = false;
  159. if (str == "") {
  160. document.getElementById("dataTable").innerHTML = "";
  161. return;
  162. }
  163. strLocal = str;
  164. if (!isLoad && str.includes("RS")) {
  165. str = str.substr(0, str.length - 2);
  166. }
  167. document.getElementById("monitorSelect2").innerHTML = strLocal;
  168. xhttp = new XMLHttpRequest();
  169. xhttp.onreadystatechange = function () {
  170. if (this.readyState == 4 && this.status == 200) {
  171. document.getElementById("tableName").innerHTML = strLocal + "資料表";
  172. saveCheckCompare = strLocal + "資料表";
  173. displayChart(str, "myChart");
  174. reset();
  175. if (isLoad) {
  176. //把現在選擇的儀器名稱(例:OW-1)傳到unity,unity找模型名稱相同的改變模型顏色以及鏡頭置中模型
  177. myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
  178. }
  179. if (!changeCamera) {
  180. ResetCamera();
  181. }
  182. document.getElementById("dataTable").innerHTML = this.responseText;
  183. $('#dataTable').DataTable();
  184. }
  185. };
  186. xhttp.open("GET", "/BIM-Monitor/script/php/getData2.php?q=" + str, true);
  187. xhttp.send();
  188. }
  189. var sparklinePieData = [];
  190. function getCheckValue() {
  191. var dataArray = [];
  192. var phase
  193. if (document.getElementById("phase") !== null) {
  194. phase = document.getElementById("phase").value;
  195. } else {
  196. phase = 7;
  197. }
  198. var option = window.localStorage.getItem("option");
  199. for (i = 0; i < errorTable.length; i++) {
  200. if (errorTable[i].table_name == option) {
  201. var method = errorTable[i].method;
  202. var table_name = errorTable[i].table_name + "data";
  203. var warning1 = errorTable[i].warning1;
  204. var warning2 = errorTable[i].warning2;
  205. var warning_Count = errorTable[i].warning_Count;
  206. }
  207. }
  208. $.ajax({
  209. url: "/BIM-Monitor/script/php/checkValue2.php",
  210. data: {
  211. method: method,
  212. table_name: table_name,
  213. warning1: warning1,
  214. warning2: warning2,
  215. warning_Count: warning_Count,
  216. phase: phase
  217. },
  218. async: false,
  219. contentType: "application/json",
  220. dataType: "json"
  221. })
  222. .success(function (response) {
  223. dataArray = response['wellTBA'];
  224. for (var i = 0; i < dataArray.length; i++) {
  225. dataArray[i] = dataArray[i].replace('_', '-');
  226. }
  227. var normal_count = response['normal_count'];
  228. var abnormal_count = response['abnormal_count'];
  229. sparklinePieData = [normal_count, abnormal_count];
  230. var all = normal_count + abnormal_count;
  231. var percent = abnormal_count / all;
  232. var url = "/BIM-Monitor/assets/javascripts/ui-elements/pie.charts.js";
  233. var script = document.createElement('script');
  234. script.setAttribute('type', 'text/javascript');
  235. script.setAttribute('src', url);
  236. document.getElementsByTagName('head')[0].appendChild(script);
  237. document.getElementById("percent").innerHTML = Math.round(percent * 100) + "%";
  238. })
  239. .error(function () {
  240. //alert("錯誤統計未正常獲取");
  241. })
  242. .complete(function () {});
  243. return dataArray;
  244. }
  245. function GetCheckAllAJAXValue() {
  246. errorArray = [];
  247. var phase
  248. if (document.getElementById("phase") !== null) {
  249. phase = document.getElementById("phase").value;
  250. } else {
  251. phase = 7;
  252. }
  253. for (i = 0; i < errorTable.length; i++) {
  254. var method = errorTable[i].method;
  255. var option = errorTable[i].table_name;
  256. var table_name = errorTable[i].table_name + "data";
  257. var warning1 = errorTable[i].warning1;
  258. var warning2 = errorTable[i].warning2;
  259. var warning_Count = errorTable[i].warning_Count;
  260. $.ajax({
  261. url: "/BIM-Monitor/script/php/checkValue2.php",
  262. data: {
  263. method: method,
  264. table_name: table_name,
  265. warning1: warning1,
  266. warning2: warning2,
  267. warning_Count: warning_Count,
  268. phase: phase
  269. },
  270. async: false,
  271. contentType: "application/json",
  272. dataType: "json"
  273. })
  274. .success(function (response) {
  275. var normal_count = response['normal_count'];
  276. var abnormal_count = response['abnormal_count'];
  277. var all_count = 0 + normal_count + abnormal_count;
  278. document.getElementById(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
  279. errorArray.push(abnormal_count);
  280. })
  281. .error(function () {
  282. alert("錯誤統計未正常獲取");
  283. })
  284. .complete(function () {});
  285. }
  286. }
  287. function CheckCompare() {
  288. var option = window.localStorage.getItem("option");
  289. var text = "";
  290. if (option == "ELP" || option == "OW") {
  291. if (option == "ELP") {
  292. text = "水壓計";
  293. } else if (option == "OW") {
  294. text = "水位觀測井";
  295. }
  296. var checkBox = document.getElementById("compareCheck");
  297. if (checkBox.checked == true) {
  298. document.getElementById("tableName").innerHTML = option + text + '總表';
  299. isCompare = true;
  300. } else {
  301. document.getElementById("tableName").innerHTML = saveCheckCompare;
  302. isCompare = false;
  303. }
  304. if (option == "ELP")
  305. displayChart("ELP-1", "myChart");
  306. else if (option == "OW")
  307. displayChart("OW-1", "myChart");
  308. }
  309. }
  310. function CheckError() {
  311. var checkBox = document.getElementById("errorCheck");
  312. if (checkBox.checked == true) {
  313. isAll = false;
  314. } else {
  315. isAll = true;
  316. }
  317. SetList();
  318. }
  319. function uploadCSV() {
  320. var input = $("#fileToUpload");
  321. var inputLength = input[0].files.length; //No of files selected
  322. var file;
  323. var formData = new FormData();
  324. for (var i = 0; i < inputLength; i++) {
  325. file = input[0].files[i];
  326. formData.append('fileToUpload[]', file);
  327. }
  328. $.ajax({
  329. url: "/BIM-Monitor/script/php/upload.php",
  330. type: "POST",
  331. data: formData,
  332. processData: false,
  333. contentType: false,
  334. beforeSend: function () {
  335. }
  336. }).done(function (data) {
  337. var stack_bar_top = {
  338. "dir1": "down",
  339. "dir2": "right",
  340. "push": "top",
  341. "spacing1": 0,
  342. "spacing2": 0
  343. };
  344. if (data.includes("IS")) {
  345. var notice = new PNotify({
  346. title: '通知',
  347. text: '上傳成功!',
  348. type: 'success',
  349. addclass: 'stack-bar-top',
  350. stack: stack_bar_top,
  351. width: "100%"
  352. });
  353. } else {
  354. var notice = new PNotify({
  355. title: '通知',
  356. text: '上傳失敗!',
  357. type: 'error',
  358. addclass: 'stack-bar-top',
  359. stack: stack_bar_top,
  360. width: "100%"
  361. });
  362. }
  363. }).error(function () {
  364. });
  365. }
  366. //Display chart
  367. function displayChart(str, elementID) {
  368. $.ajax({
  369. url: "/BIM-Monitor/script/php/getChartData2.php",
  370. type: "GET",
  371. async: false,
  372. data: {
  373. q: str
  374. }
  375. })
  376. .success(function (response) {
  377. if (str.includes("ELP") || str.includes("OW") || str.includes("SM") || str.includes("SB") || str.includes("SBM") || str.includes("VG") || str.includes("HM")) {
  378. //Split the response text into well name array, date array and value array
  379. var v_variables = response.split("*");
  380. var c_wellName = v_variables[0];
  381. var c_m_date = v_variables[1].split(" ");
  382. var c_m_value = v_variables[2].split(" ");
  383. //Start to make the chart
  384. if (isCompare) {
  385. displayCompareChart();
  386. } else {
  387. init(c_wellName, c_m_date, c_m_value, elementID);
  388. }
  389. } else if (str.includes("TI")) {
  390. var v_variables = response.split("*");
  391. var c_wellName = v_variables[0];
  392. var c_m_date = v_variables[1].split(" ");
  393. var c_m_value = v_variables[2].split(" ");
  394. //Multiple line
  395. var c2_wellName = v_variables[3];
  396. var c2_m_date = v_variables[4].split(" ");
  397. var c2_m_value = v_variables[5].split(" ");
  398. if (isCompare) {
  399. displayCompareChart();
  400. } else {
  401. init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID);
  402. }
  403. } else if (str.includes("SIS") || str.includes("SID")) {
  404. var v_variables = response.split("*");
  405. var c_m_date = v_variables[0].split(" ");
  406. var c_m_depth = v_variables[1].split(" ");
  407. var c_m_valueArray = v_variables[2].split("//");
  408. //Abnormal value, don't know why it happened so I brute force it
  409. c_m_valueArray[0] = c_m_valueArray[0].replace("0.4770.468", "0.477 0.468");
  410. var dateCount = c_m_date.length;
  411. let c_m_value = [];
  412. for (x = 0; x < dateCount; x++) {
  413. c_m_value[x] = c_m_valueArray[x].split(" ");
  414. }
  415. initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str);
  416. } else if (str.includes("RS")) {
  417. var v_variables = response.split("*");
  418. var c_wellName = v_variables[0];
  419. var c_m_date = v_variables[1].split(" ");
  420. var c_m_value = v_variables[2].split(" ");
  421. var c2_wellName = v_variables[3];
  422. var c2_m_date = v_variables[4].split(" ");
  423. var c2_m_value = v_variables[5].split(" ");
  424. var c3_wellName = v_variables[6];
  425. var c3_m_date = v_variables[7].split(" ");
  426. var c3_m_value = v_variables[8].split(" ");
  427. var c4_wellName = v_variables[9];
  428. var c4_m_date = v_variables[10].split(" ");
  429. var c4_m_value = v_variables[11].split(" ");
  430. var c5_wellName = v_variables[12];
  431. var c5_m_date = v_variables[13].split(" ");
  432. var c5_m_value = v_variables[14].split(" ");
  433. var c6_wellName = v_variables[15];
  434. var c6_m_date = v_variables[16].split(" ");
  435. var c6_m_value = v_variables[17].split(" ");
  436. init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_wellName, c3_m_value, c4_wellName, c4_m_value, c5_wellName, c5_m_value, c6_wellName, c6_m_value, elementID);
  437. }
  438. })
  439. .error(function (error) {
  440. })
  441. .complete(function () {});
  442. }
  443. function displayCompareChart() {
  444. var option = window.localStorage.getItem("option");
  445. var m_date = [];
  446. var label = [];
  447. var index = 7;
  448. if (option == "ELP")
  449. index = 14;
  450. var chart_data = new Array();
  451. for (var i = 0; i < index; i++) {
  452. chart_data[i] = new Array();
  453. for (var j = 0; j < m_date.length; j++) {
  454. chart_data[i][j] = 0;
  455. }
  456. }
  457. $.ajax({
  458. url: "/BIM-Monitor/script/php/getCompareChartData.php",
  459. async: false,
  460. contentType: "application/json",
  461. dataType: "json",
  462. data: {
  463. option: option
  464. }
  465. })
  466. .success(function (response) {
  467. m_date = response['m_date'];
  468. chart_data = response['chart_data'];
  469. label = response['label'];
  470. initCompare(m_date, chart_data, index, label);
  471. console.log("getCompareChartData正常獲取");
  472. })
  473. .error(function () {
  474. console.log("getCompareChartData未正常獲取");
  475. })
  476. .complete(function () {});
  477. }
  478. //Reset the camera
  479. function ResetCamera() {
  480. if (isLoad) {
  481. //把center、鏡頭、模型位置以及角度全部重置
  482. myGameInstance.SendMessage("MainCamera", "ResetCamera");
  483. }
  484. }
  485. function SetList() {
  486. var wellNameListsLocal = "";
  487. var isError = false;
  488. var monitorSelect = document.getElementById("monitorSelect");
  489. var monitorButton = document.getElementById("monitorButton");
  490. while (monitorSelect.hasChildNodes()) {
  491. monitorSelect.removeChild(monitorSelect.firstChild);
  492. }
  493. while (monitorButton.hasChildNodes()) {
  494. monitorButton.removeChild(monitorButton.firstChild);
  495. }
  496. monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
  497. GetCheckAllAJAXValue();
  498. for (i = 0; i < wellNameLists.length; i++) {
  499. wellNameListsLocal = wellNameLists[i];
  500. var option = document.createElement("li");
  501. var createA = document.createElement("a");
  502. var createAText = document.createTextNode(wellNameListsLocal);
  503. var createButton = document.createElement("button");
  504. var createButtonText = document.createTextNode(wellNameListsLocal);
  505. createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
  506. for (j = 0; j < wellTBA.length; j++) {
  507. if (wellNameLists[i] == (wellTBA[j])) {
  508. createA.style = "color:red;";
  509. createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
  510. isError = true;
  511. }
  512. }
  513. createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  514. createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  515. createButton.setAttribute('type', "button");
  516. if (isAll || (!isAll && isError)) {
  517. createA.appendChild(createAText);
  518. createButton.appendChild(createButtonText);
  519. option.appendChild(createA);
  520. monitorSelect.appendChild(option);
  521. monitorButton.appendChild(createButton);
  522. }
  523. isError = false;
  524. }
  525. }
  526. function UpdateGPS(GPS) {
  527. if (isLoad) {
  528. myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
  529. }
  530. }
  531. function forLoopSMOption() {
  532. var elm = document.getElementById('SM'), // get the select
  533. df = document.createDocumentFragment(); // create a document fragment to hold the options while we create them
  534. for (var i = 1; i <= 81; i++) { // loop, i like 42.
  535. var option = document.createElement('option'); // create the option element
  536. option.value = "SM-" + i; // set the value property
  537. option.appendChild(document.createTextNode("SM-" + i)); // set the textContent in a safe way.
  538. df.appendChild(option); // append the option to the document fragment
  539. }
  540. elm.appendChild(df); // append the document fragment to the DOM. this is the better way rather than setting innerHTML a bunch of times (or even once with a long string)
  541. }
  542. function forLoopHMOption() {
  543. var elm = document.getElementById('HM'),
  544. df = document.createDocumentFragment();
  545. for (var i = 1; i <= 15; i++) {
  546. var option = document.createElement('option');
  547. option.value = "HM-1-" + i;
  548. option.appendChild(document.createTextNode("HM1-" + i));
  549. df.appendChild(option);
  550. }
  551. for (var j = 1; j <= 7; j++) {
  552. var option = document.createElement('option');
  553. option.value = "HM-2-" + j;
  554. option.appendChild(document.createTextNode("HM2-" + j));
  555. df.appendChild(option);
  556. }
  557. for (var k = 1; k <= 11; k++) {
  558. var option = document.createElement('option');
  559. option.value = "HM-3-" + k;
  560. option.appendChild(document.createTextNode("HM3-" + k));
  561. df.appendChild(option);
  562. }
  563. for (var l = 1; l <= 7; l++) {
  564. var option = document.createElement('option');
  565. option.value = "HM-4-" + l;
  566. option.appendChild(document.createTextNode("HM4-" + l));
  567. df.appendChild(option);
  568. }
  569. elm.appendChild(df);
  570. }
  571. var errorChart = null;
  572. //Start making the chart
  573. function init(c_wellName, c_m_date, c_m_value, elementID) {
  574. var ctx = document.getElementById(elementID).getContext("2d");
  575. var phase = document.getElementById("phase").value;
  576. var ELPwarning = [0, -4.6, -10, -15.3, -23.2, 0];
  577. var ELP_1warning = [0, -7.9, -13.3, 0, 0, 0];
  578. //Warning value
  579. let warning = [];
  580. var OWFirstData = {
  581. "OW-1": -1.81,
  582. "OW-2": -1.59,
  583. "OW-3": -6.3,
  584. "OW-4": -3.67,
  585. "OW-5": -3.16,
  586. "OW-6": -1.78,
  587. "OW-7": -3.31
  588. };
  589. var OWwarning1 = 0;
  590. var OWwarning2 = 0;
  591. var yLabel = "";
  592. var xLabel = "";
  593. if (c_wellName.includes("ELP")) {
  594. if (c_wellName != "ELP-1" && c_wellName.includes("-1")) {
  595. if (ELP_1warning[phase - 2] != 0) {
  596. for (i = 0; i < c_m_date.length; i++) {
  597. warning.push(ELP_1warning[phase - 2]);
  598. }
  599. }
  600. } else {
  601. if (ELPwarning[phase - 2] != 0) {
  602. for (i = 0; i < c_m_date.length; i++) {
  603. warning.push(ELPwarning[phase - 2]);
  604. }
  605. }
  606. }
  607. yLabel = "水位高程GL(m)";
  608. xLabel = "日期";
  609. } else if (c_wellName.includes("OW")) {
  610. for (const [key, value] of Object.entries(OWFirstData)) {
  611. if (c_wellName == key) {
  612. OWwarning1 = value + 2;
  613. OWwarning2 = value - 2;
  614. }
  615. }
  616. for (i = 0; i < c_m_date.length; i++) {
  617. warning.push(OWwarning1);
  618. }
  619. yLabel = "水位高程GL(m)";
  620. xLabel = "日期";
  621. } else if (c_wellName.includes("SM")) {
  622. for (i = 0; i < c_m_date.length; i++) {
  623. warning.push(45);
  624. }
  625. yLabel = "沉陷量(mm)";
  626. xLabel = "日期";
  627. } else if (c_wellName.includes("SBM")) {
  628. for (i = 0; i < c_m_date.length; i++) {
  629. warning.push(9.5);
  630. }
  631. yLabel = "沉陷量(mm)";
  632. xLabel = "日期";
  633. } else if (c_wellName.includes("SB")) {
  634. for (i = 0; i < c_m_date.length; i++) {
  635. warning.push(0.0008);
  636. }
  637. yLabel = "沉陷量(mm)";
  638. xLabel = "日期";
  639. } else if (c_wellName.includes("VG")) {
  640. for (i = 0; i < c_m_date.length; i++) {
  641. warning.push(110);
  642. }
  643. yLabel = "應力值(t)";
  644. xLabel = "日期";
  645. } else if (c_wellName.includes("HM")) {
  646. for (i = 0; i < c_m_date.length; i++) {
  647. warning.push(25);
  648. }
  649. yLabel = "沉陷量(mm)";
  650. xLabel = "日期";
  651. }
  652. for (j = 0; j < c_m_value.length; j++) {
  653. if (c_m_value[j] == "") {
  654. c_m_value[j] = null;
  655. }
  656. }
  657. //Destroy chart if it already exists. If not, there'll be multiple charts stack together
  658. if (window.chart != undefined) {
  659. window.chart.destroy();
  660. }
  661. window.chart = new Chart(ctx, {
  662. //Line chart
  663. type: 'line',
  664. data: {
  665. //X-axis displays the date
  666. labels: c_m_date,
  667. datasets: [{
  668. //Label above the chart to illustrate which color has which purpose
  669. label: c_wellName,
  670. //Data value
  671. data: c_m_value,
  672. //Detemine line's color
  673. borderColor: '#3e95cd'
  674. },
  675. {
  676. label: "警戒值",
  677. data: warning,
  678. borderColor: "#FF0000",
  679. pointRadius: 0
  680. }
  681. ]
  682. },
  683. options: {
  684. spanGaps: true,
  685. maintainAspectRatio: false,
  686. responsive: true,
  687. scales: {
  688. y: {
  689. title: {
  690. display: true,
  691. text: yLabel
  692. }
  693. },
  694. x: {
  695. title: {
  696. display: true,
  697. text: xLabel
  698. }
  699. }
  700. }
  701. }
  702. });
  703. if (c_wellName.includes("SBM")) {
  704. let warning2 = [];
  705. for (i = 0; i < c_m_date.length; i++) {
  706. warning2.push(-9.5);
  707. }
  708. window.chart.data.datasets.push({
  709. label: "警戒值2",
  710. data: warning2,
  711. borderColor: "#FF0000",
  712. pointRadius: 0
  713. });
  714. window.chart.update();
  715. } else if (c_wellName.includes("SB")) {
  716. let warning2 = [];
  717. for (i = 0; i < c_m_date.length; i++) {
  718. warning2.push(-0.0008);
  719. }
  720. window.chart.data.datasets.push({
  721. label: "警戒值2",
  722. data: warning2,
  723. borderColor: "#FF0000",
  724. pointRadius: 0
  725. });
  726. window.chart.update();
  727. } else if (c_wellName.includes("OW")) {
  728. let warning2 = [];
  729. for (i = 0; i < c_m_date.length; i++) {
  730. warning2.push(OWwarning2);
  731. }
  732. window.chart.data.datasets.push({
  733. label: "警戒值2",
  734. data: warning2,
  735. borderColor: "#FF0000",
  736. pointRadius: 0
  737. });
  738. window.chart.update();
  739. }
  740. }
  741. function init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID) {
  742. var ctx = document.getElementById(elementID).getContext("2d");
  743. var yLabel = "";
  744. var xLabel = "";
  745. let warning = [];
  746. if (c_wellName.includes("TI")) {
  747. for (i = 0; i < c2_m_date.length; i++) {
  748. warning.push(0.00106);
  749. }
  750. yLabel = "徑度量(δ/ L)";
  751. xLabel = "日期";
  752. }
  753. for (j = 0; j < c_m_value.length; j++) {
  754. if (c_m_value[j] == "") {
  755. c_m_value[j] = null;
  756. }
  757. }
  758. if (window.chart != undefined) {
  759. window.chart.destroy();
  760. }
  761. c_m_value.forEach(function (item, index, array) {
  762. });
  763. window.chart = new Chart(ctx, {
  764. type: 'line',
  765. data: {
  766. labels: c_m_date,
  767. datasets: [{
  768. label: c_wellName,
  769. data: c_m_value,
  770. borderColor: '#3e95cd'
  771. },
  772. {
  773. label: c2_wellName,
  774. data: c2_m_value,
  775. borderColor: '#63fff5'
  776. }
  777. ]
  778. },
  779. options: {
  780. responsive: true,
  781. maintainAspectRatio: false,
  782. scales: {
  783. y: {
  784. title: {
  785. display: true,
  786. text: yLabel
  787. }
  788. },
  789. x: {
  790. title: {
  791. display: true,
  792. text: xLabel
  793. }
  794. }
  795. }
  796. }
  797. });
  798. //ELP does not have second warning line, so you need to update it seperately
  799. if (c_wellName.includes("TI")) {
  800. let warning2 = [];
  801. for (i = 0; i < c2_m_date.length; i++) {
  802. warning2.push(-0.00106);
  803. }
  804. window.chart.data.datasets.push({
  805. label: "警戒值2",
  806. data: warning2,
  807. borderColor: "#FF0000",
  808. pointRadius: 0
  809. });
  810. window.chart.update();
  811. }
  812. }
  813. //SIS SID's lines are vertical
  814. function initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str) {
  815. var ctx = document.getElementById(elementID).getContext("2d");
  816. var datasetValue = [];
  817. let warning = [];
  818. var phase = document.getElementById("phase").value;
  819. var SID_data = [];
  820. var SIS_data = [];
  821. var SIS_array = ['SIS-1', 'SIS-2-1', 'SIS-2-2', 'SIS-3', 'SIS-4', 'SIS-6', 'SIS-7'];
  822. var SID_array = ['SID-1', 'SID-2-1', 'SID-2-2', 'SID-3-1', 'SID-3-2', 'SID-4', 'SID-5-1', 'SID-5-2', 'SID-6', 'SID-7'];
  823. var index = 0;
  824. var num = 0;
  825. if (phase == 2) {
  826. SID_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.698, 1.698, 1.186, 1.186, 1.032];
  827. SIS_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.186, 1.032];
  828. } else if (phase == 3) {
  829. SID_data = [2.39, 1.434, 1.434, 1.434, 2.304, 2.304, 2.304, 1.7, 1.7, 1.569];
  830. SIS_data = [2.39, 1.434, 1.434, 1.434, 2.304, 1.7, 1.569];
  831. } else if (phase == 4) {
  832. SID_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.968, 2.968, 2.267, 2.267, 2.176];
  833. SIS_data = [2.89, 1.856, 1.856, 1.856, 2.968, 2.267, 2.176];
  834. } else if (phase == 5) {
  835. SID_data = [3.36, 2.626, 2.626, 2.626, 4.531, 4.531, 4.531, 3.727, 3.727, 3.285];
  836. SIS_data = [3.36, 2.626, 2.626, 2.626, 4.531, 3.727, 3.285];
  837. } else if (phase == 6) {
  838. SID_data = [4.015, 3.832, 3.832, 3.832, 7.966, 7.966, 7.966, 5.049, 5.049, 5.208];
  839. SIS_data = [4.015, 3.832, 3.832, 3.832, 7.966, 5.049, 5.208];
  840. } else if (phase == 7) {
  841. SID_data = [4.918, 4.458, 4.458, 4.458, 8.909, 8.909, 8.909, 5.797, 5.797, 5.988];
  842. SIS_data = [4.918, 4.458, 4.458, 4.458, 8.909, 5.797, 5.988];
  843. }
  844. if (str.includes("SIS")) {
  845. index = SIS_array.indexOf(str);
  846. num = SIS_data[index];
  847. } else if (str.includes("SID")) {
  848. index = SID_array.indexOf(str);
  849. num = SID_data[index];
  850. }
  851. for (i = 0; i < c_m_value[0].length; i++) {
  852. warning.push(num);
  853. }
  854. yLabel = "觀測深度GL(m)";
  855. xLabel = "變位量(cm)";
  856. for (j = 0; j < c_m_value.length; j++) {
  857. if (c_m_value[j] == "") {
  858. c_m_value[j] = null;
  859. }
  860. }
  861. if (window.chart != undefined) {
  862. window.chart.destroy();
  863. }
  864. for (j = 0; j <= c_m_date.length; j++) {
  865. if (j == c_m_date.length) {
  866. datasetValue[j] = {
  867. axis: 'y',
  868. fill: false,
  869. label: "警戒值",
  870. data: warning,
  871. borderColor: "#FF0000",
  872. pointRadius: 0
  873. }
  874. } else {
  875. datasetValue[j] = {
  876. axis: 'y',
  877. label: c_m_date[j],
  878. data: c_m_value[j],
  879. borderColor: randomColor()
  880. }
  881. }
  882. }
  883. window.chart = new Chart(ctx, {
  884. type: 'line',
  885. data: {
  886. labels: c_m_depth,
  887. datasets: datasetValue
  888. },
  889. options: {
  890. //Turns line to vertical
  891. maintainAspectRatio: false,
  892. responsive: true,
  893. indexAxis: 'y',
  894. scales: {
  895. y: {
  896. title: {
  897. display: true,
  898. text: yLabel
  899. }
  900. },
  901. x: {
  902. beginAtZero: true,
  903. title: {
  904. display: true,
  905. text: xLabel
  906. }
  907. }
  908. }
  909. }
  910. });
  911. }
  912. function init6(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_value, c3_wellName, c3_m_value, c4_wellName, c4_m_value, c5_wellName, c5_m_value, c6_wellName, c6_m_value, elementID) {
  913. var ctx = document.getElementById(elementID).getContext("2d");
  914. let warning = [];
  915. if (c_wellName.includes("RS")) {
  916. for (i = 0; i < c_m_date.length; i++) {
  917. warning.push(2000);
  918. }
  919. yLabel = "應力值(kg/cm²)";
  920. xLabel = "日期";
  921. }
  922. if (window.chart != undefined) {
  923. window.chart.destroy();
  924. }
  925. window.chart = new Chart(ctx, {
  926. type: 'line',
  927. data: {
  928. labels: c_m_date,
  929. datasets: [{
  930. label: c_wellName,
  931. data: c_m_value,
  932. borderColor: randomColor()
  933. },
  934. {
  935. label: c2_wellName,
  936. data: c2_m_value,
  937. borderColor: randomColor()
  938. },
  939. {
  940. label: c3_wellName,
  941. data: c3_m_value,
  942. borderColor: randomColor()
  943. },
  944. {
  945. label: c4_wellName,
  946. data: c4_m_value,
  947. borderColor: randomColor()
  948. },
  949. {
  950. label: c5_wellName,
  951. data: c5_m_value,
  952. borderColor: randomColor()
  953. },
  954. {
  955. label: c6_wellName,
  956. data: c6_m_value,
  957. borderColor: randomColor()
  958. },
  959. {
  960. label: "警戒值",
  961. data: warning,
  962. borderColor: "#FF0000",
  963. pointRadius: 0
  964. }
  965. ]
  966. },
  967. options: {
  968. responsive: true,
  969. maintainAspectRatio: false,
  970. scales: {
  971. y: {
  972. title: {
  973. display: true,
  974. text: yLabel
  975. }
  976. },
  977. x: {
  978. title: {
  979. display: true,
  980. text: xLabel
  981. }
  982. }
  983. }
  984. }
  985. });
  986. //ELP does not have second warning line, so you need to update it seperately
  987. if (c_wellName.includes("RS")) {
  988. let warning2 = [];
  989. for (i = 0; i < c_m_date.length; i++) {
  990. warning2.push(-2000);
  991. }
  992. window.chart.data.datasets.push({
  993. label: "警戒值2",
  994. data: warning2,
  995. borderColor: "#FF0000",
  996. pointRadius: 0
  997. });
  998. window.chart.update();
  999. }
  1000. }
  1001. function initCompare(m_date, chart_data, index, label) {
  1002. var ctx = document.getElementById("myChart").getContext("2d");
  1003. var value = -7.9;
  1004. let warning = [];
  1005. var phase = document.getElementById("phase").value;
  1006. yLabel = "水位高程GL(m)";
  1007. xLabel = "日期";
  1008. for (i = 0; i < m_date.length; i++) {
  1009. warning.push(value);
  1010. }
  1011. if (window.chart != undefined) {
  1012. window.chart.destroy();
  1013. }
  1014. window.chart = new Chart(ctx, {
  1015. type: 'line',
  1016. data: {
  1017. labels: m_date
  1018. },
  1019. options: {
  1020. responsive: true,
  1021. maintainAspectRatio: false,
  1022. scales: {
  1023. y: {
  1024. title: {
  1025. display: true,
  1026. text: yLabel
  1027. }
  1028. },
  1029. x: {
  1030. title: {
  1031. display: true,
  1032. text: xLabel
  1033. }
  1034. }
  1035. }
  1036. }
  1037. });
  1038. for (i = 1; i < index + 1; i++) {
  1039. window.chart.data.datasets.push({
  1040. label: label[i].replaceAll("_", "-"),
  1041. data: chart_data[i],
  1042. borderColor: randomColorBlue()
  1043. });
  1044. }
  1045. window.chart.update();
  1046. }
  1047. //Chart has multiple lines that need different color
  1048. function randomColor() {
  1049. return "#" + ((1 << 24) * Math.random() | 0).toString(16);
  1050. }
  1051. function randomColorBlue() {
  1052. var mid = Math.floor(Math.random() * 255);
  1053. return "#30" + mid.toString(16) + "ff";
  1054. }
  1055. //Need to display multiple epuiment's data table and can't find the function to reset it. So I kill all the nodes.
  1056. function reset() {
  1057. const myNode = document.getElementById("tabData");
  1058. while (myNode.firstChild) {
  1059. myNode.removeChild(myNode.lastChild);
  1060. }
  1061. var table = document.createElement("table");
  1062. table.id = "dataTable";
  1063. table.className = "display";
  1064. //table.style.width = "100%";
  1065. myNode.appendChild(table);
  1066. }