{"id":23275581,"url":"https://github.com/pr-dc/jslab","last_synced_at":"2025-10-27T15:30:27.500Z","repository":{"id":189542078,"uuid":"522980395","full_name":"PR-DC/JSLAB","owner":"PR-DC","description":"JavaScript LABoratory environment","archived":false,"fork":false,"pushed_at":"2024-11-09T16:56:24.000Z","size":69173,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-12-19T21:14:51.485Z","etag":null,"topics":["data-visualization","graphics","interactive-computing","javascript","javascript-environment","numeric-computing-environment","numerical-computations","plotting"],"latest_commit_sha":null,"homepage":"https://pr-dc.com/jslab/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PR-DC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-08-09T14:18:47.000Z","updated_at":"2024-11-26T10:21:43.000Z","dependencies_parsed_at":"2023-08-20T17:58:48.749Z","dependency_job_id":"e1e39f68-3353-4f89-be36-69e9cdbc04a2","html_url":"https://github.com/PR-DC/JSLAB","commit_stats":null,"previous_names":["pr-dc/jslab"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PR-DC%2FJSLAB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PR-DC%2FJSLAB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PR-DC%2FJSLAB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PR-DC%2FJSLAB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PR-DC","download_url":"https://codeload.github.com/PR-DC/JSLAB/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238514360,"owners_count":19485030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualization","graphics","interactive-computing","javascript","javascript-environment","numeric-computing-environment","numerical-computations","plotting"],"created_at":"2024-12-19T21:15:02.765Z","updated_at":"2025-10-27T15:30:17.484Z","avatar_url":"https://github.com/PR-DC.png","language":"JavaScript","readme":"# PR-DC JSLAB - JavaScript LABoratory Environment\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB.svg\" width=\"150\"\u003e\r\n\u003c/p\u003e\r\n\r\nThe **JavaScript Laboratory (JSLAB)** is an open-source environment designed for scientific computing, data visualization, and various other computer operations. Inspired by *GNU Octave* and *Matlab*, JSLAB leverages the advantages of JavaScript, including its blazing speed, extensive examples, backing by some of the largest software companies globally, and the vast community of active programmers and software engineers.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_gui.png\" width=\"800\"\u003e\r\n\u003c/p\u003e\r\n\r\nThe program was developed to fulfill the need for performing calculations in a programming language that allows for code reuse in later project stages. JavaScript was chosen for its speed, dynamic nature, interpretability, extensive library support, large existing codebase, backing by major software companies, and the ability to create both desktop and mobile applications.\r\n\r\n## Why Choose JSLAB?\r\n\r\n### 🌟 Backed by Leading Investments\r\nJavaScript is supported by major industry investments, ensuring continuous innovation and robust development. Our commitment to excellence makes JSLAB a trusted choice for professionals and organizations worldwide.\r\n\r\n### 🚀 Powered by JavaScript, Trusted by Giants\r\nJoin the ranks of top companies who leverage JavaScript for their mission-critical applications. With JSLAB, you benefit from the same reliable and scalable technology that powers some of the most advanced projects on Earth and beyond.\r\n\r\n### 👥 Thriving Community and Massive User Base\r\nBecome part of a vibrant and growing community of JavaScript developers. Extensive support network and active forums ensure you always have the resources and assistance you need to succeed.\r\n\r\n### 📈 Comprehensive Functionality Comparable to Leading Tools\r\nJSLAB bridges the gap between JavaScript and specialized scientific tools. Enjoy functionalities equivalent to MATLAB, GNU Octave, Python, R, and Julia, all within a single, unified platform. Perform data analysis, machine learning, numerical computations, and more with ease.\r\n\r\n### 🎨 Seamless and Native GUI with HTML, CSS, and SVG\r\nDesign intuitive and visually appealing graphical user interfaces using native HTML, CSS, and SVG. Create interactive dashboards, custom visualizations, and responsive layouts without the need for additional frameworks.\r\n\r\n### 🔧 Extend with Native Modules via NPM and C++/C\r\nEnhance JSLAB’s capabilities by integrating native modules from npm, built with C++ and C. Tap into a vast ecosystem of extensions and customize your environment to meet your specific needs, ensuring maximum performance and flexibility.\r\n\r\n### Join the JSLAB Revolution Today!\r\nExperience the seamless integration of powerful scientific computing and the flexibility of JavaScript. Whether you're developing complex algorithms, analyzing vast datasets, or creating innovative applications, JSLAB empowers you to achieve more.\r\n\r\n## Installation\r\n\r\nYou can install JSLAB by either downloading the latest stable release from GitHub or by building it from source. Choose the method that best fits your needs.\r\n\r\n### Download the Latest Stable Release\r\n- Visit the JSLAB Releases Page on GitHub Repository: [https://github.com/PR-DC/JSLAB/releases](https://github.com/PR-DC/JSLAB/releases)\r\n- Download the appropriate installer and install the program.\r\n- Try examples from: [https://github.com/PR-DC/JSLAB/tree/master/examples](https://github.com/PR-DC/JSLAB/tree/master/examples)\r\n\r\n## Examples\r\n\r\n\u003cdetails open\u003e\r\n\r\n\u003csummary\u003eAnimated 2D plot\u003c/summary\u003e\r\n\r\nA 2D plot animation like this is essential for visualizing real-time data changes, enabling dynamic tracking of evolving values and providing immediate insight into trends or fluctuations as they happen.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_2D_plot_animated.gif?v1\" width=\"800\"\u003e\r\n\u003c/p\u003e\r\n\r\n```javascript\r\nvar N_buffer = 500;\r\nvar t = toc();\r\nvar x = createFilledArray(N_buffer, null); x[0] = t;\r\nvar y = createFilledArray(N_buffer, null); y[0] = sin(t);\r\nvar p = plot({x: x, y: y});\r\nxlabel(\"x\");\r\nylabel(\"sin(x)\");\r\ntitle(\"Simple 2-D Plot\");\r\n\r\nawait p.ready;\r\nsetInterval(function() {\r\n  var t1 = toc();\r\n  x.push(t1);\r\n  y.push(sin(t1*2));\r\n  if(x.length \u003e N_buffer) {\r\n    x.shift();\r\n    y.shift();\r\n  }\r\n  p.update({x: [x], y: [y]}, 0);\r\n}, 33);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003e3D plot with vectors\u003c/summary\u003e\r\n\r\n3D plots are essential for illustrating spatial relationships and complex vector interactions, allowing for a deeper understanding of data across three dimensions.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_3D_plot.png?v1\" width=\"600\"\u003e\r\n\u003c/p\u003e\r\n\r\n```javascript\r\nvar x = [0, 0, 0, 1, 0];\r\nvar y = [0, 0, 0, 1, 0];\r\nvar z = [0, 0, 0, 1, 0];\r\n\r\nvar u = [1, 0, 0, 1, -1];\r\nvar v = [0, 1, 0, 1, 0];\r\nvar w = [0, 0, 1, 1, 0];\r\n\r\nvar head_scale = 0.2;\r\nvar head_angleFactor = 0.4;\r\n\r\nvar vectors = createVectors3D(x, y, z, u, v, w, head_scale, head_angleFactor, {color: \"#0f0\", width: 6});\r\n\r\nfigure(1);\r\nplot([\r\n  vectors.line, vectors.head\r\n], {'showLegend': false, 'font': {family: 'LatinModern', size: 14}});\r\nxlabel(\"x\");\r\nylabel(\"y\");\r\nzlabel(\"z\");\r\nxlim([-1, 3]);\r\nylim([-1, 3]);\r\nzlim([-1, 3]);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003e3D graphics\u003c/summary\u003e\r\n\r\n3D graphics are vital for creating immersive visualizations that bring complex structures and spatial relationships to life, enabling a more intuitive understanding and interaction with digital models in fields like simulation, design, and data analysis.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_3D_graphics.png?v1\" width=\"600\"\u003e\r\n\u003c/p\u003e\r\n\r\n```javascript\r\nvar win = await openWindow3D();\r\nwin.document.title = \"Test 3D Window - JSLAB | PR-DC\";\r\nvar THREE = win.THREE;\r\n\r\nconst width = win.innerWidth, height = win.innerHeight;\r\n\r\n// init\r\nconst camera = new THREE.PerspectiveCamera( 70, width / height, 0.01, 10 );\r\ncamera.position.z = 1;\r\n\r\nconst scene = new THREE.Scene();\r\n\r\nconst geometry = new THREE.BoxGeometry( 0.2, 0.2, 0.2 );\r\nconst material = new THREE.MeshNormalMaterial();\r\n\r\nconst mesh = new THREE.Mesh( geometry, material );\r\nscene.add( mesh );\r\n\r\nconst renderer = new THREE.WebGLRenderer( { antialias: true } );\r\nrenderer.setSize( width, height );\r\nrenderer.setAnimationLoop( animate );\r\nwin.document.body.appendChild( renderer.domElement );\r\n\r\n// Handle window resizing\r\nwindow.addEventListener('resize', onWindowResize, false);\r\n\r\nfunction onWindowResize() {\r\n  camera.aspect = win.innerWidth / win.innerHeight;\r\n  camera.updateProjectionMatrix();\r\n  renderer.setSize(win.innerWidth, win.innerHeight);\r\n}\r\n\r\nfunction animate( time ) {\r\n  mesh.rotation.x = time / 2000;\r\n  mesh.rotation.y = time / 1000;\r\n  \r\n  renderer.render( scene, camera );\r\n}\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eParallel execution\u003c/summary\u003e\r\n\r\nParallel execution is critical for handling computationally intensive tasks, as it allows multiple operations to run simultaneously, significantly reducing processing time and improving efficiency by utilizing all available CPU cores. \r\n\r\n```javascript\r\nvar computeSquare = (i) =\u003e i * i;\r\n\r\n// Run parallel exectuion \r\nvar results = await parallel.parfor(0, 20, 1, \r\n  parallel.getProcessorsNum(), {}, undefined, computeSquare);\r\ndisp(results);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eVector and Matrix operations\u003c/summary\u003e\r\n\r\nVector and matrix operations are fundamental for efficiently performing complex mathematical computations in fields like physics, engineering, and computer graphics, enabling quick transformations, optimizations, and solutions in multidimensional spaces.\r\n\r\n```javascript\r\nvar v1 = vec.new(1, 2, 3);\r\nvar v2 = vec.new([4, 8, 6]);\r\nconst v_cross = v1.cross(v2);\r\n\r\nvar A = mat.new([\r\n    [1, 2],\r\n    [3, 4]\r\n]);\r\nconst b = mat.new([\r\n    [5],\r\n    [11]\r\n]);\r\nconst x = A.linsolve(b);\r\ndisp('Solution to linear system A * x = b:');\r\ndisp(x);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eSymbolic math\u003c/summary\u003e\r\n\r\nSymbolic math computations are essential for achieving high precision in mathematical modeling, automating algebraic simplifications, and enabling dynamic formula manipulation, which enhances the accuracy and functionality of tools in scientific, engineering, and educational software.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_symbolic.png?v1\" width=\"800\"\u003e\r\n\u003c/p\u003e\r\n\r\n```javascript\r\nvar le, x, E, Iz;\r\nvar p, P, invP, N, d2N;\r\nvar k_int, k_e_stretching, k_e_torsion;\r\nvar xi = range(0, 1, 0.01);\r\n\r\nawait sym.load();\r\n[le, x, E, Iz] = sym.syms(['le', 'x', 'E', 'Iz']);\r\n\r\nP = sym.mat([\r\n  [1, 0, 0, 0], \r\n  [0, 1, 0, 0], \r\n  [1, le, sym.pow(le, 2), sym.pow(le, 3)], \r\n  [0, 1, sym.mul(2, le), sym.mul(3, sym.pow(le, 2))]\r\n]);\r\np = sym.mat([[1, x, sym.pow(x, 2), sym.pow(x, 3)]]);\r\n\r\ninvP = sym.inv(P);\r\nN = sym.mul(p, invP);\r\nd2N = sym.diff(N, 'x', 2);\r\n\r\nk_int = sym.mul(E, Iz, sym.intg(sym.mul(sym.transp(d2N), d2N), x, [0, le]));\r\n\r\nNi = sym.subs(sym.subs(N, le, 1), x, xi).toNumeric();\r\nvar N_flat = Ni.flat();\r\n\r\nsym.showLatex(N);\r\nsym.showLatex(k_int);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eFreeCAD Link\u003c/summary\u003e\r\n\r\nIntegration with FreeCAD is essential for enabling automated, precise 3D modeling workflows within applications, allowing complex geometries, structures, and engineering designs to be generated, modified, and visualized programmatically, which significantly enhances productivity in design and simulation processes.\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://pr-dc.com/web/img/github/JSLAB_FreeCADLink.png?v1\" width=\"800\"\u003e\r\n\u003c/p\u003e\r\n\r\n```javascript\r\nvar nodes = [\r\n  [0, 0, 0],\r\n  [0, 10, 0],\r\n  [10, 10, 0],\r\n  [10, 0, 0],\r\n  [0, 0, 10],\r\n  [0, 10, 10],\r\n  [10, 10, 10],\r\n  [10, 0, 10]\r\n];\r\nvar D = createFilledArray(nodes.length, 3);\r\n\r\nvar lines = [];\r\nfor(var i = 0; i \u003c 4; i++) {\r\n  var j = i+1;\r\n  if(i == 3) {\r\n    j = 0;\r\n  }\r\n  lines.push([...nodes[i], ...nodes[j]]);\r\n  lines.push([...nodes[i+4], ...nodes[j+4]]);\r\n  lines.push([...nodes[i], ...nodes[i+4]]);\r\n}\r\nvar d = createFilledArray(lines.length, 1);\r\n\r\n// Generate JSON\r\nvar nodesFile = pwd + 'out/nodes.json';\r\nvar data = {\r\n  'Coordinates': nodes,\r\n  'Diameters': D\r\n};\r\nwriteFile(nodesFile, stringify(data));\r\nvar data = {\r\n  'Coordinates': lines,\r\n  'Diameters': d\r\n};\r\nbeamsFile = pwd + 'out/beams.json';\r\nwriteFile(beamsFile, stringify(data));\r\n\r\n// Run FreeCADLink \r\nawait freecad_link.start(exe, {\r\n  port: port,\r\n  host: host,\r\n  timeout: timeout,\r\n  startup_timeout: startup_timeout\r\n}); // Start FreeCAD programa\r\n\r\nawait freecad_link.newDocument(part);\r\nawait freecad_link.callScript('MakeNodes', nodesFile, timeout);\r\nawait freecad_link.callScript('MakeBeams', beamsFile, timeout);\r\nawait freecad_link.callScript('MakeFusion', [], timeout);\r\nawait freecad_link.saveAs(model, timeout);\r\n//await freecad_link.quit(); // Close programa\r\n\r\ndeleteFile(nodesFile);\r\ndeleteFile(beamsFile);\r\n```\r\n\u003c/details\u003e\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eOpenModelica Link\u003c/summary\u003e\r\n\r\nIntegration with OpenModelica is crucial for enabling advanced simulation and analysis of complex dynamic systems directly within applications, allowing engineers to model, test, and optimize system behavior seamlessly, which enhances efficiency in design and validation processes.\r\n\r\n```javascript\r\nawait om_link.start(exe); // Start OpenModelica programa\r\ndisp(await om_link.sendExpression('getVersion()'));\r\n\r\ndisp(await om_link.sendExpression(\"model a end a;\"));\r\ndisp(await om_link.sendExpression('loadFile(\"'+model+'\")'));\r\ndisp(await om_link.sendExpression(\"getClassNames()\"));\r\ndisp(await om_link.sendExpression(\"simulate(BouncingBall)\"));\r\nawait om_link.close();\r\n```\r\n\u003c/details\u003e\r\n\r\n## Documentation\r\n\r\nComprehensive documentation is available in the root directory of this repository, provided in multiple formats: HTML, PDF, JSON, and TEX for your convenience.\r\n\r\nCode references and function details are also accessible directly within JSLAB by using the `help()` function.\r\n\r\nDocumentation is also available at: [https://pr-dc.com/jslab/doc/](https://pr-dc.com/jslab/doc/)\r\n\r\n## Build from Source\r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eBuilding from source is intended for advanced users. For details, click here.\u003c/summary\u003e\r\n\r\n### Prerequisites\r\n\r\nIn order to download necessary tools, clone the repository, and install dependencies via npm, you need network access.\r\n\r\n- **Node.js:** Ensure that Node.js is installed on your system. You can download it from the official website: [https://nodejs.org/](https://nodejs.org/)\r\n- **npm:** npm is typically installed alongside Node.js.\r\n- **node-gyp:** node-gyp is installed alongside the application but it requires additional tools and libraries depending on your operating system. Follow the instructions for your specific OS from: [https://github.com/nodejs/node-gyp](https://github.com/nodejs/node-gyp)\r\n- **Git:** Suggested for cloning the repository. Download it from the official website: [https://git-scm.com/](https://git-scm.com/)\r\n\r\n### Installation Steps\r\n\r\n1. Clone the JSLAB repository:\r\n    ```sh\r\n    git clone https://github.com/PR-DC/JSLAB.git\r\n    ```\r\n2. Navigate to the project directory:\r\n    ```sh\r\n    cd JSLAB\r\n    ```\r\n3. Install the necessary dependencies:\r\n    ```sh\r\n    npm install\r\n    ```\r\n4. Start the application:\r\n    ```sh\r\n    npm start\r\n    ```\r\n5. Check examples from: [https://github.com/PR-DC/JSLAB/tree/master/examples](https://github.com/PR-DC/JSLAB/tree/master/examples)\r\n\r\n## Contributing\r\n\r\n### Setting Up the Development Environment\r\nFollow the detailed [build instructions](build-instructions) available in this documentation.\r\n\r\n### Making Changes\r\nFollow the [coding style and best practices](coding-style) available in this documentation.\r\n\r\n### Submitting Changes\r\n1. Create a new branch for your feature or bugfix:\r\n    ```sh\r\n    git checkout -b feature/your-feature-name\r\n    ```\r\n2. Make your changes and commit them with clear messages:\r\n    ```sh\r\n    git commit -m \"Add feature X to improve Y\"\r\n    ```\r\n3. Push your branch to your forked repository:\r\n    ```sh\r\n    git push origin feature/your-feature-name\r\n    ```\r\n4. Submit a Pull Request (PR) detailing your changes.\r\n\r\n### Testing\r\nBefore submitting a PR, ensure that all tests pass and add new tests for any new functionality you introduce.\r\n\r\n### Reviewing Process\r\nAll PRs are subject to review by the maintainers. Be prepared to make revisions based on feedback to align with project standards.\r\n\r\n### Best Practices\r\n- **Consistent Formatting:** Use a consistent code formatter (e.g., Prettier) to maintain uniform code style.\r\n- **Meaningful Commit Messages:** Write clear and descriptive commit messages that explain the purpose of the changes.\r\n- **Modular Code:** Write reusable and modular code to enhance maintainability and scalability.\r\n- **Comprehensive Testing:** Implement thorough tests to ensure the reliability of your contributions.\r\n\r\n\u003c/details\u003e\r\n\r\n## Feedback\r\n\r\nYour feedback is invaluable in improving the JSLAB Library. Whether you encounter bugs, have feature requests, or need assistance, please reach out through the following channels:\r\n\r\n- **GitHub Issues:** Report bugs or suggest features by opening an issue in the GitHub repository.\r\n- **Email:** Contact us directly at [info@pr-dc.com](mailto:info@pr-dc.com) or main author at [mpetrasinovic@pr-dc.com](mailto:mpetrasinovic@pr-dc.com).\r\n\r\nWe encourage active participation and appreciate all forms of feedback that help us enhance the functionality and usability of JSLAB.\r\n\r\n## License\r\n\r\n```\r\nCopyright (C) 2024 PR-DC \u003cinfo@pr-dc.com\u003e\r\n\r\nThis program is free software: you can redistribute it and/or modify\r\nit under the terms of the GNU Lesser General Public License as\r\npublished by the Free Software Foundation, either version 3 of the\r\nLicense, or (at your option) any later version.\r\n\r\nThis program is distributed in the hope that it will be useful,\r\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\r\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r\nGNU Lesser General Public License for more details.\r\n\r\nYou should have received a copy of the GNU Lesser General Public License\r\nalong with this program.  If not, see \u003chttps://www.gnu.org/licenses/\u003e.\r\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr-dc%2Fjslab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpr-dc%2Fjslab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpr-dc%2Fjslab/lists"}