Skip to content

nickscha/tmv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmv

A C89 standard compliant, single header, nostdlib (no C Standard Library) squarified tree map viewer (TMV).

File Explorer Treemap Linear Treemap Weighted/Nested Treemap

It uses the paper "Squarified Treemaps" algorythm by Mark Bruls, Kees Huizing, and Jarke J. van Wijk.

For more information please look at the "tmv.h" file or take a look at the "examples" or "tests" folder.

Warning

THIS PROJECT IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! USE THIS PROJECT AT YOUR OWN RISK!

Quick Start

Download or clone tmv.h and include it in your project.

#include "tmv.h"

int main() {

    #define TMV_MAX_RECTS 1024

    /* The area on which the squarified treemap should be aligned */
    tmv_rect area = {0, 0, 0, 100, 100};

    /* Define a output buffer for output rects */
    tmv_rect rects[TMV_MAX_RECTS];

    /*
    Expected squarified treemap output if width = 100 and height = 100:

    id: 1, x:  0, y:  0, width: 50, height: 50
    id: 2, x:  0, y: 50, width: 50, height: 50
    id: 3, x: 50, y:  0, width: 50, height: 50
    id: 4, x: 50, y: 50, width: 50, height: 50
    id: 5, x:  0, y:  0, width: 25, height: 25  <- child1
    id: 6, x:  0, y: 25, width: 25, height: 25  <- child2
    id: 7, x: 25, y:  0, width: 25, height: 25  <- child3
    id: 8, x: 25, y: 25, width: 25, height: 25  <- child4
    */
    tmv_item items[] = {
        {1, -1, 10.0, 0, 0},
        {2, -1, 10.0, 0, 0},
        {3, -1, 10.0, 0, 0},
        {4, -1, 10.0, 0, 0},
        {5, 1, 2.5, 0, 0}, /* child has parent_id = 1 */
        {6, 1, 2.5, 0, 0}, /* child has parent_id = 1 */
        {7, 1, 2.5, 0, 0}, /* child has parent_id = 1 */
        {8, 1, 2.5, 0, 0}, /* child has parent_id = 1 */

    };

    /* The unified tmv model */
    tmv_model model = {0};

    model.rects = rects;
    model.items = items;
    model.items_count = TMV_ARRAY_SIZE(items);

    /* Build squarified recursive treemap view */
    tmv_squarify(
        &model, /* The unified tmv_model contain all data */
        area    /* The render area size for treemap       */
    );

    /* Afterwards you can iterate through the item.rects with item.rects_count */

    return 0;
}

Binary Format Specification

This library allows you to export or import the data (tmv_area & tmv_model) in its own ".tmv" binary format file.

Binary Format Specification

Run Example: nostdlib, freestsanding

In this repo you will find the "examples/tmv_win32_nostdlib.c" with the corresponding "build.bat" file which creates an executable only linked to "kernel32" and is not using the C standard library and executes the program afterwards.

"nostdlib" Motivation & Purpose

nostdlib is a lightweight, minimalistic approach to C development that removes dependencies on the standard library. The motivation behind this project is to provide developers with greater control over their code by eliminating unnecessary overhead, reducing binary size, and enabling deployment in resource-constrained environments.

Many modern development environments rely heavily on the standard library, which, while convenient, introduces unnecessary bloat, security risks, and unpredictable dependencies. nostdlib aims to give developers fine-grained control over memory management, execution flow, and system calls by working directly with the underlying platform.

Benefits

Minimal overhead

By removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.

Increased security

Standard libraries often include unnecessary functions that increase the attack surface of an application. nostdlib mitigates security risks by removing unused and potentially vulnerable components.

Reduced binary size

Without linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.

Enhanced performance

Direct control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.

Better portability

By relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.