UNPKG

node-red-contrib-prib-functions

Version:
248 lines (240 loc) 13.5 kB
<script type="text/javascript"> /*globals RED */ RED.nodes.registerType('matrix', { category: 'function', color: '#fdeea2', defaults: { name: {value:null}, action: {value: "create",required:true}, args: {value:[]}, call:{value:null}, column: {value:2},"column-type": {value:"num"}, columns: {value:2},"columns-type": {value:"num"}, dataType: {value:"Float32Array"},"columns-type": {value:"Float32Array"}, end: {value:null},"end-type": {value:"num"}, factor: {value:null},"factor-type": {value:"num"}, initialState:{value:"setZero"}, matrix: {value:"payload"},"matrix-type": {value:"msg"}, precision: {value:3},"precision-type": {value:"num"}, row: {value:3},"row-type": {value:"num"}, rows: {value:3},"rows-type": {value:"num"}, rowTarget: {value:null},"rowTarget-type": {value:"num"}, source: {value:"_matrix"},"source-type": {value:"msg"}, sourceArray: {value:"payload"},"sourceArray-type": {value:"msg,json,flow,global"}, start: {value:null},"start-type": {value:"num"}, target: {value:"_matrix"},"target-type": {value:"msg"}, value: {value:"payload"},"value-type": {value:"msg"}, vector: {value:"payload"},"vector-type": {value:"msg"} }, inputs: 1, outputs: 2, icon: "icons8-matrix-desktop-80.png", align: 'left', paletteLabel: "Matrix", inputLabels: "Message In", outputLabels: ["Message Out","Error"], label: function () { return this.name || ("Matrix "+this.action||"*** new ***"); }, oneditprepare: function() { console.log("+++") const node=this; node.properties=[]; node.editors=[]; const actions={ add:{label:"Add",show:["source"],args:["matrix"]}, addRow:{label:"Add Row",show:["source"],args:["row","vector"]}, addRow2Row:{label:"Add Row to Row",show:["source"],args:["row","target","factor","start","end"]}, addCell:{label:"Add to Cell",show:["source"],args:["row","column","value"]}, backwardSubstitution:{label:"Backward Substitution",show:["source"],args:[]}, create:{label:"Create", show:["target"],args:["initialState","rows","columns","dataType"]}, createLike:{label:"Create Like",show:["source","target"],args:[]}, clone:{label:"Clone",show:["source","target"],args:[]}, createForEachCellPairSet:{label:"Create Pair Set Cells",show:["source","target"],args:["matrix","call"],default:{call:"(baseCellValue,matrixCellValue)=>{}"}}, define:{label:"Define",show:["target"],args:["rows","columns","dataType"]}, defineEmpty:{label:"Define Empty",show:["target"],args:["rows","columns","dataType"]}, divideCell:{label:"Divide Cell",show:["source"],args:["rows","columns","value"]}, divideRow:{label:"Divide Row",show:["source"],args:["row","factor","start","end"]}, equalsNearly:{label:"Nearly Equals",show:["source"],args:[]}, fillArray:{label:"Fill",show:["source"],args:["matrix"]}, findColumnRow:{label:"Find in Column",show:["source"],args:["column","call","start","end"],default:{call:"()=>{}"}}, findRowColumn:{label:"Find in Row",show:["source"],args:["row","call","start","end"],default:{call:"(value,row,column,offset,vector)=>true"}}, forRowCells:{label:"Row Cells",show:["source"],args:["row","call","start","end"],default:{call:"()=>{}"}}, forColumnCells:{label:"Column Cells",show:["source"],args:["column","call","start","end"],default:{call:"()=>{}"}}, forEachCell:{label:"For Each Cell",show:["source"],args:["call"],default:{call:"()=>{}"}}, forEachRow:{label:"For Each Row",show:["source"],args:["call"],default:{call:"()=>{}"}}, forEachCellPairSet:{label:"For Each Cell Pair Set",show:["source"],args:["matrix","call"],default:{call:"()=>{}"}}, forwardElimination:{label:"Forward Elimination",show:["source"],args:[]}, gaussianElimination:{label:"Gaussian Elimination",show:["source"],args:[]}, get:{label:"Get Cell",show:["source","target"],args:[]}, getAdjoint:{label:"Adjoint",show:["source","target"],args:[]}, getCofactor:{label:"Cofactor",show:["source","target"],args:[]}, getComplementMinor:{label:"Complement Minor",show:["source","target"],args:[]}, getDeterminant:{label:"Determinant",show:["source","target"],args:[]}, getDeterminantUsingCofactor:{label:"Determinant (Cofactor)",show:["source","target"],args:[]}, getDeterminantUsingCofactor:{label:"Determinant (Row Echelon Form)",show:["source","target"],args:[]}, getIdentity:{label:"Identity",show:["source","target"],args:[]}, getInverse:{label:"Inverse",show:["source","target"],args:[]}, getInverseAdjointMethod:{label:"Inverse (Adjoint Method)",show:["source","target"],args:[]}, getInverseGaussJordan:{label:"Inverse (Gauss Jordan Method)",show:["source","target"],args:[]}, getIndex:{label:"Get Vector Offset",show:["source","target"],args:["row","column"]}, getMatrix:{label:"Get Sub Matrix",show:["source","target"],args:["row","column","rows","columns"]}, getRow:{label:"Get Row",show:["source","target"],args:["row"]}, getVandermonde:{label:"Vandermonde",show:["target"],args:["vector","columns"]}, getZeroed:{label:"Get Zeroed",show:["source","target"],args:["row","column"]}, maxAbsColumn:{label:"Column Maximum Absolute",show:["source","target"],args:["column","start"]}, maxColumn:{label:"Column Max",show:["source","target"],args:["column","start"]}, multiple:{label:"Multiple",show:["source","target"],args:[]}, multipleCell:{label:"Multiple Cell",show:["source","target"],args:["rows","columns","value"]}, multiplyRow:{label:"Multiply Row",show:["source"],args:["row","factor"]}, norm:{label:"Norm",show:["source","target"],args:[]}, reduceRow:{label:"Reduce Row",show:["source","target"],args:["row","call","value"],default:{call:"(agregatevalue,cellValue,row,column)=>agregatevalue+cellValue"}}, reduce:{label:"Reduce Cells",show:["source","target"],args:["call","value"],default:{call:"()=>{}"}}, reducedRowEchelonForm:{label:"Reduced Row EchelonForm",show:["source"],args:[]}, rowEchelonForm:{label:"Row Echelon Form",show:["source"],args:[]}, runningSum:{label:"Running Sum",show:["source","target"],args:[]}, set:{label:"Set Cell",show:["source"],args:["row","column","value"]}, setRow:{label:"Set Row",show:["source"],args:["vector","row"]}, subtractCell:{label:"Subtract Cell",show:["source","target"],args:["row","column","value"]}, sumRow:{label:"Sum Row",show:["source","target"],args:[]}, swapRows:{label:"Swap Rows",show:["source"],args:[]}, testIsSquare:{label:"Is Square",show:["source"],args:[]}, toArray:{label:"To Array Object",show:["source","target"],args:[]}, transpose:{label:"Transpose",show:["source","target"],args:[]} }; const baseDiv=$("#node-inputDynamicBase"); function defineProperty(property,...types) { const element=$('<div/>',{ "class": "form-row form-row-http-in-"+property.name+" hide" }).append( $('<label for="node-input-'+property.name+'" style="white-space: nowrap"><i class="fa fa-'+(property.icon||'bookmark')+'"></i> '+property.label+'</label>'), ); element.appendTo(baseDiv); node.properties.push(property.name); if(types[0]=="edit") { element.append($('<div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-'+property.name+'-editor"></div>')); node.editors[property.name] = RED.editor.createEditor({ id: 'node-input-'+property.name+'-editor', mode: 'ace/mode/'+property.mode||"text", value: node[property.name]||property.default }); } else { const inputNode=$('<input type="text" id="node-input-'+property.name+'"/>').val(node[property.name]); const typeNode=$('<input type="hidden" id="node-input-'+property.name+'-type"/>'); element.append([inputNode,typeNode]); if(types[0] instanceof Array) { $("#node-input-"+property.name).typedInput({ type:property.name, types:[{value: property.name, options: types[0] }]}) } else { const typeValue=node[property.name+"-type"]; if(typeValue) typeNode.val(typeValue); $("#node-input-"+property.name).typedInput({ type:typeValue||types[0], types:types, typeField: "#node-input-"+property.name+"-type" }); } } } defineProperty({name:"initialState",label:"Initially" ,icon:"tag"},[ { value: "setZero", label: "Zeros"}, { value: "setRandom", label: "Random Numbers"}, { value: "setIdentity", label: "Identity"}, { value: "setOne", label: "all 1"}, ]); defineProperty({name:"dataType",label:"number Type" ,icon:"tag"},[ { value: "Float32Array", label: "float32 -3.4e38 to 3.4e38" }, { value: "Float64Array", label: "double/float64 -1.8e308 to 1.8e308" }, { value: "Int8Array", label: "byte -128 to 122" }, { value: "Uint8Array", label: "octet 0 to 255" }, { value: "Uint8ClampedArray", label: "octet clamped 0 to 255" }, { value: "Int16Array", label: "short -32768 to 32767" }, { value: "Uint16Array", label: "short unsigned 0 to 65535" }, { value: "Int32Array", label: " long -2147483648 to 2147483647" }, { value: "Uint32Array", label: "long unsgined 0 to 4294967295" }, { value: "BigInt64Array", label: "bigint 2**-263 to 2**263" }, { value: "BigUint64Array", label: "bigint unsigned 0 to 2**264" }, ]); defineProperty({name:"source" ,label:"Source" ,icon:"crosshairs"},"msg","json","flow","global"); defineProperty({name:"arg" ,label:"Argument" ,icon:"tag"},"num","json","msg","flow","global","env"); defineProperty({name:"matrix" ,label:"Matrix" ,icon:"th"},"msg","flow","global"); defineProperty({name:"target" ,label:"Target" ,icon:"save"},"msg","flow","global"); defineProperty({name:"column" ,label:"Column" ,icon:"bars fa-rotate-90"},"num","msg","flow","global"); defineProperty({name:"columns" ,label:"Columns" ,icon:"bars fa-rotate-90"},"num","msg","flow","global"); defineProperty({name:"row" ,label:"Row" ,icon:"bars"},"num","msg","flow","global"); defineProperty({name:"rows" ,label:"Rows" ,icon:"bars"},"num","msg","flow","global"); defineProperty({name:"value" ,label:"Value" ,icon:"tachometer"},"num","msg","flow","global"); defineProperty({name:"rowTarget",label:"Target Row" ,icon:"bars"},"num","msg","flow","global"); defineProperty({name:"factor" ,label:"Factor" ,icon:"adjust"},"num","msg","flow","global"); defineProperty({name:"precision",label:"Precision" ,icon:"tachometer"},"num","msg","flow","global"); defineProperty({name:"start" ,label:"Start" ,icon:"tachometer"},"num","msg","flow","global"); defineProperty({name:"end" ,label:"End" ,icon:"tachometer"},"num","msg","flow","global"); defineProperty({name:"size" ,label:"Size" ,icon:"tachometer"},"num","msg","flow","global"); defineProperty({name:"vector" ,label:"Vector" ,icon:"ellipsis-h"},"json","msg","flow","global"); defineProperty({name:"call" ,label:"Call" ,icon:"js",mode:"javascript"},"edit"); const options=Object.keys(actions) .sort((a,b) => actions[a].label<actions[b].label?-1:0) .reduce((previousValue,property)=>previousValue.concat({value:property,label:actions[property].label}), []); const actionNode=$("#node-input-action"); actionNode.typedInput({ types: [{ value: "actionType", options: options }] }); actionNode.change(function() { action=$(this).val(); node.args=[]; node.properties.forEach(property=>$(".form-row-http-in-"+property).hide()); const actionDef=actions[action]; node.args=actionDef.args; node.args.forEach(property=>$(".form-row-http-in-"+property).show()); actionDef.show.forEach(property=>$(".form-row-http-in-"+property).show()); }); }, oneditsave: function() { const node=this; Object.keys(node.editors).forEach(property=>{ const editor=node.editors[property]; node[property]=editor.getValue(); editor.destroy(); delete editor; }) }, oneditcancel: function() { const node=this; Object.keys(node.editors).forEach(property=>{ const editor=node.editors[property]; editor.destroy(); delete editor; }); }, resizeRule: function(file,newWidth) { } }); </script> <script type="text/x-red" data-template-name="matrix"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name </label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-action" style="white-space: nowrap"><i class="fa fa-cog"></i> Action</label> <input type="text" id="node-input-action"> </div> <div id="node-inputDynamicBase"/> </script> <script type="text/x-red" data-help-name="matrix"> <p> Matrix manipulation </p> <h3>Inputs</h3> <dl class="message-properties"> <dt>msg <span class="property-type">topic</span></dt> <dd>incoming message with topic</dd> <dt>msg <span class="property-type">payload</span></dt> <dd></dd> </dl> </script>