@@ -49,6 +49,7 @@ document.addEventListener("DOMContentLoaded", () => {
4949 var checkbox = document . createElement ( "input" ) ;
5050 checkbox . type = "checkbox" ;
5151 checkbox . checked = true ;
52+
5253 cell0 . appendChild ( checkbox ) ;
5354
5455 //Actural depth
@@ -79,7 +80,7 @@ document.addEventListener("DOMContentLoaded", () => {
7980 document . getElementById ( "directionOptions" ) . addEventListener ( "change" , async ( event ) => {
8081
8182 //get data
82- let targetData = getTableData ( "target_table" ) ;
83+ let [ targetData ] = getTableData ( "target_table" ) ;
8384
8485 if ( event . target . value == "actual2definition" ) {
8586 calcDirection = "act->def" ;
@@ -206,7 +207,7 @@ document.addEventListener("DOMContentLoaded", () => {
206207 type :"number" ,
207208 } ;
208209 let start = parseFloat ( await window . DividerApi . inputdialog ( askData ) ) ;
209- console . log ( start )
210+
210211 if ( isNaN ( start ) ) {
211212 return ;
212213 }
@@ -303,7 +304,6 @@ document.addEventListener("DOMContentLoaded", () => {
303304 distUpper = distLower ;
304305 distLower = resultLower . distance ;
305306 }
306- console . log ( distUpper , distLower )
307307
308308 i += 1 ;
309309 }
@@ -312,7 +312,7 @@ document.addEventListener("DOMContentLoaded", () => {
312312 var table = document . getElementById ( "target_body" ) ;
313313
314314 //make new row
315- console . log ( calcDirection )
315+ // console.log(calcDirection)
316316 for ( let i = 0 ; i < targetLists . length ; i ++ ) {
317317 var row = table . insertRow ( ) ;
318318 const target = targetLists [ i ] ;
@@ -597,6 +597,7 @@ document.addEventListener("DOMContentLoaded", () => {
597597 //get depth definition data from table
598598 var table = document . getElementById ( "depth_table" ) ;
599599 var rows = table . rows ;
600+
600601 //plot section
601602 const section_height = parseFloat ( rows [ rows . length - 1 ] . cells [ 2 ] . innerText ) - parseFloat ( rows [ 1 ] . cells [ 2 ] . innerText ) ;
602603 const plot_height_rate = canvas . height / ( section_height + padding_top * 2 ) ;
@@ -688,8 +689,8 @@ document.addEventListener("DOMContentLoaded", () => {
688689 const graphW = graphH ;
689690
690691 // --- extract data and compute ranges ---
691- const defs = rowsData . map ( r => parseFloat ( r . cells [ 2 ] . innerText ) ) . filter ( v => ! isNaN ( v ) ) ;
692- const acts = rowsData . map ( r => parseFloat ( r . cells [ 3 ] . innerText ) ) . filter ( v => ! isNaN ( v ) ) ;
692+ const defs = rowsData . filter ( r => r . cells [ 0 ] . querySelector ( 'input[type="checkbox"]' ) ?. checked ) . map ( r => parseFloat ( r . cells [ 2 ] . innerText ) ) . filter ( v => ! isNaN ( v ) ) ;
693+ const acts = rowsData . filter ( r => r . cells [ 0 ] . querySelector ( 'input[type="checkbox"]' ) ?. checked ) . map ( r => parseFloat ( r . cells [ 3 ] . innerText ) ) . filter ( v => ! isNaN ( v ) ) ;
693694 const targetTable = document . getElementById ( "target_table" ) ;
694695 const targetRows = Array . from ( targetTable . tBodies [ 0 ] . rows ) ;
695696 const targetActsUpper = targetRows . map ( r => parseFloat ( r . cells [ 2 ] . innerText ) ) . filter ( v => ! isNaN ( v ) ) ;
@@ -870,17 +871,23 @@ document.addEventListener("DOMContentLoaded", () => {
870871 const table = document . getElementById ( targetName ) ;
871872 const tbody = table . querySelector ( "tbody" ) ;
872873 const rows = Array . from ( tbody . rows ) ;
873- const data = rows . map ( row => {
874- return Array . from ( row . cells ) . map ( cell => {
875- const checkbox = cell . querySelector ( 'input[type="checkbox"]' ) ;
876- if ( checkbox ) {
877- return checkbox . checked ;
878- }
879- const text = cell . innerText . trim ( ) ;
880- return text === "" ? null : text ;
881- } ) ;
882- } ) ;
883- return data ;
874+ const data = rows
875+ . map ( ( row , idx ) => {
876+ if ( ! row . querySelector ( 'input[type="checkbox"]' ) ?. checked ) return null ;
877+ return {
878+ index : idx ,
879+ values : Array . from ( row . cells ) . map ( ( cell , i ) => {
880+ if ( i === 0 ) {
881+ return true ; // checked
882+ }
883+
884+ const text = cell . innerText . trim ( ) ;
885+ return text === "" ? null : text ;
886+ } )
887+ } ;
888+ } ) . filter ( v => v !== null ) ;
889+
890+ return [ data . map ( v => v . values ) , data . map ( v => v . index ) ]
884891 }
885892 function updateTableCell ( tableId , rowIndex , colIndex , value , editable = false ) {
886893 const table = document . getElementById ( tableId ) ;
@@ -942,9 +949,9 @@ document.getElementById("definition_lower").addEventListener("click", () => {
942949 //-------------------------------------------------------------------------------------------
943950document . getElementById ( "calcButton" ) . addEventListener ( "click" , ( ) => {
944951 //get data
945- let targetData = getTableData ( "target_table" ) ;
952+ const [ targetData , targetIdx ] = getTableData ( "target_table" ) ;
946953 //const filteredTargetData = targetData.filter(row => row[0]===true);
947- let depthData = getTableData ( "depth_table" ) ;
954+ const [ depthData ] = getTableData ( "depth_table" ) ;
948955
949956 if ( targetData . length == 0 || depthData . length == 0 ) return ;
950957
@@ -954,15 +961,15 @@ document.getElementById("calcButton").addEventListener("click", () => {
954961 } ) ;
955962 depthData . sort ( ( item1 , item2 ) => {
956963 return parseFloat ( item1 [ 1 ] ) - parseFloat ( item2 [ 1 ] ) ;
957- } ) ;
964+ } ) ; 4
958965
959966 //get hole/section data
960967 const holeIdx = document . getElementById ( "holeOptions" ) . value ;
961968 const sectionIdx = document . getElementById ( "sectionOptions" ) . value ;
962969
963970 const holeId = holeList [ holeIdx ] [ 1 ] ;
964971 const secId = sectionList [ holeIdx ] [ sectionIdx ] [ 1 ] ;
965-
972+
966973 //calc main
967974 let resultList = window . DividerApi . dividerConverter ( [ holeId , secId , depthData ] , targetData , calcDirection ) ;
968975 console . log ( "[divider]: calced results" , resultList ) ;
@@ -971,44 +978,39 @@ document.getElementById("calcButton").addEventListener("click", () => {
971978 return
972979 }
973980
974- //for plot
975- interpolatedData = resultList ;
981+ //for counts
982+ const table = document . getElementById ( "target_table" ) ;
983+ const tbody = table . querySelector ( "tbody" ) ;
984+ const rows = Array . from ( tbody . rows ) ;
976985
977986 //apply table
978- for ( let i = 0 ; i < resultList . length ; i ++ ) {
979- const result = resultList [ i ] ;
980-
981- updateTableCell ( "target_table" , i , 1 , result . name ) ; //name
982- updateTableCell ( "target_table" , i , 2 , result . actual_distance_upper == null ? NaN : Math . round ( result . actual_distance_upper * 10 ) / 10 ) ; //actural upper
983- updateTableCell ( "target_table" , i , 3 , result . actual_distance_lower == null ? NaN : Math . round ( result . actual_distance_lower * 10 ) / 10 ) ; //actural lower
984- updateTableCell ( "target_table" , i , 4 , result . definition_distance_upper == null ? NaN : Math . round ( result . definition_distance_upper * 10 ) / 10 ) ; //definition upper
985- updateTableCell ( "target_table" , i , 5 , result . definition_distance_lower == null ? NaN : Math . round ( result . definition_distance_lower * 10 ) / 10 ) ; //definition lower
986- updateTableCell ( "target_table" , i , 6 , result . age_mid_upper == null ? NaN : Math . round ( result . age_mid_upper * 10 ) / 10 ) ; //age upper
987- updateTableCell ( "target_table" , i , 7 , result . age_mid_lower == null ? NaN : Math . round ( result . age_mid_lower * 10 ) / 10 ) ; //age lower
988- updateTableCell ( "target_table" , i , 8 , result . calc_type_upper + "/" + result . calc_type_lower ) ; //polation type
989-
990- /*
991- name: targetRowData[0],
992- project: depthList[0].project_name,
993- hole: depthList[0].hole_name,
994- section: depthList[0].section_name,
995- definition_distance_lower:null,
996- definition_distance_upper:null,
997- definition_cd_upper: null,
998- definition_cd_lower: null,
999- definition_efd_upper: null,
1000- definition_efd_lower: null,
1001- target_distance_lower: parseFloat(targetRowData[2]),
1002- target_distance_upper: parseFloat(targetRowData[1]),
1003- age_mid_lower:null,
1004- age_mid_upper:null,
1005- age_upper_lower:null,
1006- age_upper_upper:null,
1007- age_lower_lower:null,
1008- age_lower_upper:null,
1009- calc_type_upper: null,
1010- calc_type_lower: null
1011- */
987+ for ( let i = 0 ; i < rows . length ; i ++ ) {
988+ if ( targetIdx . includes ( i ) ) {
989+ const idx = targetIdx . indexOf ( i ) ;
990+ const result = resultList [ idx ] ;
991+
992+ updateTableCell ( "target_table" , targetIdx [ idx ] , 1 , result . name ) ; //name
993+ updateTableCell ( "target_table" , targetIdx [ idx ] , 2 , result . actual_distance_upper == null ? NaN : Math . round ( result . actual_distance_upper * 10 ) / 10 ) ; //actural upper
994+ updateTableCell ( "target_table" , targetIdx [ idx ] , 3 , result . actual_distance_lower == null ? NaN : Math . round ( result . actual_distance_lower * 10 ) / 10 ) ; //actural lower
995+ updateTableCell ( "target_table" , targetIdx [ idx ] , 4 , result . definition_distance_upper == null ? NaN : Math . round ( result . definition_distance_upper * 10 ) / 10 ) ; //definition upper
996+ updateTableCell ( "target_table" , targetIdx [ idx ] , 5 , result . definition_distance_lower == null ? NaN : Math . round ( result . definition_distance_lower * 10 ) / 10 ) ; //definition lower
997+ updateTableCell ( "target_table" , targetIdx [ idx ] , 6 , result . age_mid_upper == null ? NaN : Math . round ( result . age_mid_upper * 10 ) / 10 ) ; //age upper
998+ updateTableCell ( "target_table" , targetIdx [ idx ] , 7 , result . age_mid_lower == null ? NaN : Math . round ( result . age_mid_lower * 10 ) / 10 ) ; //age lower
999+ updateTableCell ( "target_table" , targetIdx [ idx ] , 8 , result . calc_type_upper + "/" + result . calc_type_lower ) ; //polation type
1000+ } else {
1001+ //delete data
1002+ //updateTableCell("target_table", i, 1, result.name); //name
1003+ if ( calcDirection == "def->act" ) {
1004+ updateTableCell ( "target_table" , i , 2 , null ) ; //age upper
1005+ updateTableCell ( "target_table" , i , 3 , null ) ; //age lower
1006+ } else if ( calcDirection == "act->def" ) {
1007+ updateTableCell ( "target_table" , i , 4 , null ) ; //age upper
1008+ updateTableCell ( "target_table" , i , 5 , null ) ; //age lower
1009+ }
1010+ updateTableCell ( "target_table" , i , 6 , null ) ; //age upper
1011+ updateTableCell ( "target_table" , i , 7 , null ) ; //age lower
1012+ updateTableCell ( "target_table" , i , 8 , null ) ; //polation type
1013+ }
10121014 }
10131015
10141016 updatePlot ( ) ;
0 commit comments