c3.js 38 KB

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