• Stars
    star
    347
  • Rank 122,141 (Top 3 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created about 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

web-based treemap

webtreemap

New 2017-Oct-16: master is now webtreemap v2, a complete rewrite with bug fixes, more features, and a different (simpler) API. If you're looking for the old webtreemap, see the v1 branch.

A simple treemap implementation using web technologies (DOM nodes, CSS styling and transitions) rather than a big canvas/svg/plugin. It's usable as a library as part of a larger web app, but it also includes a command-line app that dumps a self-contained HTML file that displays a map.

Play with a demo.

Usage

Web

The data format is a tree of Node, where each node is an object in the shape described at the top of tree.ts.

<script src='webtreemap.js'></script>
<script>
// Container must have its own width/height.
const container = document.getElementById('myContainer');
// See typings for full API definition.
webtreemap.render(container, data, options);

Options

Option Type Default
padding [number, number, number, number] [14, 3, 3, 3]
lowerBound number 0.1
applyMutations (node: Node) => void () => void
caption (node: Node) => string (node) => node.id
showNode (node: Node, width: number, height: number) => boolean (_, width, height) => (width > 20) && (height >= options.padding[0])
showChildren (node: Node, width: number, height: number) => boolean (_, width, height) => (width > 40) && (height > 40)
Option Description
padding In order: padding-top, padding-right, padding-bottom, padding-left of each node
lowerBound Lower bound of ratio that determines how many children can be displayed inside of a node. Example with a lower bound of 0.1: the total area taken up by displaying child nodes of any given node cannot be less than 10% of the area of its parent node.
applyMutations A function that exposes a node as an argument after it's dom element has been assigned. Use this to add inline styles and classes. Example: (node) => { node.dom.style.color = 'blue' }
caption A function that takes a node as an argument and returns a string that is used to display as the caption for the node passed in.
showNode A function that takes a node, its width, and its height, and returns a boolean that determines if that node should be displayed. Fires after showChildren.
showChildren A function that takes a node, its width, and its height, and returns a boolean that determines if that node's children should be displayed. Fires before showNode.

Command line

Install with

$ npm i webtreemap

Then run with:

$ webtreemap -o output_file < my_data

Input data format is space-separated lines of "size path", where size is a number and path is a '/'-delimited path. For example:

$ cat my_data
100 all
50 all/thing1
25 all/thing2

This is exactly the output produced by du, so this works:

$ du -ab some_path | webtreemap -o out.html

But note that there's nothing file-system-specific about the data format -- it just uses slash as a nesting delimiter.

Development

The modules of webtreemap can be used both from the web and from the command line, so the build has two layers. The command line app embeds the output of the build into its output so it's a bit confusing.

To build everything, run yarn run build.

Build layout

To hack on webtreemap, the pieces of the build are:

  1. yarn run tsc builds all the .ts files;
  2. yarn run webpack builds the UMD web version from JS of the above.

Because command line embeds the web version in its output, you need to run step 2 before running the output of step 1. Also note we intentionally don't use webpack's ts-loader because we want the TypeScript output for the command-line app.

Command line app

Use yarn run tsc -w to keep the npm-compatible JS up to date, then run e.g.:

$ du -ab node_modules/ | node build/src/cli.js --title 'node_modules usage' -o demo.html

License

webtreemap is licensed under the Apache License v2.0. See LICENSE.txt for the complete license text.

More Repositories

1

retrowin32

windows emulator
Rust
421
star
2

n2

n2 ("into"), a ninja compatible build system
Rust
268
star
3

c-repl

a C read-eval-print loop (abandoned)
Haskell
201
star
4

weave

wasm viewer
TypeScript
136
star
5

bloat

analyze code size via nm/objdump output
Python
78
star
6

go-imap

golang IMAP client library
Go
73
star
7

pocket-mini

Save to Pocket (mini), a Chrome extension for https://getpocket.com
JavaScript
44
star
8

jelly

jelly no puzzle in html5
JavaScript
39
star
9

smash

a new kind of terminal
TypeScript
38
star
10

gocairo

autogenerated full golang bindings for cairo
Go
37
star
11

js-min-bench

benchmarking js minifiers
HTML
30
star
12

git-cl

a git-command for integrating reviews on Rietveld
Python
26
star
13

cms

tiny content management system I use for my website, unlikely of interest to anyone else
Go
18
star
14

j8t

javascript minifier
Rust
14
star
15

hp

generate graphs from google-perftools heap profiles
Go
13
star
16

envelope

python script to generate envelopes
Python
13
star
17

webkit-who

webkit committers analysis
JavaScript
12
star
18

sfpng

straightforward minimal PNG decoder
C
12
star
19

config

dotfiles, not interesting to anyone but me
Emacs Lisp
11
star
20

lmnopuz

web-based crosswords (stagnant)
JavaScript
10
star
21

maddr

simple addr2line reimplementation
C++
10
star
22

lines-spent

datavis of commit changes
JavaScript
9
star
23

gat

git clone in haskell
Haskell
9
star
24

v8c

C bindings for V8 (abandoned)
C++
9
star
25

gen

golang basic lexer + lr parser generator
Go
9
star
26

sclang

header into s-expressions via clang
C++
8
star
27

fin

financial analysis
TypeScript
8
star
28

goblizzard

golang parsers for blizzard data formats
Go
6
star
29

goodbye-lj

scripts to archive and delete livejournal posts
Python
6
star
30

picasync

download picasa (google+) albums
Go
6
star
31

buildbot-error

Chrome extension to add a "next error" link to Chromium buildbot output
JavaScript
6
star
32

devhelp-index

command line (emacs) interface into devhelp
Python
6
star
33

proximo

Android app for public transit arrival times
Java
5
star
34

muni

SF muni arrival time server and Android app
Python
4
star
35

keyring-dump

quick script to dump gnome keyring
Python
4
star
36

edit-locally

quick hack to edit chrome codesearch results in local emacs
Python
4
star
37

snapz

simple screenshooting app
C
4
star
38

whisper

playing around with OpenAI Whisper
C
4
star
39

HarfBuzz-ng

Patches for the HarfBuzz rewrite
C
4
star
40

lytics

analytics without the ad network
TypeScript
3
star
41

route

simple golang url router
Go
3
star
42

h8

Haskell bindings for v8
Haskell
3
star
43

pony-express

chrome extension to prettify online mailing list archives
CoffeeScript
3
star
44

terminfo

terminfo parser for go
Go
3
star
45

python-sourcemap

python module for parsing javascript source maps
Python
3
star
46

pjs

paren js
JavaScript
3
star
47

focus

script to block time-wasting sites (news.yc, reddit, techmeme, etc.)
Shell
3
star
48

chrome-textfix-ext

A Chrome extension to add a context menu item to make body text readable.
JavaScript
3
star
49

onscreen

image cycler for wall displays
Python
2
star
50

flatzip

create mtime-equivalent directory mirror with files filled with zeros
Go
2
star
51

states

compare US states and EU countries
TypeScript
2
star
52

git-ffwd

script to forward-port old branches
Shell
2
star
53

cute-sideload

cute overload feed without the creepy babytalk
Ruby
2
star
54

diff

crostini diff tool
Go
1
star
55

hscairo

Cabalized version of gtk2hs's Cairo bindings
Haskell
1
star
56

evmar.github.io

github pages
HTML
1
star
57

tjs

Just screwing around with unification, nothing interesting to see.
JavaScript
1
star
58

tsparse

dump TypeScript lexical AST
JavaScript
1
star
59

evanhacks

random hacks on app engine
Go
1
star
60

peek

TypeScript
1
star
61

rietveld

Mirror of Rietveld, the App Engine code review site
1
star
62

rust-toys

toy apps to play with the rust language
Rust
1
star
63

HarfBuzz

Chrome-specific Harfbuzz patches
1
star
64

discord-clean

delete entries on discord
Go
1
star
65

martine.github.io

github web pages
HTML
1
star
66

chrome-readability

arc90's Readability bookmarklet as a Chrome extension
1
star