Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A tree visualisation library for p5.js

License

NotificationsYou must be signed in to change notification settings

Schnurber/treevis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

p5.treevis

With this library, one can create and customize atreemap or asunburst visualisation from any json object tree.

The json object tree should be an object with the following structure:

<Node>::= {   <Name> :string,   <Value> :number,   <Children> : [ <Node>, ... ]}

For leaf nodes, <Children> is optional. For parent nodes, <Name> and <Value> are optional.

Example:

{"children":[      {"name":"a","size":1      },      {"children":[            {"name":"b","size":2            },            {"name":"c","size":3            }         ]      }   ]}

The property names <Name>, <Value> and <Children> must be specified in a parameter-object (see example code below).

If you want, you can generate a json file containing a json tree out from any folder at your disk. Just scan it with my python script (usescandir.py in the scanner folder)

Following command scans project directory ../ and write into file

python scandir.py ../> ../examples/data/test.json

Live examples

Installation

Just include the scripts.

<scriptsrc="addons/p5.dom.min.js"></script><scriptsrc="addons/p5.treevis.js"></script>

Basic usage

This is a complete example for displaying and drawing with interactionPlease look in the source code of examples to see how to customize.Or look in the well documented source files in the src folder.

vartreevis,data;functionpreload(){// Loads json treedata=loadJSON("data/example_scan.json");}functionsetup(){createCanvas(800,600);// Description of json properties// 'children' is an array with child objects// 'name' is identifier// 'size' is content valuevarproperties={children:"children",label:"name",value:"size"};// creates a new Sunburst objecttreevis=createSunburst(data,properties);//callback functiontreevis.onSelected((v,name)=>console.log("Selected: "+name));}functiondraw(){background(255);// draws sunbursttreevis.draw();}functionmouseClicked(){if(mouseButton==RIGHT){// navigate outtreevis.up();}else{// navigate intreevis.select(mouseX,mouseY);}}

p5.treevis documentation

createTreemap()

treemap = createTreemap(json_data, props)

Creates a new treemap visualisation

Rounds corners

treemap.setCorner(5);

Makes inset

treemap.setInset(5);

createSunburst()

sunburst = createSunburst(json_data, props)

Creates a new sunburst visualisation

Sets a different angle and draws a full circle

sunburst.setAngle(90,360);

Sets text invisible

sunburst.setTextVisible(false);

This works on both treemaps and sundbursts:

Callback function

treevis.onSelected((v,name)=>console.log("Selected: "+name));

Sets size and position

treevis.setBounds(100,100,400,400);

Customize fill

treevis.onFill((level,maxLevel)=>fill(color(237,(255-level/maxLevel*255)*2/3,255)));

Navigates in when mouse is pressed

functionmousePressed(){treevis.select(mouseX,mouseY);}

Navigates out when mouse is pressed

functionmouseClicked(){treevis.up(mouseX,mouseY);}

Navigates up without test if pressed mouse position is inside visualisation

treevis.up();

Custom function for building label out of name property

treevis.onGetLabel(name=>name.substring(name.lastIndexOf("-")+1));

Interaction off, no navigation in or out

treevis.setInteraction(false);

Custom font size

treevis.setTextStyle(14);

Custom font size and type

treevis.setTextStyle(14,'Times');

[8]ページ先頭

©2009-2026 Movatter.jp