c3.js 37 KB

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