Skip to content

Commit a24fd12

Browse files
committed
added json tree user friendly visualization
1 parent 5d6044d commit a24fd12

15 files changed

+764
-592
lines changed

README.md

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# Angular JSON Tree
1+
# Angular User Friendly JSON Tree
22

3-
This plugin was created to address a common development issue: how to easily visualize JSON/JS Object trees. From a development standpoint, when querying API endpoints and wishing to easily visualize the response object—or from a design standpoint, when looking for an easy way to display a complex object—this plugin provides an easy to use directive for displaying the Object tree response.
3+
This plugin allows an easily way to visualize JSON/JS Object trees, in a user friendly manner. From a development standpoint, when querying API endpoints and wishing to easily visualize the response object—or when looking for an easy way to display a complex object— this plugin provides an easy to use directive for displaying, in a user friendly way, the Object tree response.
44

55
This is nice and easy because all you should have to do is include the directive in your app, and then pass a reference to the directive of which object on the scope you want it to display.
66

77
A live implementation of this directive can be found at [http://blog.alexwendland.com/angular-json-tree/](http://blog.alexwendland.com/angular-json-tree/) and the source for that project can be found on the [gh-pages branch](https://github.com/awendland/angular-json-tree/tree/gh-pages).
88

99
**Requirements:** AngularJS 1.2+
1010

11-
**File Size:** v1.0.1
11+
**File Size:** v2.0.0
1212

13-
* **JS**: 8.3Kb raw, 2.3Kb minified, 982b gzipped
14-
* **JS + CSS**: 9.6Kb raw, 3.3Kb minified, 1.42Kb gzipped
13+
* **JS**: 9Kb raw, 3Kb minified, 953b gzipped
14+
* **JS + CSS**: 11Kb raw, 4.3Kb minified, 1.489b gzipped
1515

1616
## Usage:
1717

18-
1. Include `angular-json-tree` as a dependency for your app
18+
1. Include `user-friendly-angular-json-tree` as a dependency for your app
1919
```javascript
20-
angular.module('myApp', ['angular-json-tree'])
20+
angular.module('myApp', ['user-friendly-angular-json-tree'])
2121
```
2222
2. Include the supplied CSS file (or create your own).
23-
3. Setup the directive and reference an object on your scope
23+
3. Setup the directive and reference a json tree and options objects on your scope
2424

2525
JavaScript:
2626

@@ -30,106 +30,131 @@ $scope.someobj = {
3030
parent: {
3131
child: "name",
3232
age: 42
33-
}
33+
},
34+
someDateInMs: 1505296820331,
35+
emptyField: ''
36+
};
37+
38+
$scope.someOptions = {
39+
toggleBranchText: 'click to expand',
40+
emptyValueText: 'none',
41+
dateFormat: 'yyyy-MM-dd HH:mm:ss'
3442
};
3543
```
3644

3745
HTML:
3846

3947
```html
40-
<json-tree object="someobj"></json-tree>
48+
<user-friendly-json-tree object="someobj"></user-friendly-json-tree>
4149
```
4250

4351
### via bower:
4452
```
45-
$ bower install angular-json-tree
53+
$ bower install user-friendly-angular-json-tree
4654
```
4755

4856
## Why I created this:
4957

50-
I was searching for a way to easily display the JSON results from an API endpoint. The objects were dynamic and followed no uniform pattern. Thus I created this AngularJS directive. Given the above input (from Usage), it would produce an expandable object similar to:
58+
I was searching for a way to easily display the JSON results from an API endpoint, in a user friendly way. The objects were dynamic and followed no uniform pattern. Thus I created this AngularJS directive. Given the above input (from Usage), it would produce an expandable object similar to:
5159

5260
![Example Output](readme/example_output.png)
5361

54-
This directive helps me with another problem while developing: visualizing JSON objects. Being able to break down JSON objects piece by piece has proven invaluably useful. To simplify that process, I threw together this website: [http://blog.alexwendland.com/angular-json-tree/](http://blog.alexwendland.com/angular-json-tree/).
62+
This directive helps me with another problem while developing: visualizing JSON objects in a user friendly way. Being able to break down JSON objects piece by piece has proven invaluably useful. To simplify that process, I threw together this website: [http://blog.alexwendland.com/angular-json-tree/](http://blog.alexwendland.com/angular-json-tree/).
5563

5664
## Directive Configuration:
5765
These attributes are available for configuration on the directive:
5866

67+
5968
### object [required]
6069

6170
The object property takes the name of an object on the $scope. This object will be displayed as an expandable tree.
6271

6372
```html
64-
<json-tree object="someobj"></json-tree>
73+
<user-friendly-json-tree object="someobj"></user-friendly-json-tree>
74+
```
75+
76+
### options
77+
78+
The object property takes the name of an options object on the $scope. This object allows the following customizations:
79+
* expandable nodes (branches) label text (`toggleBranchText` option). Default value is "click to expand"
80+
* date format for leaf fields values of type `Date` (`dateFormat` option). The directive considers a leaf node to be of type `Date`, if the node's name ends with the word "Date" and its value is a date in milliseconds. The Default value of this options is the ISO 8601 format "yyyy-MM-dd HH:mm:ss"
81+
* a user friendly text to represent empty values of nodes (`emptyValueText` option). Default value is "none"
82+
83+
84+
```html
85+
<user-friendly-json-tree object="someobj" options="someOptions"></user-friendly-json-tree>
6586
```
6687

6788
### start-expanded [optional, default=false]
6889

6990
This is an optional attribute that designates if the tree's root should display as expanded initially. This is useful when you are only showing one json-tree, but would probably be set to false if json-trees were being created with an ng-repeat loop.
7091

7192
```html
72-
<json-tree object="someobj" start-expanded="true"></json-tree>
93+
<user-friendly-json-tree object="someobj" start-expanded="true"></user-friendly-json-tree>
7394
```
7495

7596
### root-name [optional, default='Object']
7697

7798
This is an optional attribute that sets the title displayed at the root node. This is useful when you are showing sub-portions of an object or want the object root node to have a different string than 'Object'.
7899

79100
```html
80-
<json-tree object="someobj" root-name="'Name'"></json-tree>
101+
<user-friendly-json-tree object="someobj" root-name="'Name'"></user-friendly-json-tree>
81102
```
82103

83104
## Styling
84105

85106
The default CSS is separated into two parts: structure and looks. The looks section can be easily modified in order to change font, color and toggle buttons. The structure section can also be modified, but some more care will be needed because it provides the framework from which this directive provides functionality. The looks framework will be covered here while the structure framework will only be touched on.
86107

87-
The json-tree is based on recursive nodes of two basic structures. The first structure is for nodes that have no subnodes themselves (a leaf), and the other is for nodes that have children (a branch). Here the simplified template structures for each, with appropriate, style-able, class names.
108+
The user-friendly-json-tree is based on recursive nodes of two basic structures. The first structure is for nodes that have no subnodes themselves (a leaf), and the other is for nodes that have children (a branch). Here the simplified template structures for each, with appropriate, style-able, class names.
88109

89110
### Leaf Nodes
90111

91112
```html
92-
<json-node class="not-expandable">
113+
<user-friendly-json-node class="not-expandable">
93114
<span class="key">{{key}}</span>
94115
<span class="leaf-value">{{value}}</span>
95-
</json-node>
116+
</user-friendly-json-node>
96117
```
97-
In the default CSS, all `.key` elements have the same style, a bold red color. There is some padding, and then the property's value follows. By default, no special styling is applied to `.lead-value` elements.
118+
In the default CSS, all `.key` elements have the same style, a bold blue color. There is some padding, and then the property's value follows. By default, no special styling is applied to `.lead-value` elements.
98119

99120
### Branch Nodes
100121

101122
Branch nodes have two states: expanded or not-expanded. The not-expanded state is very similar to the leaf nodes and simply exchanges the `.leaf-value` class for `.branch-preview`.
102123

103124
```html
104-
<json-node class="not-expandable">
125+
<user-friendly-json-node class="not-expandable">
105126
<span class="key">{{key}}</span>
106127
<span class="branch-preview">{{value}}</span>
107-
</json-node>
128+
</user-friendly-json-node>
108129
```
109130
In the default CSS, `.branch-preview` elements are italicized, concatenated, hidden overflow, and reduced in opacity.
110131

111132
The expanded state is different and contains further subnodes that are generated with ng-repeat:
112133

113134
```html
114-
<json-node class="expandable">
135+
<user-friendly-json-node class="expandable">
115136
<span class="key">{{key}}</span>
116137
<ul class="branch-value">
117138
<li ng-repeat>
118-
<json-node>{{subnode values}}</json-node>
139+
<user-friendly-json-node>{{subnode values}}</user-friendly-json-node>
119140
</li>
120141
</ul>
121-
</json-node>
142+
</user-friendly-json-node>
122143
```
123-
The `.expandable` class adds several features to the normal `json-node` element. Particularly, by the default looks CSS, a carrot-style toggle pseudo-element will be created. This `::before` element will rotate 90 deg downward when the element is expanded.
144+
The `.expandable` class adds several features to the normal `user-friendly-json-node` element. Particularly, by the default looks CSS, a carrot-style toggle pseudo-element will be created. This `::before` element will rotate 90 deg downward when the element is expanded.
124145

125-
Additionally, `json-node` elements receive a class corresponding to their object type. For example, the `.array` class or `.object` may be placed on a `json-node`. These classes can be used for special stylings.
146+
Additionally, `user-friendly-json-node` elements receive a class corresponding to their object type. For example, the `.array` class or `.object` may be placed on a `user-friendly-json-node`. These classes can be used for special stylings.
126147

127148
## Further Explanation:
128149

129150
An example implementation of this project can be found at the [gh-pages branch](https://github.com/awendland/angular-json-tree/tree/gh-pages) of this repository.
130151

131152
## Changelog
132153

154+
#### v2.0.0
155+
* Changed *npm* and *bower* packages names
156+
* Changed JSON/JS Object tree visualization to be user friendly
157+
133158
#### v1.0.0
134159
* Update *npm* dev dependencies to latest (as of 2016-05-24) and remove unnecessary ones
135160
* Update *angular* dependency to accept all 1.x versions

bower.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
{
2-
"name": "angular-json-tree",
3-
"version": "1.0.1",
4-
"description": "Angular directive for displaying a JSON object in an expandable tree structure",
2+
"name": "angular-user-friendly-json-tree",
3+
"version": "1.0.0",
4+
"description": "Angular directive for displaying, in a user friendly way, a JSON object in an expandable tree structure",
55
"main": [
6-
"dist/angular-json-tree.js",
7-
"dist/angular-json-tree.css"
6+
"dist/user-friendly-angular-json-tree.js",
7+
"dist/user-friendly-angular-json-tree.css"
88
],
99
"authors": [
10-
"Alex Wendland <me@alexwendland.com>"
10+
"Alex Wendland <me@alexwendland.com>",
11+
"Pedro Milheiro <pmarques123@gmail.com>"
1112
],
1213
"license": "CC-BY-4.0",
1314
"keywords": [
1415
"angular",
1516
"json"
1617
],
17-
"homepage": "https://github.com/awendland/angular-json-tree",
18+
"homepage": "https://github.com/deeDude/angular-json-tree",
1819
"ignore": [
1920
"**/.*",
2021
"node_modules",

dist/angular-json-tree.css

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)