Skip to content

About

TreeTableApp is a terminal-based tool for rendering hierarchical JSON data.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

🌲📊 TreeTableApp

Python License Library

TreeTableApp aims to provide an interactive and user-friendly way to visualize hierarchical data.


🌟 Highlights

  • Dynamically visualize hierarchical JSON data in a Tree structure with expandable/collapsible nodes.
  • Associated data for each node is displayed in a Table view.
  • Customizable table columns for focused data exploration.
  • Lightweight, easy to integrate, and runs in the terminal.

ℹ️ Overview

TreeTableApp is a terminal-based tool for rendering hierarchical JSON data. It displays the structure in a tree format and provides a tabular view of the node data. It is helpful for analyzing, debugging, or exploring nested datasets interactively.


✍️ Authors

Created by Nolan Mai under the guidance of Dr. Kate Isaacs of SCI at the U. Reach out for feedback, suggestions, or contributions on GitHub.


Keyboard Commands

Key Action
Enter Select the current node
Space Expand or collapse a tree node
Up Move the cursor up
Down Move the cursor down
Tab Switch cursor between tree and table

🚀 Usage

from TreeTableApp import TreeTableApp
import json

# Load your JSON data
with open("json_files_for_testing/ExampleJsonShort.json", "r") as file:
    data = json.load(file)

# Initialize and run the app
app = TreeTableApp()
app.drawTreeTable(data)

📝 Data Format

The input JSON must follow this structure:

                      
            {
    "Data Tree": { // Whether the node is expanded (true) or collapsed (false)
                // The root must always be "Data Tree" and should not contain any data
                // (no "data" attribute for the root node).
        "open": true,
        "children": {
            "A": { //Child node
                "open": false,
                "data": {
                    "value": 5
                },
                "children": {
                    "B": {
                        "open": false,
                        "data": {
                            "value": 10
                        },
                        "children": {}
                    },
                    "C": {
                        "open": false,
                        "data": {
                            "value": 4
                        },
                        "children": {
                            "D": {
                                "open": false,
                                "data": {
                                    "value": 12,
                                    "message": "hi"
                                },
                                "children": {
                                    "E": {
                                        "open": false,
                                        "data": {
                                            "value": 13,
                                            "message": "hello"
                                        },
                                        "children": {}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Expected output:

Screenshot 2024-11-25 at 11 22 45 AM

Data Notes

  1. open: Defines whether the node is initially expanded (true) or collapsed (false).

Note for open: This attribute is optional. If there is none, the program will automatically add one open: for each node and set it to false, making the node collapse. 2. data: A dictionary containing key-value pairs associated with the node. 3. children: A dictionary of child nodes, recursively formatted.

Filtering out columns in DataTable

To filter out the unnecessary data in the input JSON, add a [columns] list as the second argument when calling drawTreeTable.

from TreeTableApp import TreeTableApp
import json

# Load your JSON data
with open("json_files_for_testing/ExampleJsonShort.json", "r") as file:
    data = json.load(file)

# Initialize and run the app
app = TreeTableApp()
app.drawTreeTable(data, ['value'])

Expected output:

Screenshot 2024-11-25 at 11 23 28 AM

⬇️ Installation

Install the required dependencies and ensure you are using Python 3.10+.

pip install textual 

💻 How to Run

  1. Clone this repository:

    git clone https://github.com/PotBorger/Independent-Study-SCI.git
    cd Independent-Study-SCI
  2. Use the sample data in json_files_for_testing/ExampleJsonShort.json or provide your own JSON file.

  3. Run the app:

    python program.py

👨‍💻 For demo/testing

Try out different example files in json_files_for_testing.

About

TreeTableApp is a terminal-based tool for rendering hierarchical JSON data.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages