Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,24 @@ 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.

| 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

Expand Down
4 changes: 2 additions & 2 deletions docs/index.html

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"webtreemap": "build/src/cli.js"
},
"dependencies": {
"commander": "^2.11.0"
"commander": "^7.2.0"
},
"devDependencies": {
"@types/commander": "^2.11.0",
"@types/node": "^8.0.34",
"prettier": "1.14.3",
"typescript": "^3.1.3",
Expand Down
18 changes: 13 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,25 @@ function humanSizeCaption(n: tree.Node): string {
return `${n.id || ''} (${size.toFixed(1)}${units[unit]})`;
}

declare interface Args {
title?: string;
output?: string;
}

async function main() {
const args = new Command()
.description(`Generate web-based treemaps.
.description(
`Generate web-based treemaps.

Reads a series of
size path
lines from stdin, splits path on '/' and outputs HTML for a treemap.
`)
.option('-o, --output [path]', 'output to file, not stdout')
.option('--title [string]', 'title of output HTML')
.parse(process.argv);
`
)
.option('-o, --output [path]', 'output to file, not stdout')
.option('--title [string]', 'title of output HTML')
.parse(process.argv)
.opts() as Args;
const node = treeFromLines(await readLines());
const treemapJS = await readFile(__dirname + '/../webtreemap.js');
const title = args.title || 'webtreemap';
Expand Down
2 changes: 1 addition & 1 deletion src/treemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function isDOMNode(e: Element): boolean {
export interface Options {
padding: [number, number, number, number];
lowerBound: number;
applyMutations(node: Node): void,
applyMutations(node: Node): void;
caption(node: Node): string;
showNode(node: Node, width: number, height: number): boolean;
showChildren(node: Node, width: number, height: number): boolean;
Expand Down
Loading