提交 f9eb7c25 编写于 作者: K Kevin Nadro

progress on generating javascript code

got the logger to print the javascript code now
上级 3b2ec688
...@@ -676,4 +676,5 @@ input[type=number]::-webkit-outer-spin-button { ...@@ -676,4 +676,5 @@ input[type=number]::-webkit-outer-spin-button {
.inputField{ .inputField{
width: 16px; width: 16px;
border: 0;
} }
...@@ -139,8 +139,14 @@ ...@@ -139,8 +139,14 @@
<input id="numColumns" type="number" value="5"> <input id="numColumns" type="number" value="5">
</div> </div>
<div>
Tracer Name:
<input id="tracerName" type="text" value="default">
</div>
<div> <div>
<button id="button-2DMatrix">Create 2DMatrix</button> <button id="button-2DMatrix">Create 2DMatrix</button>
<button id="button-generateJS">Generate Javascript</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -12,6 +12,10 @@ const getNumColumns = () => { ...@@ -12,6 +12,10 @@ const getNumColumns = () => {
return column_field.value; return column_field.value;
}; };
const getTracerName = () =>{
return document.getElementById("tracerName").value;
}
const fauxData = (r, c) => { const fauxData = (r, c) => {
var arr = new Array(r); var arr = new Array(r);
for (var i = 0; i < c; i++) { for (var i = 0; i < c; i++) {
...@@ -46,21 +50,36 @@ const makeInputFields = () =>{ ...@@ -46,21 +50,36 @@ const makeInputFields = () =>{
}; };
const generateJS = () =>{ const generateJS = (logger) =>{
var logger = new modules.LogTracer('Generated Javascript'); logger.clear();
var table = document.querySelector('.mtbl-table'); var table = document.querySelector('.mtbl-table');
var numRows = table.childNodes.length; var numRows = table.childNodes.length;
var numColumns = table.childNodes[0].childNodes.length; var numColumns = table.childNodes[0].childNodes.length;
logger.print('Copy and paste this code in your data.js file!');
logger.print('');
logger.print('let myTable = [');
var line = ''; var line = '';
for(var i = 0; i < numRows; i++){ var i;
line = ''; var j;
for(var j = 0; j < numColumns; j++){ var comma = ',';
for(i = 0; i < numRows; i++){
line = '[';
for(j = 0; j < numColumns-1; j++){
line += table.childNodes[i].childNodes[j].childNodes[0].value + ','; line += table.childNodes[i].childNodes[j].childNodes[0].value + ',';
} }
if(i === numRows - 1){comma = '';}
line += table.childNodes[i].childNodes[j++].childNodes[0].value + ']' + comma;
logger.print(line); logger.print(line);
} }
logger.print(']');
logger.print("let myTableTracer = new Array2DTracer ('"+getTracerName()+"')");
logger.print('myTableTracer._setData (myTable)');
}; };
...@@ -86,16 +105,24 @@ const positionModules = () =>{ ...@@ -86,16 +105,24 @@ const positionModules = () =>{
const setupButtons = () => { const setupButtons = () => {
var button_2DMatrix = document.getElementById("button-2DMatrix"); var button_2DMatrix = document.getElementById("button-2DMatrix");
var logger;
var arr2DTracer;
button_2DMatrix.addEventListener('click',function(){ button_2DMatrix.addEventListener('click',function(){
var arr2DTracer = new modules.Array2DTracer(); arr2DTracer = new modules.Array2DTracer();
logger = new modules.LogTracer('Generated Javascript');
var numRows = getNumRows(); var numRows = getNumRows();
var numColumns = getNumColumns(); var numColumns = getNumColumns();
var data = fauxData(numRows, numColumns); var data = fauxData(numRows, numColumns);
arr2DTracer.setData(data); arr2DTracer.setData(data);
makeInputFields(); makeInputFields();
generateJS();
positionModules(); positionModules();
arr2DTracer.refresh();
},false);
var button_JS = document.getElementById('button-generateJS');
button_JS.addEventListener('click',function(){
generateJS(logger);
},false); },false);
}; };
......
'use strict';
module.exports = {
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册