c3.js 37 KB

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