c3.js 37 KB

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