c3.js 37 KB

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