r03.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. var unityName = "R03Monitor";
  2. var errorTable;
  3. var sites = {};
  4. var display_info = {};
  5. $.ajaxSettings.async = false;
  6. var jqxhr = $.getJSON("/BIM-Monitor/assets/errorTable.json", function (json) {
  7. errorTable = json;
  8. });
  9. var C3Json = $.getJSON("/BIM-Monitor/assets/json/c3-monitorList.json", function (json) {
  10. sites["c3"] = json;
  11. });
  12. var R03Json = $.getJSON("/BIM-Monitor/assets/json/r03-monitorList.json", function (json) {
  13. sites["r03"] = json;
  14. });
  15. $.ajaxSettings.async = true;
  16. var lastNode;
  17. var errorArray = [];
  18. var switchNumber = 0;
  19. passString('SIS');
  20. var wellTBA = [];
  21. var wellNameLists = [];
  22. var isAll = true;
  23. //var isCompare = false;
  24. //var saveCheckCompare = "";
  25. var dataTable;
  26. var sparklinePieData = [];
  27. $(document).ready(function () {
  28. GetCheckAllAJAXValue();
  29. LoadPage();
  30. $("#menu > ul > li.nav-parent.nav-active.nav-expanded > ul > li.nav-parent.nav-active.nav-expanded > ul > li:nth-child(1) > a").css("color", "#0088cc");
  31. $(".monitor").on('click', function () {
  32. $('.monitor').css('color', '#abb4be')
  33. let site = $(this).parent().parent().parent().attr("monitor");
  34. $(this).css("color", "#0088cc");
  35. if (site != 'r03') {
  36. location.href = `../${site}/Index.php`;
  37. } else {
  38. let option = $(this).attr("monitor");
  39. isAll = true;
  40. //isCompare = false;
  41. passString(option);
  42. document.getElementById("monitorName").innerHTML = option + "監測儀器";
  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選擇到一個監測儀器後,在selectWell.cs會給一個監測儀器名稱(例:OW-1)給網頁
  52. function GetWellName(wellName) {
  53. showWell(wellName, true);
  54. }
  55. //網頁用SendMessage()傳Initialization()給unity時,unity會回傳一個所有監測儀器名稱(例:OW-1,OW-2 ...)給網頁
  56. function GetWellNameList(wellNameList) {
  57. window.localStorage.setItem("wellNameList", wellNameList);
  58. }
  59. //display well name and send its name to showWell function
  60. function getEquipmentName(equipment) {
  61. $.ajaxSettings.async = false;
  62. $.ajax({
  63. url: '/BIM-Monitor/script/php/getEquipmentName.php',
  64. type: "GET",
  65. data: {
  66. equipment: equipment,
  67. }
  68. }).success(function (data) {
  69. GetWellNameList(data);
  70. }).error(function (error) {
  71. console.log("錯誤");
  72. });
  73. $.ajaxSettings.async = true;
  74. }
  75. //unity載入後會先跑LoadPage();
  76. function LoadPage() {
  77. var option = window.localStorage.getItem("option");
  78. getEquipmentName(option);
  79. $('#' + window.localStorage.getItem("option")).removeClass('hidden').removeAttr('disabled');
  80. document.getElementById("monitorSelect2").innerHTML = "選擇觀測儀器";
  81. var wellTBALocal = getCheckValue();
  82. var dataValue = option;
  83. for (i = 0; i < wellTBALocal.length; i++) {
  84. dataValue = dataValue.concat(',', wellTBALocal[i]);
  85. }
  86. if (isLoad) {
  87. //dataValue = 監測儀器代號,超出警戒值的儀器名稱
  88. //AddDataTable會存option:監測儀器代號(string)
  89. // abnormal:超出警戒值的儀器名稱(array)
  90. // gameObjects:所有監測儀器名稱(array)
  91. // optionGameObjects:包含監測儀器代號的所有監測儀器名稱(array)
  92. // 到unity的DataTable.cs裡面
  93. myGameInstance.SendMessage("Monitor", "AddDataTable", dataValue);
  94. //原本的模型牆被挖空,SID、RS、VG都有建各自的牆,若選擇一種監測儀器則另外兩種隱藏掉
  95. //addData(DataTable.option);
  96. //依照DataTable的option將所有optionGameObjects改成normal的顏色
  97. //Search(DataTable.option, DataTable.abnormal);
  98. //將所有abnormal的儀器改成abnormal的顏色
  99. myGameInstance.SendMessage("Monitor", "Initialization");
  100. }
  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. //isCompare = false;
  129. //$("#compareCheck").checked = false;
  130. strLocal = str;
  131. $("#monitorSelect2").innerHTML = strLocal;
  132. getTable(str);
  133. getChart(str, "myChart");
  134. if (isLoad) {
  135. //把現在選擇的儀器名稱(例:OW-1)傳到unity,unity找模型名稱相同的改變模型顏色以及鏡頭置中模型
  136. myGameInstance.SendMessage("MainCamera", "GetDataFromWebGL", str);
  137. }
  138. if (!changeCamera) {
  139. ResetCamera();
  140. }
  141. }
  142. function getTable(monitor) {
  143. $.ajax({
  144. url: '/BIM-Monitor/script/php/get_monitor_table.php',
  145. type: "GET",
  146. dataType: "JSON",
  147. data: {
  148. monitor: monitor
  149. }
  150. }).success(function (result) {
  151. let table = result.table;
  152. let unit = result.unit;
  153. let haveDepth = result.haveDepth;
  154. let haveDirection = result.haveDirection;
  155. var header = "";
  156. if (haveDepth) {
  157. for (i = 0; i < table[0].length - 1; i++) {
  158. head = i * 0.5;
  159. if (head == 0)
  160. head = "TOP";
  161. header += `<th>${head}</th>`;
  162. }
  163. } else if (haveDirection) {
  164. header = `<th>${monitor}(1~3向)</th><th>${monitor}(2~4向)</th>`;
  165. } else {
  166. header = `<th id="unit">測量值 單位:</th>`;
  167. }
  168. $("#tabData").empty();
  169. $("#tabData").append(`<table id="dataTable" class="display">
  170. <thead>
  171. <tr id="dataTableCol">
  172. <th>測量日期</th>
  173. ${header}
  174. </tr>
  175. </thead>
  176. <tbody id="table">
  177. </tbody>
  178. </table>`);
  179. dataTable = $('#dataTable').DataTable({
  180. bProcessing: true,
  181. responsive: true,
  182. "searching": true,
  183. "pageLength": 10,
  184. "language": {
  185. "processing": "處理中...",
  186. "loadingRecords": "載入中...",
  187. "lengthMenu": "顯示 _MENU_ 項結果",
  188. "zeroRecords": "沒有符合的結果或是沒有資料",
  189. "info": "顯示第 _START_ 至 _END_ 項結果,共 _TOTAL_ 項",
  190. "infoEmpty": "顯示第 0 至 0 項結果,共 0 項",
  191. "infoFiltered": "(從 _MAX_ 項結果中過濾)",
  192. "infoPostFix": "",
  193. "search": "",
  194. "paginate": {
  195. "first": '<i class="fa fa-step-backward"></i>',
  196. "previous": '<i class="fa fa-backward"></i>',
  197. "next": '<i class="fa fa-forward"></i>',
  198. "last": '<i class="fa fa-step-forward"></i>'
  199. },
  200. "aria": {
  201. "sortAscending": ": 升冪排列",
  202. "sortDescending": ": 降冪排列"
  203. }
  204. },
  205. });
  206. if (dataTable != null) {
  207. dataTable.clear();
  208. dataTable.draw();
  209. }
  210. if (monitor == '') {
  211. monitor = '查無監測儀器或';
  212. }
  213. $("#tableName").text(monitor + "資料表");
  214. $("#unit").text(`測量值(${unit})`);
  215. table.forEach(function (data) {
  216. dataTable.row.add(data)
  217. dataTable.draw();
  218. });
  219. }).error(function (error) {
  220. console.log(error);
  221. }).complete(function (e) {
  222. });
  223. }
  224. //建立pie chart
  225. function getCheckValue() {
  226. var dataArray = [];
  227. var option = window.localStorage.getItem("option");
  228. for (i = 0; i < errorTable.length; i++) {
  229. if (errorTable[i].table_name == option) {
  230. var method = errorTable[i].method;
  231. var table_name = errorTable[i].table_name + "data";
  232. var warning1 = errorTable[i].warning1;
  233. var warning2 = errorTable[i].warning2;
  234. var warning_Count = errorTable[i].warning_Count;
  235. }
  236. }
  237. $.ajax({
  238. url: "/BIM-Monitor/script/php/get_abnormal.php",
  239. data: {
  240. type:option
  241. },
  242. async: false,
  243. contentType: "application/json",
  244. dataType: "json"
  245. })
  246. .success(function (response) {
  247. console.log(response)
  248. dataArray = response['wellTBA'];
  249. var normal_count = response['normal_count'];
  250. var abnormal_count = response['abnormal_count'];
  251. sparklinePieData = [normal_count, abnormal_count];
  252. var all = normal_count + abnormal_count;
  253. var percent = abnormal_count / all;
  254. var url = "/BIM-Monitor/assets/javascripts/ui-elements/pie.charts.js";
  255. var script = document.createElement('script');
  256. script.setAttribute('type', 'text/javascript');
  257. script.setAttribute('src', url);
  258. document.getElementsByTagName('head')[0].appendChild(script);
  259. document.getElementById("percent").innerHTML = Math.round(percent * 100) + "%";
  260. })
  261. .error(function () {
  262. //alert("錯誤統計未正常獲取");
  263. })
  264. .complete(function () {});
  265. return dataArray;
  266. var dataArray = [];
  267. return dataArray;
  268. }
  269. //建立左側監測儀器(異常數量/總數量)
  270. function GetCheckAllAJAXValue() {
  271. errorArray = [];
  272. for (i = 0; i < sites["r03"].length; i++) {
  273. var option = sites["r03"][i].code;
  274. $.ajax({
  275. url: "/BIM-Monitor/script/php/get_abnormal.php",
  276. data: {
  277. type: option
  278. },
  279. async: false,
  280. contentType: "application/json",
  281. dataType: "json"
  282. })
  283. .success(function (response) {
  284. var normal_count = response['normal_count'];
  285. var abnormal_count = response['abnormal_count'];
  286. var all_count = 0 + normal_count + abnormal_count;
  287. console.log("option: " + option);
  288. $(`.${option}`).html("(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")");
  289. //document.getElementByName(option).innerHTML = "(<font color='#FF0000'>" + abnormal_count + "</font>/" + all_count + ")";
  290. errorArray.push(abnormal_count);
  291. })
  292. .error(function () {
  293. //alert("錯誤統計未正常獲取");
  294. })
  295. .complete(function () {});
  296. }
  297. }
  298. function CheckError() {
  299. var checkBox = document.getElementById("errorCheck");
  300. if (checkBox.checked == true) {
  301. isAll = false;
  302. } else {
  303. isAll = true;
  304. }
  305. SetList();
  306. }
  307. function get_json_file(file_path) {
  308. output = {};
  309. $.ajax({
  310. dataType: "json",
  311. url: file_path,
  312. }).done(function (data) {
  313. output = data;
  314. }).error(function (error) {
  315. console.log(error);
  316. });
  317. return output;
  318. }
  319. //Display chart
  320. function getChart(monitor) {
  321. type = monitor.split("-")[0];
  322. $.ajax({
  323. url: "/BIM-Monitor/script/php/get_monitor_chart.php",
  324. type: "GET",
  325. async: false,
  326. contentType: "application/json",
  327. dataType: "json",
  328. data: {
  329. monitor: monitor
  330. }
  331. }).done(function (response) {
  332. charts = response.chart;
  333. label = response.label;
  334. unit = response.unit;
  335. console.log(charts);
  336. displayChart(monitor, label, unit, charts);
  337. }).error(function (error) {
  338. console.log(error);
  339. });
  340. }
  341. function displayChart(monitor, label, unit, charts) {
  342. var ctx = document.getElementById("myChart").getContext("2d");
  343. var date = [];
  344. var data = [];
  345. var warning1 = [];
  346. var action1 = [];
  347. var warning2 = [];
  348. var action2 = [];
  349. var type = monitor.split("-")[0];
  350. var SIS_data = {};
  351. if (window.chart != undefined) {
  352. window.chart.destroy();
  353. }
  354. // console.log(charts);
  355. if (type == "SIS" || type == "SID") {
  356. SIS_data["depth"] = [];
  357. SIS_data["warning1"] = [];
  358. SIS_data["warning2"] = [];
  359. SIS_data["action1"] = [];
  360. SIS_data["action2"] = [];
  361. SIS_data["data"] = {};
  362. charts.forEach(element => {
  363. var sis_date = element["Date"];
  364. var sis_warning = element["WarningValue"].split("±")[1];
  365. var sis_action = element["ActionValue"].split("±")[1];
  366. delete element["Date"];
  367. delete element["WarningValue"];
  368. delete element["ActionValue"];
  369. var sis_data_length = Object.keys(element).length;
  370. SIS_data["data"][sis_date] = [];
  371. for (i = 1; i <= sis_data_length; i++) {
  372. SIS_data["data"][sis_date].push(element["" + i * 0.5]);
  373. if (SIS_data["depth"].length < sis_data_length) {
  374. SIS_data["depth"].push(i * 0.5);
  375. SIS_data["warning1"].push(+sis_warning);
  376. SIS_data["warning2"].push(-sis_warning);
  377. SIS_data["action1"].push(+sis_action);
  378. SIS_data["action2"].push(-sis_action);
  379. }
  380. }
  381. });
  382. console.log(SIS_data);
  383. var datasets = [{
  384. label: "警戒值+",
  385. data: SIS_data["warning1"],
  386. borderColor: "#FF0000",
  387. borderDash: [5, 5],
  388. pointRadius: 0
  389. }, {
  390. label: "警戒值-",
  391. data: SIS_data["warning2"],
  392. borderColor: "#FF0000",
  393. borderDash: [5, 5],
  394. pointRadius: 0
  395. }, {
  396. label: "行動值+",
  397. data: SIS_data["action1"],
  398. borderColor: "#FF0000",
  399. pointRadius: 0
  400. }, {
  401. label: "行動值-",
  402. data: SIS_data["action2"],
  403. borderColor: "#FF0000",
  404. pointRadius: 0
  405. }];
  406. Object.keys(SIS_data["data"]).forEach(element => {
  407. datasets.push({
  408. label: element,
  409. data: SIS_data["data"][element],
  410. borderColor: randomColorBlue(),
  411. pointRadius: 0
  412. });
  413. });
  414. console.log(datasets);
  415. window.chart = new Chart(ctx, {
  416. //Line chart
  417. type: 'line',
  418. data: {
  419. labels: SIS_data["depth"],
  420. datasets: datasets
  421. },
  422. options: {
  423. spanGaps: true,
  424. maintainAspectRatio: false,
  425. responsive: true,
  426. indexAxis: 'y',
  427. scales: {
  428. y: {
  429. title: {
  430. display: true,
  431. text: "觀測深度(m)"
  432. }
  433. },
  434. x: {
  435. title: {
  436. display: true,
  437. text: label + '(' + unit + ')'
  438. }
  439. }
  440. }
  441. }
  442. });
  443. } else {
  444. charts.forEach(function (chart) {
  445. Object.keys(chart).forEach(function (key) {
  446. if (key == "Date") {
  447. date.push(chart[key]);
  448. } else if (key.includes("WarningValue")) {
  449. let value = 0;
  450. if (chart[key].includes("±")) {
  451. value = chart[key].split("±")[1];
  452. warning1.push(+value);
  453. warning2.push(-value);
  454. }
  455. if (key.includes("High")) {
  456. warning1.push(chart[key]);
  457. } else if (key.includes("Low")) {
  458. warning2.push(chart[key]);
  459. }
  460. } else if (key.includes("ActionValue")) {
  461. let value = 0;
  462. if (chart[key].includes("±")) {
  463. value = chart[key].split("±")[1];
  464. action1.push(+value);
  465. action2.push(-value);
  466. }
  467. if (key.includes("High")) {
  468. action1.push(chart[key]);
  469. } else if (key.includes("Low")) {
  470. action2.push(chart[key]);
  471. }
  472. } else {
  473. data.push(chart[key]);
  474. }
  475. });
  476. })
  477. var datasets = [{
  478. label: "警戒值+",
  479. data: warning1,
  480. borderColor: "#FF0000",
  481. borderDash: [5, 5],
  482. pointRadius: 0
  483. }, {
  484. label: "警戒值-",
  485. data: warning2,
  486. borderColor: "#FF0000",
  487. borderDash: [5, 5],
  488. pointRadius: 0
  489. }, {
  490. label: "行動值+",
  491. data: action1,
  492. borderColor: "#FF0000",
  493. pointRadius: 0
  494. }, {
  495. label: "行動值-",
  496. data: action2,
  497. borderColor: "#FF0000",
  498. pointRadius: 0
  499. }];
  500. if (type == "TI") {
  501. var data1 = [];
  502. var data2 = [];
  503. for (i = 0; i < data.length; i += 2) {
  504. data1.push(data[i]);
  505. data2.push(data[i + 1]);
  506. }
  507. datasets.push({
  508. label: monitor + "(1-3)",
  509. data: data1,
  510. borderColor: "#3e95cd"
  511. });
  512. datasets.push({
  513. label: monitor + "(2-4)",
  514. data: data2,
  515. borderColor: "#000000"
  516. });
  517. } else {
  518. datasets.push({
  519. label: monitor,
  520. data: data,
  521. borderColor: "#3e95cd"
  522. });
  523. }
  524. window.chart = new Chart(ctx, {
  525. //Line chart
  526. type: 'line',
  527. data: {
  528. //X-axis displays the date
  529. labels: date,
  530. datasets: datasets
  531. },
  532. options: {
  533. spanGaps: true,
  534. maintainAspectRatio: false,
  535. responsive: true,
  536. scales: {
  537. x: {
  538. title: {
  539. display: true,
  540. text: "日期"
  541. }
  542. },
  543. y: {
  544. title: {
  545. display: true,
  546. text: label + '(' + unit + ')'
  547. }
  548. }
  549. }
  550. }
  551. });
  552. }
  553. }
  554. function ResetCamera() {
  555. if (isLoad) {
  556. myGameInstance.SendMessage("MainCamera", "ResetCamera");
  557. }
  558. }
  559. function SetList() {
  560. var wellNameListsLocal = "";
  561. var isError = false;
  562. var monitorSelect = document.getElementById("monitorSelect");
  563. var monitorButton = document.getElementById("monitorButton");
  564. while (monitorSelect.hasChildNodes()) {
  565. monitorSelect.removeChild(monitorSelect.firstChild);
  566. }
  567. while (monitorButton.hasChildNodes()) {
  568. monitorButton.removeChild(monitorButton.firstChild);
  569. }
  570. monitorButton.innerHTML = "綠色為正常|紅色為異常<br>";
  571. GetCheckAllAJAXValue();
  572. for (i = 0; i < wellNameLists.length; i++) {
  573. wellNameListsLocal = wellNameLists[i];
  574. var option = document.createElement("li");
  575. var createA = document.createElement("a");
  576. var createAText = document.createTextNode(wellNameListsLocal);
  577. var createButton = document.createElement("button");
  578. var createButtonText = document.createTextNode(wellNameListsLocal);
  579. createButton.setAttribute('class', "mb-xs mt-xs mr-xs modal-with-zoom-anim btn btn-success modal-dismiss");
  580. for (j = 0; j < wellTBA.length; j++) {
  581. if (wellNameLists[i] == (wellTBA[j])) {
  582. createA.style = "color:red;";
  583. createButton.setAttribute('class', "mb-xs mt-xs mr-xs btn btn-danger modal-dismiss");
  584. isError = true;
  585. }
  586. }
  587. createA.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  588. createButton.setAttribute('onclick', "showWell('" + wellNameLists[i] + "',true)");
  589. createButton.setAttribute('type', "button");
  590. if (isAll || (!isAll && isError)) {
  591. createA.appendChild(createAText);
  592. createButton.appendChild(createButtonText);
  593. option.appendChild(createA);
  594. monitorSelect.appendChild(option);
  595. monitorButton.appendChild(createButton);
  596. }
  597. isError = false;
  598. }
  599. }
  600. function UpdateGPS(GPS) {
  601. if (isLoad) {
  602. myGameInstance.SendMessage("PlayerArmature", "UpdateGPS", GPS);
  603. }
  604. }
  605. //Start making the chart
  606. function init(c_wellName, c_m_date, c_m_value, elementID) {
  607. var ctx = document.getElementById(elementID).getContext("2d");
  608. var ELPwarning = [0, -4.6, -10, -15.3, -23.2, 0];
  609. var ELP_1warning = [0, -7.9, -13.3, 0, 0, 0];
  610. //Warning value
  611. let warning = [];
  612. var OWFirstData = {
  613. "OW-1": -1.81,
  614. "OW-2": -1.59,
  615. "OW-3": -6.3,
  616. "OW-4": -3.67,
  617. "OW-5": -3.16,
  618. "OW-6": -1.78,
  619. "OW-7": -3.31
  620. };
  621. var OWwarning1 = 0;
  622. var OWwarning2 = 0;
  623. var yLabel = "";
  624. var xLabel = "";
  625. if (c_wellName.includes("ELP")) {
  626. yLabel = "水位高程GL(m)";
  627. xLabel = "日期";
  628. } else if (c_wellName.includes("OW")) {
  629. for (const [key, value] of Object.entries(OWFirstData)) {
  630. if (c_wellName == key) {
  631. OWwarning1 = value + 2;
  632. OWwarning2 = value - 2;
  633. }
  634. }
  635. for (i = 0; i < c_m_date.length; i++) {
  636. warning.push(OWwarning1);
  637. }
  638. yLabel = "水位高程GL(m)";
  639. xLabel = "日期";
  640. } else if (c_wellName.includes("SM")) {
  641. for (i = 0; i < c_m_date.length; i++) {
  642. warning.push(45);
  643. }
  644. yLabel = "沉陷量(mm)";
  645. xLabel = "日期";
  646. } else if (c_wellName.includes("SBM")) {
  647. for (i = 0; i < c_m_date.length; i++) {
  648. warning.push(9.5);
  649. }
  650. yLabel = "沉陷量(mm)";
  651. xLabel = "日期";
  652. } else if (c_wellName.includes("SB")) {
  653. for (i = 0; i < c_m_date.length; i++) {
  654. warning.push(0.0008);
  655. }
  656. yLabel = "沉陷量(mm)";
  657. xLabel = "日期";
  658. } else if (c_wellName.includes("VG")) {
  659. for (i = 0; i < c_m_date.length; i++) {
  660. warning.push(110);
  661. }
  662. yLabel = "應力值(t)";
  663. xLabel = "日期";
  664. } else if (c_wellName.includes("HM")) {
  665. for (i = 0; i < c_m_date.length; i++) {
  666. warning.push(25);
  667. }
  668. yLabel = "沉陷量(mm)";
  669. xLabel = "日期";
  670. }
  671. for (j = 0; j < c_m_value.length; j++) {
  672. if (c_m_value[j] == "") {
  673. c_m_value[j] = null;
  674. }
  675. }
  676. //Destroy chart if it already exists. If not, there'll be multiple charts stack together
  677. if (window.chart != undefined) {
  678. window.chart.destroy();
  679. }
  680. window.chart = new Chart(ctx, {
  681. //Line chart
  682. type: 'line',
  683. data: {
  684. //X-axis displays the date
  685. labels: c_m_date,
  686. datasets: [{
  687. //Label above the chart to illustrate which color has which purpose
  688. label: c_wellName,
  689. //Data value
  690. data: c_m_value,
  691. //Detemine line's color
  692. borderColor: '#3e95cd'
  693. },
  694. {
  695. label: "警戒值",
  696. data: warning,
  697. borderColor: "#FF0000",
  698. pointRadius: 0
  699. }
  700. ]
  701. },
  702. options: {
  703. spanGaps: true,
  704. maintainAspectRatio: false,
  705. responsive: true,
  706. scales: {
  707. y: {
  708. title: {
  709. display: true,
  710. text: yLabel
  711. }
  712. },
  713. x: {
  714. title: {
  715. display: true,
  716. text: xLabel
  717. }
  718. }
  719. }
  720. }
  721. });
  722. if (c_wellName.includes("SBM")) {
  723. let warning2 = [];
  724. for (i = 0; i < c_m_date.length; i++) {
  725. warning2.push(-9.5);
  726. }
  727. window.chart.data.datasets.push({
  728. label: "警戒值2",
  729. data: warning2,
  730. borderColor: "#FF0000",
  731. pointRadius: 0
  732. });
  733. window.chart.update();
  734. } else if (c_wellName.includes("SB")) {
  735. let warning2 = [];
  736. for (i = 0; i < c_m_date.length; i++) {
  737. warning2.push(-0.0008);
  738. }
  739. window.chart.data.datasets.push({
  740. label: "警戒值2",
  741. data: warning2,
  742. borderColor: "#FF0000",
  743. pointRadius: 0
  744. });
  745. window.chart.update();
  746. } else if (c_wellName.includes("OW")) {
  747. let warning2 = [];
  748. for (i = 0; i < c_m_date.length; i++) {
  749. warning2.push(OWwarning2);
  750. }
  751. window.chart.data.datasets.push({
  752. label: "警戒值2",
  753. data: warning2,
  754. borderColor: "#FF0000",
  755. pointRadius: 0
  756. });
  757. window.chart.update();
  758. }
  759. }
  760. function init2(c_wellName, c_m_date, c_m_value, c2_wellName, c2_m_date, c2_m_value, elementID) {
  761. var ctx = document.getElementById(elementID).getContext("2d");
  762. var yLabel = "";
  763. var xLabel = "";
  764. let warning = [];
  765. if (c_wellName.includes("TI")) {
  766. for (i = 0; i < c2_m_date.length; i++) {
  767. warning.push(0.00106);
  768. }
  769. yLabel = "徑度量(δ/ L)";
  770. xLabel = "日期";
  771. }
  772. for (j = 0; j < c_m_value.length; j++) {
  773. if (c_m_value[j] == "") {
  774. c_m_value[j] = null;
  775. }
  776. }
  777. if (window.chart != undefined) {
  778. window.chart.destroy();
  779. }
  780. c_m_value.forEach(function (item, index, array) {
  781. });
  782. window.chart = new Chart(ctx, {
  783. type: 'line',
  784. data: {
  785. labels: c_m_date,
  786. datasets: [{
  787. label: c_wellName,
  788. data: c_m_value,
  789. borderColor: '#3e95cd'
  790. },
  791. {
  792. label: c2_wellName,
  793. data: c2_m_value,
  794. borderColor: '#63fff5'
  795. }
  796. ]
  797. },
  798. options: {
  799. responsive: true,
  800. maintainAspectRatio: false,
  801. scales: {
  802. y: {
  803. title: {
  804. display: true,
  805. text: yLabel
  806. }
  807. },
  808. x: {
  809. title: {
  810. display: true,
  811. text: xLabel
  812. }
  813. }
  814. }
  815. }
  816. });
  817. //ELP does not have second warning line, so you need to update it seperately
  818. if (c_wellName.includes("TI")) {
  819. let warning2 = [];
  820. for (i = 0; i < c2_m_date.length; i++) {
  821. warning2.push(-0.00106);
  822. }
  823. window.chart.data.datasets.push({
  824. label: "警戒值2",
  825. data: warning2,
  826. borderColor: "#FF0000",
  827. pointRadius: 0
  828. });
  829. window.chart.update();
  830. }
  831. }
  832. //SIS SID's lines are vertical
  833. function initSISSID(c_m_date, c_m_depth, c_m_value, elementID, str) {
  834. var ctx = document.getElementById(elementID).getContext("2d");
  835. var datasetValue = [];
  836. let warning = [];
  837. var SID_data = [];
  838. var SIS_data = [];
  839. var SIS_array = ['SIS-1', 'SIS-2-1', 'SIS-2-2', 'SIS-3', 'SIS-4', 'SIS-6', 'SIS-7'];
  840. 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'];
  841. var index = 0;
  842. var num = 0;
  843. SID_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.698, 1.698, 1.186, 1.186, 1.032];
  844. SIS_data = [1.85, 1.128, 1.128, 1.128, 1.698, 1.186, 1.032];
  845. if (str.includes("SIS")) {
  846. index = SIS_array.indexOf(str);
  847. num = SIS_data[index];
  848. } else if (str.includes("SID")) {
  849. index = SID_array.indexOf(str);
  850. num = SID_data[index];
  851. }
  852. for (i = 0; i < c_m_value[0].length; i++) {
  853. warning.push(num);
  854. }
  855. yLabel = "觀測深度GL(m)";
  856. xLabel = "變位量(cm)";
  857. for (j = 0; j < c_m_value.length; j++) {
  858. if (c_m_value[j] == "") {
  859. c_m_value[j] = null;
  860. }
  861. }
  862. if (window.chart != undefined) {
  863. window.chart.destroy();
  864. }
  865. for (j = 0; j <= c_m_date.length; j++) {
  866. if (j == c_m_date.length) {
  867. datasetValue[j] = {
  868. axis: 'y',
  869. fill: false,
  870. label: "警戒值",
  871. data: warning,
  872. borderColor: "#FF0000",
  873. pointRadius: 0
  874. }
  875. } else {
  876. datasetValue[j] = {
  877. axis: 'y',
  878. label: c_m_date[j],
  879. data: c_m_value[j],
  880. borderColor: randomColor()
  881. }
  882. }
  883. }
  884. window.chart = new Chart(ctx, {
  885. type: 'line',
  886. data: {
  887. labels: c_m_depth,
  888. datasets: datasetValue
  889. },
  890. options: {
  891. //Turns line to vertical
  892. maintainAspectRatio: false,
  893. responsive: true,
  894. indexAxis: 'y',
  895. scales: {
  896. y: {
  897. title: {
  898. display: true,
  899. text: yLabel
  900. }
  901. },
  902. x: {
  903. beginAtZero: true,
  904. title: {
  905. display: true,
  906. text: xLabel
  907. }
  908. }
  909. }
  910. }
  911. });
  912. }
  913. 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) {
  914. var ctx = document.getElementById(elementID).getContext("2d");
  915. let warning = [];
  916. if (c_wellName.includes("RS")) {
  917. for (i = 0; i < c_m_date.length; i++) {
  918. warning.push(2000);
  919. }
  920. yLabel = "應力值(kg/cm²)";
  921. xLabel = "日期";
  922. }
  923. if (window.chart != undefined) {
  924. window.chart.destroy();
  925. }
  926. window.chart = new Chart(ctx, {
  927. type: 'line',
  928. data: {
  929. labels: c_m_date,
  930. datasets: [{
  931. label: c_wellName,
  932. data: c_m_value,
  933. borderColor: randomColor()
  934. },
  935. {
  936. label: c2_wellName,
  937. data: c2_m_value,
  938. borderColor: randomColor()
  939. },
  940. {
  941. label: c3_wellName,
  942. data: c3_m_value,
  943. borderColor: randomColor()
  944. },
  945. {
  946. label: c4_wellName,
  947. data: c4_m_value,
  948. borderColor: randomColor()
  949. },
  950. {
  951. label: c5_wellName,
  952. data: c5_m_value,
  953. borderColor: randomColor()
  954. },
  955. {
  956. label: c6_wellName,
  957. data: c6_m_value,
  958. borderColor: randomColor()
  959. },
  960. {
  961. label: "警戒值",
  962. data: warning,
  963. borderColor: "#FF0000",
  964. pointRadius: 0
  965. }
  966. ]
  967. },
  968. options: {
  969. responsive: true,
  970. maintainAspectRatio: false,
  971. scales: {
  972. y: {
  973. title: {
  974. display: true,
  975. text: yLabel
  976. }
  977. },
  978. x: {
  979. title: {
  980. display: true,
  981. text: xLabel
  982. }
  983. }
  984. }
  985. }
  986. });
  987. //ELP does not have second warning line, so you need to update it seperately
  988. if (c_wellName.includes("RS")) {
  989. let warning2 = [];
  990. for (i = 0; i < c_m_date.length; i++) {
  991. warning2.push(-2000);
  992. }
  993. window.chart.data.datasets.push({
  994. label: "警戒值2",
  995. data: warning2,
  996. borderColor: "#FF0000",
  997. pointRadius: 0
  998. });
  999. window.chart.update();
  1000. }
  1001. }
  1002. //Chart has multiple lines that need different color
  1003. function randomColor() {
  1004. return "#" + ((1 << 24) * Math.random() | 0).toString(16);
  1005. }
  1006. function randomColorBlue() {
  1007. var mid = Math.floor(Math.random() * 255);
  1008. return "#30" + mid.toString(16) + "ff";
  1009. }
  1010. //Need to display multiple epuiment's data table and can't find the function to reset it. So I kill all the nodes.
  1011. function reset() {
  1012. const myNode = document.getElementById("tabData");
  1013. while (myNode.firstChild) {
  1014. myNode.removeChild(myNode.lastChild);
  1015. }
  1016. var table = document.createElement("table");
  1017. table.id = "dataTable";
  1018. table.className = "display";
  1019. myNode.appendChild(table);
  1020. }