Skip to content

Commit 14d6645

Browse files
committed
Changed jquery to vue in combinationalanalysis
1 parent 3e895dd commit 14d6645

File tree

1 file changed

+92
-66
lines changed

1 file changed

+92
-66
lines changed

src/components/DialogBox/CombinationalAnalysis.vue

+92-66
Original file line numberDiff line numberDiff line change
@@ -214,64 +214,114 @@ function createLogicTable() {
214214
}
215215
}
216216
217+
function printBooleanTable() {
218+
// Create a new div to hold the table content
219+
const tableContent = document.createElement('div')
220+
tableContent.innerHTML = tableHeader.value.map((header, index) => `
221+
<tr>
222+
<th>${header}</th>
223+
</tr>
224+
`).join('') +
225+
tableBody.value.map(row => `
226+
<tr>
227+
${row.map(cell => `<td>${cell}</td>`).join('')}
228+
</tr>
229+
`).join('')
230+
231+
const style = `
232+
<style>
233+
table {font: 40px Calibri;}
234+
table, th, td {border: solid 1px #DDD; border-collapse: collapse;}
235+
tbody {padding: 2px 3px; text-align: center;}
236+
</style>
237+
`.replace(/\n/g, '')
238+
239+
const win = window.open('', '', 'height=700,width=700')
240+
if (win) {
241+
const htmlBody = `
242+
<html>
243+
<head>
244+
<title>Boolean Logic Table</title>
245+
${style}
246+
</head>
247+
<body>
248+
<center>
249+
<table>
250+
${tableContent.innerHTML}
251+
</table>
252+
</center>
253+
</body>
254+
</html>
255+
`
256+
win.document.write(htmlBody)
257+
win.document.close()
258+
win.print()
259+
}
260+
}
261+
217262
function createBooleanPrompt(inputList, outputList, scope = globalScope) {
218-
inputListNames.value =
219-
inputList || prompt('Enter inputs separated by commas').split(',')
220-
outputListNames.value =
221-
outputList || prompt('Enter outputs separated by commas').split(',')
263+
inputListNames.value = inputList || prompt('Enter inputs separated by commas')?.split(',') || []
264+
outputListNames.value = outputList || prompt('Enter outputs separated by commas')?.split(',') || []
265+
222266
if (output.value == null) {
223-
for (var i = 0; i < outputListNames.value.length; i++) {
224-
outputListNamesInteger.value[i] = 7 * i + 13
225-
} // assigning an integer to the value, 7*i + 13 is random
267+
outputListNamesInteger.value = outputListNames.value.map((_, i) => 7 * i + 13)
226268
} else {
227269
outputListNamesInteger.value = [13]
228270
}
271+
272+
// Reset table data
229273
tableBody.value = []
230274
tableHeader.value = []
231-
let fw = 0
232-
if (inputArr.value[4].val == true) {
233-
fw = 1
275+
276+
// Add decimal column if checkbox is checked
277+
let columnOffset = 0
278+
if (inputArr.value[4].val === true) {
279+
columnOffset = 1
234280
tableHeader.value.push('dec')
235281
}
236-
for (var i = 0; i < inputListNames.value.length; i++) {
237-
tableHeader.value.push(inputListNames.value[i])
238-
}
282+
283+
// Add input headers
284+
inputListNames.value.forEach(name => {
285+
tableHeader.value.push(name)
286+
})
287+
288+
// Add output headers
239289
if (output.value == null) {
240-
for (var i = 0; i < outputListNames.value.length; i++) {
241-
tableHeader.value.push(outputListNames.value[i])
242-
}
290+
outputListNames.value.forEach(name => {
291+
tableHeader.value.push(name)
292+
})
243293
} else {
244294
tableHeader.value.push(outputListNames.value)
245295
}
246296
247-
for (var i = 0; i < 1 << inputListNames.value.length; i++) {
248-
tableBody.value[i] = new Array(tableHeader.value.length)
249-
}
250-
for (var i = 0; i < inputListNames.value.length; i++) {
251-
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
252-
tableBody.value[j][i + fw] = +(
253-
(j & (1 << (inputListNames.value.length - i - 1))) !=
254-
0
255-
)
256-
}
257-
}
258-
if (inputArr.value[4].val == true) {
259-
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
260-
tableBody.value[j][0] = j
261-
}
262-
}
263-
for (var j = 0; j < 1 << inputListNames.value.length; j++) {
264-
for (var i = 0; i < outputListNamesInteger.value.length; i++) {
265-
if (output.value == null) {
266-
tableBody.value[j][inputListNames.value.length + fw + i] = 'x'
267-
}
297+
// Generate table body
298+
const rowCount = 1 << inputListNames.value.length
299+
tableBody.value = Array(rowCount).fill(null).map((_, rowIndex) => {
300+
const row = new Array(tableHeader.value.length).fill(null)
301+
302+
// Add decimal column if needed
303+
if (columnOffset) {
304+
row[0] = rowIndex
268305
}
269-
if (output.value != null) {
270-
tableBody.value[j][inputListNames.value.length + fw] =
271-
output.value[j]
306+
307+
// Add input columns
308+
inputListNames.value.forEach((_, colIndex) => {
309+
row[colIndex + columnOffset] = +((rowIndex & (1 << (inputListNames.value.length - colIndex - 1))) !== 0)
310+
})
311+
312+
// Add output columns
313+
if (output.value == null) {
314+
outputListNamesInteger.value.forEach((_, i) => {
315+
row[inputListNames.value.length + columnOffset + i] = 'x'
316+
})
317+
} else {
318+
row[inputListNames.value.length + columnOffset] = output.value[rowIndex]
272319
}
273-
}
274-
// display Message Box
320+
321+
return row
322+
})
323+
324+
// Update UI
275325
SimulatorState.dialogBox.combinationalanalysis_dialog = true
276326
buttonArr.value = [
277327
{
@@ -284,30 +334,6 @@ function createBooleanPrompt(inputList, outputList, scope = globalScope) {
284334
},
285335
]
286336
}
287-
288-
function printBooleanTable() {
289-
var sTable = $('.messageBox .v-card-text')[0].innerHTML
290-
291-
var style =
292-
`<style>
293-
table {font: 40px Calibri;}
294-
table, th, td {border: solid 1px #DDD;border-collapse: 0;}
295-
tbody {padding: 2px 3px;text-align: center;}
296-
</style>`.replace(/\n/g, "")
297-
var win = window.open('', '', 'height=700,width=700')
298-
var htmlBody = `
299-
<html><head>\
300-
<title>Boolean Logic Table</title>\
301-
${style}\
302-
</head>\
303-
<body>\
304-
<center>${sTable}</center>\
305-
</body></html>
306-
`
307-
win.document.write(htmlBody)
308-
win.document.close()
309-
win.print()
310-
}
311337
</script>
312338

313339
<style scoped>

0 commit comments

Comments
 (0)