A C89 standard compliant, single header, nostdlib (no C Standard Library) squarified tree map viewer (TMV).
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!
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;
}
This library allows you to export or import the data (tmv_area & tmv_model) in its own ".tmv" binary format file.
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 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.
By removing the standard library, nostdlib significantly reduces runtime overhead, allowing for faster execution and smaller binary sizes.
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.
Without linking to the standard library, binaries are smaller, making them ideal for embedded systems, bootloaders, and operating systems where storage is limited.
Direct control over system calls and memory management leads to performance gains by eliminating abstraction layers imposed by standard libraries.
By relying only on fundamental system interfaces, nostdlib allows for easier porting across different platforms without worrying about standard library availability.