{"id":17095624,"url":"https://github.com/meyfa/nsdlib","last_synced_at":"2025-03-23T17:41:58.926Z","repository":{"id":68200455,"uuid":"82521552","full_name":"meyfa/nsdlib","owner":"meyfa","description":"Nassi–Shneiderman diagrams (structograms) with Java","archived":false,"fork":false,"pushed_at":"2020-08-04T16:50:26.000Z","size":103,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T23:31:24.107Z","etag":null,"topics":["drawing","library","nassi-shneiderman-diagrams","nsd","reader","rendering","structograms","structorizer"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meyfa.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"meyfa"}},"created_at":"2017-02-20T05:49:05.000Z","updated_at":"2020-08-04T16:50:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"07b51303-000f-4421-bf10-b69ed9e9437d","html_url":"https://github.com/meyfa/nsdlib","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fnsdlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fnsdlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fnsdlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Fnsdlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meyfa","download_url":"https://codeload.github.com/meyfa/nsdlib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245144021,"owners_count":20568049,"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":["drawing","library","nassi-shneiderman-diagrams","nsd","reader","rendering","structograms","structorizer"],"created_at":"2024-10-14T14:43:22.409Z","updated_at":"2025-03-23T17:41:58.891Z","avatar_url":"https://github.com/meyfa.png","language":"Java","funding_links":["https://github.com/sponsors/meyfa"],"categories":[],"sub_categories":[],"readme":"# nsdlib\n\n[![Build Status](https://travis-ci.com/meyfa/nsdlib.svg?branch=master)](https://travis-ci.com/meyfa/nsdlib)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/c0a3b52c6757567ba2f5/test_coverage)](https://codeclimate.com/github/meyfa/nsdlib/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/c0a3b52c6757567ba2f5/maintainability)](https://codeclimate.com/github/meyfa/nsdlib/maintainability)\n\nThis is a Java library for working with [Nassi-Shneiderman diagrams](https://en.wikipedia.org/wiki/Nassi–Shneiderman_diagram)\n(structograms).\n\nIt offers the following functionality:\n\n* **Construct elements through code**\n  - All standard block types supported\n* **Read structograms from files**\n  - Currently only support for the [Structorizer](http://structorizer.fisch.lu/)\n    format, but easy to add your own\n* **Render structograms as images**\n  - Basic layouting, dynamic size calculation\n  - High amount of abstraction through `RenderAdapter` (AWT adapter included;\n    support for custom adapters for other targets, e.g. Android)\n\n\n\n## Reading a Structogram\n\nThe following code reads a structogram stored in Structorizer's XML format.\n\n```java\nNSDReader reader = new StructorizerReader();\n\nNSDRoot root;\n\nFile file = new File(\"/path/to/file.nsd\");\ntry (FileInputStream in = new FileInputStream(file)) {\n    root = reader.read(in);\n} catch (NSDReaderException | IOException e) {\n    e.printStackTrace();\n}\n\n// do something with `root`\n```\n\nFeel free to submit a PR or open an issue if you require support for other\nformats. The custom reader should implement the `NSDReader` interface.\n\n\n\n## Rendering a Structogram\n\nTo render a structogram (or part of one), the following steps need to be done:\n\n1. Convert the element into a `RenderPart` (do this for the root element).\n2. Layout the render part.\n3. Render the actual image.\n\nThe following example uses the `AwtRenderer` for rendering to a `BufferedImage`,\nbut you can easily substitute a custom renderer instead.\n\n```java\nAwtRenderer renderer = new AwtRenderer();\n\n// 1. convert (`diagram` is an instance of `NSDRoot`)\nRenderPart part = diagram.toRenderPart();\n\n// 2. layout\npart.layout(renderer.createContext());\n// optional: get the resulting size\n// Size s = part.getSize();\n\n// 3. render\nBufferedImage img = renderer.render(part);\n```\n\n\n\n## Manual Structogram Construction\n\nConstructing a structogram with code is as simple as invoking a few\nconstructors.\n\n```java\nNSDRoot diagram = new NSDRoot(\"When start clicked\");\n\nNSDDecision dec = new NSDDecision(\"(pick random 1 to 10) = 1\");\n{\n    dec.getThen().addChild(new NSDInstruction(\"say \\\"You're lucky!\\\"\"));\n    dec.getElse().addChild(new NSDInstruction(\"say \\\"Not so lucky.\\\"\"));\n}\ndiagram.addChild(dec);\n\nNSDForever forever = new NSDForever(Arrays.asList(\n    new NSDInstruction(\"wait 1 secs\")\n));\ndiagram.addChild(forever);\n\n// etc\n```\n\n\n\n## Element Types\n\nThe base class for every element is `nsdlib.elements.NSDElement`. Elements that\ncontain other elements extend its subclass `nsdlib.elements.NSDContainer`.\n\n| Type                 | Package                        | Class              |\n| -------------------- | ------------------------------ | ------------------ |\n| Root element         | `nsdlib.elements`              | `NSDRoot`          |\n| Instruction          | `nsdlib.elements`              | `NSDInstruction`   |\n| If/Then/Else         | `nsdlib.elements.alternatives` | `NSDDecision`      |\n| Switch-Case          | `nsdlib.elements.alternatives` | `NSDCase`          |\n| Test-first loop      | `nsdlib.elements.loops`        | `NSDTestFirstLoop` |\n| Test-last loop       | `nsdlib.elements.loops`        | `NSDTestLastLoop`  |\n| Unconditional loop   | `nsdlib.elements.loops`        | `NSDForever`       |\n| Concurrent execution | `nsdlib.elements.parallel`     | `NSDParallel`      |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Fnsdlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeyfa%2Fnsdlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Fnsdlib/lists"}