{"id":16964981,"url":"https://github.com/propensive/dendrology","last_synced_at":"2025-04-11T23:03:35.049Z","repository":{"id":80754919,"uuid":"586363004","full_name":"propensive/dendrology","owner":"propensive","description":"Rendering of trees and DAGs in the console","archived":false,"fork":false,"pushed_at":"2025-01-26T12:13:16.000Z","size":1501,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-20T01:38:45.105Z","etag":null,"topics":["ascii","ascii-art","ascii-graphics","ascii-tree","console"],"latest_commit_sha":null,"homepage":"https://soundness.dev/dendrology/","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"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}},"created_at":"2023-01-07T21:31:56.000Z","updated_at":"2025-01-26T12:13:20.000Z","dependencies_parsed_at":"2023-10-11T15:48:14.640Z","dependency_job_id":"b5c71cdc-c33f-4d6b-84cb-09dc8c12ba76","html_url":"https://github.com/propensive/dendrology","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fdendrology","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fdendrology/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fdendrology/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fdendrology/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/dendrology/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239805880,"owners_count":19700200,"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":["ascii","ascii-art","ascii-graphics","ascii-tree","console"],"created_at":"2024-10-13T23:44:46.067Z","updated_at":"2025-02-20T08:31:38.426Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/dendrology/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/dendrology/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Dendrology\n\n__Rendering of trees and DAGs in the console__\n\n__Dendrology__ provides methods for rendering data in a tree or directed acyclic graph\nstructure as lines, for rendering in a monospaced font, typically in a terminal. It can use\n[Unicode box-drawing characters](https://en.wikipedia.org/wiki/Box-drawing_characters) or\nplain ASCII to render semigraphical diagrams.\n\n## Features\n\n- display any tree-structured data as a tree in a console\n- tree data can be of any type whose children can be accessed recursively\n- display directed acyclic graphs in a console\n- output is a linearized sequence of any type\n- tree input is processed lazily, and output is a stream\n- can be easily adapted to any grid-like layout, e.g. an HTML table\n- custom textual renderings are available\n\n\n## Availability\n\nDendrology is available as a binary for Scala 3.4.0 and later, from [Maven\nCentral](https://central.sonatype.com). To include it in an `sbt` build, use\nthe coordinates:\n```scala\nlibraryDependencies += \"dev.soundness\" % \"dendrology-tree\" % \"0.2.0\"\nlibraryDependencies += \"dev.soundness\" % \"dendrology-dag\" % \"0.2.0\"\n```\n\n\n\n\n\n\n\n## Getting Started\n\nDendrology can render tree-like structures as text, such as the following,\n```mono\n├─● Plantae\n├─● Fungi\n│ ├─● Rozellomyceta\n│ ├─● Aphelidiomyceta\n│ └─● Eumycota\n├─● Protozoa\n├─● Bacteria\n└─● Animalia\n  └─● Chordata\n    └─● Mammalia\n      └─● Carnivora\n        ├─● Feliadae\n        ├─● Canidae\n        │ └─● Canis\n        └─● Ursidae\n```\nand DAGs such as this:\n```mono\n▪ Any\n└─▪ Matchable\n  ├─▪ AnyRef\n  │ ├─▪ List[Int]\n  └─│─│─▪ AnyVal\n    │ │ ├─▪ Boolean\n    │ │ ├─│─▪ Int\n    │ │ └─│─│─▪ Unit\n    └─│───│─│─│─▪ String\n      └───│─│─│─┴─▪ Null\n          └─┴─┴───┴─▪ Nothing\n```\n\nDendrology is versatile, and can represent data in a variety of input and output types, so long as methods are\nspecified for working with those types.\n\nAll Dendrology terms and types are in the `dendrology` package.\n```scala\nimport dendrology.*\n```\n\n## Trees\n\nTo create a tree, all we need is the root node (or nodes), of some type, and a way to access a node's children\n(of the same type). This can then be applied recursively to the root node to fully expand the tree. This\napproach has the advantage that it does not require the data to be reshaped into a particular data structure to\nbe used.\n\nDendrology makes it possible to define the method for accessing a node's children in two ways: either as a\nlambda when a `TreeDiagram` is constructed, like so,\n```scala\nimport anticipation.Text\n\ncase class Person(name: Text, age: Int, children: List[Person])\nval daughter = Person(t\"Jill\", 7, List())\nval son = Person(t\"Jack\", 9, List())\nval headOfFamily = Person(t\"John\", 37, List(son, daughter))\n\nval diagram = TreeDiagram.by[Person](person =\u003e person.children)(headOfFamily)\n```\nor alternatively through a contextual instance of the typeclass `Expandable` for the given node type. Types\nwhich are naturally hierarchical can, of course, define their own `Expandable` instances so they can be used in\ntree-structures without the need to specify how child nodes should be accessed. For example:\n```scala\ngiven Expandable[Person] = _.children\nval diagram2 = TreeDiagram(headOfFamily)\n```\n\nIt's possible to include multiple root nodes as parameters to `TreeDiagram`, which will appear as top-level\nsiblings in the tree.\n\nInstances of `TreeDiagram` provide a few methods to help with rendering a diagram. The `render` method will\nmeet most requirements for rendering a tree diagram as a series of lines. The `render` method takes a single\nparameter, a lambda for converting from the type of the nodes, `NodeType`, to a serialized type of each line,\n`LineType`. Typical choices might be a `NodeType` of some user-defined type like `Person`, and a `LineType` of\n`Text`.\n\nFor example, we could write,\n```scala\nimport treeStyles.default\n\nval lines = diagram2.render(_.name)\n@main\ndef run(): Unit =\n  lines.foreach(Out.println(_))\n```\n\nThe algorithm performs a depth-first traversal of the data, mapping each node to a line, and flattening the data\nin the process. The output will be a `LazyList[LineType]`.\n\nThe parameter to the `render` method, `_.name`, will determine the `LineType` is `Text`, which will resolve a\ncontextual `TreeStyle[Text]`, which is needed to render the horizontal and vertical lines of the diagram as\n`Text`. The `dendrology.treeStyles` package provides `default`, `rounded` and `ascii` renderings for `Text` and\nother `Textual` types.\n\nIn addition to `render`, the method `TreeDiagram#nodes` can recover the node value used to generate each line in\nthe diagram. A common way to make use of this is to zip it with the output from `render` to get a\n`LazyList[(LineType, NodeType)]` which could be used to perform additional post-processing of each line, based\non information from its corresponding node.\n\n### Laziness\n\nThe `drawTree` implementation accesses the tree data structure mostly lazily, but _does_ need to know the number\nof elements in each ancestor of the current node, yet does not need to know anything about the descendants of\nsubsequent nodes in the traversal until they are reached in their natural order.\n\nThis is necessary because any subsequent siblings of any ancestor nodes will require an additional descending\nvertical line to be rendered in the appropriate column of the current line, whereas that vertical line should be\nabsent for each ancestor that is the last of its siblings.\n\n## Directed Acyclic Graphs\n\nA DAG diagram is represented by the `DagDiagram` class, and should be constructed from a `Dag` instance from\n[Acyclicity](https://github.com/propensive/acyclicity/).\n\nFor example, given a value `dag`, an instance of `Dag[Person]`, we can construct a new `DagDiagram` with\n`DagDiagram(dag)`. Unlike `TreeDiagram`, `DagDiagram` always takes exactly one parameter.\n\nLike `TreeDiagram`, though, `DagDiagram` provides `render` and `nodes` methods with the same purpose. While\n`TreeDiagram` returns a `LazyList`, `DagDiagram` cannot (due to the nature of the data it represents) evaluate\nlazily, and provides a strict `List`.\n\nHere is the full code used to create the example DAG above:\n```scala\nimport acyclicity.Dag\nimport gossamer.t\nimport turbulence.Out, turbulence.stdioSources.jvm\nimport dagStyles.default\n\nval dag = Dag(\n  t\"Any\"       -\u003e Set(),\n  t\"Matchable\" -\u003e Set(t\"Any\"),\n  t\"AnyVal\"    -\u003e Set(t\"Matchable\"),\n  t\"AnyRef\"    -\u003e Set(t\"Matchable\"),\n  t\"Unit\"      -\u003e Set(t\"AnyVal\"),\n  t\"Boolean\"   -\u003e Set(t\"AnyVal\"),\n  t\"Int\"       -\u003e Set(t\"AnyVal\"),\n  t\"String\"    -\u003e Set(t\"AnyRef\"),\n  t\"List[Int]\" -\u003e Set(t\"AnyRef\"),\n  t\"Null\"      -\u003e Set(t\"String\", t\"List[Int]\"),\n  t\"Nothing\"   -\u003e Set(t\"Null\", t\"Unit\", t\"Boolean\", t\"Int\")\n)\n\n@main\ndef run2(): Unit =\n  DagDiagram(dag).render { node =\u003e t\"▪ $node\" }.foreach(Out.println(_))\n```\n\n\n\n\n## Status\n\nDendrology is classified as __maturescent__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nDendrology is designed to be _small_. Its entire source code currently consists\nof 212 lines of code.\n\n## Building\n\nDendrology will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Dendrology?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Dendrology's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Dendrology and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `dendrology`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Dendrology's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Dendrology are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/dendrology/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Dendrology\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nDendrology was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\n_Dendrology_ is the study of trees.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo shows a pattern of leaves from a tree; trees being the subject of Dendrology.\n\n## License\n\nDendrology is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fdendrology","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fdendrology","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fdendrology/lists"}